Skip to content

Commit d00412a

Browse files
legendecasUlisesGascon
authored andcommitted
src: create fs_dir per isolate properties
PR-URL: #48655 Backport-PR-URL: #51239 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 14cc3b9 commit d00412a

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/node_binding.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static_assert(static_cast<int>(NM_F_LINKED) ==
3737
V(contextify) \
3838
V(encoding_binding) \
3939
V(fs) \
40+
V(fs_dir) \
4041
V(messaging) \
4142
V(mksnapshot) \
4243
V(performance) \

src/node_dir.cc

+16-12
Original file line numberDiff line numberDiff line change
@@ -423,27 +423,29 @@ static void OpenDirSync(const FunctionCallbackInfo<Value>& args) {
423423
args.GetReturnValue().Set(handle->object().As<Value>());
424424
}
425425

426-
void Initialize(Local<Object> target,
427-
Local<Value> unused,
428-
Local<Context> context,
429-
void* priv) {
430-
Environment* env = Environment::GetCurrent(context);
431-
Isolate* isolate = env->isolate();
426+
void CreatePerIsolateProperties(IsolateData* isolate_data,
427+
Local<ObjectTemplate> target) {
428+
Isolate* isolate = isolate_data->isolate();
432429

433-
SetMethod(context, target, "opendir", OpenDir);
434-
SetMethod(context, target, "opendirSync", OpenDirSync);
430+
SetMethod(isolate, target, "opendir", OpenDir);
431+
SetMethod(isolate, target, "opendirSync", OpenDirSync);
435432

436433
// Create FunctionTemplate for DirHandle
437434
Local<FunctionTemplate> dir = NewFunctionTemplate(isolate, DirHandle::New);
438-
dir->Inherit(AsyncWrap::GetConstructorTemplate(env));
435+
dir->Inherit(AsyncWrap::GetConstructorTemplate(isolate_data));
439436
SetProtoMethod(isolate, dir, "read", DirHandle::Read);
440437
SetProtoMethod(isolate, dir, "close", DirHandle::Close);
441438
Local<ObjectTemplate> dirt = dir->InstanceTemplate();
442439
dirt->SetInternalFieldCount(DirHandle::kInternalFieldCount);
443-
SetConstructorFunction(context, target, "DirHandle", dir);
444-
env->set_dir_instance_template(dirt);
440+
SetConstructorFunction(isolate, target, "DirHandle", dir);
441+
isolate_data->set_dir_instance_template(dirt);
445442
}
446443

444+
void CreatePerContextProperties(Local<Object> target,
445+
Local<Value> unused,
446+
Local<Context> context,
447+
void* priv) {}
448+
447449
void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
448450
registry->Register(OpenDir);
449451
registry->Register(OpenDirSync);
@@ -456,6 +458,8 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
456458

457459
} // end namespace node
458460

459-
NODE_BINDING_CONTEXT_AWARE_INTERNAL(fs_dir, node::fs_dir::Initialize)
461+
NODE_BINDING_CONTEXT_AWARE_INTERNAL(fs_dir,
462+
node::fs_dir::CreatePerContextProperties)
463+
NODE_BINDING_PER_ISOLATE_INIT(fs_dir, node::fs_dir::CreatePerIsolateProperties)
460464
NODE_BINDING_EXTERNAL_REFERENCE(fs_dir,
461465
node::fs_dir::RegisterExternalReferences)

0 commit comments

Comments
 (0)