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

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

Issue 2199343002: Do an access check before compiling code via eval() (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 years, 4 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/builtins/builtins-global.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 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 11658 matching lines...) Expand 10 before | Expand all | Expand 10 after
11669 11669
11670 11670
11671 // Test that calling eval in a context which has been detached from 11671 // Test that calling eval in a context which has been detached from
11672 // its global proxy works. 11672 // its global proxy works.
11673 THREADED_TEST(EvalInDetachedGlobal) { 11673 THREADED_TEST(EvalInDetachedGlobal) {
11674 v8::Isolate* isolate = CcTest::isolate(); 11674 v8::Isolate* isolate = CcTest::isolate();
11675 v8::HandleScope scope(isolate); 11675 v8::HandleScope scope(isolate);
11676 11676
11677 v8::Local<Context> context0 = Context::New(isolate); 11677 v8::Local<Context> context0 = Context::New(isolate);
11678 v8::Local<Context> context1 = Context::New(isolate); 11678 v8::Local<Context> context1 = Context::New(isolate);
11679 Local<String> token = v8_str("<security token>");
11680 context0->SetSecurityToken(token);
11681 context1->SetSecurityToken(token);
11679 11682
11680 // Set up function in context0 that uses eval from context0. 11683 // Set up function in context0 that uses eval from context0.
11681 context0->Enter(); 11684 context0->Enter();
11682 v8::Local<v8::Value> fun = CompileRun( 11685 v8::Local<v8::Value> fun = CompileRun(
11683 "var x = 42;" 11686 "var x = 42;"
11684 "(function() {" 11687 "(function() {"
11685 " var e = eval;" 11688 " var e = eval;"
11686 " return function(s) { return e(s); }" 11689 " return function(s) { return e(s); }"
11687 "})()"); 11690 "})()");
11688 context0->Exit(); 11691 context0->Exit();
11689 11692
11690 // Put the function into context1 and call it before and after 11693 // Put the function into context1 and call it before and after
11691 // detaching the global. Before detaching, the call succeeds and 11694 // detaching the global. Before detaching, the call succeeds and
11692 // after detaching and exception is thrown. 11695 // after detaching undefined is returned.
11693 context1->Enter(); 11696 context1->Enter();
11694 CHECK(context1->Global()->Set(context1, v8_str("fun"), fun).FromJust()); 11697 CHECK(context1->Global()->Set(context1, v8_str("fun"), fun).FromJust());
11695 v8::Local<v8::Value> x_value = CompileRun("fun('x')"); 11698 v8::Local<v8::Value> x_value = CompileRun("fun('x')");
11696 CHECK_EQ(42, x_value->Int32Value(context1).FromJust()); 11699 CHECK_EQ(42, x_value->Int32Value(context1).FromJust());
11697 context0->DetachGlobal(); 11700 context0->DetachGlobal();
11698 v8::TryCatch catcher(isolate);
11699 x_value = CompileRun("fun('x')"); 11701 x_value = CompileRun("fun('x')");
11700 CHECK_EQ(42, x_value->Int32Value(context1).FromJust()); 11702 CHECK(x_value->IsUndefined());
11701 context1->Exit(); 11703 context1->Exit();
11702 } 11704 }
11703 11705
11704 11706
11705 THREADED_TEST(CrossLazyLoad) { 11707 THREADED_TEST(CrossLazyLoad) {
11706 v8::HandleScope scope(CcTest::isolate()); 11708 v8::HandleScope scope(CcTest::isolate());
11707 LocalContext other; 11709 LocalContext other;
11708 LocalContext current; 11710 LocalContext current;
11709 11711
11710 Local<String> token = v8_str("<security token>"); 11712 Local<String> token = v8_str("<security token>");
(...skipping 13750 matching lines...) Expand 10 before | Expand all | Expand 10 after
25461 25463
25462 // Put the function into context1 and call it. Since the access check 25464 // Put the function into context1 and call it. Since the access check
25463 // callback always returns true, the call succeeds even though the tokens 25465 // callback always returns true, the call succeeds even though the tokens
25464 // are different. 25466 // are different.
25465 context1->Enter(); 25467 context1->Enter();
25466 context1->Global()->Set(context1, v8_str("fun"), fun).FromJust(); 25468 context1->Global()->Set(context1, v8_str("fun"), fun).FromJust();
25467 v8::Local<v8::Value> x_value = CompileRun("fun('x')"); 25469 v8::Local<v8::Value> x_value = CompileRun("fun('x')");
25468 CHECK_EQ(42, x_value->Int32Value(context1).FromJust()); 25470 CHECK_EQ(42, x_value->Int32Value(context1).FromJust());
25469 context1->Exit(); 25471 context1->Exit();
25470 } 25472 }
OLDNEW
« no previous file with comments | « src/builtins/builtins-global.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698