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

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

Issue 2707263002: [api] Fix DescriptorInterceptor with access check. (Closed)
Patch Set: Check access if needed. Created 3 years, 9 months 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 | « src/objects.cc ('k') | no next file » | 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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 CHECK_EQ(44, v8::Script::Compile(ctx, code) 569 CHECK_EQ(44, v8::Script::Compile(ctx, code)
570 .ToLocalChecked() 570 .ToLocalChecked()
571 ->Run(ctx) 571 ->Run(ctx)
572 .ToLocalChecked() 572 .ToLocalChecked()
573 ->Int32Value(ctx) 573 ->Int32Value(ctx)
574 .FromJust()); 574 .FromJust());
575 CHECK_EQ(3, set_was_called_counter); 575 CHECK_EQ(3, set_was_called_counter);
576 } 576 }
577 577
578 namespace { 578 namespace {
579 int descriptor_was_called;
580
581 void PropertyDescriptorCallback(
582 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
583 // Intercept the callback by setting a different descriptor.
584 descriptor_was_called++;
585 const char* code =
586 "var desc = {value: 5};"
587 "desc;";
588 Local<Value> descriptor = v8_compile(code)
589 ->Run(info.GetIsolate()->GetCurrentContext())
590 .ToLocalChecked();
591 info.GetReturnValue().Set(descriptor);
592 }
593 } // namespace
594
595 // Check that the descriptor callback is called on the global object.
596 THREADED_TEST(DescriptorCallbackOnGlobalObject) {
597 v8::HandleScope scope(CcTest::isolate());
598 LocalContext env;
599 v8::Local<v8::FunctionTemplate> templ =
600 v8::FunctionTemplate::New(CcTest::isolate());
601
602 v8::Local<ObjectTemplate> object_template = templ->InstanceTemplate();
603 object_template->SetHandler(v8::NamedPropertyHandlerConfiguration(
604 nullptr, nullptr, PropertyDescriptorCallback, nullptr, nullptr, nullptr));
605 v8::Local<v8::Context> ctx =
606 v8::Context::New(CcTest::isolate(), nullptr, object_template);
607
608 descriptor_was_called = 0;
609
610 // Declare function.
611 v8::Local<v8::String> code = v8_str(
612 "var x = 42; var desc = Object.getOwnPropertyDescriptor(this, 'x'); "
613 "desc.value;");
614 CHECK_EQ(5, v8::Script::Compile(ctx, code)
615 .ToLocalChecked()
616 ->Run(ctx)
617 .ToLocalChecked()
618 ->Int32Value(ctx)
619 .FromJust());
620 CHECK_EQ(1, descriptor_was_called);
621 }
622
623 namespace {
579 void QueryCallbackSetDontDelete( 624 void QueryCallbackSetDontDelete(
580 Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) { 625 Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) {
581 info.GetReturnValue().Set(v8::PropertyAttribute::DontDelete); 626 info.GetReturnValue().Set(v8::PropertyAttribute::DontDelete);
582 } 627 }
583 628
584 } // namespace 629 } // namespace
585 630
586 // Regression for a Node.js test that fails in debug mode. 631 // Regression for a Node.js test that fails in debug mode.
587 THREADED_TEST(InterceptorFunctionRedeclareWithQueryCallback) { 632 THREADED_TEST(InterceptorFunctionRedeclareWithQueryCallback) {
588 v8::HandleScope scope(CcTest::isolate()); 633 v8::HandleScope scope(CcTest::isolate());
(...skipping 4040 matching lines...) Expand 10 before | Expand all | Expand 10 after
4629 .FromJust(); 4674 .FromJust();
4630 CompileRun( 4675 CompileRun(
4631 "checked.__proto__ = intercepted_1;" 4676 "checked.__proto__ = intercepted_1;"
4632 "intercepted_1.__proto__ = intercepted_0;"); 4677 "intercepted_1.__proto__ = intercepted_0;");
4633 4678
4634 CHECK_EQ(3, access_check_data.count); 4679 CHECK_EQ(3, access_check_data.count);
4635 4680
4636 ExpectInt32("checked.whatever", 17); 4681 ExpectInt32("checked.whatever", 17);
4637 CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')") 4682 CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')")
4638 ->IsUndefined()); 4683 ->IsUndefined());
4639 CHECK_EQ(5, access_check_data.count); 4684 CHECK_EQ(6, access_check_data.count);
4640 4685
4641 access_check_data.result = false; 4686 access_check_data.result = false;
4642 ExpectInt32("checked.whatever", intercept_data_0.value); 4687 ExpectInt32("checked.whatever", intercept_data_0.value);
4643 { 4688 {
4644 v8::TryCatch try_catch(isolate); 4689 v8::TryCatch try_catch(isolate);
4645 CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')"); 4690 CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')");
4646 CHECK(try_catch.HasCaught()); 4691 CHECK(try_catch.HasCaught());
4647 } 4692 }
4648 CHECK_EQ(7, access_check_data.count); 4693 CHECK_EQ(9, access_check_data.count);
4649 4694
4650 intercept_data_1.should_intercept = true; 4695 intercept_data_1.should_intercept = true;
4651 ExpectInt32("checked.whatever", intercept_data_1.value); 4696 ExpectInt32("checked.whatever", intercept_data_1.value);
4652 { 4697 {
4653 v8::TryCatch try_catch(isolate); 4698 v8::TryCatch try_catch(isolate);
4654 CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')"); 4699 CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')");
4655 CHECK(try_catch.HasCaught()); 4700 CHECK(try_catch.HasCaught());
4656 } 4701 }
4657 CHECK_EQ(9, access_check_data.count); 4702 CHECK_EQ(12, access_check_data.count);
4658 g_access_check_data = nullptr; 4703 g_access_check_data = nullptr;
4659 } 4704 }
4660 4705
4661 4706
4662 TEST(IndexedAllCanReadInterceptor) { 4707 TEST(IndexedAllCanReadInterceptor) {
4663 auto isolate = CcTest::isolate(); 4708 auto isolate = CcTest::isolate();
4664 v8::HandleScope handle_scope(isolate); 4709 v8::HandleScope handle_scope(isolate);
4665 LocalContext context; 4710 LocalContext context;
4666 4711
4667 AccessCheckData access_check_data; 4712 AccessCheckData access_check_data;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
4716 CompileRun( 4761 CompileRun(
4717 "checked.__proto__ = intercepted_1;" 4762 "checked.__proto__ = intercepted_1;"
4718 "intercepted_1.__proto__ = intercepted_0;"); 4763 "intercepted_1.__proto__ = intercepted_0;");
4719 4764
4720 CHECK_EQ(3, access_check_data.count); 4765 CHECK_EQ(3, access_check_data.count);
4721 4766
4722 access_check_data.result = true; 4767 access_check_data.result = true;
4723 ExpectInt32("checked[15]", 17); 4768 ExpectInt32("checked[15]", 17);
4724 CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, '15')") 4769 CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, '15')")
4725 ->IsUndefined()); 4770 ->IsUndefined());
4726 CHECK_EQ(5, access_check_data.count); 4771 CHECK_EQ(6, access_check_data.count);
4727 4772
4728 access_check_data.result = false; 4773 access_check_data.result = false;
4729 ExpectInt32("checked[15]", intercept_data_0.value); 4774 ExpectInt32("checked[15]", intercept_data_0.value);
4730 { 4775 {
4731 v8::TryCatch try_catch(isolate); 4776 v8::TryCatch try_catch(isolate);
4732 CompileRun("Object.getOwnPropertyDescriptor(checked, '15')"); 4777 CompileRun("Object.getOwnPropertyDescriptor(checked, '15')");
4733 CHECK(try_catch.HasCaught()); 4778 CHECK(try_catch.HasCaught());
4734 } 4779 }
4735 CHECK_EQ(7, access_check_data.count); 4780 CHECK_EQ(9, access_check_data.count);
4736 4781
4737 intercept_data_1.should_intercept = true; 4782 intercept_data_1.should_intercept = true;
4738 ExpectInt32("checked[15]", intercept_data_1.value); 4783 ExpectInt32("checked[15]", intercept_data_1.value);
4739 { 4784 {
4740 v8::TryCatch try_catch(isolate); 4785 v8::TryCatch try_catch(isolate);
4741 CompileRun("Object.getOwnPropertyDescriptor(checked, '15')"); 4786 CompileRun("Object.getOwnPropertyDescriptor(checked, '15')");
4742 CHECK(try_catch.HasCaught()); 4787 CHECK(try_catch.HasCaught());
4743 } 4788 }
4744 CHECK_EQ(9, access_check_data.count); 4789 CHECK_EQ(12, access_check_data.count);
4745 4790
4746 g_access_check_data = nullptr; 4791 g_access_check_data = nullptr;
4747 } 4792 }
4748 4793
4749 4794
4750 THREADED_TEST(NonMaskingInterceptorOwnProperty) { 4795 THREADED_TEST(NonMaskingInterceptorOwnProperty) {
4751 auto isolate = CcTest::isolate(); 4796 auto isolate = CcTest::isolate();
4752 v8::HandleScope handle_scope(isolate); 4797 v8::HandleScope handle_scope(isolate);
4753 LocalContext context; 4798 LocalContext context;
4754 4799
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
4970 ->Set(env.local(), v8_str("Fun"), 5015 ->Set(env.local(), v8_str("Fun"),
4971 fun_templ->GetFunction(env.local()).ToLocalChecked()) 5016 fun_templ->GetFunction(env.local()).ToLocalChecked())
4972 .FromJust()); 5017 .FromJust());
4973 5018
4974 CompileRun( 5019 CompileRun(
4975 "var f = new Fun();" 5020 "var f = new Fun();"
4976 "Number.prototype.__proto__ = f;" 5021 "Number.prototype.__proto__ = f;"
4977 "var a = 42;" 5022 "var a = 42;"
4978 "for (var i = 0; i<3; i++) { a.foo; }"); 5023 "for (var i = 0; i<3; i++) { a.foo; }");
4979 } 5024 }
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698