diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-11-08 20:40:46 +0200 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2019-11-12 06:29:23 +0100 |
commit | e66a2acc4cb9fc09fc32d1833b89ae56468a0931 (patch) | |
tree | 2db9ffe469a2c662eda46cef848a17d39b8a3787 /src/js_native_api_v8.cc | |
parent | f8c069f5b88a25304ee2fc638c51464b4df196dd (diff) | |
download | android-node-v8-e66a2acc4cb9fc09fc32d1833b89ae56468a0931.tar.gz android-node-v8-e66a2acc4cb9fc09fc32d1833b89ae56468a0931.tar.bz2 android-node-v8-e66a2acc4cb9fc09fc32d1833b89ae56468a0931.zip |
src: migrate off ArrayBuffer::GetContents
V8 deprecates `GetContents()` in favour of `GetBackingStore()`.
Update our code to reflect that.
V8 also deprecates `Externalize()` and `IsExternal()`; we should
be able to remove all usage of this once V8 8.0 is there.
PR-URL: https://github.com/nodejs/node/pull/30339
Refs: https://github.com/v8/v8/commit/bfe3d6bce734e596e312465e207bcfd55a59fe34
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Diffstat (limited to 'src/js_native_api_v8.cc')
-rw-r--r-- | src/js_native_api_v8.cc | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index 1f5b6c012f..ef1edb92ee 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -2562,7 +2562,7 @@ napi_status 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->GetContents().Data(); + *data = buffer->GetBackingStore()->Data(); } *result = v8impl::JsValueFromV8LocalValue(buffer); @@ -2608,15 +2608,15 @@ napi_status 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); - v8::ArrayBuffer::Contents contents = - value.As<v8::ArrayBuffer>()->GetContents(); + std::shared_ptr<v8::BackingStore> backing_store = + value.As<v8::ArrayBuffer>()->GetBackingStore(); if (data != nullptr) { - *data = contents.Data(); + *data = backing_store->Data(); } if (byte_length != nullptr) { - *byte_length = contents.ByteLength(); + *byte_length = backing_store->ByteLength(); } return napi_clear_last_error(env); @@ -2747,9 +2747,15 @@ napi_status napi_get_typedarray_info(napi_env env, *length = array->Length(); } - v8::Local<v8::ArrayBuffer> buffer = array->Buffer(); + v8::Local<v8::ArrayBuffer> buffer; + if (data != nullptr || arraybuffer != nullptr) { + // Calling Buffer() may have the side effect of allocating the buffer, + // so only do this when it’s needed. + buffer = array->Buffer(); + } + if (data != nullptr) { - *data = static_cast<uint8_t*>(buffer->GetContents().Data()) + + *data = static_cast<uint8_t*>(buffer->GetBackingStore()->Data()) + array->ByteOffset(); } @@ -2821,9 +2827,15 @@ napi_status napi_get_dataview_info(napi_env env, *byte_length = array->ByteLength(); } - v8::Local<v8::ArrayBuffer> buffer = array->Buffer(); + v8::Local<v8::ArrayBuffer> buffer; + if (data != nullptr || arraybuffer != nullptr) { + // Calling Buffer() may have the side effect of allocating the buffer, + // so only do this when it’s needed. + buffer = array->Buffer(); + } + if (data != nullptr) { - *data = static_cast<uint8_t*>(buffer->GetContents().Data()) + + *data = static_cast<uint8_t*>(buffer->GetBackingStore()->Data()) + array->ByteOffset(); } @@ -3015,6 +3027,7 @@ napi_status napi_detach_arraybuffer(napi_env env, napi_value arraybuffer) { env, value->IsArrayBuffer(), napi_arraybuffer_expected); v8::Local<v8::ArrayBuffer> it = value.As<v8::ArrayBuffer>(); + // TODO(addaleax): Remove the first condition once we have V8 8.0. RETURN_STATUS_IF_FALSE( env, it->IsExternal(), napi_detachable_arraybuffer_expected); RETURN_STATUS_IF_FALSE( |