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 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 { | 1039 { |
1040 DisallowCompilation no_compile_expected(isolate); | 1040 DisallowCompilation no_compile_expected(isolate); |
1041 copy = Compiler::CompileScript( | 1041 copy = Compiler::CompileScript( |
1042 source_str, Handle<String>(), 0, 0, false, | 1042 source_str, Handle<String>(), 0, 0, false, |
1043 Handle<Context>(isolate->native_context()), NULL, &cache, | 1043 Handle<Context>(isolate->native_context()), NULL, &cache, |
1044 v8::ScriptCompiler::kConsumeCodeCache, NOT_NATIVES_CODE); | 1044 v8::ScriptCompiler::kConsumeCodeCache, NOT_NATIVES_CODE); |
1045 } | 1045 } |
1046 CHECK_NE(*orig, *copy); | 1046 CHECK_NE(*orig, *copy); |
1047 | 1047 |
1048 Handle<JSFunction> copy_fun = | 1048 Handle<JSFunction> copy_fun = |
1049 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 1049 f->NewFunctionFromSharedFunctionInfo(copy, isolate->native_context()); |
1050 copy, isolate->native_context()); | |
1051 | 1050 |
1052 Handle<Object> copy_result = | 1051 Handle<Object> copy_result = |
1053 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); | 1052 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); |
1054 | 1053 |
1055 CHECK_EQ(42.0f, copy_result->Number()); | 1054 CHECK_EQ(42.0f, copy_result->Number()); |
1056 | 1055 |
1057 delete cache; | 1056 delete cache; |
1058 string.Dispose(); | 1057 string.Dispose(); |
1059 } | 1058 } |
1060 | 1059 |
1061 | 1060 |
| 1061 TEST(SerializeToplevelExternalScriptName) { |
| 1062 FLAG_serialize_toplevel = true; |
| 1063 LocalContext context; |
| 1064 Isolate* isolate = CcTest::i_isolate(); |
| 1065 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. |
| 1066 |
| 1067 Factory* f = isolate->factory(); |
| 1068 |
| 1069 v8::HandleScope scope(CcTest::isolate()); |
| 1070 |
| 1071 const char* source = |
| 1072 "var a = [1, 2, 3, 4];" |
| 1073 "a.reduce(function(x, y) { return x + y }, 0)"; |
| 1074 |
| 1075 Handle<String> source_string = |
| 1076 f->NewStringFromUtf8(CStrVector(source)).ToHandleChecked(); |
| 1077 |
| 1078 const SerializerOneByteResource one_byte_resource("one_byte", 8); |
| 1079 Handle<String> name = |
| 1080 f->NewExternalStringFromOneByte(&one_byte_resource).ToHandleChecked(); |
| 1081 CHECK(name->IsExternalOneByteString()); |
| 1082 CHECK(!name->IsInternalizedString()); |
| 1083 |
| 1084 Handle<JSObject> global(isolate->context()->global_object()); |
| 1085 ScriptData* cache = NULL; |
| 1086 |
| 1087 Handle<SharedFunctionInfo> orig = Compiler::CompileScript( |
| 1088 source_string, name, 0, 0, false, |
| 1089 Handle<Context>(isolate->native_context()), NULL, &cache, |
| 1090 v8::ScriptCompiler::kProduceCodeCache, NOT_NATIVES_CODE); |
| 1091 |
| 1092 Handle<SharedFunctionInfo> copy; |
| 1093 { |
| 1094 DisallowCompilation no_compile_expected(isolate); |
| 1095 copy = Compiler::CompileScript( |
| 1096 source_string, name, 0, 0, false, |
| 1097 Handle<Context>(isolate->native_context()), NULL, &cache, |
| 1098 v8::ScriptCompiler::kConsumeCodeCache, NOT_NATIVES_CODE); |
| 1099 } |
| 1100 CHECK_NE(*orig, *copy); |
| 1101 |
| 1102 Handle<JSFunction> copy_fun = |
| 1103 f->NewFunctionFromSharedFunctionInfo(copy, isolate->native_context()); |
| 1104 |
| 1105 Handle<Object> copy_result = |
| 1106 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); |
| 1107 |
| 1108 CHECK_EQ(10.0f, copy_result->Number()); |
| 1109 |
| 1110 delete cache; |
| 1111 } |
| 1112 |
| 1113 |
1062 TEST(SerializeToplevelIsolates) { | 1114 TEST(SerializeToplevelIsolates) { |
1063 FLAG_serialize_toplevel = true; | 1115 FLAG_serialize_toplevel = true; |
1064 | 1116 |
1065 const char* source = "function f() { return 'abc'; }; f() + 'def'"; | 1117 const char* source = "function f() { return 'abc'; }; f() + 'def'"; |
1066 v8::ScriptCompiler::CachedData* cache; | 1118 v8::ScriptCompiler::CachedData* cache; |
1067 | 1119 |
1068 v8::Isolate* isolate1 = v8::Isolate::New(); | 1120 v8::Isolate* isolate1 = v8::Isolate::New(); |
1069 { | 1121 { |
1070 v8::Isolate::Scope iscope(isolate1); | 1122 v8::Isolate::Scope iscope(isolate1); |
1071 v8::HandleScope scope(isolate1); | 1123 v8::HandleScope scope(isolate1); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 { | 1155 { |
1104 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); | 1156 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); |
1105 script = v8::ScriptCompiler::CompileUnbound( | 1157 script = v8::ScriptCompiler::CompileUnbound( |
1106 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); | 1158 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); |
1107 } | 1159 } |
1108 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); | 1160 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
1109 CHECK(result->ToString()->Equals(v8_str("abcdef"))); | 1161 CHECK(result->ToString()->Equals(v8_str("abcdef"))); |
1110 } | 1162 } |
1111 isolate2->Dispose(); | 1163 isolate2->Dispose(); |
1112 } | 1164 } |
OLD | NEW |