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_wrap only allow one wrapper to one object #266

Closed
sampsongao opened this issue Jul 24, 2017 · 1 comment
Closed

napi_wrap only allow one wrapper to one object #266

sampsongao opened this issue Jul 24, 2017 · 1 comment

Comments

@sampsongao
Copy link
Collaborator

I was updating the node-sass code to the current napi and I found an issue with napi_wrap check. So in napi_wrap, if we see the object is a wrapper, we return napi_invalid_arg. However, in node-sass, we do something like this:

template <class T>
napi_value SassValueWrapper<T>::get_js_object(napi_env env) {
  if (this->js_object == nullptr) {
  napi_value wrapper;
  napi_value ctor = T::get_constructor(env);
  CHECK_NAPI_RESULT(napi_new_instance(env, ctor, 0, nullptr, &wrapper));
  void* wrapped;
  CHECK_NAPI_RESULT(napi_unwrap(env, wrapper, &wrapped));
  delete static_cast<T*>(wrapped);
  CHECK_NAPI_RESULT(napi_wrap(env, wrapper, this, nullptr, nullptr, nullptr)); -----------> check failed
  CHECK_NAPI_RESULT(napi_create_reference(env, wrapper, 1, &this->js_object));
}
@mhdawson
Copy link
Member

mhdawson commented Jul 24, 2017

My first thought is that we should add a

napi_remove_wrap(napi_env env, napi_value wrapper);

This would cover the case where you want to associate new object to a wrapper (which we know is needed by node-sass) and the case where you just want to remove the wrapping from an object.

The other option is simply to remove the existing check and allow the second wrap to just succeed. I'm thinking its better to be sure it was the intention of the developer by having them use napi_remove_wrap.

@nodejs/addon-api what are your thoughts.

gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this issue Aug 17, 2017
Calling napi_wrap() twice on the same object has the result of returning
napi_invalid_arg on the second call. However, sometimes it is necessary
to replace the native pointer associated with a given object. This new
API allows one to remove an existing pointer, returning the object to
its pristine, non-wrapped state.

Fixes: nodejs/abi-stable-node#266
addaleax pushed a commit to addaleax/ayo that referenced this issue Aug 25, 2017
Calling napi_wrap() twice on the same object has the result of returning
napi_invalid_arg on the second call. However, sometimes it is necessary
to replace the native pointer associated with a given object. This new
API allows one to remove an existing pointer, returning the object to
its pristine, non-wrapped state.

PR-URL: nodejs/node#14658
Reviewed-By: Michael Dawson <[email protected]>
Fixes: nodejs/abi-stable-node#266
addaleax pushed a commit to ayojs/ayo that referenced this issue Aug 28, 2017
Calling napi_wrap() twice on the same object has the result of returning
napi_invalid_arg on the second call. However, sometimes it is necessary
to replace the native pointer associated with a given object. This new
API allows one to remove an existing pointer, returning the object to
its pristine, non-wrapped state.

PR-URL: nodejs/node#14658
Reviewed-By: Michael Dawson <[email protected]>
Fixes: nodejs/abi-stable-node#266
MylesBorins pushed a commit to nodejs/node that referenced this issue Sep 10, 2017
Calling napi_wrap() twice on the same object has the result of returning
napi_invalid_arg on the second call. However, sometimes it is necessary
to replace the native pointer associated with a given object. This new
API allows one to remove an existing pointer, returning the object to
its pristine, non-wrapped state.

PR-URL: #14658
Reviewed-By: Michael Dawson <[email protected]>
Fixes: nodejs/abi-stable-node#266
MylesBorins pushed a commit to nodejs/node that referenced this issue Sep 12, 2017
Calling napi_wrap() twice on the same object has the result of returning
napi_invalid_arg on the second call. However, sometimes it is necessary
to replace the native pointer associated with a given object. This new
API allows one to remove an existing pointer, returning the object to
its pristine, non-wrapped state.

PR-URL: #14658
Reviewed-By: Michael Dawson <[email protected]>
Fixes: nodejs/abi-stable-node#266
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this issue Apr 10, 2018
Calling napi_wrap() twice on the same object has the result of returning
napi_invalid_arg on the second call. However, sometimes it is necessary
to replace the native pointer associated with a given object. This new
API allows one to remove an existing pointer, returning the object to
its pristine, non-wrapped state.

PR-URL: nodejs#14658
Reviewed-By: Michael Dawson <[email protected]>
Fixes: nodejs/abi-stable-node#266
MylesBorins pushed a commit to nodejs/node that referenced this issue Apr 16, 2018
Calling napi_wrap() twice on the same object has the result of returning
napi_invalid_arg on the second call. However, sometimes it is necessary
to replace the native pointer associated with a given object. This new
API allows one to remove an existing pointer, returning the object to
its pristine, non-wrapped state.

Backport-PR-URL: #19447
PR-URL: #14658
Reviewed-By: Michael Dawson <[email protected]>
Fixes: nodejs/abi-stable-node#266
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants