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 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 delete cache; | 792 delete cache; |
793 } | 793 } |
794 | 794 |
795 | 795 |
796 TEST(SerializeToplevelIsolates) { | 796 TEST(SerializeToplevelIsolates) { |
797 FLAG_serialize_toplevel = true; | 797 FLAG_serialize_toplevel = true; |
798 | 798 |
799 const char* source = "function f() { return 'abc'; }; f() + 'def'"; | 799 const char* source = "function f() { return 'abc'; }; f() + 'def'"; |
800 v8::ScriptCompiler::CachedData* cache; | 800 v8::ScriptCompiler::CachedData* cache; |
801 | 801 |
802 v8::Isolate* isolate = v8::Isolate::New(); | 802 v8::Isolate* isolate1 = v8::Isolate::New(); |
| 803 v8::Isolate* isolate2 = v8::Isolate::New(); |
803 { | 804 { |
804 v8::Isolate::Scope iscope(isolate); | 805 v8::Isolate::Scope iscope(isolate1); |
805 v8::HandleScope scope(isolate); | 806 v8::HandleScope scope(isolate1); |
806 v8::Local<v8::Context> context = v8::Context::New(isolate); | 807 v8::Local<v8::Context> context = v8::Context::New(isolate1); |
807 v8::Context::Scope context_scope(context); | 808 v8::Context::Scope context_scope(context); |
808 | 809 |
809 v8::Local<v8::String> source_str = v8_str(source); | 810 v8::Local<v8::String> source_str = v8_str(source); |
810 v8::ScriptOrigin origin(v8_str("test")); | 811 v8::ScriptOrigin origin(v8_str("test")); |
811 v8::ScriptCompiler::Source source(source_str, origin); | 812 v8::ScriptCompiler::Source source(source_str, origin); |
812 v8::Local<v8::UnboundScript> script = v8::ScriptCompiler::CompileUnbound( | 813 v8::Local<v8::UnboundScript> script = v8::ScriptCompiler::CompileUnbound( |
813 isolate, &source, v8::ScriptCompiler::kProduceCodeCache); | 814 isolate1, &source, v8::ScriptCompiler::kProduceCodeCache); |
814 const v8::ScriptCompiler::CachedData* data = source.GetCachedData(); | 815 const v8::ScriptCompiler::CachedData* data = source.GetCachedData(); |
815 // Persist cached data. | 816 // Persist cached data. |
816 uint8_t* buffer = NewArray<uint8_t>(data->length); | 817 uint8_t* buffer = NewArray<uint8_t>(data->length); |
817 MemCopy(buffer, data->data, data->length); | 818 MemCopy(buffer, data->data, data->length); |
818 cache = new v8::ScriptCompiler::CachedData( | 819 cache = new v8::ScriptCompiler::CachedData( |
819 buffer, data->length, v8::ScriptCompiler::CachedData::BufferOwned); | 820 buffer, data->length, v8::ScriptCompiler::CachedData::BufferOwned); |
820 | 821 |
821 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); | 822 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
822 CHECK(result->ToString()->Equals(v8_str("abcdef"))); | 823 CHECK(result->ToString()->Equals(v8_str("abcdef"))); |
823 } | 824 } |
824 isolate->Dispose(); | 825 isolate1->Dispose(); |
825 | 826 |
826 isolate = v8::Isolate::New(); | |
827 { | 827 { |
828 v8::Isolate::Scope iscope(isolate); | 828 v8::Isolate::Scope iscope(isolate2); |
829 v8::HandleScope scope(isolate); | 829 v8::HandleScope scope(isolate2); |
830 v8::Local<v8::Context> context = v8::Context::New(isolate); | 830 v8::Local<v8::Context> context = v8::Context::New(isolate2); |
831 v8::Context::Scope context_scope(context); | 831 v8::Context::Scope context_scope(context); |
832 | 832 |
833 v8::Local<v8::String> source_str = v8_str(source); | 833 v8::Local<v8::String> source_str = v8_str(source); |
834 v8::ScriptOrigin origin(v8_str("test")); | 834 v8::ScriptOrigin origin(v8_str("test")); |
835 v8::ScriptCompiler::Source source(source_str, origin, cache); | 835 v8::ScriptCompiler::Source source(source_str, origin, cache); |
836 v8::Local<v8::UnboundScript> script; | 836 v8::Local<v8::UnboundScript> script; |
837 { | 837 { |
838 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate)); | 838 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); |
839 script = v8::ScriptCompiler::CompileUnbound( | 839 script = v8::ScriptCompiler::CompileUnbound( |
840 isolate, &source, v8::ScriptCompiler::kConsumeCodeCache); | 840 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); |
841 } | 841 } |
842 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); | 842 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
843 CHECK(result->ToString()->Equals(v8_str("abcdef"))); | 843 CHECK(result->ToString()->Equals(v8_str("abcdef"))); |
844 } | 844 } |
845 isolate->Dispose(); | 845 isolate2->Dispose(); |
846 } | 846 } |
OLD | NEW |