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 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 | 1155 |
1156 Handle<Object> copy_result = | 1156 Handle<Object> copy_result = |
1157 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); | 1157 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); |
1158 | 1158 |
1159 CHECK_EQ(10.0f, copy_result->Number()); | 1159 CHECK_EQ(10.0f, copy_result->Number()); |
1160 | 1160 |
1161 delete cache; | 1161 delete cache; |
1162 } | 1162 } |
1163 | 1163 |
1164 | 1164 |
| 1165 static bool toplevel_test_code_event_found = false; |
| 1166 |
| 1167 |
| 1168 static void SerializerCodeEventListener(const v8::JitCodeEvent* event) { |
| 1169 if (event->type == v8::JitCodeEvent::CODE_ADDED && |
| 1170 memcmp(event->name.str, "Script:~test", 12) == 0) { |
| 1171 toplevel_test_code_event_found = true; |
| 1172 } |
| 1173 } |
| 1174 |
| 1175 |
1165 TEST(SerializeToplevelIsolates) { | 1176 TEST(SerializeToplevelIsolates) { |
1166 FLAG_serialize_toplevel = true; | 1177 FLAG_serialize_toplevel = true; |
1167 | 1178 |
1168 const char* source = "function f() { return 'abc'; }; f() + 'def'"; | 1179 const char* source = "function f() { return 'abc'; }; f() + 'def'"; |
1169 v8::ScriptCompiler::CachedData* cache; | 1180 v8::ScriptCompiler::CachedData* cache; |
1170 | 1181 |
1171 v8::Isolate* isolate1 = v8::Isolate::New(); | 1182 v8::Isolate* isolate1 = v8::Isolate::New(); |
1172 { | 1183 { |
1173 v8::Isolate::Scope iscope(isolate1); | 1184 v8::Isolate::Scope iscope(isolate1); |
1174 v8::HandleScope scope(isolate1); | 1185 v8::HandleScope scope(isolate1); |
(...skipping 12 matching lines...) Expand all Loading... |
1187 MemCopy(buffer, data->data, data->length); | 1198 MemCopy(buffer, data->data, data->length); |
1188 cache = new v8::ScriptCompiler::CachedData( | 1199 cache = new v8::ScriptCompiler::CachedData( |
1189 buffer, data->length, v8::ScriptCompiler::CachedData::BufferOwned); | 1200 buffer, data->length, v8::ScriptCompiler::CachedData::BufferOwned); |
1190 | 1201 |
1191 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); | 1202 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
1192 CHECK(result->ToString()->Equals(v8_str("abcdef"))); | 1203 CHECK(result->ToString()->Equals(v8_str("abcdef"))); |
1193 } | 1204 } |
1194 isolate1->Dispose(); | 1205 isolate1->Dispose(); |
1195 | 1206 |
1196 v8::Isolate* isolate2 = v8::Isolate::New(); | 1207 v8::Isolate* isolate2 = v8::Isolate::New(); |
| 1208 isolate2->SetJitCodeEventHandler(v8::kJitCodeEventDefault, |
| 1209 SerializerCodeEventListener); |
| 1210 toplevel_test_code_event_found = false; |
1197 { | 1211 { |
1198 v8::Isolate::Scope iscope(isolate2); | 1212 v8::Isolate::Scope iscope(isolate2); |
1199 v8::HandleScope scope(isolate2); | 1213 v8::HandleScope scope(isolate2); |
1200 v8::Local<v8::Context> context = v8::Context::New(isolate2); | 1214 v8::Local<v8::Context> context = v8::Context::New(isolate2); |
1201 v8::Context::Scope context_scope(context); | 1215 v8::Context::Scope context_scope(context); |
1202 | 1216 |
1203 v8::Local<v8::String> source_str = v8_str(source); | 1217 v8::Local<v8::String> source_str = v8_str(source); |
1204 v8::ScriptOrigin origin(v8_str("test")); | 1218 v8::ScriptOrigin origin(v8_str("test")); |
1205 v8::ScriptCompiler::Source source(source_str, origin, cache); | 1219 v8::ScriptCompiler::Source source(source_str, origin, cache); |
1206 v8::Local<v8::UnboundScript> script; | 1220 v8::Local<v8::UnboundScript> script; |
1207 { | 1221 { |
1208 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); | 1222 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); |
1209 script = v8::ScriptCompiler::CompileUnbound( | 1223 script = v8::ScriptCompiler::CompileUnbound( |
1210 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); | 1224 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); |
1211 } | 1225 } |
1212 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); | 1226 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
1213 CHECK(result->ToString()->Equals(v8_str("abcdef"))); | 1227 CHECK(result->ToString()->Equals(v8_str("abcdef"))); |
1214 } | 1228 } |
| 1229 DCHECK(toplevel_test_code_event_found); |
1215 isolate2->Dispose(); | 1230 isolate2->Dispose(); |
1216 } | 1231 } |
1217 | 1232 |
1218 | 1233 |
1219 TEST(Bug3628) { | 1234 TEST(Bug3628) { |
1220 FLAG_serialize_toplevel = true; | 1235 FLAG_serialize_toplevel = true; |
1221 FLAG_harmony_scoping = true; | 1236 FLAG_harmony_scoping = true; |
1222 | 1237 |
1223 const char* source1 = "'use strict'; let x = 'X'"; | 1238 const char* source1 = "'use strict'; let x = 'X'"; |
1224 const char* source2 = "'use strict'; let y = 'Y'"; | 1239 const char* source2 = "'use strict'; let y = 'Y'"; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 { | 1287 { |
1273 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); | 1288 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); |
1274 script = v8::ScriptCompiler::CompileUnbound( | 1289 script = v8::ScriptCompiler::CompileUnbound( |
1275 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); | 1290 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); |
1276 } | 1291 } |
1277 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); | 1292 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
1278 CHECK(result->ToString()->Equals(v8_str("XY"))); | 1293 CHECK(result->ToString()->Equals(v8_str("XY"))); |
1279 } | 1294 } |
1280 isolate2->Dispose(); | 1295 isolate2->Dispose(); |
1281 } | 1296 } |
OLD | NEW |