ruipin / fvtt-lib-wrapper

Library for Foundry VTT which provides module developers with a simple way to modify core Foundry VTT code, while reducing the likelihood of conflict with other modules.
GNU Lesser General Public License v3.0
35 stars 15 forks source link

Shim and module code function differently for OVERRIDE type #1

Closed shemetz closed 4 years ago

shemetz commented 4 years ago

In the shim code, functions are called like this:

obj[fn_name] = function() { return fn.call(this, original, ...arguments); };

In the module code they're called like this:

result = fn.call(obj, next_fn, ...args);

except if they're OVERRIDE type, in which case they're called like this:

return fn.apply(obj, args);

This breaks the behavior of shimmed override functions (e.g. in my module, ZoomPanOptions) when the module exists. The next_fn argument is not passed.

shemetz commented 4 years ago

I believe the fix is to add a type argument to the shim register function, and if that type is override, to call fn without the original argument.

ruipin commented 4 years ago

You are completely right, this was an oversight from my end.

Originally, the OVERRIDE type would also receive the next_fn argument. This was changed later on, but by then I had already written the shim, and forgot to change the test-case for it.

3259c85 fixes this, by properly checking the type parameter for OVERRIDE. It also tweaks the test cases to ensure that this situation (OVERRIDE with parameters) is correctly tested.

Thanks for the report, and sorry for any inconvenience!