Skip to content

Commit

Permalink
src: remove usages of GetBackingStore in node-api
Browse files Browse the repository at this point in the history
This removes all usages of GetBackingStore in `node-api`. See the linked
issue for an explanation.

Refs: #32226
Refs: #43921
PR-URL: #44075
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
kvakil authored and ruyadorno committed Aug 22, 2022
1 parent cddf3ed commit 8e1b7e2
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2780,7 +2780,7 @@ napi_status NAPI_CDECL napi_create_arraybuffer(napi_env env,
// Optionally return a pointer to the buffer's data, to avoid another call to
// retrieve it.
if (data != nullptr) {
*data = buffer->GetBackingStore()->Data();
*data = buffer->Data();
}

*result = v8impl::JsValueFromV8LocalValue(buffer);
Expand Down Expand Up @@ -2814,15 +2814,14 @@ napi_status NAPI_CDECL napi_get_arraybuffer_info(napi_env env,
v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(arraybuffer);
RETURN_STATUS_IF_FALSE(env, value->IsArrayBuffer(), napi_invalid_arg);

std::shared_ptr<v8::BackingStore> backing_store =
value.As<v8::ArrayBuffer>()->GetBackingStore();
v8::Local<v8::ArrayBuffer> ab = value.As<v8::ArrayBuffer>();

if (data != nullptr) {
*data = backing_store->Data();
*data = ab->Data();
}

if (byte_length != nullptr) {
*byte_length = backing_store->ByteLength();
*byte_length = ab->ByteLength();
}

return napi_clear_last_error(env);
Expand Down Expand Up @@ -2963,8 +2962,7 @@ napi_status NAPI_CDECL napi_get_typedarray_info(napi_env env,
}

if (data != nullptr) {
*data = static_cast<uint8_t*>(buffer->GetBackingStore()->Data()) +
array->ByteOffset();
*data = static_cast<uint8_t*>(buffer->Data()) + array->ByteOffset();
}

if (arraybuffer != nullptr) {
Expand Down Expand Up @@ -3044,8 +3042,7 @@ napi_status NAPI_CDECL napi_get_dataview_info(napi_env env,
}

if (data != nullptr) {
*data = static_cast<uint8_t*>(buffer->GetBackingStore()->Data()) +
array->ByteOffset();
*data = static_cast<uint8_t*>(buffer->Data()) + array->ByteOffset();
}

if (arraybuffer != nullptr) {
Expand Down Expand Up @@ -3255,8 +3252,8 @@ napi_status NAPI_CDECL napi_is_detached_arraybuffer(napi_env env,

v8::Local<v8::Value> value = v8impl::V8LocalValueFromJsValue(arraybuffer);

*result = value->IsArrayBuffer() &&
value.As<v8::ArrayBuffer>()->GetBackingStore()->Data() == nullptr;
*result =
value->IsArrayBuffer() && value.As<v8::ArrayBuffer>()->Data() == nullptr;

return napi_clear_last_error(env);
}

0 comments on commit 8e1b7e2

Please sign in to comment.