Zaphod icon indicating copy to clipboard operation
Zaphod copied to clipboard

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

Open beala opened this issue 12 years ago • 1 comments

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 avatar Feb 02 '13 21:02 beala

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.

beala avatar Feb 03 '13 20:02 beala