Bug 151120 - [ES6] Implement Symbol.hasInstance.
Summary: [ES6] Implement Symbol.hasInstance.
Status: RESOLVED DUPLICATE of bug 151839
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Keith Miller
Depends on:
Reported: 2015-11-10 16:12 PST by Keith Miller
Modified: 2016-06-06 20:53 PDT (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Keith Miller 2015-11-10 16:12:39 PST
ES6 enables users to override the instanceof expression by setting the Symbol.hasInstance property of the constructor to a function that takes the object and returns a boolean. As an example:

function Constructor() {}
var obj = new Constructor();

Constructor[Symbol.hasInstance] = function(inst) { return obj !== inst; };

return obj instanceof Constructor;

will return false. Previously, if someone wanted to override the default hasInstance we would store the a bit on the TypeInfo of the object that would specify if the constructor had a custom instanceof function. Then, when emitting bytecodes for a instanceof expression we would check the value of the bit flag and call custom C code implementing expression if the bit was set. The proposed solution, which hopefully should not break backwards compatibility, is to remove the custom instanceof bit from the TypeInfo and instead use a GetById to fetch the value of Symbol.hasInstance and call it if it's not undefined. Then for any API users that set a custom hasInstance function we wrap that function and store it on the their constructor's callback object as the Symbol.hasInstance property.
Comment 1 Joseph Pecoraro 2016-06-06 20:53:33 PDT
Fixed by your change:

[ES6] Add support for Symbol.hasInstance

*** This bug has been marked as a duplicate of bug 151839 ***