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

n-api: avoid crash in napi_escape_scope() #13651

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,19 @@ class HandleScopeWrapper {
class EscapableHandleScopeWrapper {
public:
explicit EscapableHandleScopeWrapper(v8::Isolate* isolate) :
scope(isolate), escapeCalled(false) {}
bool escapeAllreadyCalled(void) {
return escapeCalled;
scope(isolate), _escapeCalled(false) {}
bool escapeAlreadyCalled(void) {
return _escapeCalled;
}
Copy link
Member

Choose a reason for hiding this comment

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

Style issues: method should be bool escape_called() const {, the data member should be escape_called_.

template <typename T>
v8::Local<T> Escape(v8::Local<T> handle) {
escapeCalled = true;
_escapeCalled = true;
return scope.Escape(handle);
}

private:
v8::EscapableHandleScope scope;
bool escapeCalled;
bool _escapeCalled;
Copy link
Member

Choose a reason for hiding this comment

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

just an extremely minor nit... in various places in core we use _ as a suffix on private fields, in others we seem to use it as a prefix. It would be great to have consistency there.

};

napi_handle_scope JsHandleScopeFromV8HandleScope(HandleScopeWrapper* s) {
Expand Down Expand Up @@ -2218,7 +2218,7 @@ napi_status napi_escape_handle(napi_env env,

v8impl::EscapableHandleScopeWrapper* s =
v8impl::V8EscapableHandleScopeFromJsEscapableHandleScope(scope);
if (!s->escapeAllreadyCalled()) {
if (!s->escapeAlreadyCalled()) {
*result = v8impl::JsValueFromV8LocalValue(
s->Escape(v8impl::V8LocalValueFromJsValue(escapee)));
return napi_clear_last_error(env);
Expand Down