@@ -827,6 +827,49 @@ THREADED_TEST(InterceptorFunctionRedeclareWithQueryCallback) {
827827 v8::Script::Compile (ctx, code).ToLocalChecked ()->Run (ctx).ToLocalChecked ();
828828}
829829
830+ // A lexical declaration must throw when the interceptor reports the property
831+ // as non-configurable (DontDelete), per HasRestrictedGlobalProperty checks in
832+ // https://tc39.es/ecma262/#sec-globaldeclarationinstantiation.
833+ THREADED_TEST (LexicalDeclThrowsForRestrictedGlobalViaInterceptor) {
834+ v8::HandleScope scope (CcTest::isolate ());
835+ LocalContext env;
836+ v8::Local<v8::FunctionTemplate> templ =
837+ v8::FunctionTemplate::New (CcTest::isolate ());
838+
839+ v8::Local<ObjectTemplate> object_template = templ->InstanceTemplate ();
840+ object_template->SetHandler (v8::NamedPropertyHandlerConfiguration (
841+ nullptr , nullptr , QueryCallbackSetDontDelete, nullptr , nullptr ,
842+ v8::Local<v8::Value>(),
843+ v8::PropertyHandlerFlags::kHasDontDeleteProperty ));
844+ v8::Local<v8::Context> ctx =
845+ v8::Context::New (CcTest::isolate (), nullptr , object_template);
846+
847+ v8::TryCatch try_catch (CcTest::isolate ());
848+ v8::Local<v8::String> code = v8_str (" let x;" );
849+ CHECK (v8::Script::Compile (ctx, code).ToLocalChecked ()->Run (ctx).IsEmpty ());
850+ CHECK (try_catch.HasCaught ());
851+ }
852+
853+ // Without kHasDontDeleteProperty, the interceptor is not consulted for
854+ // HasRestrictedGlobalProperty and lexical declarations succeed.
855+ THREADED_TEST (LexicalDeclSucceedsWithoutRestrictedGlobalFlag) {
856+ v8::HandleScope scope (CcTest::isolate ());
857+ LocalContext env;
858+ v8::Local<v8::FunctionTemplate> templ =
859+ v8::FunctionTemplate::New (CcTest::isolate ());
860+
861+ v8::Local<ObjectTemplate> object_template = templ->InstanceTemplate ();
862+ object_template->SetHandler (v8::NamedPropertyHandlerConfiguration (
863+ nullptr , nullptr , QueryCallbackSetDontDelete));
864+ v8::Local<v8::Context> ctx =
865+ v8::Context::New (CcTest::isolate (), nullptr , object_template);
866+
867+ v8::TryCatch try_catch (CcTest::isolate ());
868+ v8::Local<v8::String> code = v8_str (" let x;" );
869+ CHECK (!v8::Script::Compile (ctx, code).ToLocalChecked ()->Run (ctx).IsEmpty ());
870+ CHECK (!try_catch.HasCaught ());
871+ }
872+
830873// Regression test for chromium bug 656648.
831874// Do not crash on non-masking, intercepting setter callbacks.
832875THREADED_TEST (NonMaskingInterceptor) {
0 commit comments