diff options
Diffstat (limited to 'deps/v8/test/cctest/test-api-interceptors.cc')
-rw-r--r-- | deps/v8/test/cctest/test-api-interceptors.cc | 128 |
1 files changed, 73 insertions, 55 deletions
diff --git a/deps/v8/test/cctest/test-api-interceptors.cc b/deps/v8/test/cctest/test-api-interceptors.cc index 396efca01d..6aebba67bc 100644 --- a/deps/v8/test/cctest/test-api-interceptors.cc +++ b/deps/v8/test/cctest/test-api-interceptors.cc @@ -380,11 +380,8 @@ void InterceptorHasOwnPropertyGetterGC( CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask); } -} // namespace - int query_counter_int = 0; -namespace { void QueryCallback(Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) { query_counter_int++; @@ -479,12 +476,13 @@ THREADED_TEST(QueryInterceptor) { CHECK_EQ(query_counter_int, 8); } +namespace { + bool get_was_called = false; bool set_was_called = false; int set_was_called_counter = 0; -namespace { void GetterCallback(Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) { get_was_called = true; @@ -609,56 +607,13 @@ THREADED_TEST(SetterCallbackFunctionDeclarationInterceptorThrow) { CHECK_EQ(set_was_called, false); } -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 { bool get_was_called_in_order = false; bool define_was_called_in_order = false; -namespace { - void GetterCallbackOrder(Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) { get_was_called_in_order = true; @@ -700,6 +655,68 @@ THREADED_TEST(DefinerCallbackGetAndDefine) { CHECK_EQ(define_was_called_in_order, true); } +namespace { // namespace for InObjectLiteralDefinitionWithInterceptor + +// Workaround for no-snapshot builds: only intercept once Context::New() is +// done, otherwise we'll intercept +// bootstrapping like defining array on the global object. +bool context_is_done = false; +bool getter_callback_was_called = false; + +void ReturnUndefinedGetterCallback( + Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) { + if (context_is_done) { + 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); + + context_is_done = true; + + // 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(); @@ -1954,8 +1971,9 @@ THREADED_TEST(PropertyDescriptorCallback) { } } +namespace { int echo_indexed_call_count = 0; - +} // namespace static void EchoIndexedProperty( uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) { @@ -4560,7 +4578,7 @@ TEST(NamedAllCanReadInterceptor) { ExpectInt32("checked.whatever", 17); CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')") ->IsUndefined()); - CHECK_EQ(6, access_check_data.count); + CHECK_EQ(5, access_check_data.count); access_check_data.result = false; ExpectInt32("checked.whatever", intercept_data_0.value); @@ -4569,7 +4587,7 @@ TEST(NamedAllCanReadInterceptor) { CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')"); CHECK(try_catch.HasCaught()); } - CHECK_EQ(9, access_check_data.count); + CHECK_EQ(7, access_check_data.count); intercept_data_1.should_intercept = true; ExpectInt32("checked.whatever", intercept_data_1.value); @@ -4578,7 +4596,7 @@ TEST(NamedAllCanReadInterceptor) { CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')"); CHECK(try_catch.HasCaught()); } - CHECK_EQ(12, access_check_data.count); + CHECK_EQ(9, access_check_data.count); g_access_check_data = nullptr; } @@ -4647,7 +4665,7 @@ TEST(IndexedAllCanReadInterceptor) { ExpectInt32("checked[15]", 17); CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, '15')") ->IsUndefined()); - CHECK_EQ(6, access_check_data.count); + CHECK_EQ(5, access_check_data.count); access_check_data.result = false; ExpectInt32("checked[15]", intercept_data_0.value); @@ -4656,7 +4674,7 @@ TEST(IndexedAllCanReadInterceptor) { CompileRun("Object.getOwnPropertyDescriptor(checked, '15')"); CHECK(try_catch.HasCaught()); } - CHECK_EQ(9, access_check_data.count); + CHECK_EQ(7, access_check_data.count); intercept_data_1.should_intercept = true; ExpectInt32("checked[15]", intercept_data_1.value); @@ -4665,7 +4683,7 @@ TEST(IndexedAllCanReadInterceptor) { CompileRun("Object.getOwnPropertyDescriptor(checked, '15')"); CHECK(try_catch.HasCaught()); } - CHECK_EQ(12, access_check_data.count); + CHECK_EQ(9, access_check_data.count); g_access_check_data = nullptr; } |