-
Notifications
You must be signed in to change notification settings - Fork 465
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
scope: disallow copying scopes to prevent double close of scopes #565
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.
I think that this should prevent runtime error in case of double close. @legendecas Am I right?
Yes, Though I've found that return statuses of napi_close_*_scope have been ignored 🤔 https://github.com/nodejs/node-addon-api/blob/master/napi-inl.h#L3475. Are these behavior expected? |
@legendecas I believe the reason for that is that, if C++ exceptions are turned on, one would be throwing a C++ exception from a destructor which by my understanding is a big no-no. |
Since no exceptions were expected to be thrown in the destructor, I'd think to disallow copying of scopes should be an intuitive approach. What do you think? @gabrielschulhof |
This would be a breaking change. While we've not said that will never happen for node-addon-api, we have chosen to avoid those in all cases before. I think we'd want to have a really good reason to introduce a breaking change and I'm not sure it's going to be worth it in this case. |
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.
Marking as request changes until there is a discussion on whether making a breaking change is what we want to do.
Technically it would depend on platforms and possibly crash on double closing a handle scope -- since in node core So I'd wonder there would hardly be possible any use case in the wild. But yes, it is a breaking change. |
Append: node core has a pre-condition of deleting the |
PPS: still, I could produce the crash with the following snippet: Value doubleCloseScopeNapi(const CallbackInfo& info) {
Env env = info.Env();
HandleScope scope(env);
HandleScope scope2(env);
HandleScope scope3 = scope2;
return env.Undefined();
} Output:
|
Discussed in meeting today:
Consensus is we should we remove them. |
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
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
We did discuss and this should land as a SemVer major even though it should not affect any existing code. |
Landed as 34c11cf |
Early detect and prevent unexpected crashing on closing an already closed handle scope.
npm test
passed