-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
n-api: implement wrapping using private properties #18311
n-api: implement wrapping using private properties #18311
Conversation
src/node_api.cc
Outdated
v8::String::NewFromOneByte(isolate, | ||
reinterpret_cast<const uint8_t*>(key), | ||
v8::NewStringType::kInternalized).ToLocalChecked()); | ||
} |
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.
env.h
has some convenience wrappers for accessing private methods (look for PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES
), can we use those?
src/node_api.cc
Outdated
@@ -815,24 +791,38 @@ static | |||
napi_status Unwrap(napi_env env, | |||
napi_value js_object, | |||
void** result, | |||
v8::Local<v8::Object>* wrapper, | |||
v8::Local<v8::Object>* parent = nullptr) { | |||
bool removeWrap) { |
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.
We generally use snake_case
for local variables and parameters
2465f08
to
b6d330e
Compare
@addaleax I have addressed your review comments. |
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
src/node_api.cc
Outdated
@@ -46,6 +47,9 @@ struct napi_env__ { | |||
uv_loop_t* loop = nullptr; | |||
}; | |||
|
|||
#define NAPI_PRIVATE_KEY(isolate, prefix) \ | |||
(node::Environment::GetCurrent((isolate))->napi_ ## prefix()) |
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.
s/prefix/suffix/?
src/node_api.cc
Outdated
reinterpret_cast<const uint8_t*>("N-API Environment"), | ||
v8::NewStringType::kInternalized).ToLocalChecked()); | ||
auto value = global->GetPrivate(context, key).ToLocalChecked(); | ||
auto value = global->GetPrivate(context, NAPI_PRIVATE_KEY(isolate, env)) |
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.
Since you have a reference to the v8::Context
, it would be more efficient to call Environment::GetCurrent(context)
once and then call env->napi_env()
directly.
Applies to a few more spots. I won't point them out individually.
src/node_api.cc
Outdated
@@ -815,24 +782,37 @@ static | |||
napi_status Unwrap(napi_env env, | |||
napi_value js_object, | |||
void** result, | |||
v8::Local<v8::Object>* wrapper, | |||
v8::Local<v8::Object>* parent = nullptr) { | |||
bool remove_wrap) { |
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.
Consider using an enum instead of a bool. More self-descriptive at the call site.
src/node_api.cc
Outdated
} else { | ||
// Create a self-deleting reference. | ||
reference = v8impl::Reference::New(env, obj, 0, true, finalize_cb, | ||
native_object, finalize_cb == nullptr ? nullptr: finalize_hint); |
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.
Space before :
.
src/node_api.cc
Outdated
wrapper->SetInternalField(2, v8::External::New(isolate, reference)); | ||
} | ||
CHECK(obj->SetPrivate(context, NAPI_PRIVATE_KEY(isolate, wrapper), | ||
v8::External::New(isolate, reference)).FromJust()); |
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.
Can you line up the arguments?
b6d330e
to
92488fe
Compare
I re-ran the node-test-commit-arm portion, and it passed: https://ci.nodejs.org/job/node-test-commit-arm/13589/ |
Landed in 1286923. |
Should this be backported to |
@MylesBorins this is part of #19265. |
PR-URL: nodejs#18311 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Fixes: nodejs#14367
PR-URL: nodejs#18311 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Fixes: nodejs#14367
PR-URL: nodejs#18311 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Fixes: nodejs#14367
Fixes: #14367
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
n-api