@@ -122,6 +122,32 @@ void BindingData::Deserialize(v8::Local<v8::Context> context,
122
122
CHECK_NOT_NULL (binding);
123
123
}
124
124
125
+ void BindingData::Access (const FunctionCallbackInfo<Value>& args) {
126
+ Environment* env = Environment::GetCurrent (args);
127
+ Isolate* isolate = env->isolate ();
128
+
129
+ const int argc = args.Length ();
130
+ CHECK_GE (argc, 2 );
131
+
132
+ CHECK (args[1 ]->IsInt32 ());
133
+ int mode = args[1 ].As <Int32>()->Value ();
134
+
135
+ BufferValue path (isolate, args[0 ]);
136
+ CHECK_NOT_NULL (*path);
137
+ THROW_IF_INSUFFICIENT_PERMISSIONS (
138
+ env, permission::PermissionScope::kFileSystemRead , path.ToStringView ());
139
+
140
+ uv_fs_t req;
141
+ auto make = OnScopeLeave ([&req]() { uv_fs_req_cleanup (&req); });
142
+ FS_SYNC_TRACE_BEGIN (access);
143
+ uv_fs_access (nullptr , &req, *path, mode, nullptr );
144
+ FS_SYNC_TRACE_END (access);
145
+
146
+ if (req.result < 0 ) {
147
+ return args.GetReturnValue ().Set (int (req.result ));
148
+ }
149
+ }
150
+
125
151
bool BindingData::ExistsInternal (const std::string_view path) {
126
152
uv_fs_t req;
127
153
auto make = OnScopeLeave ([&req]() { uv_fs_req_cleanup (&req); });
@@ -237,6 +263,7 @@ void BindingData::ReadFileUtf8(const FunctionCallbackInfo<Value>& args) {
237
263
void BindingData::CreatePerIsolateProperties (IsolateData* isolate_data,
238
264
Local<ObjectTemplate> target) {
239
265
Isolate* isolate = isolate_data->isolate ();
266
+ SetMethodNoSideEffect (isolate, target, " access" , Access);
240
267
SetFastMethodNoSideEffect (isolate, target, " exists" , Exists, &fast_exists_);
241
268
SetMethodNoSideEffect (isolate, target, " readFileUtf8" , ReadFileUtf8);
242
269
}
@@ -251,6 +278,7 @@ void BindingData::CreatePerContextProperties(Local<Object> target,
251
278
252
279
void BindingData::RegisterExternalReferences (
253
280
ExternalReferenceRegistry* registry) {
281
+ registry->Register (Access);
254
282
registry->Register (Exists);
255
283
registry->Register (FastExists);
256
284
registry->Register (fast_exists_.GetTypeInfo ());
0 commit comments