Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instanceof doesn't handle objects/classes from the host interpreter correctly. #2

Open
beala opened this issue Feb 2, 2013 · 1 comment

Comments

@beala
Copy link
Contributor

beala commented Feb 2, 2013

This returns false, but should return true:

(new ReferenceError()) instanceof ReferenceError

I believe this has something to do with how objects from the host interpreter get wrapped with a Proxy.

@beala
Copy link
Contributor Author

beala commented Feb 3, 2013

I think I've found the problem. The __hasInstance__ method on Function.prototype is defined thusly:

definitions.defineProperty(Fp, "__hasInstance__",
                                   function (v) {
                                       return v instanceof Function || v instanceof global.Function;
                                   }, true, true, true);

Host objects inherit this method. When, for example (new ReferenceError()) instanceof ReferenceError) is called, the __hasInstance__ defined above is called. Since (new ReferenceError()) is not an instanceof Function, false is incorrectly returned.

The fix is to define __hasInstance__ per the spec, as has been done for FunctionObject.prototype. I'll submit a pull request momentarily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant