Index: test/cctest/test-serialize.cc |
diff --git a/test/cctest/test-serialize.cc b/test/cctest/test-serialize.cc |
index ba3738e2e7413796c14bd46deea5eaf45be6ac2f..9644d0962428a245672aa8214af8c4c3561eea13 100644 |
--- a/test/cctest/test-serialize.cc |
+++ b/test/cctest/test-serialize.cc |
@@ -285,7 +285,8 @@ static void PartiallySerializeObject(Vector<const byte>* startup_blob_out, |
isolate, v8::SnapshotCreator::FunctionCodeHandling::kClear); |
startup_serializer.SerializeStrongReferences(); |
- PartialSerializer partial_serializer(isolate, &startup_serializer, nullptr); |
+ PartialSerializer partial_serializer(isolate, &startup_serializer, |
+ v8::SerializeInternalFieldsCallback()); |
partial_serializer.Serialize(&raw_foo, false); |
startup_serializer.SerializeWeakReferencesAndDeferred(); |
@@ -321,7 +322,9 @@ UNINITIALIZED_TEST(PartialSerializerObject) { |
{ |
SnapshotData snapshot_data(partial_blob); |
Deserializer deserializer(&snapshot_data); |
- root = deserializer.DeserializePartial(isolate, global_proxy, nullptr) |
+ root = deserializer |
+ .DeserializePartial(isolate, global_proxy, |
+ v8::DeserializeInternalFieldsCallback()) |
.ToHandleChecked(); |
CHECK(root->IsString()); |
} |
@@ -330,7 +333,9 @@ UNINITIALIZED_TEST(PartialSerializerObject) { |
{ |
SnapshotData snapshot_data(partial_blob); |
Deserializer deserializer(&snapshot_data); |
- root2 = deserializer.DeserializePartial(isolate, global_proxy, nullptr) |
+ root2 = deserializer |
+ .DeserializePartial(isolate, global_proxy, |
+ v8::DeserializeInternalFieldsCallback()) |
.ToHandleChecked(); |
CHECK(root2->IsString()); |
CHECK(root.is_identical_to(root2)); |
@@ -385,7 +390,8 @@ static void PartiallySerializeContext(Vector<const byte>* startup_blob_out, |
startup_serializer.SerializeStrongReferences(); |
SnapshotByteSink partial_sink; |
- PartialSerializer partial_serializer(isolate, &startup_serializer, nullptr); |
+ PartialSerializer partial_serializer(isolate, &startup_serializer, |
+ v8::SerializeInternalFieldsCallback()); |
partial_serializer.Serialize(&raw_context, false); |
startup_serializer.SerializeWeakReferencesAndDeferred(); |
@@ -419,7 +425,9 @@ UNINITIALIZED_TEST(PartialSerializerContext) { |
{ |
SnapshotData snapshot_data(partial_blob); |
Deserializer deserializer(&snapshot_data); |
- root = deserializer.DeserializePartial(isolate, global_proxy, nullptr) |
+ root = deserializer |
+ .DeserializePartial(isolate, global_proxy, |
+ v8::DeserializeInternalFieldsCallback()) |
.ToHandleChecked(); |
CHECK(root->IsContext()); |
CHECK(Handle<Context>::cast(root)->global_proxy() == *global_proxy); |
@@ -429,7 +437,9 @@ UNINITIALIZED_TEST(PartialSerializerContext) { |
{ |
SnapshotData snapshot_data(partial_blob); |
Deserializer deserializer(&snapshot_data); |
- root2 = deserializer.DeserializePartial(isolate, global_proxy, nullptr) |
+ root2 = deserializer |
+ .DeserializePartial(isolate, global_proxy, |
+ v8::DeserializeInternalFieldsCallback()) |
.ToHandleChecked(); |
CHECK(root2->IsContext()); |
CHECK(!root.is_identical_to(root2)); |
@@ -505,7 +515,8 @@ static void PartiallySerializeCustomContext( |
startup_serializer.SerializeStrongReferences(); |
SnapshotByteSink partial_sink; |
- PartialSerializer partial_serializer(isolate, &startup_serializer, nullptr); |
+ PartialSerializer partial_serializer(isolate, &startup_serializer, |
+ v8::SerializeInternalFieldsCallback()); |
partial_serializer.Serialize(&raw_context, false); |
startup_serializer.SerializeWeakReferencesAndDeferred(); |
@@ -539,7 +550,9 @@ UNINITIALIZED_TEST(PartialSerializerCustomContext) { |
{ |
SnapshotData snapshot_data(partial_blob); |
Deserializer deserializer(&snapshot_data); |
- root = deserializer.DeserializePartial(isolate, global_proxy, nullptr) |
+ root = deserializer |
+ .DeserializePartial(isolate, global_proxy, |
+ v8::DeserializeInternalFieldsCallback()) |
.ToHandleChecked(); |
CHECK(root->IsContext()); |
Handle<Context> context = Handle<Context>::cast(root); |
@@ -2161,25 +2174,27 @@ struct InternalFieldData { |
uint32_t data; |
}; |
-v8::StartupData SerializeInternalFields(v8::Local<v8::Object> holder, |
- int index) { |
- InternalFieldData* data = static_cast<InternalFieldData*>( |
+v8::StartupData SerializeInternalFields(v8::Local<v8::Object> holder, int index, |
+ void* data) { |
+ CHECK_EQ(reinterpret_cast<void*>(2016), data); |
+ InternalFieldData* internal_field = static_cast<InternalFieldData*>( |
holder->GetAlignedPointerFromInternalField(index)); |
- int size = sizeof(*data); |
+ int size = sizeof(*internal_field); |
char* payload = new char[size]; |
// We simply use memcpy to serialize the content. |
- memcpy(payload, data, size); |
+ memcpy(payload, internal_field, size); |
return {payload, size}; |
} |
std::vector<InternalFieldData*> deserialized_data; |
void DeserializeInternalFields(v8::Local<v8::Object> holder, int index, |
- v8::StartupData payload) { |
- InternalFieldData* data = new InternalFieldData{0}; |
- memcpy(data, payload.data, payload.raw_size); |
- holder->SetAlignedPointerInInternalField(index, data); |
- deserialized_data.push_back(data); |
+ v8::StartupData payload, void* data) { |
+ CHECK_EQ(reinterpret_cast<void*>(2017), data); |
+ InternalFieldData* internal_field = new InternalFieldData{0}; |
+ memcpy(internal_field, payload.data, payload.raw_size); |
+ holder->SetAlignedPointerInInternalField(index, internal_field); |
+ deserialized_data.push_back(internal_field); |
} |
TEST(SnapshotCreatorTemplates) { |
@@ -2231,7 +2246,10 @@ TEST(SnapshotCreatorTemplates) { |
c->SetInternalField(2, field_external); |
CHECK(context->Global()->Set(context, v8_str("a"), a).FromJust()); |
- CHECK_EQ(0u, creator.AddContext(context, SerializeInternalFields)); |
+ CHECK_EQ(0u, |
+ creator.AddContext(context, v8::SerializeInternalFieldsCallback( |
+ SerializeInternalFields, |
+ reinterpret_cast<void*>(2016)))); |
CHECK_EQ(0u, creator.AddTemplate(callback)); |
CHECK_EQ(1u, creator.AddTemplate(global_template)); |
} |
@@ -2255,7 +2273,10 @@ TEST(SnapshotCreatorTemplates) { |
// Create a new context without a new object template. |
v8::HandleScope handle_scope(isolate); |
v8::Local<v8::Context> context = |
- v8::Context::FromSnapshot(isolate, 0, DeserializeInternalFields) |
+ v8::Context::FromSnapshot( |
+ isolate, 0, |
+ v8::DeserializeInternalFieldsCallback( |
+ DeserializeInternalFields, reinterpret_cast<void*>(2017))) |
.ToLocalChecked(); |
v8::Context::Scope context_scope(context); |
ExpectInt32("f()", 42); |
@@ -2408,7 +2429,10 @@ TEST(SnapshotCreatorIncludeGlobalProxy) { |
.ToLocalChecked()) |
.FromJust()); |
- CHECK_EQ(0u, creator.AddContext(context, SerializeInternalFields)); |
+ CHECK_EQ(0u, |
+ creator.AddContext(context, v8::SerializeInternalFieldsCallback( |
+ SerializeInternalFields, |
+ reinterpret_cast<void*>(2016)))); |
} |
blob = |
creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); |
@@ -2452,8 +2476,12 @@ TEST(SnapshotCreatorIncludeGlobalProxy) { |
// will use the global object from the snapshot, including interceptor. |
v8::HandleScope handle_scope(isolate); |
v8::Local<v8::Context> context = |
- v8::Context::FromSnapshot(isolate, 0, DeserializeInternalFields) |
+ v8::Context::FromSnapshot( |
+ isolate, 0, |
+ v8::DeserializeInternalFieldsCallback( |
+ DeserializeInternalFields, reinterpret_cast<void*>(2017))) |
.ToLocalChecked(); |
+ |
{ |
v8::Context::Scope context_scope(context); |
ExpectInt32("f()", 42); |
@@ -2480,8 +2508,11 @@ TEST(SnapshotCreatorIncludeGlobalProxy) { |
// New context, but reuse global proxy. |
v8::ExtensionConfiguration* no_extensions = nullptr; |
v8::Local<v8::Context> context2 = |
- v8::Context::FromSnapshot(isolate, 0, DeserializeInternalFields, |
- no_extensions, global) |
+ v8::Context::FromSnapshot( |
+ isolate, 0, |
+ v8::DeserializeInternalFieldsCallback( |
+ DeserializeInternalFields, reinterpret_cast<void*>(2017)), |
+ no_extensions, global) |
.ToLocalChecked(); |
{ |
v8::Context::Scope context_scope(context2); |