@@ -127,7 +127,6 @@ static void Has(const FunctionCallbackInfo<Value>& args) {
127127
128128static bool FastHas (Local<Value> receiver,
129129 Local<Value> scope_arg,
130- Local<Value> resource_arg,
131130 // NOLINTNEXTLINE(runtime/references) This is V8 api.
132131 FastApiCallbackOptions& options) {
133132 TRACK_V8_FAST_API_CALL (" permission.has" );
@@ -148,8 +147,30 @@ static bool FastHas(Local<Value> receiver,
148147 return false ;
149148 }
150149
151- if (resource_arg->IsUndefined ()) {
152- return env->permission ()->is_granted (env, scope);
150+ return env->permission ()->is_granted (env, scope);
151+ }
152+
153+ static bool FastHasResource (Local<Value> receiver,
154+ Local<Value> scope_arg,
155+ Local<Value> resource_arg,
156+ // NOLINTNEXTLINE(runtime/references) This is V8 api.
157+ FastApiCallbackOptions& options) {
158+ TRACK_V8_FAST_API_CALL (" permission.has" );
159+ auto isolate = options.isolate ;
160+ v8::HandleScope handle_scope (isolate);
161+ auto context = isolate->GetCurrentContext ();
162+
163+ Environment* env = Environment::GetCurrent (context);
164+
165+ Local<String> str;
166+ if (!scope_arg->ToString (context).ToLocal (&str)) {
167+ return false ;
168+ }
169+ Utf8Value utf8_scope (isolate, str);
170+ PermissionScope scope =
171+ Permission::StringToPermission (utf8_scope.ToStringView ());
172+ if (scope == PermissionScope::kPermissionsRoot ) {
173+ return false ;
153174 }
154175
155176 Local<String> res_str;
@@ -164,7 +185,8 @@ static bool FastHas(Local<Value> receiver,
164185 return env->permission ()->is_granted (env, scope, utf8_res.ToStringView ());
165186}
166187
167- static CFunction fast_has_ (CFunction::Make(FastHas));
188+ static CFunction fast_has_methods_[] = {CFunction::Make (FastHas),
189+ CFunction::Make (FastHasResource)};
168190
169191} // namespace
170192
@@ -370,15 +392,18 @@ void Initialize(Local<Object> target,
370392 Local<Value> unused,
371393 Local<Context> context,
372394 void * priv) {
373- SetFastMethodNoSideEffect (context, target, " has" , Has, &fast_has_);
395+ SetFastMethodNoSideEffect (
396+ context, target, " has" , Has, {fast_has_methods_, 2 });
374397 SetMethod (context, target, " drop" , Drop);
375398
376399 target->SetIntegrityLevel (context, IntegrityLevel::kFrozen ).FromJust ();
377400}
378401
379402void RegisterExternalReferences (ExternalReferenceRegistry* registry) {
380403 registry->Register (Has);
381- registry->Register (fast_has_);
404+ for (const CFunction& method : fast_has_methods_) {
405+ registry->Register (method);
406+ }
382407 registry->Register (Drop);
383408}
384409
0 commit comments