Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(846)

Side by Side Diff: test/cctest/test-api-interceptors.cc

Issue 2501553002: [test] Add tests for definitions in object literal. (Closed)
Patch Set: Do not intercept before Context::New() is done. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/object-literal.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 namespace { // namespace for InObjectLiteralDefinitionWithInterceptor
660
661 // Workaround for no-snapshot builds: only intercept once Context::New() is
662 // done, otherwise we'll intercept
663 // bootstrapping like defining array on the global object.
664 bool context_is_done = false;
665 bool getter_callback_was_called = false;
666
667 void ReturnUndefinedGetterCallback(
668 Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) {
669 if (context_is_done) {
670 getter_callback_was_called = true;
671 info.GetReturnValue().SetUndefined();
672 }
673 }
674
675 } // namespace
676
677 // Check that an interceptor is not invoked during ES6 style definitions inside
678 // an object literal.
679 THREADED_TEST(InObjectLiteralDefinitionWithInterceptor) {
680 v8::HandleScope scope(CcTest::isolate());
681 LocalContext env;
682
683 // Set up a context in which all global object definitions are intercepted.
684 v8::Local<v8::FunctionTemplate> templ =
685 v8::FunctionTemplate::New(CcTest::isolate());
686 v8::Local<ObjectTemplate> object_template = templ->InstanceTemplate();
687 object_template->SetHandler(
688 v8::NamedPropertyHandlerConfiguration(ReturnUndefinedGetterCallback));
689 v8::Local<v8::Context> ctx =
690 v8::Context::New(CcTest::isolate(), nullptr, object_template);
691
692 context_is_done = true;
693
694 // The interceptor returns undefined for any global object,
695 // so setting a property on an object should throw.
696 v8::Local<v8::String> code = v8_str("var o = {}; o.x = 5");
697 {
698 getter_callback_was_called = false;
699 v8::TryCatch try_catch(CcTest::isolate());
700 CHECK(v8::Script::Compile(ctx, code).ToLocalChecked()->Run(ctx).IsEmpty());
701 CHECK(try_catch.HasCaught());
702 CHECK(getter_callback_was_called);
703 }
704
705 // Defining a property in the object literal should not throw
706 // because the interceptor is not invoked.
707 {
708 getter_callback_was_called = false;
709 v8::TryCatch try_catch(CcTest::isolate());
710 code = v8_str("var l = {x: 5};");
711 CHECK(v8::Script::Compile(ctx, code)
712 .ToLocalChecked()
713 ->Run(ctx)
714 .ToLocalChecked()
715 ->IsUndefined());
716 CHECK(!try_catch.HasCaught());
717 CHECK(!getter_callback_was_called);
718 }
719 }
720
659 THREADED_TEST(InterceptorHasOwnProperty) { 721 THREADED_TEST(InterceptorHasOwnProperty) {
660 LocalContext context; 722 LocalContext context;
661 v8::Isolate* isolate = context->GetIsolate(); 723 v8::Isolate* isolate = context->GetIsolate();
662 v8::HandleScope scope(isolate); 724 v8::HandleScope scope(isolate);
663 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); 725 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate);
664 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); 726 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
665 instance_templ->SetHandler( 727 instance_templ->SetHandler(
666 v8::NamedPropertyHandlerConfiguration(InterceptorHasOwnPropertyGetter)); 728 v8::NamedPropertyHandlerConfiguration(InterceptorHasOwnPropertyGetter));
667 Local<Function> function = 729 Local<Function> function =
668 fun_templ->GetFunction(context.local()).ToLocalChecked(); 730 fun_templ->GetFunction(context.local()).ToLocalChecked();
(...skipping 4181 matching lines...) Expand 10 before | Expand all | Expand 10 after
4850 ->Set(env.local(), v8_str("Fun"), 4912 ->Set(env.local(), v8_str("Fun"),
4851 fun_templ->GetFunction(env.local()).ToLocalChecked()) 4913 fun_templ->GetFunction(env.local()).ToLocalChecked())
4852 .FromJust()); 4914 .FromJust());
4853 4915
4854 CompileRun( 4916 CompileRun(
4855 "var f = new Fun();" 4917 "var f = new Fun();"
4856 "Number.prototype.__proto__ = f;" 4918 "Number.prototype.__proto__ = f;"
4857 "var a = 42;" 4919 "var a = 42;"
4858 "for (var i = 0; i<3; i++) { a.foo; }"); 4920 "for (var i = 0; i<3; i++) { a.foo; }");
4859 } 4921 }
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/object-literal.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698