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