OLD | NEW |
1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 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 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 v8::Local<v8::Context> context = v8::Context::New(isolate2); | 741 v8::Local<v8::Context> context = v8::Context::New(isolate2); |
742 delete[] data2.data; // We can dispose of the snapshot blob now. | 742 delete[] data2.data; // We can dispose of the snapshot blob now. |
743 v8::Context::Scope c_scope(context); | 743 v8::Context::Scope c_scope(context); |
744 CHECK_EQ(86, CompileRun("f()")->ToInt32(isolate2)->Int32Value()); | 744 CHECK_EQ(86, CompileRun("f()")->ToInt32(isolate2)->Int32Value()); |
745 CHECK_EQ(43, CompileRun("g()")->ToInt32(isolate2)->Int32Value()); | 745 CHECK_EQ(43, CompileRun("g()")->ToInt32(isolate2)->Int32Value()); |
746 } | 746 } |
747 isolate2->Dispose(); | 747 isolate2->Dispose(); |
748 } | 748 } |
749 | 749 |
750 | 750 |
| 751 TEST(PerIsolateSnapshotBlobsWithLocker) { |
| 752 // Disable experimental natives that are loaded after deserialization. |
| 753 FLAG_harmony_shipping = false; |
| 754 FlagList::EnforceFlagImplications(); |
| 755 |
| 756 v8::Isolate* isolate0 = v8::Isolate::New(); |
| 757 { |
| 758 v8::Locker locker(isolate0); |
| 759 v8::Isolate::Scope i_scope(isolate0); |
| 760 v8::HandleScope h_scope(isolate0); |
| 761 v8::Local<v8::Context> context = v8::Context::New(isolate0); |
| 762 v8::Context::Scope c_scope(context); |
| 763 CHECK_EQ(1, CompileRun("Math.cos(0)")->ToInt32(isolate0)->Int32Value()); |
| 764 } |
| 765 isolate0->Dispose(); |
| 766 |
| 767 const char* source1 = "function f() { return 42; }"; |
| 768 const char* source2 = |
| 769 "function f() { return g() * 2; }" |
| 770 "function g() { return 43; }"; |
| 771 |
| 772 v8::StartupData data1 = v8::V8::CreateSnapshotDataBlob(source1); |
| 773 v8::StartupData data2 = v8::V8::CreateSnapshotDataBlob(source2); |
| 774 |
| 775 v8::Isolate::CreateParams params1; |
| 776 params1.snapshot_blob = &data1; |
| 777 v8::Isolate* isolate1 = v8::Isolate::New(params1); |
| 778 { |
| 779 v8::Locker locker(isolate1); |
| 780 v8::Isolate::Scope i_scope(isolate1); |
| 781 v8::HandleScope h_scope(isolate1); |
| 782 v8::Local<v8::Context> context = v8::Context::New(isolate1); |
| 783 delete[] data1.data; // We can dispose of the snapshot blob now. |
| 784 v8::Context::Scope c_scope(context); |
| 785 CHECK_EQ(42, CompileRun("f()")->ToInt32(isolate1)->Int32Value()); |
| 786 CHECK(CompileRun("this.g")->IsUndefined()); |
| 787 } |
| 788 isolate1->Dispose(); |
| 789 |
| 790 v8::Isolate::CreateParams params2; |
| 791 params2.snapshot_blob = &data2; |
| 792 v8::Isolate* isolate2 = v8::Isolate::New(params2); |
| 793 { |
| 794 v8::Locker locker(isolate2); |
| 795 v8::Isolate::Scope i_scope(isolate2); |
| 796 v8::HandleScope h_scope(isolate2); |
| 797 v8::Local<v8::Context> context = v8::Context::New(isolate2); |
| 798 delete[] data2.data; // We can dispose of the snapshot blob now. |
| 799 v8::Context::Scope c_scope(context); |
| 800 CHECK_EQ(86, CompileRun("f()")->ToInt32(isolate2)->Int32Value()); |
| 801 CHECK_EQ(43, CompileRun("g()")->ToInt32(isolate2)->Int32Value()); |
| 802 } |
| 803 isolate2->Dispose(); |
| 804 } |
| 805 |
| 806 |
751 TEST(TestThatAlwaysSucceeds) { | 807 TEST(TestThatAlwaysSucceeds) { |
752 } | 808 } |
753 | 809 |
754 | 810 |
755 TEST(TestThatAlwaysFails) { | 811 TEST(TestThatAlwaysFails) { |
756 bool ArtificialFailure = false; | 812 bool ArtificialFailure = false; |
757 CHECK(ArtificialFailure); | 813 CHECK(ArtificialFailure); |
758 } | 814 } |
759 | 815 |
760 | 816 |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1460 { | 1516 { |
1461 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); | 1517 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); |
1462 script = v8::ScriptCompiler::CompileUnbound( | 1518 script = v8::ScriptCompiler::CompileUnbound( |
1463 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); | 1519 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); |
1464 } | 1520 } |
1465 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); | 1521 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
1466 CHECK(result->ToString(isolate2)->Equals(v8_str("XY"))); | 1522 CHECK(result->ToString(isolate2)->Equals(v8_str("XY"))); |
1467 } | 1523 } |
1468 isolate2->Dispose(); | 1524 isolate2->Dispose(); |
1469 } | 1525 } |
OLD | NEW |