-
Notifications
You must be signed in to change notification settings - Fork 340
n-api: enable napi_wrap() to work with any object #269
Conversation
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.
LGTM
Change to inserting an external object into the wrapper object's prototype chain, instead of injecting an alternate `this` object in the constructor callback adapter. The latter approach didn't work in certain scenarios because the JSRT runtime still returned the original `this` object. And with this change, the setting and checking of the extension flag, which distinguished wrapper objects from external objects, can be removed. I was never happy with that abuse of the extension flag even when I coded it. Also removing the CallbackInfo.returnValue field which is not used anymore (since we switched to direct return values).
Pushed a commit to address feedback at nodejs/node#13250 (comment), so the Node-ChakraCore implementation stays in sync with Node-V8, and passes the additional test cases I added there. |
src/node_api_jsrt.cc
Outdated
bool hasExternalData = false; | ||
do { | ||
CHECK_JSRT(JsGetPrototype(wrapper, &wrapper)); | ||
if (wrapper == 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.
nit: JS_INVALID_REFERENCE
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.
LGTM
CI: https://ci.nodejs.org/job/chakracore-test/84/ |
Looks like the CI failures were all related to processes launched by skipped tests not getting cleaned up. You should be good to go. |
Change to inserting an external object into the wrapper object's prototype chain, instead of injecting an alternate `this` object in the constructor callback adapter. The latter approach didn't work in certain scenarios because the JSRT runtime still returned the original `this` object. And with this change, the setting and checking of the extension flag, which distinguished wrapper objects from external objects, can be removed. Also removing the CallbackInfo.returnValue field which is not used anymore (since we switched to direct return values). PR-URL: #269 Reviewed-By: Taylor Woll <[email protected]> Reviewed-By: Kyle Farnung <[email protected]>
Landed as 9cc4824 |
Change to inserting an external object into the wrapper object's prototype chain, instead of injecting an alternate `this` object in the constructor callback adapter. The latter approach didn't work in certain scenarios because the JSRT runtime still returned the original `this` object. And with this change, the setting and checking of the extension flag, which distinguished wrapper objects from external objects, can be removed. Also removing the CallbackInfo.returnValue field which is not used anymore (since we switched to direct return values). PR-URL: nodejs#269 Reviewed-By: Taylor Woll <[email protected]> Reviewed-By: Kyle Farnung <[email protected]>
Change to inserting an external object into the wrapper object's prototype chain, instead of injecting an alternate `this` object in the constructor callback adapter. The latter approach didn't work in certain scenarios because the JSRT runtime still returned the original `this` object. And with this change, the setting and checking of the extension flag, which distinguished wrapper objects from external objects, can be removed. Also removing the CallbackInfo.returnValue field which is not used anymore (since we switched to direct return values). PR-URL: nodejs#269 Reviewed-By: Taylor Woll <[email protected]> Reviewed-By: Kyle Farnung <[email protected]>
Change to inserting an external object into the wrapper object's prototype chain, instead of injecting an alternate
this
object in the constructor callback adapter. The latter approach didn't work in certain scenarios because the JSRT runtime still returned the originalthis
object.And with this change, the setting and checking of the extension flag, which distinguished wrapper objects from external objects, can be removed. I was never happy with that abuse of the extension flag even when I coded it.
Also removing the CallbackInfo.returnValue field which is not used anymore (since we switched to direct return values).
See also my PR at nodejs/node#13250, which gives further details and includes a new test case that validates this change. While it's not included in this PR, I have manually run that test to validate this change.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
n-api