-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Update JsInstanceOf to use OP_IsInst #5527
Conversation
I'm targeting at release/1.10 in hopes of getting this into node-chakracore, but can retarget to master if necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me. Any concerns about changing behavior of JsInstanceOf
since it's shipping as a Windows API?
lib/Jsrt/Jsrt.cpp
Outdated
@@ -1415,7 +1415,8 @@ CHAKRA_API JsInstanceOf(_In_ JsValueRef object, _In_ JsValueRef constructor, _Ou | |||
VALIDATE_INCOMING_REFERENCE(constructor, scriptContext); | |||
PARAM_NOT_NULL(result); | |||
|
|||
*result = Js::RecyclableObject::FromVar(constructor)->HasInstance(object, scriptContext) ? true : false; | |||
Js::Var booleanValue = Js::JavascriptOperators::OP_IsInst(object, constructor, scriptContext, nullptr); | |||
*result = Js::JavascriptBoolean::FromVar(booleanValue)->GetValue() ? true : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little clunky but alright. You could write this as !!Js::JavascriptBoolean::FromVar(booleanValue)->GetValue()
, though I don't really like this syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to change it, I just lifted this from JsBooleanToBool later in this file.
lib/Jsrt/Jsrt.cpp
Outdated
@@ -1415,7 +1415,8 @@ CHAKRA_API JsInstanceOf(_In_ JsValueRef object, _In_ JsValueRef constructor, _Ou | |||
VALIDATE_INCOMING_REFERENCE(constructor, scriptContext); | |||
PARAM_NOT_NULL(result); | |||
|
|||
*result = Js::RecyclableObject::FromVar(constructor)->HasInstance(object, scriptContext) ? true : false; | |||
Js::Var booleanValue = Js::JavascriptOperators::OP_IsInst(object, constructor, scriptContext, nullptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might not be guaranteed to return a Js::JavascriptBoolean
? It looks like in the case of a callable Symbol.hasInstance
that it will return the result of the function, and it is possible to define a function that doesn't return a Boolean. If I do that from script, then foo instanceof bar
appears to return the truthiness of whatever I return, but I don't see that in the OP_IsInst
codepath
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might need to use JavascriptConversion::ToBoolean
here, and then the next line should be safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah; I misread the code in IsInst
and it does in fact do the conversion there. Disregard!
@boingoing It's a pretty subtle change in behavior and seems like a bug fix rather than a behavioral change. |
@digitalinfinity any objections to this change landing in release/1.10? |
Is JsInstanceOf experimental or part of the Windows API surface? If its the former, no objections. If it's the latter, I'd say this goes into master and can later make a release once the Windows Compat folks have signed off |
It's in |
`OP_IsInst` correctly handles the ES6 `Symbol.hasInstance` property when determining whether an object is an instance of a constructor.
@mrkmarron Is that all I need to change for TTD? |
OP_IsInst
correctly handles the ES6Symbol.hasInstance
propertywhen determining whether an object is an instance of a constructor.