Zaphod
Zaphod copied to clipboard
`instanceof` doesn't handle objects/classes from the host interpreter correctly.
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.
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.