You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello everyone, just a question regarding the expected behavior of TypeError(napi_env env, napi_value value). According to the docs, it initializes a Napi::TypeError C++ instance from an existing error object, where value is a Napi::Error.
The first problem is that we do not have a cast operator overload that converts a Napi::Error object to a napi_value , so we can't call this ctor with a Napi::Error object directly.
Second of all, my assumption was this ctor accepts an error object and creates a JS TypeError in V8 and a C++ stack object. However, it looks like we simply call the Error ctor with the napi_value. For example, If we give the ctor a napi_value passed from JS, where the napi_value is a RangeError, the resulting Napi::TypedError, when ThrowAsJavaScript, will yield an RangeError still.
So my question is, what is the correct interpretation of this particular API, and what should we do to tweak the implementation to comply with that spec? Thank you!
the purpose of which is to wrap a value coming in from C. You can wrap any JS value using any of our classes, without validation.
In the next major version, we may wanna
add a ::Wrap(napi_env env, napi_value value) static method to these classes, which performs validation, rejecting, for each class, a napi_value that does not have the corresponding JS type, and
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.
Activity
gabrielschulhof commentedon Mar 22, 2023
I think this is a general problem with all our constructors of the form
JSValueType::JSValueType(napi_env env, napi_value value): JSValueSuperClass(env, value) {}the purpose of which is to wrap a value coming in from C. You can wrap any JS value using any of our classes, without validation.
In the next major version, we may wanna
::Wrap(napi_env env, napi_value value)static method to these classes, which performs validation, rejecting, for each class, anapi_valuethat does not have the corresponding JS type, andgithub-actions commentedon Jun 21, 2023
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.