Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: test/cctest/test-serialize.cc

Issue 2741683004: [rename] Rename internal field to embedder field. (Closed)
Patch Set: DEPRECATE_SOON(GetInternalField) Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 v8::HandleScope handle_scope(v8_isolate); 280 v8::HandleScope handle_scope(v8_isolate);
281 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); 281 v8::Local<v8::Context>::New(v8_isolate, env)->Exit();
282 } 282 }
283 env.Reset(); 283 env.Reset();
284 284
285 StartupSerializer startup_serializer( 285 StartupSerializer startup_serializer(
286 isolate, v8::SnapshotCreator::FunctionCodeHandling::kClear); 286 isolate, v8::SnapshotCreator::FunctionCodeHandling::kClear);
287 startup_serializer.SerializeStrongReferences(); 287 startup_serializer.SerializeStrongReferences();
288 288
289 PartialSerializer partial_serializer(isolate, &startup_serializer, 289 PartialSerializer partial_serializer(isolate, &startup_serializer,
290 v8::SerializeInternalFieldsCallback()); 290 v8::SerializeEmbedderFieldsCallback());
291 partial_serializer.Serialize(&raw_foo, false); 291 partial_serializer.Serialize(&raw_foo, false);
292 292
293 startup_serializer.SerializeWeakReferencesAndDeferred(); 293 startup_serializer.SerializeWeakReferencesAndDeferred();
294 294
295 SnapshotData startup_snapshot(&startup_serializer); 295 SnapshotData startup_snapshot(&startup_serializer);
296 SnapshotData partial_snapshot(&partial_serializer); 296 SnapshotData partial_snapshot(&partial_serializer);
297 297
298 *partial_blob_out = WritePayload(partial_snapshot.RawData()); 298 *partial_blob_out = WritePayload(partial_snapshot.RawData());
299 *startup_blob_out = WritePayload(startup_snapshot.RawData()); 299 *startup_blob_out = WritePayload(startup_snapshot.RawData());
300 } 300 }
(...skipping 17 matching lines...) Expand all
318 HandleScope handle_scope(isolate); 318 HandleScope handle_scope(isolate);
319 Handle<Object> root; 319 Handle<Object> root;
320 // Intentionally empty handle. The deserializer should not come across 320 // Intentionally empty handle. The deserializer should not come across
321 // any references to the global proxy in this test. 321 // any references to the global proxy in this test.
322 Handle<JSGlobalProxy> global_proxy = Handle<JSGlobalProxy>::null(); 322 Handle<JSGlobalProxy> global_proxy = Handle<JSGlobalProxy>::null();
323 { 323 {
324 SnapshotData snapshot_data(partial_blob); 324 SnapshotData snapshot_data(partial_blob);
325 Deserializer deserializer(&snapshot_data); 325 Deserializer deserializer(&snapshot_data);
326 root = deserializer 326 root = deserializer
327 .DeserializePartial(isolate, global_proxy, 327 .DeserializePartial(isolate, global_proxy,
328 v8::DeserializeInternalFieldsCallback()) 328 v8::DeserializeEmbedderFieldsCallback())
329 .ToHandleChecked(); 329 .ToHandleChecked();
330 CHECK(root->IsString()); 330 CHECK(root->IsString());
331 } 331 }
332 332
333 Handle<Object> root2; 333 Handle<Object> root2;
334 { 334 {
335 SnapshotData snapshot_data(partial_blob); 335 SnapshotData snapshot_data(partial_blob);
336 Deserializer deserializer(&snapshot_data); 336 Deserializer deserializer(&snapshot_data);
337 root2 = deserializer 337 root2 = deserializer
338 .DeserializePartial(isolate, global_proxy, 338 .DeserializePartial(isolate, global_proxy,
339 v8::DeserializeInternalFieldsCallback()) 339 v8::DeserializeEmbedderFieldsCallback())
340 .ToHandleChecked(); 340 .ToHandleChecked();
341 CHECK(root2->IsString()); 341 CHECK(root2->IsString());
342 CHECK(root.is_identical_to(root2)); 342 CHECK(root.is_identical_to(root2));
343 } 343 }
344 partial_blob.Dispose(); 344 partial_blob.Dispose();
345 } 345 }
346 v8_isolate->Dispose(); 346 v8_isolate->Dispose();
347 } 347 }
348 348
349 static void PartiallySerializeContext(Vector<const byte>* startup_blob_out, 349 static void PartiallySerializeContext(Vector<const byte>* startup_blob_out,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 385
386 env.Reset(); 386 env.Reset();
387 387
388 SnapshotByteSink startup_sink; 388 SnapshotByteSink startup_sink;
389 StartupSerializer startup_serializer( 389 StartupSerializer startup_serializer(
390 isolate, v8::SnapshotCreator::FunctionCodeHandling::kClear); 390 isolate, v8::SnapshotCreator::FunctionCodeHandling::kClear);
391 startup_serializer.SerializeStrongReferences(); 391 startup_serializer.SerializeStrongReferences();
392 392
393 SnapshotByteSink partial_sink; 393 SnapshotByteSink partial_sink;
394 PartialSerializer partial_serializer(isolate, &startup_serializer, 394 PartialSerializer partial_serializer(isolate, &startup_serializer,
395 v8::SerializeInternalFieldsCallback()); 395 v8::SerializeEmbedderFieldsCallback());
396 partial_serializer.Serialize(&raw_context, false); 396 partial_serializer.Serialize(&raw_context, false);
397 startup_serializer.SerializeWeakReferencesAndDeferred(); 397 startup_serializer.SerializeWeakReferencesAndDeferred();
398 398
399 SnapshotData startup_snapshot(&startup_serializer); 399 SnapshotData startup_snapshot(&startup_serializer);
400 SnapshotData partial_snapshot(&partial_serializer); 400 SnapshotData partial_snapshot(&partial_serializer);
401 401
402 *partial_blob_out = WritePayload(partial_snapshot.RawData()); 402 *partial_blob_out = WritePayload(partial_snapshot.RawData());
403 *startup_blob_out = WritePayload(startup_snapshot.RawData()); 403 *startup_blob_out = WritePayload(startup_snapshot.RawData());
404 } 404 }
405 v8_isolate->Dispose(); 405 v8_isolate->Dispose();
406 } 406 }
407 407
408 UNINITIALIZED_TEST(PartialSerializerContext) { 408 UNINITIALIZED_TEST(PartialSerializerContext) {
409 DisableAlwaysOpt(); 409 DisableAlwaysOpt();
410 Vector<const byte> startup_blob; 410 Vector<const byte> startup_blob;
411 Vector<const byte> partial_blob; 411 Vector<const byte> partial_blob;
412 PartiallySerializeContext(&startup_blob, &partial_blob); 412 PartiallySerializeContext(&startup_blob, &partial_blob);
413 413
414 v8::Isolate* v8_isolate = InitializeFromBlob(startup_blob); 414 v8::Isolate* v8_isolate = InitializeFromBlob(startup_blob);
415 CHECK(v8_isolate); 415 CHECK(v8_isolate);
416 startup_blob.Dispose(); 416 startup_blob.Dispose();
417 { 417 {
418 v8::Isolate::Scope isolate_scope(v8_isolate); 418 v8::Isolate::Scope isolate_scope(v8_isolate);
419 419
420 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); 420 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
421 HandleScope handle_scope(isolate); 421 HandleScope handle_scope(isolate);
422 Handle<Object> root; 422 Handle<Object> root;
423 Handle<JSGlobalProxy> global_proxy = 423 Handle<JSGlobalProxy> global_proxy =
424 isolate->factory()->NewUninitializedJSGlobalProxy( 424 isolate->factory()->NewUninitializedJSGlobalProxy(
425 JSGlobalProxy::SizeWithInternalFields(0)); 425 JSGlobalProxy::SizeWithEmbedderFields(0));
426 { 426 {
427 SnapshotData snapshot_data(partial_blob); 427 SnapshotData snapshot_data(partial_blob);
428 Deserializer deserializer(&snapshot_data); 428 Deserializer deserializer(&snapshot_data);
429 root = deserializer 429 root = deserializer
430 .DeserializePartial(isolate, global_proxy, 430 .DeserializePartial(isolate, global_proxy,
431 v8::DeserializeInternalFieldsCallback()) 431 v8::DeserializeEmbedderFieldsCallback())
432 .ToHandleChecked(); 432 .ToHandleChecked();
433 CHECK(root->IsContext()); 433 CHECK(root->IsContext());
434 CHECK(Handle<Context>::cast(root)->global_proxy() == *global_proxy); 434 CHECK(Handle<Context>::cast(root)->global_proxy() == *global_proxy);
435 } 435 }
436 436
437 Handle<Object> root2; 437 Handle<Object> root2;
438 { 438 {
439 SnapshotData snapshot_data(partial_blob); 439 SnapshotData snapshot_data(partial_blob);
440 Deserializer deserializer(&snapshot_data); 440 Deserializer deserializer(&snapshot_data);
441 root2 = deserializer 441 root2 = deserializer
442 .DeserializePartial(isolate, global_proxy, 442 .DeserializePartial(isolate, global_proxy,
443 v8::DeserializeInternalFieldsCallback()) 443 v8::DeserializeEmbedderFieldsCallback())
444 .ToHandleChecked(); 444 .ToHandleChecked();
445 CHECK(root2->IsContext()); 445 CHECK(root2->IsContext());
446 CHECK(!root.is_identical_to(root2)); 446 CHECK(!root.is_identical_to(root2));
447 } 447 }
448 partial_blob.Dispose(); 448 partial_blob.Dispose();
449 } 449 }
450 v8_isolate->Dispose(); 450 v8_isolate->Dispose();
451 } 451 }
452 452
453 static void PartiallySerializeCustomContext( 453 static void PartiallySerializeCustomContext(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 510
511 env.Reset(); 511 env.Reset();
512 512
513 SnapshotByteSink startup_sink; 513 SnapshotByteSink startup_sink;
514 StartupSerializer startup_serializer( 514 StartupSerializer startup_serializer(
515 isolate, v8::SnapshotCreator::FunctionCodeHandling::kClear); 515 isolate, v8::SnapshotCreator::FunctionCodeHandling::kClear);
516 startup_serializer.SerializeStrongReferences(); 516 startup_serializer.SerializeStrongReferences();
517 517
518 SnapshotByteSink partial_sink; 518 SnapshotByteSink partial_sink;
519 PartialSerializer partial_serializer(isolate, &startup_serializer, 519 PartialSerializer partial_serializer(isolate, &startup_serializer,
520 v8::SerializeInternalFieldsCallback()); 520 v8::SerializeEmbedderFieldsCallback());
521 partial_serializer.Serialize(&raw_context, false); 521 partial_serializer.Serialize(&raw_context, false);
522 startup_serializer.SerializeWeakReferencesAndDeferred(); 522 startup_serializer.SerializeWeakReferencesAndDeferred();
523 523
524 SnapshotData startup_snapshot(&startup_serializer); 524 SnapshotData startup_snapshot(&startup_serializer);
525 SnapshotData partial_snapshot(&partial_serializer); 525 SnapshotData partial_snapshot(&partial_serializer);
526 526
527 *partial_blob_out = WritePayload(partial_snapshot.RawData()); 527 *partial_blob_out = WritePayload(partial_snapshot.RawData());
528 *startup_blob_out = WritePayload(startup_snapshot.RawData()); 528 *startup_blob_out = WritePayload(startup_snapshot.RawData());
529 } 529 }
530 v8_isolate->Dispose(); 530 v8_isolate->Dispose();
531 } 531 }
532 532
533 UNINITIALIZED_TEST(PartialSerializerCustomContext) { 533 UNINITIALIZED_TEST(PartialSerializerCustomContext) {
534 DisableAlwaysOpt(); 534 DisableAlwaysOpt();
535 Vector<const byte> startup_blob; 535 Vector<const byte> startup_blob;
536 Vector<const byte> partial_blob; 536 Vector<const byte> partial_blob;
537 PartiallySerializeCustomContext(&startup_blob, &partial_blob); 537 PartiallySerializeCustomContext(&startup_blob, &partial_blob);
538 538
539 v8::Isolate* v8_isolate = InitializeFromBlob(startup_blob); 539 v8::Isolate* v8_isolate = InitializeFromBlob(startup_blob);
540 CHECK(v8_isolate); 540 CHECK(v8_isolate);
541 startup_blob.Dispose(); 541 startup_blob.Dispose();
542 { 542 {
543 v8::Isolate::Scope isolate_scope(v8_isolate); 543 v8::Isolate::Scope isolate_scope(v8_isolate);
544 544
545 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); 545 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
546 HandleScope handle_scope(isolate); 546 HandleScope handle_scope(isolate);
547 Handle<Object> root; 547 Handle<Object> root;
548 Handle<JSGlobalProxy> global_proxy = 548 Handle<JSGlobalProxy> global_proxy =
549 isolate->factory()->NewUninitializedJSGlobalProxy( 549 isolate->factory()->NewUninitializedJSGlobalProxy(
550 JSGlobalProxy::SizeWithInternalFields(0)); 550 JSGlobalProxy::SizeWithEmbedderFields(0));
551 { 551 {
552 SnapshotData snapshot_data(partial_blob); 552 SnapshotData snapshot_data(partial_blob);
553 Deserializer deserializer(&snapshot_data); 553 Deserializer deserializer(&snapshot_data);
554 root = deserializer 554 root = deserializer
555 .DeserializePartial(isolate, global_proxy, 555 .DeserializePartial(isolate, global_proxy,
556 v8::DeserializeInternalFieldsCallback()) 556 v8::DeserializeEmbedderFieldsCallback())
557 .ToHandleChecked(); 557 .ToHandleChecked();
558 CHECK(root->IsContext()); 558 CHECK(root->IsContext());
559 Handle<Context> context = Handle<Context>::cast(root); 559 Handle<Context> context = Handle<Context>::cast(root);
560 560
561 // Add context to the weak native context list 561 // Add context to the weak native context list
562 context->set(Context::NEXT_CONTEXT_LINK, 562 context->set(Context::NEXT_CONTEXT_LINK,
563 isolate->heap()->native_contexts_list(), 563 isolate->heap()->native_contexts_list(),
564 UPDATE_WEAK_WRITE_BARRIER); 564 UPDATE_WEAK_WRITE_BARRIER);
565 isolate->heap()->set_native_contexts_list(*context); 565 isolate->heap()->set_native_contexts_list(*context);
566 566
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 ExpectInt32("f()", 42); 2075 ExpectInt32("f()", 42);
2076 2076
2077 creator.SetDefaultContext(context); 2077 creator.SetDefaultContext(context);
2078 } 2078 }
2079 v8::StartupData blob = 2079 v8::StartupData blob =
2080 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); 2080 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
2081 2081
2082 delete[] blob.data; 2082 delete[] blob.data;
2083 } 2083 }
2084 2084
2085 struct InternalFieldData { 2085 struct EmbedderFieldData {
2086 uint32_t data; 2086 uint32_t data;
2087 }; 2087 };
2088 2088
2089 v8::StartupData SerializeInternalFields(v8::Local<v8::Object> holder, int index, 2089 v8::StartupData SerializeEmbedderFields(v8::Local<v8::Object> holder, int index,
2090 void* data) { 2090 void* data) {
2091 CHECK_EQ(reinterpret_cast<void*>(2016), data); 2091 CHECK_EQ(reinterpret_cast<void*>(2016), data);
2092 InternalFieldData* internal_field = static_cast<InternalFieldData*>( 2092 EmbedderFieldData* embedder_field = static_cast<EmbedderFieldData*>(
2093 holder->GetAlignedPointerFromInternalField(index)); 2093 holder->GetAlignedPointerFromEmbedderField(index));
2094 int size = sizeof(*internal_field); 2094 int size = sizeof(*embedder_field);
2095 char* payload = new char[size]; 2095 char* payload = new char[size];
2096 // We simply use memcpy to serialize the content. 2096 // We simply use memcpy to serialize the content.
2097 memcpy(payload, internal_field, size); 2097 memcpy(payload, embedder_field, size);
2098 return {payload, size}; 2098 return {payload, size};
2099 } 2099 }
2100 2100
2101 std::vector<InternalFieldData*> deserialized_data; 2101 std::vector<EmbedderFieldData*> deserialized_data;
2102 2102
2103 void DeserializeInternalFields(v8::Local<v8::Object> holder, int index, 2103 void DeserializeEmbedderFields(v8::Local<v8::Object> holder, int index,
2104 v8::StartupData payload, void* data) { 2104 v8::StartupData payload, void* data) {
2105 CHECK_EQ(reinterpret_cast<void*>(2017), data); 2105 CHECK_EQ(reinterpret_cast<void*>(2017), data);
2106 InternalFieldData* internal_field = new InternalFieldData{0}; 2106 EmbedderFieldData* embedder_field = new EmbedderFieldData{0};
2107 memcpy(internal_field, payload.data, payload.raw_size); 2107 memcpy(embedder_field, payload.data, payload.raw_size);
2108 holder->SetAlignedPointerInInternalField(index, internal_field); 2108 holder->SetAlignedPointerInEmbedderField(index, embedder_field);
2109 deserialized_data.push_back(internal_field); 2109 deserialized_data.push_back(embedder_field);
2110 } 2110 }
2111 2111
2112 TEST(SnapshotCreatorTemplates) { 2112 TEST(SnapshotCreatorTemplates) {
2113 DisableAlwaysOpt(); 2113 DisableAlwaysOpt();
2114 v8::StartupData blob; 2114 v8::StartupData blob;
2115 2115
2116 { 2116 {
2117 InternalFieldData* a1 = new InternalFieldData{11}; 2117 EmbedderFieldData* a1 = new EmbedderFieldData{11};
2118 InternalFieldData* b0 = new InternalFieldData{20}; 2118 EmbedderFieldData* b0 = new EmbedderFieldData{20};
2119 InternalFieldData* c0 = new InternalFieldData{30}; 2119 EmbedderFieldData* c0 = new EmbedderFieldData{30};
2120 2120
2121 v8::SnapshotCreator creator(original_external_references); 2121 v8::SnapshotCreator creator(original_external_references);
2122 v8::Isolate* isolate = creator.GetIsolate(); 2122 v8::Isolate* isolate = creator.GetIsolate();
2123 { 2123 {
2124 v8::HandleScope handle_scope(isolate); 2124 v8::HandleScope handle_scope(isolate);
2125 v8::ExtensionConfiguration* no_extension = nullptr; 2125 v8::ExtensionConfiguration* no_extension = nullptr;
2126 v8::Local<v8::ObjectTemplate> global_template = 2126 v8::Local<v8::ObjectTemplate> global_template =
2127 v8::ObjectTemplate::New(isolate); 2127 v8::ObjectTemplate::New(isolate);
2128 v8::Local<v8::FunctionTemplate> callback = 2128 v8::Local<v8::FunctionTemplate> callback =
2129 v8::FunctionTemplate::New(isolate, SerializedCallback); 2129 v8::FunctionTemplate::New(isolate, SerializedCallback);
2130 global_template->Set(v8_str("f"), callback); 2130 global_template->Set(v8_str("f"), callback);
2131 v8::Local<v8::Context> context = 2131 v8::Local<v8::Context> context =
2132 v8::Context::New(isolate, no_extension, global_template); 2132 v8::Context::New(isolate, no_extension, global_template);
2133 creator.SetDefaultContext(context); 2133 creator.SetDefaultContext(context);
2134 context = v8::Context::New(isolate, no_extension, global_template); 2134 context = v8::Context::New(isolate, no_extension, global_template);
2135 v8::Local<v8::ObjectTemplate> object_template = 2135 v8::Local<v8::ObjectTemplate> object_template =
2136 v8::ObjectTemplate::New(isolate); 2136 v8::ObjectTemplate::New(isolate);
2137 object_template->SetInternalFieldCount(3); 2137 object_template->SetEmbedderFieldCount(3);
2138 2138
2139 v8::Context::Scope context_scope(context); 2139 v8::Context::Scope context_scope(context);
2140 ExpectInt32("f()", 42); 2140 ExpectInt32("f()", 42);
2141 2141
2142 v8::Local<v8::Object> a = 2142 v8::Local<v8::Object> a =
2143 object_template->NewInstance(context).ToLocalChecked(); 2143 object_template->NewInstance(context).ToLocalChecked();
2144 v8::Local<v8::Object> b = 2144 v8::Local<v8::Object> b =
2145 object_template->NewInstance(context).ToLocalChecked(); 2145 object_template->NewInstance(context).ToLocalChecked();
2146 v8::Local<v8::Object> c = 2146 v8::Local<v8::Object> c =
2147 object_template->NewInstance(context).ToLocalChecked(); 2147 object_template->NewInstance(context).ToLocalChecked();
2148 v8::Local<v8::External> null_external = 2148 v8::Local<v8::External> null_external =
2149 v8::External::New(isolate, nullptr); 2149 v8::External::New(isolate, nullptr);
2150 v8::Local<v8::External> field_external = 2150 v8::Local<v8::External> field_external =
2151 v8::External::New(isolate, &serialized_static_field); 2151 v8::External::New(isolate, &serialized_static_field);
2152 a->SetInternalField(0, b); 2152 a->SetEmbedderField(0, b);
2153 a->SetAlignedPointerInInternalField(1, a1); 2153 a->SetAlignedPointerInEmbedderField(1, a1);
2154 b->SetAlignedPointerInInternalField(0, b0); 2154 b->SetAlignedPointerInEmbedderField(0, b0);
2155 b->SetInternalField(1, c); 2155 b->SetEmbedderField(1, c);
2156 c->SetAlignedPointerInInternalField(0, c0); 2156 c->SetAlignedPointerInEmbedderField(0, c0);
2157 c->SetInternalField(1, null_external); 2157 c->SetEmbedderField(1, null_external);
2158 c->SetInternalField(2, field_external); 2158 c->SetEmbedderField(2, field_external);
2159 CHECK(context->Global()->Set(context, v8_str("a"), a).FromJust()); 2159 CHECK(context->Global()->Set(context, v8_str("a"), a).FromJust());
2160 2160
2161 CHECK_EQ(0u, 2161 CHECK_EQ(0u,
2162 creator.AddContext(context, v8::SerializeInternalFieldsCallback( 2162 creator.AddContext(context, v8::SerializeEmbedderFieldsCallback(
2163 SerializeInternalFields, 2163 SerializeEmbedderFields,
2164 reinterpret_cast<void*>(2016)))); 2164 reinterpret_cast<void*>(2016))));
2165 CHECK_EQ(0u, creator.AddTemplate(callback)); 2165 CHECK_EQ(0u, creator.AddTemplate(callback));
2166 CHECK_EQ(1u, creator.AddTemplate(global_template)); 2166 CHECK_EQ(1u, creator.AddTemplate(global_template));
2167 } 2167 }
2168 blob = 2168 blob =
2169 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); 2169 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
2170 2170
2171 delete a1; 2171 delete a1;
2172 delete b0; 2172 delete b0;
2173 delete c0; 2173 delete c0;
2174 } 2174 }
2175 2175
2176 { 2176 {
2177 v8::Isolate::CreateParams params; 2177 v8::Isolate::CreateParams params;
2178 params.snapshot_blob = &blob; 2178 params.snapshot_blob = &blob;
2179 params.array_buffer_allocator = CcTest::array_buffer_allocator(); 2179 params.array_buffer_allocator = CcTest::array_buffer_allocator();
2180 params.external_references = original_external_references; 2180 params.external_references = original_external_references;
2181 v8::Isolate* isolate = v8::Isolate::New(params); 2181 v8::Isolate* isolate = v8::Isolate::New(params);
2182 { 2182 {
2183 v8::Isolate::Scope isolate_scope(isolate); 2183 v8::Isolate::Scope isolate_scope(isolate);
2184 { 2184 {
2185 // Create a new context without a new object template. 2185 // Create a new context without a new object template.
2186 v8::HandleScope handle_scope(isolate); 2186 v8::HandleScope handle_scope(isolate);
2187 v8::Local<v8::Context> context = 2187 v8::Local<v8::Context> context =
2188 v8::Context::FromSnapshot( 2188 v8::Context::FromSnapshot(
2189 isolate, 0, 2189 isolate, 0,
2190 v8::DeserializeInternalFieldsCallback( 2190 v8::DeserializeEmbedderFieldsCallback(
2191 DeserializeInternalFields, reinterpret_cast<void*>(2017))) 2191 DeserializeEmbedderFields, reinterpret_cast<void*>(2017)))
2192 .ToLocalChecked(); 2192 .ToLocalChecked();
2193 v8::Context::Scope context_scope(context); 2193 v8::Context::Scope context_scope(context);
2194 ExpectInt32("f()", 42); 2194 ExpectInt32("f()", 42);
2195 2195
2196 // Retrieve the snapshotted object template. 2196 // Retrieve the snapshotted object template.
2197 v8::Local<v8::ObjectTemplate> obj_template = 2197 v8::Local<v8::ObjectTemplate> obj_template =
2198 v8::ObjectTemplate::FromSnapshot(isolate, 1).ToLocalChecked(); 2198 v8::ObjectTemplate::FromSnapshot(isolate, 1).ToLocalChecked();
2199 CHECK(!obj_template.IsEmpty()); 2199 CHECK(!obj_template.IsEmpty());
2200 v8::Local<v8::Object> object = 2200 v8::Local<v8::Object> object =
2201 obj_template->NewInstance(context).ToLocalChecked(); 2201 obj_template->NewInstance(context).ToLocalChecked();
2202 CHECK(context->Global()->Set(context, v8_str("o"), object).FromJust()); 2202 CHECK(context->Global()->Set(context, v8_str("o"), object).FromJust());
2203 ExpectInt32("o.f()", 42); 2203 ExpectInt32("o.f()", 42);
2204 // Check that it instantiates to the same prototype. 2204 // Check that it instantiates to the same prototype.
2205 ExpectTrue("o.f.prototype === f.prototype"); 2205 ExpectTrue("o.f.prototype === f.prototype");
2206 2206
2207 // Retrieve the snapshotted function template. 2207 // Retrieve the snapshotted function template.
2208 v8::Local<v8::FunctionTemplate> fun_template = 2208 v8::Local<v8::FunctionTemplate> fun_template =
2209 v8::FunctionTemplate::FromSnapshot(isolate, 0).ToLocalChecked(); 2209 v8::FunctionTemplate::FromSnapshot(isolate, 0).ToLocalChecked();
2210 CHECK(!fun_template.IsEmpty()); 2210 CHECK(!fun_template.IsEmpty());
2211 v8::Local<v8::Function> fun = 2211 v8::Local<v8::Function> fun =
2212 fun_template->GetFunction(context).ToLocalChecked(); 2212 fun_template->GetFunction(context).ToLocalChecked();
2213 CHECK(context->Global()->Set(context, v8_str("g"), fun).FromJust()); 2213 CHECK(context->Global()->Set(context, v8_str("g"), fun).FromJust());
2214 ExpectInt32("g()", 42); 2214 ExpectInt32("g()", 42);
2215 // Check that it instantiates to the same prototype. 2215 // Check that it instantiates to the same prototype.
2216 ExpectTrue("g.prototype === f.prototype"); 2216 ExpectTrue("g.prototype === f.prototype");
2217 2217
2218 // Retrieve internal fields. 2218 // Retrieve embedder fields.
2219 v8::Local<v8::Object> a = context->Global() 2219 v8::Local<v8::Object> a = context->Global()
2220 ->Get(context, v8_str("a")) 2220 ->Get(context, v8_str("a"))
2221 .ToLocalChecked() 2221 .ToLocalChecked()
2222 ->ToObject(context) 2222 ->ToObject(context)
2223 .ToLocalChecked(); 2223 .ToLocalChecked();
2224 v8::Local<v8::Object> b = 2224 v8::Local<v8::Object> b =
2225 a->GetInternalField(0)->ToObject(context).ToLocalChecked(); 2225 a->GetEmbedderField(0)->ToObject(context).ToLocalChecked();
2226 InternalFieldData* a1 = reinterpret_cast<InternalFieldData*>( 2226 EmbedderFieldData* a1 = reinterpret_cast<EmbedderFieldData*>(
2227 a->GetAlignedPointerFromInternalField(1)); 2227 a->GetAlignedPointerFromEmbedderField(1));
2228 v8::Local<v8::Value> a2 = a->GetInternalField(2); 2228 v8::Local<v8::Value> a2 = a->GetEmbedderField(2);
2229 2229
2230 InternalFieldData* b0 = reinterpret_cast<InternalFieldData*>( 2230 EmbedderFieldData* b0 = reinterpret_cast<EmbedderFieldData*>(
2231 b->GetAlignedPointerFromInternalField(0)); 2231 b->GetAlignedPointerFromEmbedderField(0));
2232 v8::Local<v8::Object> c = 2232 v8::Local<v8::Object> c =
2233 b->GetInternalField(1)->ToObject(context).ToLocalChecked(); 2233 b->GetEmbedderField(1)->ToObject(context).ToLocalChecked();
2234 v8::Local<v8::Value> b2 = b->GetInternalField(2); 2234 v8::Local<v8::Value> b2 = b->GetEmbedderField(2);
2235 2235
2236 InternalFieldData* c0 = reinterpret_cast<InternalFieldData*>( 2236 EmbedderFieldData* c0 = reinterpret_cast<EmbedderFieldData*>(
2237 c->GetAlignedPointerFromInternalField(0)); 2237 c->GetAlignedPointerFromEmbedderField(0));
2238 v8::Local<v8::Value> c1 = c->GetInternalField(1); 2238 v8::Local<v8::Value> c1 = c->GetEmbedderField(1);
2239 v8::Local<v8::Value> c2 = c->GetInternalField(2); 2239 v8::Local<v8::Value> c2 = c->GetEmbedderField(2);
2240 2240
2241 CHECK_EQ(11u, a1->data); 2241 CHECK_EQ(11u, a1->data);
2242 CHECK(a2->IsUndefined()); 2242 CHECK(a2->IsUndefined());
2243 CHECK_EQ(20u, b0->data); 2243 CHECK_EQ(20u, b0->data);
2244 CHECK(b2->IsUndefined()); 2244 CHECK(b2->IsUndefined());
2245 CHECK_EQ(30u, c0->data); 2245 CHECK_EQ(30u, c0->data);
2246 CHECK(c1->IsExternal()); 2246 CHECK(c1->IsExternal());
2247 CHECK_NULL(v8::Local<v8::External>::Cast(c1)->Value()); 2247 CHECK_NULL(v8::Local<v8::External>::Cast(c1)->Value());
2248 CHECK_EQ(static_cast<void*>(&serialized_static_field), 2248 CHECK_EQ(static_cast<void*>(&serialized_static_field),
2249 v8::Local<v8::External>::Cast(c2)->Value()); 2249 v8::Local<v8::External>::Cast(c2)->Value());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2298 { 2298 {
2299 // Add additional context. This context implicitly *does* serialize 2299 // Add additional context. This context implicitly *does* serialize
2300 // the global proxy, and upon deserialization one has to be created 2300 // the global proxy, and upon deserialization one has to be created
2301 // in the bootstrapper from the global object template. 2301 // in the bootstrapper from the global object template.
2302 // Side effects from extensions are persisted. 2302 // Side effects from extensions are persisted.
2303 v8::HandleScope handle_scope(isolate); 2303 v8::HandleScope handle_scope(isolate);
2304 v8::Local<v8::ObjectTemplate> global_template = 2304 v8::Local<v8::ObjectTemplate> global_template =
2305 v8::ObjectTemplate::New(isolate); 2305 v8::ObjectTemplate::New(isolate);
2306 v8::Local<v8::FunctionTemplate> callback = 2306 v8::Local<v8::FunctionTemplate> callback =
2307 v8::FunctionTemplate::New(isolate, SerializedCallback); 2307 v8::FunctionTemplate::New(isolate, SerializedCallback);
2308 global_template->SetInternalFieldCount(3); 2308 global_template->SetEmbedderFieldCount(3);
2309 global_template->Set(v8_str("f"), callback); 2309 global_template->Set(v8_str("f"), callback);
2310 global_template->SetHandler(v8::NamedPropertyHandlerConfiguration( 2310 global_template->SetHandler(v8::NamedPropertyHandlerConfiguration(
2311 NamedPropertyGetterForSerialization)); 2311 NamedPropertyGetterForSerialization));
2312 global_template->SetAccessor(v8_str("y"), AccessorForSerialization); 2312 global_template->SetAccessor(v8_str("y"), AccessorForSerialization);
2313 v8::Local<v8::Private> priv = 2313 v8::Local<v8::Private> priv =
2314 v8::Private::ForApi(isolate, v8_str("cached")); 2314 v8::Private::ForApi(isolate, v8_str("cached"));
2315 global_template->SetAccessorProperty( 2315 global_template->SetAccessorProperty(
2316 v8_str("cached"), 2316 v8_str("cached"),
2317 v8::FunctionTemplate::NewWithCache(isolate, SerializedCallback, priv, 2317 v8::FunctionTemplate::NewWithCache(isolate, SerializedCallback, priv,
2318 v8::Local<v8::Value>())); 2318 v8::Local<v8::Value>()));
(...skipping 16 matching lines...) Expand all
2335 ExpectInt32("o.p", 7); 2335 ExpectInt32("o.p", 7);
2336 ExpectInt32("x", 2016); 2336 ExpectInt32("x", 2016);
2337 ExpectInt32("y", 2017); 2337 ExpectInt32("y", 2017);
2338 CHECK(v8_str("hidden string") 2338 CHECK(v8_str("hidden string")
2339 ->Equals(context, context->Global() 2339 ->Equals(context, context->Global()
2340 ->GetPrivate(context, hidden) 2340 ->GetPrivate(context, hidden)
2341 .ToLocalChecked()) 2341 .ToLocalChecked())
2342 .FromJust()); 2342 .FromJust());
2343 2343
2344 CHECK_EQ(0u, 2344 CHECK_EQ(0u,
2345 creator.AddContext(context, v8::SerializeInternalFieldsCallback( 2345 creator.AddContext(context, v8::SerializeEmbedderFieldsCallback(
2346 SerializeInternalFields, 2346 SerializeEmbedderFields,
2347 reinterpret_cast<void*>(2016)))); 2347 reinterpret_cast<void*>(2016))));
2348 } 2348 }
2349 blob = 2349 blob =
2350 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); 2350 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
2351 } 2351 }
2352 2352
2353 { 2353 {
2354 v8::Isolate::CreateParams params; 2354 v8::Isolate::CreateParams params;
2355 params.snapshot_blob = &blob; 2355 params.snapshot_blob = &blob;
2356 params.array_buffer_allocator = CcTest::array_buffer_allocator(); 2356 params.array_buffer_allocator = CcTest::array_buffer_allocator();
(...skipping 26 matching lines...) Expand all
2383 CHECK(CompileRun("x").IsEmpty()); 2383 CHECK(CompileRun("x").IsEmpty());
2384 CHECK(try_catch.HasCaught()); 2384 CHECK(try_catch.HasCaught());
2385 } 2385 }
2386 { 2386 {
2387 // Create a new context from first additional context snapshot. This 2387 // Create a new context from first additional context snapshot. This
2388 // will use the global object from the snapshot, including interceptor. 2388 // will use the global object from the snapshot, including interceptor.
2389 v8::HandleScope handle_scope(isolate); 2389 v8::HandleScope handle_scope(isolate);
2390 v8::Local<v8::Context> context = 2390 v8::Local<v8::Context> context =
2391 v8::Context::FromSnapshot( 2391 v8::Context::FromSnapshot(
2392 isolate, 0, 2392 isolate, 0,
2393 v8::DeserializeInternalFieldsCallback( 2393 v8::DeserializeEmbedderFieldsCallback(
2394 DeserializeInternalFields, reinterpret_cast<void*>(2017))) 2394 DeserializeEmbedderFields, reinterpret_cast<void*>(2017)))
2395 .ToLocalChecked(); 2395 .ToLocalChecked();
2396 2396
2397 { 2397 {
2398 v8::Context::Scope context_scope(context); 2398 v8::Context::Scope context_scope(context);
2399 ExpectInt32("f()", 42); 2399 ExpectInt32("f()", 42);
2400 ExpectInt32("g()", 12); 2400 ExpectInt32("g()", 12);
2401 ExpectInt32("h()", 13); 2401 ExpectInt32("h()", 13);
2402 ExpectInt32("i()", 24); 2402 ExpectInt32("i()", 24);
2403 ExpectInt32("j()", 25); 2403 ExpectInt32("j()", 25);
2404 ExpectInt32("o.p", 8); 2404 ExpectInt32("o.p", 8);
2405 ExpectInt32("x", 2016); 2405 ExpectInt32("x", 2016);
2406 v8::Local<v8::Private> hidden = 2406 v8::Local<v8::Private> hidden =
2407 v8::Private::ForApi(isolate, v8_str("hidden")); 2407 v8::Private::ForApi(isolate, v8_str("hidden"));
2408 CHECK(v8_str("hidden string") 2408 CHECK(v8_str("hidden string")
2409 ->Equals(context, context->Global() 2409 ->Equals(context, context->Global()
2410 ->GetPrivate(context, hidden) 2410 ->GetPrivate(context, hidden)
2411 .ToLocalChecked()) 2411 .ToLocalChecked())
2412 .FromJust()); 2412 .FromJust());
2413 ExpectString("cached", "cached string"); 2413 ExpectString("cached", "cached string");
2414 } 2414 }
2415 2415
2416 v8::Local<v8::Object> global = context->Global(); 2416 v8::Local<v8::Object> global = context->Global();
2417 CHECK_EQ(3, global->InternalFieldCount()); 2417 CHECK_EQ(3, global->EmbedderFieldCount());
2418 context->DetachGlobal(); 2418 context->DetachGlobal();
2419 2419
2420 // New context, but reuse global proxy. 2420 // New context, but reuse global proxy.
2421 v8::ExtensionConfiguration* no_extensions = nullptr; 2421 v8::ExtensionConfiguration* no_extensions = nullptr;
2422 v8::Local<v8::Context> context2 = 2422 v8::Local<v8::Context> context2 =
2423 v8::Context::FromSnapshot( 2423 v8::Context::FromSnapshot(
2424 isolate, 0, 2424 isolate, 0,
2425 v8::DeserializeInternalFieldsCallback( 2425 v8::DeserializeEmbedderFieldsCallback(
2426 DeserializeInternalFields, reinterpret_cast<void*>(2017)), 2426 DeserializeEmbedderFields, reinterpret_cast<void*>(2017)),
2427 no_extensions, global) 2427 no_extensions, global)
2428 .ToLocalChecked(); 2428 .ToLocalChecked();
2429 { 2429 {
2430 v8::Context::Scope context_scope(context2); 2430 v8::Context::Scope context_scope(context2);
2431 ExpectInt32("f()", 42); 2431 ExpectInt32("f()", 42);
2432 ExpectInt32("g()", 12); 2432 ExpectInt32("g()", 12);
2433 ExpectInt32("h()", 13); 2433 ExpectInt32("h()", 13);
2434 ExpectInt32("i()", 24); 2434 ExpectInt32("i()", 24);
2435 ExpectInt32("j()", 25); 2435 ExpectInt32("j()", 25);
2436 ExpectInt32("o.p", 8); 2436 ExpectInt32("o.p", 8);
(...skipping 22 matching lines...) Expand all
2459 } 2459 }
2460 delete[] blob.data; 2460 delete[] blob.data;
2461 } 2461 }
2462 2462
2463 TEST(SerializationMemoryStats) { 2463 TEST(SerializationMemoryStats) {
2464 FLAG_profile_deserialization = true; 2464 FLAG_profile_deserialization = true;
2465 FLAG_always_opt = false; 2465 FLAG_always_opt = false;
2466 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); 2466 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob();
2467 delete[] blob.data; 2467 delete[] blob.data;
2468 } 2468 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698