Skip to content
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

[napi] properly initialize and check status (#12279) #12283

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2162,7 +2162,7 @@ napi_status napi_instanceof(napi_env env,

if (env->has_instance_available) {
napi_value value, js_result, has_instance = nullptr;
napi_status status;
napi_status status = napi_generic_failure;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why initiate with failure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because then everything will come tumbling down if you compare the value without setting it first - on every platform, all the time.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean why not napi_ok (which is 0)?

napi_valuetype value_type;

// Get "Symbol" from the global object
Expand All @@ -2185,14 +2185,12 @@ napi_status napi_instanceof(napi_env env,
if (value_type == napi_symbol) {
env->has_instance.Reset(env->isolate,
v8impl::V8LocalValueFromJsValue(value));
if (status != napi_ok) return status;
has_instance = value;
}
}
} else {
has_instance = v8impl::JsValueFromV8LocalValue(
v8::Local<v8::Value>::New(env->isolate, env->has_instance));
if (status != napi_ok) return status;
}

if (has_instance) {
Expand Down