Skip to content

Commit

Permalink
v1.13.1.0 Ensure consistent calling behaviour with v1.12.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ruipin committed Sep 26, 2024
1 parent 740db9e commit a4c48df
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.13.1.0 (2024-09-25)

- Ensure calling behaviour when a method has only listeners is consistent with libWrapper v1.12.15.0 and older.
- Miscellaneous clean-up.

# 1.13.0.1 (2024-09-17)

- No code changes, re-released to clear issue caused by accidentally pushing a broken commit for a few seconds, which was cached in Forge as v1.13.0.0.
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "lib-wrapper",
"title": "libWrapper",
"description": "Library for wrapping core Foundry VTT methods, meant to improve compatibility between packages that wrap the same methods.",
"version": "1.13.0.1",
"version": "1.13.1.0",
"authors": [{
"name": "Rui Pinheiro",
"url": "https://github.com/ruipin"
Expand Down
40 changes: 26 additions & 14 deletions src/lib/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ export class Wrapper {
// Trigger listeners
_this.call_listeners(this, /*is_setter=*/ false, ...args);

// Decide what to call next
if(_this.get_fn_data(false, false).length == 0)
// If the current handler is valid, and there are no non-listner wrappers, we can short-circuit the call
if(handler_id == _this._current_handler_id && !_this.get_fn_data(false, false).length)
return _this.get_wrapped(this, false, wrapped).apply(this, args);
// Decide what to call next
else if(is_static_dispatch)
return _this.get_static_dispatch_chain(this).apply(_this, args);
else
Expand Down Expand Up @@ -493,23 +494,15 @@ export class Wrapper {
// Calling the wrapped method
call_wrapped(state, obj, ...args) {
// Keep track of call state
if(state)
if(state && state !== true)
this._call_wrapper_update_state(state);

// Load necessary state
const is_setter = state?.setter ?? false;
const is_dynamic_dispatch = (!!state);
const is_dynamic_dispatch = (!!state); // state can be both an object and a bool

// If necessary, set this wrapped call as pending
let pend = undefined;
if(!this.is_property) {
this._pending_wrapped_calls_cnt++;

if(is_dynamic_dispatch) {
pend = obj;
this._pending_wrapped_calls.push(pend);
}
}
// Pre hook
const pend = this._pre_call_wrapped(obj, is_dynamic_dispatch);

// Try-catch block to handle normal exception flow
let result = undefined;
Expand All @@ -524,6 +517,25 @@ export class Wrapper {
throw e;
}

// Post hook
return this._post_call_wrapped(result, pend, is_dynamic_dispatch);
}

_pre_call_wrapped(obj, is_dynamic_dispatch) {
// If necessary, set this wrapped call as pending
if(!this.is_property) {
this._pending_wrapped_calls_cnt++;

if(is_dynamic_dispatch) {
this._pending_wrapped_calls.push(obj);
return obj;
}
}
// Otherwise, do nothing
return null;
}

_post_call_wrapped(result, pend, is_dynamic_dispatch) {
// We only need to keep track of pending calls when we're not wrapping a property
if(this.is_property)
return result;
Expand Down

0 comments on commit a4c48df

Please sign in to comment.