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 2154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2165 int index) { | 2165 int index) { |
2166 InternalFieldData* data = static_cast<InternalFieldData*>( | 2166 InternalFieldData* data = static_cast<InternalFieldData*>( |
2167 holder->GetAlignedPointerFromInternalField(index)); | 2167 holder->GetAlignedPointerFromInternalField(index)); |
2168 int size = sizeof(*data); | 2168 int size = sizeof(*data); |
2169 char* payload = new char[size]; | 2169 char* payload = new char[size]; |
2170 // We simply use memcpy to serialize the content. | 2170 // We simply use memcpy to serialize the content. |
2171 memcpy(payload, data, size); | 2171 memcpy(payload, data, size); |
2172 return {payload, size}; | 2172 return {payload, size}; |
2173 } | 2173 } |
2174 | 2174 |
| 2175 std::vector<InternalFieldData*> deserialized_data; |
| 2176 |
2175 void DeserializeInternalFields(v8::Local<v8::Object> holder, int index, | 2177 void DeserializeInternalFields(v8::Local<v8::Object> holder, int index, |
2176 v8::StartupData payload) { | 2178 v8::StartupData payload) { |
2177 InternalFieldData* data = new InternalFieldData{0}; | 2179 InternalFieldData* data = new InternalFieldData{0}; |
2178 memcpy(data, payload.data, payload.raw_size); | 2180 memcpy(data, payload.data, payload.raw_size); |
2179 holder->SetAlignedPointerInInternalField(index, data); | 2181 holder->SetAlignedPointerInInternalField(index, data); |
| 2182 deserialized_data.push_back(data); |
2180 } | 2183 } |
2181 | 2184 |
2182 TEST(SnapshotCreatorTemplates) { | 2185 TEST(SnapshotCreatorTemplates) { |
2183 DisableAlwaysOpt(); | 2186 DisableAlwaysOpt(); |
2184 v8::StartupData blob; | 2187 v8::StartupData blob; |
2185 | 2188 |
2186 { | 2189 { |
2187 InternalFieldData* a1 = new InternalFieldData{11}; | 2190 InternalFieldData* a1 = new InternalFieldData{11}; |
2188 InternalFieldData* b0 = new InternalFieldData{20}; | 2191 InternalFieldData* b0 = new InternalFieldData{20}; |
2189 InternalFieldData* c0 = new InternalFieldData{30}; | 2192 InternalFieldData* c0 = new InternalFieldData{30}; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2307 CHECK(c1->IsExternal()); | 2310 CHECK(c1->IsExternal()); |
2308 CHECK_NULL(v8::Local<v8::External>::Cast(c1)->Value()); | 2311 CHECK_NULL(v8::Local<v8::External>::Cast(c1)->Value()); |
2309 CHECK_EQ(static_cast<void*>(&serialized_static_field), | 2312 CHECK_EQ(static_cast<void*>(&serialized_static_field), |
2310 v8::Local<v8::External>::Cast(c2)->Value()); | 2313 v8::Local<v8::External>::Cast(c2)->Value()); |
2311 | 2314 |
2312 // Accessing out of bound returns empty MaybeHandle. | 2315 // Accessing out of bound returns empty MaybeHandle. |
2313 CHECK(v8::ObjectTemplate::FromSnapshot(isolate, 2).IsEmpty()); | 2316 CHECK(v8::ObjectTemplate::FromSnapshot(isolate, 2).IsEmpty()); |
2314 CHECK(v8::FunctionTemplate::FromSnapshot(isolate, 2).IsEmpty()); | 2317 CHECK(v8::FunctionTemplate::FromSnapshot(isolate, 2).IsEmpty()); |
2315 CHECK(v8::Context::FromSnapshot(isolate, 1).IsEmpty()); | 2318 CHECK(v8::Context::FromSnapshot(isolate, 1).IsEmpty()); |
2316 | 2319 |
2317 delete a1; | 2320 for (auto data : deserialized_data) delete data; |
2318 delete b0; | 2321 deserialized_data.clear(); |
2319 delete c0; | |
2320 } | 2322 } |
2321 | 2323 |
2322 { | 2324 { |
2323 // Create a context with a new object template. It is merged into the | 2325 // Create a context with a new object template. It is merged into the |
2324 // deserialized global object. | 2326 // deserialized global object. |
2325 v8::HandleScope handle_scope(isolate); | 2327 v8::HandleScope handle_scope(isolate); |
2326 v8::ExtensionConfiguration* no_extension = nullptr; | 2328 v8::ExtensionConfiguration* no_extension = nullptr; |
2327 v8::Local<v8::ObjectTemplate> global_template = | 2329 v8::Local<v8::ObjectTemplate> global_template = |
2328 v8::ObjectTemplate::New(isolate); | 2330 v8::ObjectTemplate::New(isolate); |
2329 global_template->Set( | 2331 global_template->Set( |
2330 v8_str("g"), | 2332 v8_str("g"), |
2331 v8::FunctionTemplate::New(isolate, SerializedCallbackReplacement)); | 2333 v8::FunctionTemplate::New(isolate, SerializedCallbackReplacement)); |
2332 v8::Local<v8::Context> context = | 2334 v8::Local<v8::Context> context = |
2333 v8::Context::New(isolate, no_extension, global_template); | 2335 v8::Context::New(isolate, no_extension, global_template); |
2334 v8::Context::Scope context_scope(context); | 2336 v8::Context::Scope context_scope(context); |
2335 ExpectInt32("g()", 1337); | 2337 ExpectInt32("g()", 1337); |
2336 ExpectInt32("f()", 42); | 2338 ExpectInt32("f()", 42); |
| 2339 |
| 2340 for (auto data : deserialized_data) delete data; |
| 2341 deserialized_data.clear(); |
2337 } | 2342 } |
2338 } | 2343 } |
2339 isolate->Dispose(); | 2344 isolate->Dispose(); |
2340 } | 2345 } |
2341 delete[] blob.data; | 2346 delete[] blob.data; |
2342 } | 2347 } |
2343 | 2348 |
2344 TEST(SnapshotCreatorIncludeGlobalProxy) { | 2349 TEST(SnapshotCreatorIncludeGlobalProxy) { |
2345 DisableAlwaysOpt(); | 2350 DisableAlwaysOpt(); |
2346 v8::StartupData blob; | 2351 v8::StartupData blob; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2527 } | 2532 } |
2528 delete[] blob.data; | 2533 delete[] blob.data; |
2529 } | 2534 } |
2530 | 2535 |
2531 TEST(SerializationMemoryStats) { | 2536 TEST(SerializationMemoryStats) { |
2532 FLAG_profile_deserialization = true; | 2537 FLAG_profile_deserialization = true; |
2533 FLAG_always_opt = false; | 2538 FLAG_always_opt = false; |
2534 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 2539 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
2535 delete[] blob.data; | 2540 delete[] blob.data; |
2536 } | 2541 } |
OLD | NEW |