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

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

Issue 781953002: Allow eval in detached contexts (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years 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/v8natives.js ('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 11531 matching lines...) Expand 10 before | Expand all | Expand 10 after
11542 11542
11543 // Check that you cannot use 'eval.call' with another object than the 11543 // Check that you cannot use 'eval.call' with another object than the
11544 // current global object. 11544 // current global object.
11545 script = v8_compile("other.y = 1; eval.call(other, 'y')"); 11545 script = v8_compile("other.y = 1; eval.call(other, 'y')");
11546 result = script->Run(); 11546 result = script->Run();
11547 CHECK(try_catch.HasCaught()); 11547 CHECK(try_catch.HasCaught());
11548 } 11548 }
11549 11549
11550 11550
11551 // Test that calling eval in a context which has been detached from 11551 // Test that calling eval in a context which has been detached from
11552 // its global throws an exception. This behavior is consistent with 11552 // its global proxy works.
11553 // other JavaScript implementations.
11554 THREADED_TEST(EvalInDetachedGlobal) { 11553 THREADED_TEST(EvalInDetachedGlobal) {
11555 v8::Isolate* isolate = CcTest::isolate(); 11554 v8::Isolate* isolate = CcTest::isolate();
11556 v8::HandleScope scope(isolate); 11555 v8::HandleScope scope(isolate);
11557 11556
11558 v8::Local<Context> context0 = Context::New(isolate); 11557 v8::Local<Context> context0 = Context::New(isolate);
11559 v8::Local<Context> context1 = Context::New(isolate); 11558 v8::Local<Context> context1 = Context::New(isolate);
11560 11559
11561 // Set up function in context0 that uses eval from context0. 11560 // Set up function in context0 that uses eval from context0.
11562 context0->Enter(); 11561 context0->Enter();
11563 v8::Handle<v8::Value> fun = 11562 v8::Handle<v8::Value> fun =
11564 CompileRun("var x = 42;" 11563 CompileRun("var x = 42;"
11565 "(function() {" 11564 "(function() {"
11566 " var e = eval;" 11565 " var e = eval;"
11567 " return function(s) { return e(s); }" 11566 " return function(s) { return e(s); }"
11568 "})()"); 11567 "})()");
11569 context0->Exit(); 11568 context0->Exit();
11570 11569
11571 // Put the function into context1 and call it before and after 11570 // Put the function into context1 and call it before and after
11572 // detaching the global. Before detaching, the call succeeds and 11571 // detaching the global. Before detaching, the call succeeds and
11573 // after detaching and exception is thrown. 11572 // after detaching and exception is thrown.
11574 context1->Enter(); 11573 context1->Enter();
11575 context1->Global()->Set(v8_str("fun"), fun); 11574 context1->Global()->Set(v8_str("fun"), fun);
11576 v8::Handle<v8::Value> x_value = CompileRun("fun('x')"); 11575 v8::Handle<v8::Value> x_value = CompileRun("fun('x')");
11577 CHECK_EQ(42, x_value->Int32Value()); 11576 CHECK_EQ(42, x_value->Int32Value());
11578 context0->DetachGlobal(); 11577 context0->DetachGlobal();
11579 v8::TryCatch catcher; 11578 v8::TryCatch catcher;
11580 x_value = CompileRun("fun('x')"); 11579 x_value = CompileRun("fun('x')");
11581 CHECK(x_value.IsEmpty()); 11580 CHECK_EQ(42, x_value->Int32Value());
11582 CHECK(catcher.HasCaught());
11583 context1->Exit(); 11581 context1->Exit();
11584 } 11582 }
11585 11583
11586 11584
11587 THREADED_TEST(CrossLazyLoad) { 11585 THREADED_TEST(CrossLazyLoad) {
11588 v8::HandleScope scope(CcTest::isolate()); 11586 v8::HandleScope scope(CcTest::isolate());
11589 LocalContext other; 11587 LocalContext other;
11590 LocalContext current; 11588 LocalContext current;
11591 11589
11592 Local<String> token = v8_str("<security token>"); 11590 Local<String> token = v8_str("<security token>");
(...skipping 12877 matching lines...) Expand 10 before | Expand all | Expand 10 after
24470 v8::HandleScope scope(CcTest::isolate()); 24468 v8::HandleScope scope(CcTest::isolate());
24471 RandomLengthOneByteResource* r = 24469 RandomLengthOneByteResource* r =
24472 new RandomLengthOneByteResource(i::String::kMaxLength); 24470 new RandomLengthOneByteResource(i::String::kMaxLength);
24473 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), r); 24471 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), r);
24474 CHECK(!str.IsEmpty()); 24472 CHECK(!str.IsEmpty());
24475 v8::TryCatch try_catch; 24473 v8::TryCatch try_catch;
24476 v8::Local<v8::String> result = v8::String::Concat(str, str); 24474 v8::Local<v8::String> result = v8::String::Concat(str, str);
24477 CHECK(result.IsEmpty()); 24475 CHECK(result.IsEmpty());
24478 CHECK(!try_catch.HasCaught()); 24476 CHECK(!try_catch.HasCaught());
24479 } 24477 }
OLDNEW
« no previous file with comments | « src/v8natives.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698