Taritsyn/JavaScriptEngineSwitcher

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

tomasdeml opened this issue · 3 comments

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

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.

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();
}

Hello, Tomáš!

This error is fixed in version 3.0.7.