Skip to content

Exotic object function call - JSInterop#65556

Open
OrthFelix wants to merge 1 commit intodotnet:mainfrom
OrthFelix:exotic-objects-call
Open

Exotic object function call - JSInterop#65556
OrthFelix wants to merge 1 commit intodotnet:mainfrom
OrthFelix:exotic-objects-call

Conversation

@OrthFelix
Copy link

@OrthFelix OrthFelix commented Feb 27, 2026

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]])

For example postMessage on WindowProxy
Copilot AI review requested due to automatic review settings February 27, 2026 18:52
@OrthFelix OrthFelix requested a review from a team as a code owner February 27, 2026 18:52
@github-actions github-actions bot added the area-blazor Includes: Blazor, Razor Components label Feb 27, 2026
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 27, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 wrapJSCallAsFunction to use typeof operator instead of instanceof for detecting callable objects

Comment on lines +619 to 622
if (typeof func === 'function') {
return func.bind(parent);
} else {
throw new Error(`The value '${identifier}' is not a function.`);
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants