Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdlib.h> | 5 #include <stdlib.h> |
| 6 | 6 |
| 7 #include "test/cctest/test-api.h" | 7 #include "test/cctest/test-api.h" |
| 8 | 8 |
| 9 #include "include/v8-util.h" | 9 #include "include/v8-util.h" |
| 10 #include "src/api.h" | 10 #include "src/api.h" |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 649 CHECK_EQ(get_was_called_in_order, false); | 649 CHECK_EQ(get_was_called_in_order, false); |
| 650 CHECK_EQ(define_was_called_in_order, false); | 650 CHECK_EQ(define_was_called_in_order, false); |
| 651 | 651 |
| 652 v8_compile("Object.defineProperty(obj, 'x', {set: function() {return 17;}});") | 652 v8_compile("Object.defineProperty(obj, 'x', {set: function() {return 17;}});") |
| 653 ->Run(env.local()) | 653 ->Run(env.local()) |
| 654 .ToLocalChecked(); | 654 .ToLocalChecked(); |
| 655 CHECK_EQ(get_was_called_in_order, true); | 655 CHECK_EQ(get_was_called_in_order, true); |
| 656 CHECK_EQ(define_was_called_in_order, true); | 656 CHECK_EQ(define_was_called_in_order, true); |
| 657 } | 657 } |
| 658 | 658 |
| 659 bool getter_callback_was_called = false; | |
|
Benedikt Meurer
2016/11/14 12:12:49
Nit: Move this into the namespace.
| |
| 660 | |
| 661 namespace { // namespace for InObjectLiteralDefinitionWithInterceptor | |
| 662 | |
| 663 void ReturnUndefinedGetterCallback( | |
| 664 Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) { | |
| 665 getter_callback_was_called = true; | |
| 666 info.GetReturnValue().SetUndefined(); | |
| 667 } | |
| 668 | |
| 669 } // namespace | |
| 670 | |
| 671 // Check that an interceptor is not invoked during ES6 style definitions inside | |
| 672 // an object literal. | |
| 673 THREADED_TEST(InObjectLiteralDefinitionWithInterceptor) { | |
| 674 v8::HandleScope scope(CcTest::isolate()); | |
| 675 LocalContext env; | |
| 676 | |
| 677 // Set up a context in which all global object definitions are intercepted. | |
| 678 v8::Local<v8::FunctionTemplate> templ = | |
| 679 v8::FunctionTemplate::New(CcTest::isolate()); | |
| 680 v8::Local<ObjectTemplate> object_template = templ->InstanceTemplate(); | |
| 681 object_template->SetHandler( | |
| 682 v8::NamedPropertyHandlerConfiguration(ReturnUndefinedGetterCallback)); | |
| 683 v8::Local<v8::Context> ctx = | |
| 684 v8::Context::New(CcTest::isolate(), nullptr, object_template); | |
| 685 | |
| 686 // The interceptor returns undefined for any global object, | |
| 687 // so setting a property on an object should throw. | |
| 688 v8::Local<v8::String> code = v8_str("var o = {}; o.x = 5"); | |
| 689 { | |
| 690 getter_callback_was_called = false; | |
| 691 v8::TryCatch try_catch(CcTest::isolate()); | |
| 692 CHECK(v8::Script::Compile(ctx, code).ToLocalChecked()->Run(ctx).IsEmpty()); | |
| 693 CHECK(try_catch.HasCaught()); | |
| 694 CHECK(getter_callback_was_called); | |
| 695 } | |
| 696 | |
| 697 // Defining a property in the object literal should not throw | |
| 698 // because the interceptor is not invoked. | |
| 699 { | |
| 700 getter_callback_was_called = false; | |
| 701 v8::TryCatch try_catch(CcTest::isolate()); | |
| 702 code = v8_str("var l = {x: 5};"); | |
| 703 CHECK(v8::Script::Compile(ctx, code) | |
| 704 .ToLocalChecked() | |
| 705 ->Run(ctx) | |
| 706 .ToLocalChecked() | |
| 707 ->IsUndefined()); | |
| 708 CHECK(!try_catch.HasCaught()); | |
| 709 CHECK(!getter_callback_was_called); | |
| 710 } | |
| 711 } | |
| 712 | |
| 659 THREADED_TEST(InterceptorHasOwnProperty) { | 713 THREADED_TEST(InterceptorHasOwnProperty) { |
| 660 LocalContext context; | 714 LocalContext context; |
| 661 v8::Isolate* isolate = context->GetIsolate(); | 715 v8::Isolate* isolate = context->GetIsolate(); |
| 662 v8::HandleScope scope(isolate); | 716 v8::HandleScope scope(isolate); |
| 663 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); | 717 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); |
| 664 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); | 718 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); |
| 665 instance_templ->SetHandler( | 719 instance_templ->SetHandler( |
| 666 v8::NamedPropertyHandlerConfiguration(InterceptorHasOwnPropertyGetter)); | 720 v8::NamedPropertyHandlerConfiguration(InterceptorHasOwnPropertyGetter)); |
| 667 Local<Function> function = | 721 Local<Function> function = |
| 668 fun_templ->GetFunction(context.local()).ToLocalChecked(); | 722 fun_templ->GetFunction(context.local()).ToLocalChecked(); |
| (...skipping 4181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4850 ->Set(env.local(), v8_str("Fun"), | 4904 ->Set(env.local(), v8_str("Fun"), |
| 4851 fun_templ->GetFunction(env.local()).ToLocalChecked()) | 4905 fun_templ->GetFunction(env.local()).ToLocalChecked()) |
| 4852 .FromJust()); | 4906 .FromJust()); |
| 4853 | 4907 |
| 4854 CompileRun( | 4908 CompileRun( |
| 4855 "var f = new Fun();" | 4909 "var f = new Fun();" |
| 4856 "Number.prototype.__proto__ = f;" | 4910 "Number.prototype.__proto__ = f;" |
| 4857 "var a = 42;" | 4911 "var a = 42;" |
| 4858 "for (var i = 0; i<3; i++) { a.foo; }"); | 4912 "for (var i = 0; i<3; i++) { a.foo; }"); |
| 4859 } | 4913 } |
| OLD | NEW |