@@ -28,6 +28,7 @@ namespace node {
2828
2929using v8::Array;
3030using v8::ArrayBuffer;
31+ using v8::BackingStore;
3132using v8::Context;
3233using v8::FunctionCallbackInfo;
3334using v8::HeapCodeStatistics;
@@ -162,12 +163,22 @@ void Initialize(Local<Object> target,
162163 const size_t heap_statistics_buffer_byte_length =
163164 sizeof (*env->heap_statistics_buffer ()) * kHeapStatisticsPropertiesCount ;
164165
166+ std::unique_ptr<BackingStore> heap_statistics_backing =
167+ ArrayBuffer::NewBackingStore (env->heap_statistics_buffer (),
168+ heap_statistics_buffer_byte_length,
169+ [](void *, size_t , void *){},
170+ nullptr );
171+ Local<ArrayBuffer> heap_statistics_ab =
172+ ArrayBuffer::New (env->isolate (),
173+ std::move (heap_statistics_backing));
174+ // TODO(thangktran): drop this check when V8 is pumped to 8.0 .
175+ if (!heap_statistics_ab->IsExternal ())
176+ heap_statistics_ab->Externalize (
177+ heap_statistics_ab->GetBackingStore ());
165178 target->Set (env->context (),
166179 FIXED_ONE_BYTE_STRING (env->isolate (),
167180 " heapStatisticsArrayBuffer" ),
168- ArrayBuffer::New (env->isolate (),
169- env->heap_statistics_buffer (),
170- heap_statistics_buffer_byte_length)).Check ();
181+ heap_statistics_ab).Check ();
171182
172183#define V (i, _, name ) \
173184 target->Set (env->context (), \
@@ -189,12 +200,22 @@ void Initialize(Local<Object> target,
189200 sizeof (*env->heap_code_statistics_buffer ())
190201 * kHeapCodeStatisticsPropertiesCount ;
191202
203+ std::unique_ptr<BackingStore> heap_code_statistics_backing =
204+ ArrayBuffer::NewBackingStore (env->heap_code_statistics_buffer (),
205+ heap_code_statistics_buffer_byte_length,
206+ [](void *, size_t , void *){},
207+ nullptr );
208+ Local<ArrayBuffer> heap_code_statistics_ab =
209+ ArrayBuffer::New (env->isolate (),
210+ std::move (heap_code_statistics_backing));
211+ // TODO(thangktran): drop this check when V8 is pumped to 8.0 .
212+ if (!heap_code_statistics_ab->IsExternal ())
213+ heap_code_statistics_ab->Externalize (
214+ heap_code_statistics_ab->GetBackingStore ());
192215 target->Set (env->context (),
193216 FIXED_ONE_BYTE_STRING (env->isolate (),
194217 " heapCodeStatisticsArrayBuffer" ),
195- ArrayBuffer::New (env->isolate (),
196- env->heap_code_statistics_buffer (),
197- heap_code_statistics_buffer_byte_length))
218+ heap_code_statistics_ab)
198219 .Check ();
199220
200221#define V (i, _, name ) \
@@ -244,12 +265,22 @@ void Initialize(Local<Object> target,
244265 kHeapSpaceStatisticsPropertiesCount *
245266 number_of_heap_spaces;
246267
268+ std::unique_ptr<BackingStore> heap_space_statistics_backing =
269+ ArrayBuffer::NewBackingStore (env->heap_space_statistics_buffer (),
270+ heap_space_statistics_buffer_byte_length,
271+ [](void *, size_t , void *){},
272+ nullptr );
273+ Local<ArrayBuffer> heap_space_statistics_ab =
274+ ArrayBuffer::New (env->isolate (),
275+ std::move (heap_space_statistics_backing));
276+ // TODO(thangktran): drop this check when V8 is pumped to 8.0 .
277+ if (!heap_space_statistics_ab->IsExternal ())
278+ heap_space_statistics_ab->Externalize (
279+ heap_space_statistics_ab->GetBackingStore ());
247280 target->Set (env->context (),
248281 FIXED_ONE_BYTE_STRING (env->isolate (),
249282 " heapSpaceStatisticsArrayBuffer" ),
250- ArrayBuffer::New (env->isolate (),
251- env->heap_space_statistics_buffer (),
252- heap_space_statistics_buffer_byte_length))
283+ heap_space_statistics_ab)
253284 .Check ();
254285
255286#define V (i, _, name ) \
0 commit comments