@@ -1152,13 +1152,33 @@ void SetBufferPrototype(const FunctionCallbackInfo<Value>& args) {
11521152}
11531153
11541154
1155+ void GetZeroFillField (const FunctionCallbackInfo<Value>& args) {
1156+ Environment* env = Environment::GetCurrent (args);
1157+
1158+ // This can be a nullptr when running inside an isolate where we
1159+ // do not own the ArrayBuffer allocator.
1160+ NodeArrayBufferAllocator* allocator = env->isolate_data ()->node_allocator ();
1161+ if (allocator == nullptr ) return ;
1162+
1163+ std::shared_ptr<v8::BackingStore> backing = allocator->zero_fill_field ();
1164+ Local<ArrayBuffer> array_buffer =
1165+ ArrayBuffer::New (env->isolate (), std::move (backing));
1166+ array_buffer->SetPrivate (
1167+ env->context (),
1168+ env->arraybuffer_untransferable_private_symbol (),
1169+ True (env->isolate ())).Check ();
1170+ args.GetReturnValue ().Set (Uint32Array::New (array_buffer, 0 , 1 ));
1171+ }
1172+
1173+
11551174void Initialize (Local<Object> target,
11561175 Local<Value> unused,
11571176 Local<Context> context,
11581177 void * priv) {
11591178 Environment* env = Environment::GetCurrent (context);
11601179
11611180 env->SetMethod (target, " setBufferPrototype" , SetBufferPrototype);
1181+ env->SetMethod (target, " getZeroFillField" , GetZeroFillField);
11621182 env->SetMethodNoSideEffect (target, " createFromString" , CreateFromString);
11631183
11641184 env->SetMethodNoSideEffect (target, " byteLengthUtf8" , ByteLengthUtf8);
@@ -1198,34 +1218,12 @@ void Initialize(Local<Object> target,
11981218 env->SetMethod (target, " hexWrite" , StringWrite<HEX>);
11991219 env->SetMethod (target, " ucs2Write" , StringWrite<UCS2>);
12001220 env->SetMethod (target, " utf8Write" , StringWrite<UTF8>);
1201-
1202- // It can be a nullptr when running inside an isolate where we
1203- // do not own the ArrayBuffer allocator.
1204- if (NodeArrayBufferAllocator* allocator =
1205- env->isolate_data ()->node_allocator ()) {
1206- uint32_t * zero_fill_field = allocator->zero_fill_field ();
1207- std::unique_ptr<BackingStore> backing =
1208- ArrayBuffer::NewBackingStore (zero_fill_field,
1209- sizeof (*zero_fill_field),
1210- [](void *, size_t , void *){},
1211- nullptr );
1212- Local<ArrayBuffer> array_buffer =
1213- ArrayBuffer::New (env->isolate (), std::move (backing));
1214- array_buffer->SetPrivate (
1215- env->context (),
1216- env->arraybuffer_untransferable_private_symbol (),
1217- True (env->isolate ())).Check ();
1218- CHECK (target
1219- ->Set (env->context (),
1220- FIXED_ONE_BYTE_STRING (env->isolate (), " zeroFill" ),
1221- Uint32Array::New (array_buffer, 0 , 1 ))
1222- .FromJust ());
1223- }
12241221}
12251222
12261223static ExternalReferences external_references {
12271224 __FILE__,
12281225 SetBufferPrototype,
1226+ GetZeroFillField,
12291227 CreateFromString,
12301228 ByteLengthUtf8,
12311229 Copy,
0 commit comments