@@ -74,7 +74,6 @@ using v8::Object;
74
74
using v8::ObjectTemplate;
75
75
using v8::Promise;
76
76
using v8::String;
77
- using v8::Symbol;
78
77
using v8::Undefined;
79
78
using v8::Value;
80
79
@@ -2827,121 +2826,117 @@ InternalFieldInfoBase* BindingData::Serialize(int index) {
2827
2826
return info;
2828
2827
}
2829
2828
2830
- void Initialize (Local<Object> target,
2831
- Local<Value> unused,
2832
- Local<Context> context,
2833
- void * priv) {
2834
- Realm* realm = Realm::GetCurrent (context);
2835
- Environment* env = realm->env ();
2836
- Isolate* isolate = env->isolate ();
2837
- BindingData* const binding_data =
2838
- realm->AddBindingData <BindingData>(context, target);
2839
- if (binding_data == nullptr ) return ;
2840
-
2841
- SetMethod (context, target, " access" , Access);
2842
- SetMethod (context, target, " close" , Close);
2843
- SetMethod (context, target, " open" , Open);
2844
- SetMethod (context, target, " openFileHandle" , OpenFileHandle);
2845
- SetMethod (context, target, " read" , Read);
2846
- SetMethod (context, target, " readBuffers" , ReadBuffers);
2847
- SetMethod (context, target, " fdatasync" , Fdatasync);
2848
- SetMethod (context, target, " fsync" , Fsync);
2849
- SetMethod (context, target, " rename" , Rename);
2850
- SetMethod (context, target, " ftruncate" , FTruncate);
2851
- SetMethod (context, target, " rmdir" , RMDir);
2852
- SetMethod (context, target, " mkdir" , MKDir);
2853
- SetMethod (context, target, " readdir" , ReadDir);
2854
- SetMethod (context, target, " internalModuleReadJSON" , InternalModuleReadJSON);
2855
- SetMethod (context, target, " internalModuleStat" , InternalModuleStat);
2856
- SetMethod (context, target, " stat" , Stat);
2857
- SetMethod (context, target, " lstat" , LStat);
2858
- SetMethod (context, target, " fstat" , FStat);
2859
- SetMethod (context, target, " statfs" , StatFs);
2860
- SetMethod (context, target, " link" , Link);
2861
- SetMethod (context, target, " symlink" , Symlink);
2862
- SetMethod (context, target, " readlink" , ReadLink);
2863
- SetMethod (context, target, " unlink" , Unlink);
2864
- SetMethod (context, target, " writeBuffer" , WriteBuffer);
2865
- SetMethod (context, target, " writeBuffers" , WriteBuffers);
2866
- SetMethod (context, target, " writeString" , WriteString);
2867
- SetMethod (context, target, " realpath" , RealPath);
2868
- SetMethod (context, target, " copyFile" , CopyFile);
2869
-
2870
- SetMethod (context, target, " chmod" , Chmod);
2871
- SetMethod (context, target, " fchmod" , FChmod);
2872
-
2873
- SetMethod (context, target, " chown" , Chown);
2874
- SetMethod (context, target, " fchown" , FChown);
2875
- SetMethod (context, target, " lchown" , LChown);
2876
-
2877
- SetMethod (context, target, " utimes" , UTimes);
2878
- SetMethod (context, target, " futimes" , FUTimes);
2879
- SetMethod (context, target, " lutimes" , LUTimes);
2880
-
2881
- SetMethod (context, target, " mkdtemp" , Mkdtemp);
2882
-
2883
- target
2884
- ->Set (context,
2885
- FIXED_ONE_BYTE_STRING (isolate, " kFsStatsFieldsNumber" ),
2886
- Integer::New (
2887
- isolate,
2888
- static_cast <int32_t >(FsStatsOffset::kFsStatsFieldsNumber )))
2889
- .Check ();
2890
-
2891
- StatWatcher::Initialize (env, target);
2829
+ static void CreatePerIsolateProperties (IsolateData* isolate_data,
2830
+ Local<FunctionTemplate> ctor) {
2831
+ Isolate* isolate = isolate_data->isolate ();
2832
+ Local<ObjectTemplate> target = ctor->InstanceTemplate ();
2833
+
2834
+ SetMethod (isolate, target, " access" , Access);
2835
+ SetMethod (isolate, target, " close" , Close);
2836
+ SetMethod (isolate, target, " open" , Open);
2837
+ SetMethod (isolate, target, " openFileHandle" , OpenFileHandle);
2838
+ SetMethod (isolate, target, " read" , Read);
2839
+ SetMethod (isolate, target, " readBuffers" , ReadBuffers);
2840
+ SetMethod (isolate, target, " fdatasync" , Fdatasync);
2841
+ SetMethod (isolate, target, " fsync" , Fsync);
2842
+ SetMethod (isolate, target, " rename" , Rename);
2843
+ SetMethod (isolate, target, " ftruncate" , FTruncate);
2844
+ SetMethod (isolate, target, " rmdir" , RMDir);
2845
+ SetMethod (isolate, target, " mkdir" , MKDir);
2846
+ SetMethod (isolate, target, " readdir" , ReadDir);
2847
+ SetMethod (isolate, target, " internalModuleReadJSON" , InternalModuleReadJSON);
2848
+ SetMethod (isolate, target, " internalModuleStat" , InternalModuleStat);
2849
+ SetMethod (isolate, target, " stat" , Stat);
2850
+ SetMethod (isolate, target, " lstat" , LStat);
2851
+ SetMethod (isolate, target, " fstat" , FStat);
2852
+ SetMethod (isolate, target, " statfs" , StatFs);
2853
+ SetMethod (isolate, target, " link" , Link);
2854
+ SetMethod (isolate, target, " symlink" , Symlink);
2855
+ SetMethod (isolate, target, " readlink" , ReadLink);
2856
+ SetMethod (isolate, target, " unlink" , Unlink);
2857
+ SetMethod (isolate, target, " writeBuffer" , WriteBuffer);
2858
+ SetMethod (isolate, target, " writeBuffers" , WriteBuffers);
2859
+ SetMethod (isolate, target, " writeString" , WriteString);
2860
+ SetMethod (isolate, target, " realpath" , RealPath);
2861
+ SetMethod (isolate, target, " copyFile" , CopyFile);
2862
+
2863
+ SetMethod (isolate, target, " chmod" , Chmod);
2864
+ SetMethod (isolate, target, " fchmod" , FChmod);
2865
+
2866
+ SetMethod (isolate, target, " chown" , Chown);
2867
+ SetMethod (isolate, target, " fchown" , FChown);
2868
+ SetMethod (isolate, target, " lchown" , LChown);
2869
+
2870
+ SetMethod (isolate, target, " utimes" , UTimes);
2871
+ SetMethod (isolate, target, " futimes" , FUTimes);
2872
+ SetMethod (isolate, target, " lutimes" , LUTimes);
2873
+
2874
+ SetMethod (isolate, target, " mkdtemp" , Mkdtemp);
2875
+
2876
+ StatWatcher::CreatePerIsolateProperties (isolate_data, ctor);
2877
+
2878
+ target->Set (
2879
+ FIXED_ONE_BYTE_STRING (isolate, " kFsStatsFieldsNumber" ),
2880
+ Integer::New (isolate,
2881
+ static_cast <int32_t >(FsStatsOffset::kFsStatsFieldsNumber )));
2892
2882
2893
2883
// Create FunctionTemplate for FSReqCallback
2894
2884
Local<FunctionTemplate> fst = NewFunctionTemplate (isolate, NewFSReqCallback);
2895
2885
fst->InstanceTemplate ()->SetInternalFieldCount (
2896
2886
FSReqBase::kInternalFieldCount );
2897
- fst->Inherit (AsyncWrap::GetConstructorTemplate (env ));
2898
- SetConstructorFunction (context , target, " FSReqCallback" , fst);
2887
+ fst->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data ));
2888
+ SetConstructorFunction (isolate , target, " FSReqCallback" , fst);
2899
2889
2900
2890
// Create FunctionTemplate for FileHandleReadWrap. There’s no need
2901
2891
// to do anything in the constructor, so we only store the instance template.
2902
2892
Local<FunctionTemplate> fh_rw = FunctionTemplate::New (isolate);
2903
2893
fh_rw->InstanceTemplate ()->SetInternalFieldCount (
2904
2894
FSReqBase::kInternalFieldCount );
2905
- fh_rw->Inherit (AsyncWrap::GetConstructorTemplate (env ));
2895
+ fh_rw->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data ));
2906
2896
Local<String> fhWrapString =
2907
2897
FIXED_ONE_BYTE_STRING (isolate, " FileHandleReqWrap" );
2908
2898
fh_rw->SetClassName (fhWrapString);
2909
- env->set_filehandlereadwrap_template (
2910
- fst->InstanceTemplate ());
2899
+ isolate_data->set_filehandlereadwrap_template (fst->InstanceTemplate ());
2911
2900
2912
2901
// Create Function Template for FSReqPromise
2913
2902
Local<FunctionTemplate> fpt = FunctionTemplate::New (isolate);
2914
- fpt->Inherit (AsyncWrap::GetConstructorTemplate (env ));
2903
+ fpt->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data ));
2915
2904
Local<String> promiseString =
2916
2905
FIXED_ONE_BYTE_STRING (isolate, " FSReqPromise" );
2917
2906
fpt->SetClassName (promiseString);
2918
2907
Local<ObjectTemplate> fpo = fpt->InstanceTemplate ();
2919
2908
fpo->SetInternalFieldCount (FSReqBase::kInternalFieldCount );
2920
- env ->set_fsreqpromise_constructor_template (fpo);
2909
+ isolate_data ->set_fsreqpromise_constructor_template (fpo);
2921
2910
2922
2911
// Create FunctionTemplate for FileHandle
2923
2912
Local<FunctionTemplate> fd = NewFunctionTemplate (isolate, FileHandle::New);
2924
- fd->Inherit (AsyncWrap::GetConstructorTemplate (env ));
2913
+ fd->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data ));
2925
2914
SetProtoMethod (isolate, fd, " close" , FileHandle::Close);
2926
2915
SetProtoMethod (isolate, fd, " releaseFD" , FileHandle::ReleaseFD);
2927
2916
Local<ObjectTemplate> fdt = fd->InstanceTemplate ();
2928
2917
fdt->SetInternalFieldCount (FileHandle::kInternalFieldCount );
2929
- StreamBase::AddMethods (env , fd);
2930
- SetConstructorFunction (context , target, " FileHandle" , fd);
2931
- env ->set_fd_constructor_template (fdt);
2918
+ StreamBase::AddMethods (isolate_data , fd);
2919
+ SetConstructorFunction (isolate , target, " FileHandle" , fd);
2920
+ isolate_data ->set_fd_constructor_template (fdt);
2932
2921
2933
2922
// Create FunctionTemplate for FileHandle::CloseReq
2934
2923
Local<FunctionTemplate> fdclose = FunctionTemplate::New (isolate);
2935
2924
fdclose->SetClassName (FIXED_ONE_BYTE_STRING (isolate,
2936
2925
" FileHandleCloseReq" ));
2937
- fdclose->Inherit (AsyncWrap::GetConstructorTemplate (env ));
2926
+ fdclose->Inherit (AsyncWrap::GetConstructorTemplate (isolate_data ));
2938
2927
Local<ObjectTemplate> fdcloset = fdclose->InstanceTemplate ();
2939
2928
fdcloset->SetInternalFieldCount (FSReqBase::kInternalFieldCount );
2940
- env ->set_fdclose_constructor_template (fdcloset);
2929
+ isolate_data ->set_fdclose_constructor_template (fdcloset);
2941
2930
2942
- target->Set (context,
2943
- FIXED_ONE_BYTE_STRING (isolate, " kUsePromises" ),
2944
- env->fs_use_promises_symbol ()).Check ();
2931
+ target->Set (isolate, " kUsePromises" , isolate_data->fs_use_promises_symbol ());
2932
+ }
2933
+
2934
+ static void CreatePerContextProperties (Local<Object> target,
2935
+ Local<Value> unused,
2936
+ Local<Context> context,
2937
+ void * priv) {
2938
+ Realm* realm = Realm::GetCurrent (context);
2939
+ realm->AddBindingData <BindingData>(context, target);
2945
2940
}
2946
2941
2947
2942
BindingData* FSReqBase::binding_data () {
@@ -3004,5 +2999,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
3004
2999
3005
3000
} // end namespace node
3006
3001
3007
- NODE_BINDING_CONTEXT_AWARE_INTERNAL (fs, node::fs::Initialize)
3002
+ NODE_BINDING_CONTEXT_AWARE_INTERNAL (fs, node::fs::CreatePerContextProperties)
3003
+ NODE_BINDING_PER_ISOLATE_INIT(fs, node::fs::CreatePerIsolateProperties)
3008
3004
NODE_BINDING_EXTERNAL_REFERENCE(fs, node::fs::RegisterExternalReferences)
0 commit comments