Bug 151120

Summary: [ES6] Implement Symbol.hasInstance.
Product: WebKit Reporter: Keith Miller <keith_miller>
Component: JavaScriptCoreAssignee: Keith Miller <keith_miller>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: joepeck
Priority: P2    
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   

Keith Miller
Reported 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.
Attachments
Joseph Pecoraro
Comment 1 2016-06-06 20:53:33 PDT
Fixed by your change: [ES6] Add support for Symbol.hasInstance https://bugs.webkit.org/show_bug.cgi?id=151839 http://trac.webkit.org/changeset/194248 *** This bug has been marked as a duplicate of bug 151839 ***
Note You need to log in before you can comment on or make changes to this bug.