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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 { | 278 { |
279 v8::HandleScope handle_scope(v8_isolate); | 279 v8::HandleScope handle_scope(v8_isolate); |
280 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); | 280 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); |
281 } | 281 } |
282 env.Reset(); | 282 env.Reset(); |
283 | 283 |
284 StartupSerializer startup_serializer( | 284 StartupSerializer startup_serializer( |
285 isolate, v8::SnapshotCreator::FunctionCodeHandling::kClear); | 285 isolate, v8::SnapshotCreator::FunctionCodeHandling::kClear); |
286 startup_serializer.SerializeStrongReferences(); | 286 startup_serializer.SerializeStrongReferences(); |
287 | 287 |
288 PartialSerializer partial_serializer(isolate, &startup_serializer, nullptr); | 288 PartialSerializer partial_serializer(isolate, &startup_serializer, |
| 289 v8::SerializeInternalFieldsCallback()); |
289 partial_serializer.Serialize(&raw_foo, false); | 290 partial_serializer.Serialize(&raw_foo, false); |
290 | 291 |
291 startup_serializer.SerializeWeakReferencesAndDeferred(); | 292 startup_serializer.SerializeWeakReferencesAndDeferred(); |
292 | 293 |
293 SnapshotData startup_snapshot(&startup_serializer); | 294 SnapshotData startup_snapshot(&startup_serializer); |
294 SnapshotData partial_snapshot(&partial_serializer); | 295 SnapshotData partial_snapshot(&partial_serializer); |
295 | 296 |
296 *partial_blob_out = WritePayload(partial_snapshot.RawData()); | 297 *partial_blob_out = WritePayload(partial_snapshot.RawData()); |
297 *startup_blob_out = WritePayload(startup_snapshot.RawData()); | 298 *startup_blob_out = WritePayload(startup_snapshot.RawData()); |
298 } | 299 } |
(...skipping 15 matching lines...) Expand all Loading... |
314 | 315 |
315 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 316 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
316 HandleScope handle_scope(isolate); | 317 HandleScope handle_scope(isolate); |
317 Handle<Object> root; | 318 Handle<Object> root; |
318 // Intentionally empty handle. The deserializer should not come across | 319 // Intentionally empty handle. The deserializer should not come across |
319 // any references to the global proxy in this test. | 320 // any references to the global proxy in this test. |
320 Handle<JSGlobalProxy> global_proxy = Handle<JSGlobalProxy>::null(); | 321 Handle<JSGlobalProxy> global_proxy = Handle<JSGlobalProxy>::null(); |
321 { | 322 { |
322 SnapshotData snapshot_data(partial_blob); | 323 SnapshotData snapshot_data(partial_blob); |
323 Deserializer deserializer(&snapshot_data); | 324 Deserializer deserializer(&snapshot_data); |
324 root = deserializer.DeserializePartial(isolate, global_proxy, nullptr) | 325 root = deserializer |
| 326 .DeserializePartial(isolate, global_proxy, |
| 327 v8::DeserializeInternalFieldsCallback()) |
325 .ToHandleChecked(); | 328 .ToHandleChecked(); |
326 CHECK(root->IsString()); | 329 CHECK(root->IsString()); |
327 } | 330 } |
328 | 331 |
329 Handle<Object> root2; | 332 Handle<Object> root2; |
330 { | 333 { |
331 SnapshotData snapshot_data(partial_blob); | 334 SnapshotData snapshot_data(partial_blob); |
332 Deserializer deserializer(&snapshot_data); | 335 Deserializer deserializer(&snapshot_data); |
333 root2 = deserializer.DeserializePartial(isolate, global_proxy, nullptr) | 336 root2 = deserializer |
| 337 .DeserializePartial(isolate, global_proxy, |
| 338 v8::DeserializeInternalFieldsCallback()) |
334 .ToHandleChecked(); | 339 .ToHandleChecked(); |
335 CHECK(root2->IsString()); | 340 CHECK(root2->IsString()); |
336 CHECK(root.is_identical_to(root2)); | 341 CHECK(root.is_identical_to(root2)); |
337 } | 342 } |
338 partial_blob.Dispose(); | 343 partial_blob.Dispose(); |
339 } | 344 } |
340 v8_isolate->Dispose(); | 345 v8_isolate->Dispose(); |
341 } | 346 } |
342 | 347 |
343 static void PartiallySerializeContext(Vector<const byte>* startup_blob_out, | 348 static void PartiallySerializeContext(Vector<const byte>* startup_blob_out, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 i::Object* raw_context = *v8::Utils::OpenPersistent(env); | 383 i::Object* raw_context = *v8::Utils::OpenPersistent(env); |
379 | 384 |
380 env.Reset(); | 385 env.Reset(); |
381 | 386 |
382 SnapshotByteSink startup_sink; | 387 SnapshotByteSink startup_sink; |
383 StartupSerializer startup_serializer( | 388 StartupSerializer startup_serializer( |
384 isolate, v8::SnapshotCreator::FunctionCodeHandling::kClear); | 389 isolate, v8::SnapshotCreator::FunctionCodeHandling::kClear); |
385 startup_serializer.SerializeStrongReferences(); | 390 startup_serializer.SerializeStrongReferences(); |
386 | 391 |
387 SnapshotByteSink partial_sink; | 392 SnapshotByteSink partial_sink; |
388 PartialSerializer partial_serializer(isolate, &startup_serializer, nullptr); | 393 PartialSerializer partial_serializer(isolate, &startup_serializer, |
| 394 v8::SerializeInternalFieldsCallback()); |
389 partial_serializer.Serialize(&raw_context, false); | 395 partial_serializer.Serialize(&raw_context, false); |
390 startup_serializer.SerializeWeakReferencesAndDeferred(); | 396 startup_serializer.SerializeWeakReferencesAndDeferred(); |
391 | 397 |
392 SnapshotData startup_snapshot(&startup_serializer); | 398 SnapshotData startup_snapshot(&startup_serializer); |
393 SnapshotData partial_snapshot(&partial_serializer); | 399 SnapshotData partial_snapshot(&partial_serializer); |
394 | 400 |
395 *partial_blob_out = WritePayload(partial_snapshot.RawData()); | 401 *partial_blob_out = WritePayload(partial_snapshot.RawData()); |
396 *startup_blob_out = WritePayload(startup_snapshot.RawData()); | 402 *startup_blob_out = WritePayload(startup_snapshot.RawData()); |
397 } | 403 } |
398 v8_isolate->Dispose(); | 404 v8_isolate->Dispose(); |
(...skipping 13 matching lines...) Expand all Loading... |
412 | 418 |
413 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 419 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
414 HandleScope handle_scope(isolate); | 420 HandleScope handle_scope(isolate); |
415 Handle<Object> root; | 421 Handle<Object> root; |
416 Handle<JSGlobalProxy> global_proxy = | 422 Handle<JSGlobalProxy> global_proxy = |
417 isolate->factory()->NewUninitializedJSGlobalProxy( | 423 isolate->factory()->NewUninitializedJSGlobalProxy( |
418 JSGlobalProxy::SizeWithInternalFields(0)); | 424 JSGlobalProxy::SizeWithInternalFields(0)); |
419 { | 425 { |
420 SnapshotData snapshot_data(partial_blob); | 426 SnapshotData snapshot_data(partial_blob); |
421 Deserializer deserializer(&snapshot_data); | 427 Deserializer deserializer(&snapshot_data); |
422 root = deserializer.DeserializePartial(isolate, global_proxy, nullptr) | 428 root = deserializer |
| 429 .DeserializePartial(isolate, global_proxy, |
| 430 v8::DeserializeInternalFieldsCallback()) |
423 .ToHandleChecked(); | 431 .ToHandleChecked(); |
424 CHECK(root->IsContext()); | 432 CHECK(root->IsContext()); |
425 CHECK(Handle<Context>::cast(root)->global_proxy() == *global_proxy); | 433 CHECK(Handle<Context>::cast(root)->global_proxy() == *global_proxy); |
426 } | 434 } |
427 | 435 |
428 Handle<Object> root2; | 436 Handle<Object> root2; |
429 { | 437 { |
430 SnapshotData snapshot_data(partial_blob); | 438 SnapshotData snapshot_data(partial_blob); |
431 Deserializer deserializer(&snapshot_data); | 439 Deserializer deserializer(&snapshot_data); |
432 root2 = deserializer.DeserializePartial(isolate, global_proxy, nullptr) | 440 root2 = deserializer |
| 441 .DeserializePartial(isolate, global_proxy, |
| 442 v8::DeserializeInternalFieldsCallback()) |
433 .ToHandleChecked(); | 443 .ToHandleChecked(); |
434 CHECK(root2->IsContext()); | 444 CHECK(root2->IsContext()); |
435 CHECK(!root.is_identical_to(root2)); | 445 CHECK(!root.is_identical_to(root2)); |
436 } | 446 } |
437 partial_blob.Dispose(); | 447 partial_blob.Dispose(); |
438 } | 448 } |
439 v8_isolate->Dispose(); | 449 v8_isolate->Dispose(); |
440 } | 450 } |
441 | 451 |
442 static void PartiallySerializeCustomContext( | 452 static void PartiallySerializeCustomContext( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 i::Object* raw_context = *v8::Utils::OpenPersistent(env); | 508 i::Object* raw_context = *v8::Utils::OpenPersistent(env); |
499 | 509 |
500 env.Reset(); | 510 env.Reset(); |
501 | 511 |
502 SnapshotByteSink startup_sink; | 512 SnapshotByteSink startup_sink; |
503 StartupSerializer startup_serializer( | 513 StartupSerializer startup_serializer( |
504 isolate, v8::SnapshotCreator::FunctionCodeHandling::kClear); | 514 isolate, v8::SnapshotCreator::FunctionCodeHandling::kClear); |
505 startup_serializer.SerializeStrongReferences(); | 515 startup_serializer.SerializeStrongReferences(); |
506 | 516 |
507 SnapshotByteSink partial_sink; | 517 SnapshotByteSink partial_sink; |
508 PartialSerializer partial_serializer(isolate, &startup_serializer, nullptr); | 518 PartialSerializer partial_serializer(isolate, &startup_serializer, |
| 519 v8::SerializeInternalFieldsCallback()); |
509 partial_serializer.Serialize(&raw_context, false); | 520 partial_serializer.Serialize(&raw_context, false); |
510 startup_serializer.SerializeWeakReferencesAndDeferred(); | 521 startup_serializer.SerializeWeakReferencesAndDeferred(); |
511 | 522 |
512 SnapshotData startup_snapshot(&startup_serializer); | 523 SnapshotData startup_snapshot(&startup_serializer); |
513 SnapshotData partial_snapshot(&partial_serializer); | 524 SnapshotData partial_snapshot(&partial_serializer); |
514 | 525 |
515 *partial_blob_out = WritePayload(partial_snapshot.RawData()); | 526 *partial_blob_out = WritePayload(partial_snapshot.RawData()); |
516 *startup_blob_out = WritePayload(startup_snapshot.RawData()); | 527 *startup_blob_out = WritePayload(startup_snapshot.RawData()); |
517 } | 528 } |
518 v8_isolate->Dispose(); | 529 v8_isolate->Dispose(); |
(...skipping 13 matching lines...) Expand all Loading... |
532 | 543 |
533 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 544 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); |
534 HandleScope handle_scope(isolate); | 545 HandleScope handle_scope(isolate); |
535 Handle<Object> root; | 546 Handle<Object> root; |
536 Handle<JSGlobalProxy> global_proxy = | 547 Handle<JSGlobalProxy> global_proxy = |
537 isolate->factory()->NewUninitializedJSGlobalProxy( | 548 isolate->factory()->NewUninitializedJSGlobalProxy( |
538 JSGlobalProxy::SizeWithInternalFields(0)); | 549 JSGlobalProxy::SizeWithInternalFields(0)); |
539 { | 550 { |
540 SnapshotData snapshot_data(partial_blob); | 551 SnapshotData snapshot_data(partial_blob); |
541 Deserializer deserializer(&snapshot_data); | 552 Deserializer deserializer(&snapshot_data); |
542 root = deserializer.DeserializePartial(isolate, global_proxy, nullptr) | 553 root = deserializer |
| 554 .DeserializePartial(isolate, global_proxy, |
| 555 v8::DeserializeInternalFieldsCallback()) |
543 .ToHandleChecked(); | 556 .ToHandleChecked(); |
544 CHECK(root->IsContext()); | 557 CHECK(root->IsContext()); |
545 Handle<Context> context = Handle<Context>::cast(root); | 558 Handle<Context> context = Handle<Context>::cast(root); |
546 | 559 |
547 // Add context to the weak native context list | 560 // Add context to the weak native context list |
548 context->set(Context::NEXT_CONTEXT_LINK, | 561 context->set(Context::NEXT_CONTEXT_LINK, |
549 isolate->heap()->native_contexts_list(), | 562 isolate->heap()->native_contexts_list(), |
550 UPDATE_WEAK_WRITE_BARRIER); | 563 UPDATE_WEAK_WRITE_BARRIER); |
551 isolate->heap()->set_native_contexts_list(*context); | 564 isolate->heap()->set_native_contexts_list(*context); |
552 | 565 |
(...skipping 1601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2154 v8::StartupData blob = | 2167 v8::StartupData blob = |
2155 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); | 2168 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); |
2156 | 2169 |
2157 delete[] blob.data; | 2170 delete[] blob.data; |
2158 } | 2171 } |
2159 | 2172 |
2160 struct InternalFieldData { | 2173 struct InternalFieldData { |
2161 uint32_t data; | 2174 uint32_t data; |
2162 }; | 2175 }; |
2163 | 2176 |
2164 v8::StartupData SerializeInternalFields(v8::Local<v8::Object> holder, | 2177 v8::StartupData SerializeInternalFields(v8::Local<v8::Object> holder, int index, |
2165 int index) { | 2178 void* data) { |
2166 InternalFieldData* data = static_cast<InternalFieldData*>( | 2179 CHECK_EQ(reinterpret_cast<void*>(2016), data); |
| 2180 InternalFieldData* internal_field = static_cast<InternalFieldData*>( |
2167 holder->GetAlignedPointerFromInternalField(index)); | 2181 holder->GetAlignedPointerFromInternalField(index)); |
2168 int size = sizeof(*data); | 2182 int size = sizeof(*internal_field); |
2169 char* payload = new char[size]; | 2183 char* payload = new char[size]; |
2170 // We simply use memcpy to serialize the content. | 2184 // We simply use memcpy to serialize the content. |
2171 memcpy(payload, data, size); | 2185 memcpy(payload, internal_field, size); |
2172 return {payload, size}; | 2186 return {payload, size}; |
2173 } | 2187 } |
2174 | 2188 |
2175 std::vector<InternalFieldData*> deserialized_data; | 2189 std::vector<InternalFieldData*> deserialized_data; |
2176 | 2190 |
2177 void DeserializeInternalFields(v8::Local<v8::Object> holder, int index, | 2191 void DeserializeInternalFields(v8::Local<v8::Object> holder, int index, |
2178 v8::StartupData payload) { | 2192 v8::StartupData payload, void* data) { |
2179 InternalFieldData* data = new InternalFieldData{0}; | 2193 CHECK_EQ(reinterpret_cast<void*>(2017), data); |
2180 memcpy(data, payload.data, payload.raw_size); | 2194 InternalFieldData* internal_field = new InternalFieldData{0}; |
2181 holder->SetAlignedPointerInInternalField(index, data); | 2195 memcpy(internal_field, payload.data, payload.raw_size); |
2182 deserialized_data.push_back(data); | 2196 holder->SetAlignedPointerInInternalField(index, internal_field); |
| 2197 deserialized_data.push_back(internal_field); |
2183 } | 2198 } |
2184 | 2199 |
2185 TEST(SnapshotCreatorTemplates) { | 2200 TEST(SnapshotCreatorTemplates) { |
2186 DisableAlwaysOpt(); | 2201 DisableAlwaysOpt(); |
2187 v8::StartupData blob; | 2202 v8::StartupData blob; |
2188 | 2203 |
2189 { | 2204 { |
2190 InternalFieldData* a1 = new InternalFieldData{11}; | 2205 InternalFieldData* a1 = new InternalFieldData{11}; |
2191 InternalFieldData* b0 = new InternalFieldData{20}; | 2206 InternalFieldData* b0 = new InternalFieldData{20}; |
2192 InternalFieldData* c0 = new InternalFieldData{30}; | 2207 InternalFieldData* c0 = new InternalFieldData{30}; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2224 v8::External::New(isolate, &serialized_static_field); | 2239 v8::External::New(isolate, &serialized_static_field); |
2225 a->SetInternalField(0, b); | 2240 a->SetInternalField(0, b); |
2226 a->SetAlignedPointerInInternalField(1, a1); | 2241 a->SetAlignedPointerInInternalField(1, a1); |
2227 b->SetAlignedPointerInInternalField(0, b0); | 2242 b->SetAlignedPointerInInternalField(0, b0); |
2228 b->SetInternalField(1, c); | 2243 b->SetInternalField(1, c); |
2229 c->SetAlignedPointerInInternalField(0, c0); | 2244 c->SetAlignedPointerInInternalField(0, c0); |
2230 c->SetInternalField(1, null_external); | 2245 c->SetInternalField(1, null_external); |
2231 c->SetInternalField(2, field_external); | 2246 c->SetInternalField(2, field_external); |
2232 CHECK(context->Global()->Set(context, v8_str("a"), a).FromJust()); | 2247 CHECK(context->Global()->Set(context, v8_str("a"), a).FromJust()); |
2233 | 2248 |
2234 CHECK_EQ(0u, creator.AddContext(context, SerializeInternalFields)); | 2249 CHECK_EQ(0u, |
| 2250 creator.AddContext(context, v8::SerializeInternalFieldsCallback( |
| 2251 SerializeInternalFields, |
| 2252 reinterpret_cast<void*>(2016)))); |
2235 CHECK_EQ(0u, creator.AddTemplate(callback)); | 2253 CHECK_EQ(0u, creator.AddTemplate(callback)); |
2236 CHECK_EQ(1u, creator.AddTemplate(global_template)); | 2254 CHECK_EQ(1u, creator.AddTemplate(global_template)); |
2237 } | 2255 } |
2238 blob = | 2256 blob = |
2239 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); | 2257 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); |
2240 | 2258 |
2241 delete a1; | 2259 delete a1; |
2242 delete b0; | 2260 delete b0; |
2243 delete c0; | 2261 delete c0; |
2244 } | 2262 } |
2245 | 2263 |
2246 { | 2264 { |
2247 v8::Isolate::CreateParams params; | 2265 v8::Isolate::CreateParams params; |
2248 params.snapshot_blob = &blob; | 2266 params.snapshot_blob = &blob; |
2249 params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 2267 params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
2250 params.external_references = original_external_references; | 2268 params.external_references = original_external_references; |
2251 v8::Isolate* isolate = v8::Isolate::New(params); | 2269 v8::Isolate* isolate = v8::Isolate::New(params); |
2252 { | 2270 { |
2253 v8::Isolate::Scope isolate_scope(isolate); | 2271 v8::Isolate::Scope isolate_scope(isolate); |
2254 { | 2272 { |
2255 // Create a new context without a new object template. | 2273 // Create a new context without a new object template. |
2256 v8::HandleScope handle_scope(isolate); | 2274 v8::HandleScope handle_scope(isolate); |
2257 v8::Local<v8::Context> context = | 2275 v8::Local<v8::Context> context = |
2258 v8::Context::FromSnapshot(isolate, 0, DeserializeInternalFields) | 2276 v8::Context::FromSnapshot( |
| 2277 isolate, 0, |
| 2278 v8::DeserializeInternalFieldsCallback( |
| 2279 DeserializeInternalFields, reinterpret_cast<void*>(2017))) |
2259 .ToLocalChecked(); | 2280 .ToLocalChecked(); |
2260 v8::Context::Scope context_scope(context); | 2281 v8::Context::Scope context_scope(context); |
2261 ExpectInt32("f()", 42); | 2282 ExpectInt32("f()", 42); |
2262 | 2283 |
2263 // Retrieve the snapshotted object template. | 2284 // Retrieve the snapshotted object template. |
2264 v8::Local<v8::ObjectTemplate> obj_template = | 2285 v8::Local<v8::ObjectTemplate> obj_template = |
2265 v8::ObjectTemplate::FromSnapshot(isolate, 1).ToLocalChecked(); | 2286 v8::ObjectTemplate::FromSnapshot(isolate, 1).ToLocalChecked(); |
2266 CHECK(!obj_template.IsEmpty()); | 2287 CHECK(!obj_template.IsEmpty()); |
2267 v8::Local<v8::Object> object = | 2288 v8::Local<v8::Object> object = |
2268 obj_template->NewInstance(context).ToLocalChecked(); | 2289 obj_template->NewInstance(context).ToLocalChecked(); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2401 ExpectInt32("h()", 13); | 2422 ExpectInt32("h()", 13); |
2402 ExpectInt32("o.p", 7); | 2423 ExpectInt32("o.p", 7); |
2403 ExpectInt32("x", 2016); | 2424 ExpectInt32("x", 2016); |
2404 ExpectInt32("y", 2017); | 2425 ExpectInt32("y", 2017); |
2405 CHECK(v8_str("hidden string") | 2426 CHECK(v8_str("hidden string") |
2406 ->Equals(context, context->Global() | 2427 ->Equals(context, context->Global() |
2407 ->GetPrivate(context, hidden) | 2428 ->GetPrivate(context, hidden) |
2408 .ToLocalChecked()) | 2429 .ToLocalChecked()) |
2409 .FromJust()); | 2430 .FromJust()); |
2410 | 2431 |
2411 CHECK_EQ(0u, creator.AddContext(context, SerializeInternalFields)); | 2432 CHECK_EQ(0u, |
| 2433 creator.AddContext(context, v8::SerializeInternalFieldsCallback( |
| 2434 SerializeInternalFields, |
| 2435 reinterpret_cast<void*>(2016)))); |
2412 } | 2436 } |
2413 blob = | 2437 blob = |
2414 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); | 2438 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); |
2415 } | 2439 } |
2416 | 2440 |
2417 { | 2441 { |
2418 v8::Isolate::CreateParams params; | 2442 v8::Isolate::CreateParams params; |
2419 params.snapshot_blob = &blob; | 2443 params.snapshot_blob = &blob; |
2420 params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 2444 params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
2421 params.external_references = original_external_references; | 2445 params.external_references = original_external_references; |
(...skipping 23 matching lines...) Expand all Loading... |
2445 ExpectInt32("o.p", 8); | 2469 ExpectInt32("o.p", 8); |
2446 v8::TryCatch try_catch(isolate); | 2470 v8::TryCatch try_catch(isolate); |
2447 CHECK(CompileRun("x").IsEmpty()); | 2471 CHECK(CompileRun("x").IsEmpty()); |
2448 CHECK(try_catch.HasCaught()); | 2472 CHECK(try_catch.HasCaught()); |
2449 } | 2473 } |
2450 { | 2474 { |
2451 // Create a new context from first additional context snapshot. This | 2475 // Create a new context from first additional context snapshot. This |
2452 // will use the global object from the snapshot, including interceptor. | 2476 // will use the global object from the snapshot, including interceptor. |
2453 v8::HandleScope handle_scope(isolate); | 2477 v8::HandleScope handle_scope(isolate); |
2454 v8::Local<v8::Context> context = | 2478 v8::Local<v8::Context> context = |
2455 v8::Context::FromSnapshot(isolate, 0, DeserializeInternalFields) | 2479 v8::Context::FromSnapshot( |
| 2480 isolate, 0, |
| 2481 v8::DeserializeInternalFieldsCallback( |
| 2482 DeserializeInternalFields, reinterpret_cast<void*>(2017))) |
2456 .ToLocalChecked(); | 2483 .ToLocalChecked(); |
| 2484 |
2457 { | 2485 { |
2458 v8::Context::Scope context_scope(context); | 2486 v8::Context::Scope context_scope(context); |
2459 ExpectInt32("f()", 42); | 2487 ExpectInt32("f()", 42); |
2460 ExpectInt32("g()", 12); | 2488 ExpectInt32("g()", 12); |
2461 ExpectInt32("h()", 13); | 2489 ExpectInt32("h()", 13); |
2462 ExpectInt32("i()", 24); | 2490 ExpectInt32("i()", 24); |
2463 ExpectInt32("j()", 25); | 2491 ExpectInt32("j()", 25); |
2464 ExpectInt32("o.p", 8); | 2492 ExpectInt32("o.p", 8); |
2465 ExpectInt32("x", 2016); | 2493 ExpectInt32("x", 2016); |
2466 v8::Local<v8::Private> hidden = | 2494 v8::Local<v8::Private> hidden = |
2467 v8::Private::ForApi(isolate, v8_str("hidden")); | 2495 v8::Private::ForApi(isolate, v8_str("hidden")); |
2468 CHECK(v8_str("hidden string") | 2496 CHECK(v8_str("hidden string") |
2469 ->Equals(context, context->Global() | 2497 ->Equals(context, context->Global() |
2470 ->GetPrivate(context, hidden) | 2498 ->GetPrivate(context, hidden) |
2471 .ToLocalChecked()) | 2499 .ToLocalChecked()) |
2472 .FromJust()); | 2500 .FromJust()); |
2473 ExpectString("cached", "cached string"); | 2501 ExpectString("cached", "cached string"); |
2474 } | 2502 } |
2475 | 2503 |
2476 v8::Local<v8::Object> global = context->Global(); | 2504 v8::Local<v8::Object> global = context->Global(); |
2477 CHECK_EQ(3, global->InternalFieldCount()); | 2505 CHECK_EQ(3, global->InternalFieldCount()); |
2478 context->DetachGlobal(); | 2506 context->DetachGlobal(); |
2479 | 2507 |
2480 // New context, but reuse global proxy. | 2508 // New context, but reuse global proxy. |
2481 v8::ExtensionConfiguration* no_extensions = nullptr; | 2509 v8::ExtensionConfiguration* no_extensions = nullptr; |
2482 v8::Local<v8::Context> context2 = | 2510 v8::Local<v8::Context> context2 = |
2483 v8::Context::FromSnapshot(isolate, 0, DeserializeInternalFields, | 2511 v8::Context::FromSnapshot( |
2484 no_extensions, global) | 2512 isolate, 0, |
| 2513 v8::DeserializeInternalFieldsCallback( |
| 2514 DeserializeInternalFields, reinterpret_cast<void*>(2017)), |
| 2515 no_extensions, global) |
2485 .ToLocalChecked(); | 2516 .ToLocalChecked(); |
2486 { | 2517 { |
2487 v8::Context::Scope context_scope(context2); | 2518 v8::Context::Scope context_scope(context2); |
2488 ExpectInt32("f()", 42); | 2519 ExpectInt32("f()", 42); |
2489 ExpectInt32("g()", 12); | 2520 ExpectInt32("g()", 12); |
2490 ExpectInt32("h()", 13); | 2521 ExpectInt32("h()", 13); |
2491 ExpectInt32("i()", 24); | 2522 ExpectInt32("i()", 24); |
2492 ExpectInt32("j()", 25); | 2523 ExpectInt32("j()", 25); |
2493 ExpectInt32("o.p", 8); | 2524 ExpectInt32("o.p", 8); |
2494 ExpectInt32("x", 2016); | 2525 ExpectInt32("x", 2016); |
(...skipping 21 matching lines...) Expand all Loading... |
2516 } | 2547 } |
2517 delete[] blob.data; | 2548 delete[] blob.data; |
2518 } | 2549 } |
2519 | 2550 |
2520 TEST(SerializationMemoryStats) { | 2551 TEST(SerializationMemoryStats) { |
2521 FLAG_profile_deserialization = true; | 2552 FLAG_profile_deserialization = true; |
2522 FLAG_always_opt = false; | 2553 FLAG_always_opt = false; |
2523 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 2554 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
2524 delete[] blob.data; | 2555 delete[] blob.data; |
2525 } | 2556 } |
OLD | NEW |