Exotic object function call - JSInterop#65556
Conversation
For example postMessage on WindowProxy
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where calling functions on exotic JavaScript objects (such as WindowProxy's postMessage) throws a "not a function" exception. The fix changes the callable check from instanceof Function to typeof func === 'function', which properly detects objects with the [[Call]] internal method according to ECMAScript specifications.
Changes:
- Updated callable check in
wrapJSCallAsFunctionto usetypeofoperator instead ofinstanceoffor detecting callable objects
| if (typeof func === 'function') { | ||
| return func.bind(parent); | ||
| } else { | ||
| throw new Error(`The value '${identifier}' is not a function.`); |
There was a problem hiding this comment.
Consider adding a test case that verifies function calls work correctly with exotic objects (such as WindowProxy methods like postMessage). This would ensure the fix for exotic objects is properly validated and prevent regression. A test could create a Proxy with a callable handler or use a built-in exotic object to verify the typeof check works correctly where instanceof would fail.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
Exotic object function call
Allow calling functions on exotic objects
Description
Calling functions on exotic js objects leads to an exception, that the member is not a function. Example: postMessage of WindowProxy.
I fixed the issue by using typeof instead of instanceof.
typeof checks if the object is callable (has [[Call]])