Chromium Code Reviews| Index: test/cctest/test-api-interceptors.cc |
| diff --git a/test/cctest/test-api-interceptors.cc b/test/cctest/test-api-interceptors.cc |
| index 572487976e97ff8cebfab4390ea9056ac6d185e5..f489fe351022179866d9c2fc7a5d3065f7bbe6fc 100644 |
| --- a/test/cctest/test-api-interceptors.cc |
| +++ b/test/cctest/test-api-interceptors.cc |
| @@ -656,6 +656,60 @@ THREADED_TEST(DefinerCallbackGetAndDefine) { |
| CHECK_EQ(define_was_called_in_order, true); |
| } |
| +bool getter_callback_was_called = false; |
|
Benedikt Meurer
2016/11/14 12:12:49
Nit: Move this into the namespace.
|
| + |
| +namespace { // namespace for InObjectLiteralDefinitionWithInterceptor |
| + |
| +void ReturnUndefinedGetterCallback( |
| + Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) { |
| + getter_callback_was_called = true; |
| + info.GetReturnValue().SetUndefined(); |
| +} |
| + |
| +} // namespace |
| + |
| +// Check that an interceptor is not invoked during ES6 style definitions inside |
| +// an object literal. |
| +THREADED_TEST(InObjectLiteralDefinitionWithInterceptor) { |
| + v8::HandleScope scope(CcTest::isolate()); |
| + LocalContext env; |
| + |
| + // Set up a context in which all global object definitions are intercepted. |
| + v8::Local<v8::FunctionTemplate> templ = |
| + v8::FunctionTemplate::New(CcTest::isolate()); |
| + v8::Local<ObjectTemplate> object_template = templ->InstanceTemplate(); |
| + object_template->SetHandler( |
| + v8::NamedPropertyHandlerConfiguration(ReturnUndefinedGetterCallback)); |
| + v8::Local<v8::Context> ctx = |
| + v8::Context::New(CcTest::isolate(), nullptr, object_template); |
| + |
| + // The interceptor returns undefined for any global object, |
| + // so setting a property on an object should throw. |
| + v8::Local<v8::String> code = v8_str("var o = {}; o.x = 5"); |
| + { |
| + getter_callback_was_called = false; |
| + v8::TryCatch try_catch(CcTest::isolate()); |
| + CHECK(v8::Script::Compile(ctx, code).ToLocalChecked()->Run(ctx).IsEmpty()); |
| + CHECK(try_catch.HasCaught()); |
| + CHECK(getter_callback_was_called); |
| + } |
| + |
| + // Defining a property in the object literal should not throw |
| + // because the interceptor is not invoked. |
| + { |
| + getter_callback_was_called = false; |
| + v8::TryCatch try_catch(CcTest::isolate()); |
| + code = v8_str("var l = {x: 5};"); |
| + CHECK(v8::Script::Compile(ctx, code) |
| + .ToLocalChecked() |
| + ->Run(ctx) |
| + .ToLocalChecked() |
| + ->IsUndefined()); |
| + CHECK(!try_catch.HasCaught()); |
| + CHECK(!getter_callback_was_called); |
| + } |
| +} |
| + |
| THREADED_TEST(InterceptorHasOwnProperty) { |
| LocalContext context; |
| v8::Isolate* isolate = context->GetIsolate(); |