Skip to content

Commit

Permalink
src: create fs_dir per isolate properties
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
legendecas authored and UlisesGascon committed Jan 9, 2024
1 parent 14cc3b9 commit d00412a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/node_binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static_assert(static_cast<int>(NM_F_LINKED) ==
V(contextify) \
V(encoding_binding) \
V(fs) \
V(fs_dir) \
V(messaging) \
V(mksnapshot) \
V(performance) \
Expand Down
28 changes: 16 additions & 12 deletions src/node_dir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -423,27 +423,29 @@ static void OpenDirSync(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(handle->object().As<Value>());
}

void Initialize(Local<Object> target,
Local<Value> unused,
Local<Context> context,
void* priv) {
Environment* env = Environment::GetCurrent(context);
Isolate* isolate = env->isolate();
void CreatePerIsolateProperties(IsolateData* isolate_data,
Local<ObjectTemplate> target) {
Isolate* isolate = isolate_data->isolate();

SetMethod(context, target, "opendir", OpenDir);
SetMethod(context, target, "opendirSync", OpenDirSync);
SetMethod(isolate, target, "opendir", OpenDir);
SetMethod(isolate, target, "opendirSync", OpenDirSync);

// Create FunctionTemplate for DirHandle
Local<FunctionTemplate> dir = NewFunctionTemplate(isolate, DirHandle::New);
dir->Inherit(AsyncWrap::GetConstructorTemplate(env));
dir->Inherit(AsyncWrap::GetConstructorTemplate(isolate_data));
SetProtoMethod(isolate, dir, "read", DirHandle::Read);
SetProtoMethod(isolate, dir, "close", DirHandle::Close);
Local<ObjectTemplate> dirt = dir->InstanceTemplate();
dirt->SetInternalFieldCount(DirHandle::kInternalFieldCount);
SetConstructorFunction(context, target, "DirHandle", dir);
env->set_dir_instance_template(dirt);
SetConstructorFunction(isolate, target, "DirHandle", dir);
isolate_data->set_dir_instance_template(dirt);
}

void CreatePerContextProperties(Local<Object> target,
Local<Value> unused,
Local<Context> context,
void* priv) {}

void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(OpenDir);
registry->Register(OpenDirSync);
Expand All @@ -456,6 +458,8 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {

} // end namespace node

NODE_BINDING_CONTEXT_AWARE_INTERNAL(fs_dir, node::fs_dir::Initialize)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(fs_dir,
node::fs_dir::CreatePerContextProperties)
NODE_BINDING_PER_ISOLATE_INIT(fs_dir, node::fs_dir::CreatePerIsolateProperties)
NODE_BINDING_EXTERNAL_REFERENCE(fs_dir,
node::fs_dir::RegisterExternalReferences)

0 comments on commit d00412a

Please sign in to comment.