Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

n-api: enable napi_wrap() to work with any object #269

Closed
wants to merge 3 commits into from

Conversation

jasongin
Copy link
Member

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).

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
Affected core subsystem(s)

n-api

Copy link
Contributor

@boingoing boingoing left a 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).
@jasongin
Copy link
Member Author

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.

@jasongin jasongin requested a review from kfarnung June 1, 2017 22:53
bool hasExternalData = false;
do {
CHECK_JSRT(JsGetPrototype(wrapper, &wrapper));
if (wrapper == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: JS_INVALID_REFERENCE

Copy link
Contributor

@kfarnung kfarnung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jasongin
Copy link
Member Author

jasongin commented Jun 2, 2017

CI: https://ci.nodejs.org/job/chakracore-test/84/
The addons-napi tests all passed. I don't know exactly what other failures are expected in the CI for Node-ChakraCore.

@kfarnung
Copy link
Contributor

kfarnung commented Jun 2, 2017

Looks like the CI failures were all related to processes launched by skipped tests not getting cleaned up. You should be good to go.

jasongin added a commit that referenced this pull request Jun 2, 2017
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]>
@jasongin
Copy link
Member Author

jasongin commented Jun 2, 2017

Landed as 9cc4824

@jasongin jasongin closed this Jun 2, 2017
kfarnung pushed a commit to kfarnung/node-chakracore that referenced this pull request Jun 5, 2017
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]>
kfarnung pushed a commit to kfarnung/node-chakracore that referenced this pull request Jun 5, 2017
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]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants