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