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

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

Issue 15837007: remove use of context scope with persistent argument (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « src/d8.cc ('k') | test/cctest/test-lockers.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 17309 matching lines...) Expand 10 before | Expand all | Expand 10 after
17320 v8::Isolate* isolate1 = v8::Isolate::New(); 17320 v8::Isolate* isolate1 = v8::Isolate::New();
17321 isolate1->Enter(); 17321 isolate1->Enter();
17322 v8::Persistent<v8::Context> context1; 17322 v8::Persistent<v8::Context> context1;
17323 { 17323 {
17324 v8::HandleScope scope(isolate1); 17324 v8::HandleScope scope(isolate1);
17325 context1.Reset(isolate1, Context::New(isolate1)); 17325 context1.Reset(isolate1, Context::New(isolate1));
17326 } 17326 }
17327 17327
17328 { 17328 {
17329 v8::HandleScope scope(isolate1); 17329 v8::HandleScope scope(isolate1);
17330 v8::Context::Scope cscope(isolate1, context1); 17330 v8::Local<v8::Context> context =
17331 v8::Local<v8::Context>::New(isolate1, context1);
17332 v8::Context::Scope context_scope(context);
17331 // Run something in new isolate. 17333 // Run something in new isolate.
17332 CompileRun("var foo = 'isolate 1';"); 17334 CompileRun("var foo = 'isolate 1';");
17333 ExpectString("function f() { return foo; }; f()", "isolate 1"); 17335 ExpectString("function f() { return foo; }; f()", "isolate 1");
17334 } 17336 }
17335 17337
17336 // Run isolate 2. 17338 // Run isolate 2.
17337 v8::Isolate* isolate2 = v8::Isolate::New(); 17339 v8::Isolate* isolate2 = v8::Isolate::New();
17338 v8::Persistent<v8::Context> context2; 17340 v8::Persistent<v8::Context> context2;
17339 17341
17340 { 17342 {
17341 v8::Isolate::Scope iscope(isolate2); 17343 v8::Isolate::Scope iscope(isolate2);
17342 v8::HandleScope scope(isolate2); 17344 v8::HandleScope scope(isolate2);
17343 context2.Reset(isolate2, Context::New(isolate2)); 17345 context2.Reset(isolate2, Context::New(isolate2));
17344 v8::Context::Scope cscope(isolate2, context2); 17346 v8::Local<v8::Context> context =
17347 v8::Local<v8::Context>::New(isolate2, context2);
17348 v8::Context::Scope context_scope(context);
17345 17349
17346 // Run something in new isolate. 17350 // Run something in new isolate.
17347 CompileRun("var foo = 'isolate 2';"); 17351 CompileRun("var foo = 'isolate 2';");
17348 ExpectString("function f() { return foo; }; f()", "isolate 2"); 17352 ExpectString("function f() { return foo; }; f()", "isolate 2");
17349 } 17353 }
17350 17354
17351 { 17355 {
17352 v8::HandleScope scope(isolate1); 17356 v8::HandleScope scope(isolate1);
17353 v8::Context::Scope cscope(isolate1, context1); 17357 v8::Local<v8::Context> context =
17358 v8::Local<v8::Context>::New(isolate1, context1);
17359 v8::Context::Scope context_scope(context);
17354 // Now again in isolate 1 17360 // Now again in isolate 1
17355 ExpectString("function f() { return foo; }; f()", "isolate 1"); 17361 ExpectString("function f() { return foo; }; f()", "isolate 1");
17356 } 17362 }
17357 17363
17358 isolate1->Exit(); 17364 isolate1->Exit();
17359 17365
17360 // Run some stuff in default isolate. 17366 // Run some stuff in default isolate.
17361 v8::Persistent<v8::Context> context_default; 17367 v8::Persistent<v8::Context> context_default;
17362 { 17368 {
17363 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 17369 v8::Isolate* isolate = v8::Isolate::GetCurrent();
17364 v8::Isolate::Scope iscope(isolate); 17370 v8::Isolate::Scope iscope(isolate);
17365 v8::HandleScope scope(isolate); 17371 v8::HandleScope scope(isolate);
17366 context_default.Reset(isolate, Context::New(isolate)); 17372 context_default.Reset(isolate, Context::New(isolate));
17367 } 17373 }
17368 17374
17369 { 17375 {
17370 v8::HandleScope scope(v8::Isolate::GetCurrent()); 17376 v8::HandleScope scope(v8::Isolate::GetCurrent());
17371 v8::Context::Scope cscope(v8::Isolate::GetCurrent(), context_default); 17377 v8::Local<v8::Context> context =
17378 v8::Local<v8::Context>::New(v8::Isolate::GetCurrent(), context_default);
17379 v8::Context::Scope context_scope(context);
17372 // Variables in other isolates should be not available, verify there 17380 // Variables in other isolates should be not available, verify there
17373 // is an exception. 17381 // is an exception.
17374 ExpectTrue("function f() {" 17382 ExpectTrue("function f() {"
17375 " try {" 17383 " try {"
17376 " foo;" 17384 " foo;"
17377 " return false;" 17385 " return false;"
17378 " } catch(e) {" 17386 " } catch(e) {"
17379 " return true;" 17387 " return true;"
17380 " }" 17388 " }"
17381 "};" 17389 "};"
17382 "var isDefaultIsolate = true;" 17390 "var isDefaultIsolate = true;"
17383 "f()"); 17391 "f()");
17384 } 17392 }
17385 17393
17386 isolate1->Enter(); 17394 isolate1->Enter();
17387 17395
17388 { 17396 {
17389 v8::Isolate::Scope iscope(isolate2); 17397 v8::Isolate::Scope iscope(isolate2);
17390 v8::HandleScope scope(v8::Isolate::GetCurrent()); 17398 v8::HandleScope scope(v8::Isolate::GetCurrent());
17391 v8::Context::Scope cscope(isolate2, context2); 17399 v8::Local<v8::Context> context =
17400 v8::Local<v8::Context>::New(isolate2, context2);
17401 v8::Context::Scope context_scope(context);
17392 ExpectString("function f() { return foo; }; f()", "isolate 2"); 17402 ExpectString("function f() { return foo; }; f()", "isolate 2");
17393 } 17403 }
17394 17404
17395 { 17405 {
17396 v8::HandleScope scope(v8::Isolate::GetCurrent()); 17406 v8::HandleScope scope(v8::Isolate::GetCurrent());
17397 v8::Context::Scope cscope(v8::Isolate::GetCurrent(), context1); 17407 v8::Local<v8::Context> context =
17408 v8::Local<v8::Context>::New(v8::Isolate::GetCurrent(), context1);
17409 v8::Context::Scope context_scope(context);
17398 ExpectString("function f() { return foo; }; f()", "isolate 1"); 17410 ExpectString("function f() { return foo; }; f()", "isolate 1");
17399 } 17411 }
17400 17412
17401 { 17413 {
17402 v8::Isolate::Scope iscope(isolate2); 17414 v8::Isolate::Scope iscope(isolate2);
17403 context2.Dispose(context2->GetIsolate()); 17415 context2.Dispose(context2->GetIsolate());
17404 } 17416 }
17405 17417
17406 context1.Dispose(context1->GetIsolate()); 17418 context1.Dispose(context1->GetIsolate());
17407 isolate1->Exit(); 17419 isolate1->Exit();
17408 17420
17409 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 17421 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
17410 last_location = last_message = NULL; 17422 last_location = last_message = NULL;
17411 17423
17412 isolate1->Dispose(); 17424 isolate1->Dispose();
17413 CHECK_EQ(last_location, NULL); 17425 CHECK_EQ(last_location, NULL);
17414 CHECK_EQ(last_message, NULL); 17426 CHECK_EQ(last_message, NULL);
17415 17427
17416 isolate2->Dispose(); 17428 isolate2->Dispose();
17417 CHECK_EQ(last_location, NULL); 17429 CHECK_EQ(last_location, NULL);
17418 CHECK_EQ(last_message, NULL); 17430 CHECK_EQ(last_message, NULL);
17419 17431
17420 // Check that default isolate still runs. 17432 // Check that default isolate still runs.
17421 { 17433 {
17422 v8::HandleScope scope(v8::Isolate::GetCurrent()); 17434 v8::HandleScope scope(v8::Isolate::GetCurrent());
17423 v8::Context::Scope cscope(v8::Isolate::GetCurrent(), context_default); 17435 v8::Local<v8::Context> context =
17436 v8::Local<v8::Context>::New(v8::Isolate::GetCurrent(), context_default);
17437 v8::Context::Scope context_scope(context);
17424 ExpectTrue("function f() { return isDefaultIsolate; }; f()"); 17438 ExpectTrue("function f() { return isDefaultIsolate; }; f()");
17425 } 17439 }
17426 } 17440 }
17427 17441
17428 static int CalcFibonacci(v8::Isolate* isolate, int limit) { 17442 static int CalcFibonacci(v8::Isolate* isolate, int limit) {
17429 v8::Isolate::Scope isolate_scope(isolate); 17443 v8::Isolate::Scope isolate_scope(isolate);
17430 v8::HandleScope scope(isolate); 17444 v8::HandleScope scope(isolate);
17431 LocalContext context; 17445 LocalContext context;
17432 i::ScopedVector<char> code(1024); 17446 i::ScopedVector<char> code(1024);
17433 i::OS::SNPrintF(code, "function fib(n) {" 17447 i::OS::SNPrintF(code, "function fib(n) {"
(...skipping 1894 matching lines...) Expand 10 before | Expand all | Expand 10 after
19328 i::Semaphore* sem_; 19342 i::Semaphore* sem_;
19329 volatile int sem_value_; 19343 volatile int sem_value_;
19330 }; 19344 };
19331 19345
19332 19346
19333 THREADED_TEST(SemaphoreInterruption) { 19347 THREADED_TEST(SemaphoreInterruption) {
19334 ThreadInterruptTest().RunTest(); 19348 ThreadInterruptTest().RunTest();
19335 } 19349 }
19336 19350
19337 #endif // WIN32 19351 #endif // WIN32
OLDNEW
« no previous file with comments | « src/d8.cc ('k') | test/cctest/test-lockers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698