Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThang Tran <trankimthang279@gmail.com>2019-12-04 01:22:08 +0300
committerAnna Henningsen <anna@addaleax.net>2019-12-12 18:05:44 +0300
commit4f523c2c1a1c4cef33a1f925cb9102d5b8a51dab (patch)
treebe295cff8198607f79a2b555cb3ad940b847fa82 /src/node_v8.cc
parent2dff8ddafb3cd8ca6555d9e3731a1541c6a1bb2f (diff)
src: migrate to new V8 ArrayBuffer API
ArrayBuffer without BackingStore will soon be deprecated. Fixes:https://github.com/nodejs/node/issues/30529 PR-URL: https://github.com/nodejs/node/pull/30782 Fixes: https://github.com/nodejs/node/issues/30529 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/node_v8.cc')
-rw-r--r--src/node_v8.cc49
1 files changed, 40 insertions, 9 deletions
diff --git a/src/node_v8.cc b/src/node_v8.cc
index ed2e71de106..1f4ef0e35f5 100644
--- a/src/node_v8.cc
+++ b/src/node_v8.cc
@@ -28,6 +28,7 @@ namespace node {
using v8::Array;
using v8::ArrayBuffer;
+using v8::BackingStore;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::HeapCodeStatistics;
@@ -162,12 +163,22 @@ void Initialize(Local<Object> target,
const size_t heap_statistics_buffer_byte_length =
sizeof(*env->heap_statistics_buffer()) * kHeapStatisticsPropertiesCount;
+ std::unique_ptr<BackingStore> heap_statistics_backing =
+ ArrayBuffer::NewBackingStore(env->heap_statistics_buffer(),
+ heap_statistics_buffer_byte_length,
+ [](void*, size_t, void*){},
+ nullptr);
+ Local<ArrayBuffer> heap_statistics_ab =
+ ArrayBuffer::New(env->isolate(),
+ std::move(heap_statistics_backing));
+ // TODO(thangktran): drop this check when V8 is pumped to 8.0 .
+ if (!heap_statistics_ab->IsExternal())
+ heap_statistics_ab->Externalize(
+ heap_statistics_ab->GetBackingStore());
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(),
"heapStatisticsArrayBuffer"),
- ArrayBuffer::New(env->isolate(),
- env->heap_statistics_buffer(),
- heap_statistics_buffer_byte_length)).Check();
+ heap_statistics_ab).Check();
#define V(i, _, name) \
target->Set(env->context(), \
@@ -189,12 +200,22 @@ void Initialize(Local<Object> target,
sizeof(*env->heap_code_statistics_buffer())
* kHeapCodeStatisticsPropertiesCount;
+ std::unique_ptr<BackingStore> heap_code_statistics_backing =
+ ArrayBuffer::NewBackingStore(env->heap_code_statistics_buffer(),
+ heap_code_statistics_buffer_byte_length,
+ [](void*, size_t, void*){},
+ nullptr);
+ Local<ArrayBuffer> heap_code_statistics_ab =
+ ArrayBuffer::New(env->isolate(),
+ std::move(heap_code_statistics_backing));
+ // TODO(thangktran): drop this check when V8 is pumped to 8.0 .
+ if (!heap_code_statistics_ab->IsExternal())
+ heap_code_statistics_ab->Externalize(
+ heap_code_statistics_ab->GetBackingStore());
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(),
"heapCodeStatisticsArrayBuffer"),
- ArrayBuffer::New(env->isolate(),
- env->heap_code_statistics_buffer(),
- heap_code_statistics_buffer_byte_length))
+ heap_code_statistics_ab)
.Check();
#define V(i, _, name) \
@@ -244,12 +265,22 @@ void Initialize(Local<Object> target,
kHeapSpaceStatisticsPropertiesCount *
number_of_heap_spaces;
+ std::unique_ptr<BackingStore> heap_space_statistics_backing =
+ ArrayBuffer::NewBackingStore(env->heap_space_statistics_buffer(),
+ heap_space_statistics_buffer_byte_length,
+ [](void*, size_t, void*){},
+ nullptr);
+ Local<ArrayBuffer> heap_space_statistics_ab =
+ ArrayBuffer::New(env->isolate(),
+ std::move(heap_space_statistics_backing));
+ // TODO(thangktran): drop this check when V8 is pumped to 8.0 .
+ if (!heap_space_statistics_ab->IsExternal())
+ heap_space_statistics_ab->Externalize(
+ heap_space_statistics_ab->GetBackingStore());
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(),
"heapSpaceStatisticsArrayBuffer"),
- ArrayBuffer::New(env->isolate(),
- env->heap_space_statistics_buffer(),
- heap_space_statistics_buffer_byte_length))
+ heap_space_statistics_ab)
.Check();
#define V(i, _, name) \