-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Added napi_is_detached_arraybuffer method #30317
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2569,6 +2569,38 @@ napi_status napi_create_arraybuffer(napi_env env, | |||||
return GET_RETURN_STATUS(env); | ||||||
} | ||||||
|
||||||
napi_status napi_is_detached_arraybuffer(napi_env env, | ||||||
napi_value value, | ||||||
napi_value* result) { | ||||||
NAPI_PREAMBLE(env); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need |
||||||
CHECK_ARG(env, result); | ||||||
v8::Isolate* isolate = env->isolate; | ||||||
|
||||||
v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value); | ||||||
|
||||||
if (!val->IsObject()) { | ||||||
napi_throw_type_error(env, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No JavaScript exceptions were expected on N-API checks. See discussion at #29849. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could just remove this check and let the below one handle returning false. |
||||||
"ERR_NAPI_CONS_FUNCTION", | ||||||
"Value must be an Object"); | ||||||
GET_RETURN_STATUS(env); | ||||||
} | ||||||
|
||||||
if (!val->IsArrayBuffer()) { | ||||||
*result = v8impl::JsValueFromV8LocalValue(v8::False(isolate)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall result setting might be doable with less lines. |
||||||
return GET_RETURN_STATUS(env); | ||||||
} | ||||||
|
||||||
v8::Local<v8::ArrayBuffer> buffer = v8::Local<v8::ArrayBuffer>::Cast(val); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(It’s not important, just more common this way in our source tree) |
||||||
|
||||||
if (buffer->GetContents().Data() != nullptr) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this correct? We can create Also, just fyi, |
||||||
*result = v8impl::JsValueFromV8LocalValue(v8::True(isolate)); | ||||||
} else { | ||||||
*result = v8impl::JsValueFromV8LocalValue(v8::False(isolate)); | ||||||
} | ||||||
|
||||||
return GET_RETURN_STATUS(env); | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps IIUC bool is_detached = val->IsArrayBuffer() &&
val.As<v8::ArrayBuffer>()->GetContents().Data() != nullptr;
auto ctor = is_detached ? v8::True : v8::False;
*result = v8impl::JsValueFromV8LocalValue(ctor(isolate));
return GET_RETURN_STATUS(env); Though maybe simple if/else may be better instead of ternary. |
||||||
|
||||||
napi_status napi_create_external_arraybuffer(napi_env env, | ||||||
void* external_data, | ||||||
size_t byte_length, | ||||||
|
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.
This needs to go in the
#ifdef NAPI_EXPERIMENTAL
section to start.