| OLD | NEW |
| 1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 11461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11472 // Still entered, should fail. | 11472 // Still entered, should fail. |
| 11473 isolate->Dispose(); | 11473 isolate->Dispose(); |
| 11474 CHECK_NE(last_location, NULL); | 11474 CHECK_NE(last_location, NULL); |
| 11475 CHECK_NE(last_message, NULL); | 11475 CHECK_NE(last_message, NULL); |
| 11476 } | 11476 } |
| 11477 | 11477 |
| 11478 TEST(RunTwoIsolatesOnSingleThread) { | 11478 TEST(RunTwoIsolatesOnSingleThread) { |
| 11479 // Run isolate 1. | 11479 // Run isolate 1. |
| 11480 v8::Isolate* isolate1 = v8::Isolate::New(); | 11480 v8::Isolate* isolate1 = v8::Isolate::New(); |
| 11481 isolate1->Enter(); | 11481 isolate1->Enter(); |
| 11482 v8::HandleScope scope1; | 11482 v8::Persistent<v8::Context> context1 = v8::Context::New(); |
| 11483 LocalContext context1; | |
| 11484 | 11483 |
| 11485 // Run something in new isolate. | 11484 { |
| 11486 CompileRun("var foo = 'isolate 1';"); | 11485 v8::Context::Scope cscope(context1); |
| 11487 ExpectString("function f() { return foo; }; f()", "isolate 1"); | 11486 v8::HandleScope scope; |
| 11487 // Run something in new isolate. |
| 11488 CompileRun("var foo = 'isolate 1';"); |
| 11489 ExpectString("function f() { return foo; }; f()", "isolate 1"); |
| 11490 } |
| 11488 | 11491 |
| 11489 // Run isolate 2. | 11492 // Run isolate 2. |
| 11490 v8::Isolate* isolate2 = v8::Isolate::New(); | 11493 v8::Isolate* isolate2 = v8::Isolate::New(); |
| 11491 isolate2->Enter(); | 11494 v8::Persistent<v8::Context> context2; |
| 11492 v8::HandleScope scope2; | |
| 11493 LocalContext context2; | |
| 11494 | 11495 |
| 11495 // Run something in new isolate. | 11496 { |
| 11496 CompileRun("var foo = 'isolate 2';"); | 11497 v8::Isolate::Scope iscope(isolate2); |
| 11497 ExpectString("function f() { return foo; }; f()", "isolate 2"); | 11498 context2 = v8::Context::New(); |
| 11499 v8::Context::Scope cscope(context2); |
| 11500 v8::HandleScope scope; |
| 11498 | 11501 |
| 11499 isolate2->Exit(); | 11502 // Run something in new isolate. |
| 11503 CompileRun("var foo = 'isolate 2';"); |
| 11504 ExpectString("function f() { return foo; }; f()", "isolate 2"); |
| 11505 } |
| 11500 | 11506 |
| 11501 // Now again in isolate 1 | 11507 { |
| 11502 | 11508 v8::Context::Scope cscope(context1); |
| 11503 ExpectString("function f() { return foo; }; f()", "isolate 1"); | 11509 v8::HandleScope scope; |
| 11510 // Now again in isolate 1 |
| 11511 ExpectString("function f() { return foo; }; f()", "isolate 1"); |
| 11512 } |
| 11504 | 11513 |
| 11505 isolate1->Exit(); | 11514 isolate1->Exit(); |
| 11506 | 11515 |
| 11507 // Run some stuff in default isolate. | 11516 // Run some stuff in default isolate. |
| 11508 v8::HandleScope scope_default; | 11517 v8::Persistent<v8::Context> context_default = v8::Context::New(); |
| 11509 LocalContext context_default; | |
| 11510 | 11518 |
| 11511 // Variables in other isolates should be not available, verify there | 11519 { |
| 11512 // is an exception. | 11520 v8::Context::Scope cscope(context_default); |
| 11513 ExpectTrue("function f() {" | 11521 v8::HandleScope scope; |
| 11514 " try {" | 11522 // Variables in other isolates should be not available, verify there |
| 11515 " foo;" | 11523 // is an exception. |
| 11516 " return false;" | 11524 ExpectTrue("function f() {" |
| 11517 " } catch(e) {" | 11525 " try {" |
| 11518 " return true;" | 11526 " foo;" |
| 11519 " }" | 11527 " return false;" |
| 11520 "};" | 11528 " } catch(e) {" |
| 11521 "var isDefaultIsolate = true;" | 11529 " return true;" |
| 11522 "f()"); | 11530 " }" |
| 11531 "};" |
| 11532 "var isDefaultIsolate = true;" |
| 11533 "f()"); |
| 11534 } |
| 11523 | 11535 |
| 11524 isolate1->Enter(); | 11536 isolate1->Enter(); |
| 11525 | 11537 |
| 11526 { | 11538 { |
| 11527 v8::Isolate::Scope isolate_scope(isolate2); | 11539 v8::Isolate::Scope iscope(isolate2); |
| 11540 v8::Context::Scope cscope(context2); |
| 11541 v8::HandleScope scope; |
| 11528 ExpectString("function f() { return foo; }; f()", "isolate 2"); | 11542 ExpectString("function f() { return foo; }; f()", "isolate 2"); |
| 11529 } | 11543 } |
| 11530 | 11544 |
| 11531 ExpectString("function f() { return foo; }; f()", "isolate 1"); | 11545 { |
| 11546 v8::Context::Scope cscope(context1); |
| 11547 v8::HandleScope scope; |
| 11548 ExpectString("function f() { return foo; }; f()", "isolate 1"); |
| 11549 } |
| 11550 |
| 11551 { |
| 11552 v8::Isolate::Scope iscope(isolate2); |
| 11553 context2.Dispose(); |
| 11554 } |
| 11555 |
| 11556 context1.Dispose(); |
| 11532 isolate1->Exit(); | 11557 isolate1->Exit(); |
| 11533 | 11558 |
| 11534 v8::V8::SetFatalErrorHandler(StoringErrorCallback); | 11559 v8::V8::SetFatalErrorHandler(StoringErrorCallback); |
| 11535 last_location = last_message = NULL; | 11560 last_location = last_message = NULL; |
| 11536 | 11561 |
| 11537 isolate1->Dispose(); | 11562 isolate1->Dispose(); |
| 11538 CHECK_EQ(last_location, NULL); | 11563 CHECK_EQ(last_location, NULL); |
| 11539 CHECK_EQ(last_message, NULL); | 11564 CHECK_EQ(last_message, NULL); |
| 11540 | 11565 |
| 11541 isolate2->Dispose(); | 11566 isolate2->Dispose(); |
| 11542 CHECK_EQ(last_location, NULL); | 11567 CHECK_EQ(last_location, NULL); |
| 11543 CHECK_EQ(last_message, NULL); | 11568 CHECK_EQ(last_message, NULL); |
| 11544 | 11569 |
| 11545 // Check that default isolate still runs. | 11570 // Check that default isolate still runs. |
| 11546 ExpectTrue("function f() { return isDefaultIsolate; }; f()"); | 11571 { |
| 11572 v8::Context::Scope cscope(context_default); |
| 11573 v8::HandleScope scope; |
| 11574 ExpectTrue("function f() { return isDefaultIsolate; }; f()"); |
| 11575 } |
| 11547 } | 11576 } |
| 11548 | 11577 |
| 11549 static int CalcFibonacci(v8::Isolate* isolate, int limit) { | 11578 static int CalcFibonacci(v8::Isolate* isolate, int limit) { |
| 11550 v8::Isolate::Scope isolate_scope(isolate); | 11579 v8::Isolate::Scope isolate_scope(isolate); |
| 11551 v8::HandleScope scope; | 11580 v8::HandleScope scope; |
| 11552 LocalContext context; | 11581 LocalContext context; |
| 11553 i::ScopedVector<char> code(1024); | 11582 i::ScopedVector<char> code(1024); |
| 11554 i::OS::SNPrintF(code, "function fib(n) {" | 11583 i::OS::SNPrintF(code, "function fib(n) {" |
| 11555 " if (n <= 2) return 1;" | 11584 " if (n <= 2) return 1;" |
| 11556 " return fib(n-1) + fib(n-2);" | 11585 " return fib(n-1) + fib(n-2);" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11670 | 11699 |
| 11671 { | 11700 { |
| 11672 // Change the Boolean.prototype in the second context and check | 11701 // Change the Boolean.prototype in the second context and check |
| 11673 // that the right function gets called. | 11702 // that the right function gets called. |
| 11674 v8::HandleScope scope; | 11703 v8::HandleScope scope; |
| 11675 LocalContext context2; | 11704 LocalContext context2; |
| 11676 CompileRun("Boolean.prototype.toString = function() { return \"\"; }"); | 11705 CompileRun("Boolean.prototype.toString = function() { return \"\"; }"); |
| 11677 ExpectString(code, ""); | 11706 ExpectString(code, ""); |
| 11678 } | 11707 } |
| 11679 } | 11708 } |
| OLD | NEW |