@@ -28,6 +28,7 @@ namespace node {
28
28
29
29
using v8::Array;
30
30
using v8::ArrayBuffer;
31
+ using v8::BackingStore;
31
32
using v8::Context;
32
33
using v8::FunctionCallbackInfo;
33
34
using v8::HeapCodeStatistics;
@@ -162,12 +163,22 @@ void Initialize(Local<Object> target,
162
163
const size_t heap_statistics_buffer_byte_length =
163
164
sizeof (*env->heap_statistics_buffer ()) * kHeapStatisticsPropertiesCount ;
164
165
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 ());
165
178
target->Set (env->context (),
166
179
FIXED_ONE_BYTE_STRING (env->isolate (),
167
180
" heapStatisticsArrayBuffer" ),
168
- ArrayBuffer::New (env->isolate (),
169
- env->heap_statistics_buffer (),
170
- heap_statistics_buffer_byte_length)).Check ();
181
+ heap_statistics_ab).Check ();
171
182
172
183
#define V (i, _, name ) \
173
184
target->Set (env->context (), \
@@ -189,12 +200,22 @@ void Initialize(Local<Object> target,
189
200
sizeof (*env->heap_code_statistics_buffer ())
190
201
* kHeapCodeStatisticsPropertiesCount ;
191
202
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 ());
192
215
target->Set (env->context (),
193
216
FIXED_ONE_BYTE_STRING (env->isolate (),
194
217
" heapCodeStatisticsArrayBuffer" ),
195
- ArrayBuffer::New (env->isolate (),
196
- env->heap_code_statistics_buffer (),
197
- heap_code_statistics_buffer_byte_length))
218
+ heap_code_statistics_ab)
198
219
.Check ();
199
220
200
221
#define V (i, _, name ) \
@@ -244,12 +265,22 @@ void Initialize(Local<Object> target,
244
265
kHeapSpaceStatisticsPropertiesCount *
245
266
number_of_heap_spaces;
246
267
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 ());
247
280
target->Set (env->context (),
248
281
FIXED_ONE_BYTE_STRING (env->isolate (),
249
282
" heapSpaceStatisticsArrayBuffer" ),
250
- ArrayBuffer::New (env->isolate (),
251
- env->heap_space_statistics_buffer (),
252
- heap_space_statistics_buffer_byte_length))
283
+ heap_space_statistics_ab)
253
284
.Check ();
254
285
255
286
#define V (i, _, name ) \
0 commit comments