Index: test/cctest/test-api-interceptors.cc |
diff --git a/test/cctest/test-api-interceptors.cc b/test/cctest/test-api-interceptors.cc |
index d6a827c7f43193378f34fe0bf0cb80162dabeb0b..b34360adaf0925927e1aba48a7ce50e5e292d8ce 100644 |
--- a/test/cctest/test-api-interceptors.cc |
+++ b/test/cctest/test-api-interceptors.cc |
@@ -576,6 +576,51 @@ THREADED_TEST(SetterCallbackFunctionDeclarationInterceptor) { |
} |
namespace { |
+int descriptor_was_called; |
+ |
+void PropertyDescriptorCallback( |
+ Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
+ // Intercept the callback by setting a different descriptor. |
+ descriptor_was_called++; |
+ const char* code = |
+ "var desc = {value: 5};" |
+ "desc;"; |
+ Local<Value> descriptor = v8_compile(code) |
+ ->Run(info.GetIsolate()->GetCurrentContext()) |
+ .ToLocalChecked(); |
+ info.GetReturnValue().Set(descriptor); |
+} |
+} // namespace |
+ |
+// Check that the descriptor callback is called on the global object. |
+THREADED_TEST(DescriptorCallbackOnGlobalObject) { |
+ v8::HandleScope scope(CcTest::isolate()); |
+ LocalContext env; |
+ v8::Local<v8::FunctionTemplate> templ = |
+ v8::FunctionTemplate::New(CcTest::isolate()); |
+ |
+ v8::Local<ObjectTemplate> object_template = templ->InstanceTemplate(); |
+ object_template->SetHandler(v8::NamedPropertyHandlerConfiguration( |
+ nullptr, nullptr, PropertyDescriptorCallback, nullptr, nullptr, nullptr)); |
+ v8::Local<v8::Context> ctx = |
+ v8::Context::New(CcTest::isolate(), nullptr, object_template); |
+ |
+ descriptor_was_called = 0; |
+ |
+ // Declare function. |
+ v8::Local<v8::String> code = v8_str( |
+ "var x = 42; var desc = Object.getOwnPropertyDescriptor(this, 'x'); " |
+ "desc.value;"); |
+ CHECK_EQ(5, v8::Script::Compile(ctx, code) |
+ .ToLocalChecked() |
+ ->Run(ctx) |
+ .ToLocalChecked() |
+ ->Int32Value(ctx) |
+ .FromJust()); |
+ CHECK_EQ(1, descriptor_was_called); |
+} |
+ |
+namespace { |
void QueryCallbackSetDontDelete( |
Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) { |
info.GetReturnValue().Set(v8::PropertyAttribute::DontDelete); |