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

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

Issue 1217893012: Remove deprecated v8::Object::TurnOnAccessCheck() from the V8 API. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Deoptimizer::DeoptimizeGlobalObject() removed Created 5 years, 5 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/runtime/runtime-object.cc ('k') | test/cctest/test-api-interceptors.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 8260 matching lines...) Expand 10 before | Expand all | Expand 10 after
8271 "function get_x_w() { return (function() {return this.x;})(); }"); 8271 "function get_x_w() { return (function() {return this.x;})(); }");
8272 env1->Global()->Set(v8_str("bound_x"), CompileRun("bound_x")); 8272 env1->Global()->Set(v8_str("bound_x"), CompileRun("bound_x"));
8273 env1->Global()->Set(v8_str("get_x"), CompileRun("get_x")); 8273 env1->Global()->Set(v8_str("get_x"), CompileRun("get_x"));
8274 env1->Global()->Set(v8_str("get_x_w"), CompileRun("get_x_w")); 8274 env1->Global()->Set(v8_str("get_x_w"), CompileRun("get_x_w"));
8275 env1->Global()->Set( 8275 env1->Global()->Set(
8276 v8_str("this_x"), 8276 v8_str("this_x"),
8277 CompileRun("Object.getOwnPropertyDescriptor(this, 'this_x').get")); 8277 CompileRun("Object.getOwnPropertyDescriptor(this, 'this_x').get"));
8278 } 8278 }
8279 8279
8280 Local<Object> env2_global = env2->Global(); 8280 Local<Object> env2_global = env2->Global();
8281 env2_global->TurnOnAccessCheck();
8282 env2->DetachGlobal(); 8281 env2->DetachGlobal();
8283 8282
8284 Local<Value> result; 8283 Local<Value> result;
8285 result = CompileRun("bound_x()"); 8284 result = CompileRun("bound_x()");
8286 CHECK(v8_str("env2_x")->Equals(result)); 8285 CHECK(v8_str("env2_x")->Equals(result));
8287 result = CompileRun("get_x()"); 8286 result = CompileRun("get_x()");
8288 CHECK(result.IsEmpty()); 8287 CHECK(result.IsEmpty());
8289 result = CompileRun("get_x_w()"); 8288 result = CompileRun("get_x_w()");
8290 CHECK(result.IsEmpty()); 8289 CHECK(result.IsEmpty());
8291 result = CompileRun("this_x()"); 8290 result = CompileRun("this_x()");
(...skipping 4461 matching lines...) Expand 10 before | Expand all | Expand 10 after
12753 CHECK(value_1.IsEmpty()); 12752 CHECK(value_1.IsEmpty());
12754 12753
12755 Local<v8::Object> instance_2 = templ->NewInstance(); 12754 Local<v8::Object> instance_2 = templ->NewInstance();
12756 context->Global()->Set(v8_str("obj_2"), instance_2); 12755 context->Global()->Set(v8_str("obj_2"), instance_2);
12757 12756
12758 Local<Value> value_2 = CompileRun("obj_2.a"); 12757 Local<Value> value_2 = CompileRun("obj_2.a");
12759 CHECK(value_2.IsEmpty()); 12758 CHECK(value_2.IsEmpty());
12760 } 12759 }
12761 12760
12762 12761
12763 THREADED_TEST(TurnOnAccessCheck) {
12764 v8::Isolate* isolate = CcTest::isolate();
12765 v8::HandleScope handle_scope(isolate);
12766
12767 // Create an environment with access check to the global object disabled by
12768 // default.
12769 v8::Handle<v8::ObjectTemplate> global_template =
12770 v8::ObjectTemplate::New(isolate);
12771 global_template->SetAccessCheckCallbacks(AccessAlwaysBlocked, NULL,
12772 v8::Handle<v8::Value>(), false);
12773 v8::Local<Context> context = Context::New(isolate, NULL, global_template);
12774 Context::Scope context_scope(context);
12775
12776 // Set up a property and a number of functions.
12777 context->Global()->Set(v8_str("a"), v8_num(1));
12778 CompileRun("function f1() {return a;}"
12779 "function f2() {return a;}"
12780 "function g1() {return h();}"
12781 "function g2() {return h();}"
12782 "function h() {return 1;}");
12783 Local<Function> f1 =
12784 Local<Function>::Cast(context->Global()->Get(v8_str("f1")));
12785 Local<Function> f2 =
12786 Local<Function>::Cast(context->Global()->Get(v8_str("f2")));
12787 Local<Function> g1 =
12788 Local<Function>::Cast(context->Global()->Get(v8_str("g1")));
12789 Local<Function> g2 =
12790 Local<Function>::Cast(context->Global()->Get(v8_str("g2")));
12791 Local<Function> h =
12792 Local<Function>::Cast(context->Global()->Get(v8_str("h")));
12793
12794 // Get the global object.
12795 v8::Handle<v8::Object> global = context->Global();
12796
12797 // Call f1 one time and f2 a number of times. This will ensure that f1 still
12798 // uses the runtime system to retreive property a whereas f2 uses global load
12799 // inline cache.
12800 CHECK(f1->Call(global, 0, NULL)->Equals(v8_num(1)));
12801 for (int i = 0; i < 4; i++) {
12802 CHECK(f2->Call(global, 0, NULL)->Equals(v8_num(1)));
12803 }
12804
12805 // Same for g1 and g2.
12806 CHECK(g1->Call(global, 0, NULL)->Equals(v8_num(1)));
12807 for (int i = 0; i < 4; i++) {
12808 CHECK(g2->Call(global, 0, NULL)->Equals(v8_num(1)));
12809 }
12810
12811 // Detach the global and turn on access check.
12812 Local<Object> hidden_global = Local<Object>::Cast(
12813 context->Global()->GetPrototype());
12814 context->DetachGlobal();
12815 hidden_global->TurnOnAccessCheck();
12816
12817 // Failing access check results in exception.
12818 CHECK(f1->Call(global, 0, NULL).IsEmpty());
12819 CHECK(f2->Call(global, 0, NULL).IsEmpty());
12820 CHECK(g1->Call(global, 0, NULL).IsEmpty());
12821 CHECK(g2->Call(global, 0, NULL).IsEmpty());
12822
12823 // No failing access check when just returning a constant.
12824 CHECK(h->Call(global, 0, NULL)->Equals(v8_num(1)));
12825 }
12826
12827
12828 // Tests that ScriptData can be serialized and deserialized. 12762 // Tests that ScriptData can be serialized and deserialized.
12829 TEST(PreCompileSerialization) { 12763 TEST(PreCompileSerialization) {
12830 v8::V8::Initialize(); 12764 v8::V8::Initialize();
12831 LocalContext env; 12765 LocalContext env;
12832 v8::Isolate* isolate = env->GetIsolate(); 12766 v8::Isolate* isolate = env->GetIsolate();
12833 HandleScope handle_scope(isolate); 12767 HandleScope handle_scope(isolate);
12834 12768
12835 i::FLAG_min_preparse_length = 0; 12769 i::FLAG_min_preparse_length = 0;
12836 const char* script = "function foo(a) { return a+1; }"; 12770 const char* script = "function foo(a) { return a+1; }";
12837 v8::ScriptCompiler::Source source(v8_str(script)); 12771 v8::ScriptCompiler::Source source(v8_str(script));
(...skipping 3955 matching lines...) Expand 10 before | Expand all | Expand 10 after
16793 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC); 16727 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC);
16794 16728
16795 v8::Isolate* isolate = CcTest::isolate(); 16729 v8::Isolate* isolate = CcTest::isolate();
16796 v8::HandleScope scope(isolate); 16730 v8::HandleScope scope(isolate);
16797 16731
16798 // Create an ObjectTemplate for global objects and install access 16732 // Create an ObjectTemplate for global objects and install access
16799 // check callbacks that will block access. 16733 // check callbacks that will block access.
16800 v8::Handle<v8::ObjectTemplate> global_template = 16734 v8::Handle<v8::ObjectTemplate> global_template =
16801 v8::ObjectTemplate::New(isolate); 16735 v8::ObjectTemplate::New(isolate);
16802 global_template->SetAccessCheckCallbacks(AccessAlwaysBlocked, NULL, 16736 global_template->SetAccessCheckCallbacks(AccessAlwaysBlocked, NULL,
16803 v8::Handle<v8::Value>(), false); 16737 v8::Handle<v8::Value>());
16804 16738
16805 // Create a context and set an x property on it's global object. 16739 // Create a context and set an x property on it's global object.
16806 LocalContext context0(NULL, global_template); 16740 LocalContext context0(NULL, global_template);
16807 context0->Global()->Set(v8_str("x"), v8_num(42)); 16741 context0->Global()->Set(v8_str("x"), v8_num(42));
16808 v8::Handle<v8::Object> global0 = context0->Global(); 16742 v8::Handle<v8::Object> global0 = context0->Global();
16809 16743
16810 // Create a context with a different security token so that the 16744 // Create a context with a different security token so that the
16811 // failed access check callback will be called on each access. 16745 // failed access check callback will be called on each access.
16812 LocalContext context1(NULL, global_template); 16746 LocalContext context1(NULL, global_template);
16813 context1->Global()->Set(v8_str("other"), global0); 16747 context1->Global()->Set(v8_str("other"), global0);
(...skipping 2425 matching lines...) Expand 10 before | Expand all | Expand 10 after
19239 global0->Set(v8_str("toJSON"), toJSON->GetFunction()); 19173 global0->Set(v8_str("toJSON"), toJSON->GetFunction());
19240 } 19174 }
19241 // Create a context with a different security token so that the 19175 // Create a context with a different security token so that the
19242 // failed access check callback will be called on each access. 19176 // failed access check callback will be called on each access.
19243 LocalContext context1(NULL, global_template); 19177 LocalContext context1(NULL, global_template);
19244 context1->Global()->Set(v8_str("other"), global0); 19178 context1->Global()->Set(v8_str("other"), global0);
19245 19179
19246 CHECK(CompileRun("JSON.stringify(other)").IsEmpty()); 19180 CHECK(CompileRun("JSON.stringify(other)").IsEmpty());
19247 CHECK(CompileRun("JSON.stringify({ 'a' : other, 'b' : ['c'] })").IsEmpty()); 19181 CHECK(CompileRun("JSON.stringify({ 'a' : other, 'b' : ['c'] })").IsEmpty());
19248 CHECK(CompileRun("JSON.stringify([other, 'b', 'c'])").IsEmpty()); 19182 CHECK(CompileRun("JSON.stringify([other, 'b', 'c'])").IsEmpty());
19249
19250 v8::Handle<v8::Array> array = v8::Array::New(isolate, 2);
19251 array->Set(0, v8_str("a"));
19252 array->Set(1, v8_str("b"));
19253 context1->Global()->Set(v8_str("array"), array);
19254 ExpectString("JSON.stringify(array)", "[\"a\",\"b\"]");
19255 array->TurnOnAccessCheck();
19256 CHECK(CompileRun("JSON.stringify(array)").IsEmpty());
19257 CHECK(CompileRun("JSON.stringify([array])").IsEmpty());
19258 CHECK(CompileRun("JSON.stringify({'a' : array})").IsEmpty());
19259 } 19183 }
19260 } 19184 }
19261 19185
19262 19186
19263 bool access_check_fail_thrown = false; 19187 bool access_check_fail_thrown = false;
19264 bool catch_callback_called = false; 19188 bool catch_callback_called = false;
19265 19189
19266 19190
19267 // Failed access check callback that performs a GC on each invocation. 19191 // Failed access check callback that performs a GC on each invocation.
19268 void FailedAccessCheckThrows(Local<v8::Object> target, 19192 void FailedAccessCheckThrows(Local<v8::Object> target,
(...skipping 2387 matching lines...) Expand 10 before | Expand all | Expand 10 after
21656 CHECK(set->Has(env.local(), set).FromJust()); 21580 CHECK(set->Has(env.local(), set).FromJust());
21657 21581
21658 CHECK(set->Delete(env.local(), set).FromJust()); 21582 CHECK(set->Delete(env.local(), set).FromJust());
21659 CHECK_EQ(2U, set->Size()); 21583 CHECK_EQ(2U, set->Size());
21660 CHECK(!set->Has(env.local(), set).FromJust()); 21584 CHECK(!set->Has(env.local(), set).FromJust());
21661 CHECK(!set->Delete(env.local(), set).FromJust()); 21585 CHECK(!set->Delete(env.local(), set).FromJust());
21662 21586
21663 set->Clear(); 21587 set->Clear();
21664 CHECK_EQ(0U, set->Size()); 21588 CHECK_EQ(0U, set->Size());
21665 } 21589 }
OLDNEW
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | test/cctest/test-api-interceptors.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698