Taritsyn / JavaScriptEngineSwitcher

JavaScript Engine Switcher determines unified interface for access to the basic features of popular JavaScript engines. This library allows you to quickly and easily switch to using of another JavaScript engine.
Apache License 2.0
440 stars 49 forks source link

Embedded delegates are no longer linked with the `Function` prototype. #68

Closed tomasdeml closed 5 years ago

tomasdeml commented 5 years ago

See failing test for ChakraCore in #67. The test was passing in v3.0.1 but now fails (v3.0.5).

Taritsyn commented 5 years ago

Hello, Tomáš!

This error also occurs in the MSIE, V8 and Vroom modules. In ChakraCore and MSIE modules, it is caused by the implementation of garbage collection mechanism for embedded objects (see the source code).

In general, an embedded delegate does not have to be a function, it just has to work as a function. I will certainly see what can be done, but I will not change the existing garbage collection mechanism. In any case, this unit test will not pass in the V8 and Vroom modules.

Taritsyn commented 5 years ago

If you just use this expression to check whether an embedded object is a function:

Object.getPrototypeOf(embeddedFunc) === Function.prototype

It is better to use the following code (does not work only in the MSIE module):

typeof embeddedFunc === 'function'

If you pass an embedded delegate to some library, where this check is performed, you can simply wrap the delegate to function:

function wrappedFunc() {
    return embeddedFunc();
}
Taritsyn commented 5 years ago

Hello, Tomáš!

This error is fixed in version 3.0.7.