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 2004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2015 | 2015 |
2016 void SerializedCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { | 2016 void SerializedCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { |
2017 args.GetReturnValue().Set(v8_num(42)); | 2017 args.GetReturnValue().Set(v8_num(42)); |
2018 } | 2018 } |
2019 | 2019 |
2020 void SerializedCallbackReplacement( | 2020 void SerializedCallbackReplacement( |
2021 const v8::FunctionCallbackInfo<v8::Value>& args) { | 2021 const v8::FunctionCallbackInfo<v8::Value>& args) { |
2022 args.GetReturnValue().Set(v8_num(1337)); | 2022 args.GetReturnValue().Set(v8_num(1337)); |
2023 } | 2023 } |
2024 | 2024 |
| 2025 static int serialized_static_field = 314; |
| 2026 |
2025 intptr_t original_external_references[] = { | 2027 intptr_t original_external_references[] = { |
2026 reinterpret_cast<intptr_t>(SerializedCallback), 0}; | 2028 reinterpret_cast<intptr_t>(SerializedCallback), |
| 2029 reinterpret_cast<intptr_t>(&serialized_static_field), 0}; |
2027 | 2030 |
2028 intptr_t replaced_external_references[] = { | 2031 intptr_t replaced_external_references[] = { |
2029 reinterpret_cast<intptr_t>(SerializedCallbackReplacement), 0}; | 2032 reinterpret_cast<intptr_t>(SerializedCallbackReplacement), |
| 2033 reinterpret_cast<intptr_t>(&serialized_static_field), 0}; |
2030 | 2034 |
2031 TEST(SnapshotCreatorExternalReferences) { | 2035 TEST(SnapshotCreatorExternalReferences) { |
2032 DisableAlwaysOpt(); | 2036 DisableAlwaysOpt(); |
2033 v8::StartupData blob; | 2037 v8::StartupData blob; |
2034 { | 2038 { |
2035 v8::SnapshotCreator creator(original_external_references); | 2039 v8::SnapshotCreator creator(original_external_references); |
2036 v8::Isolate* isolate = creator.GetIsolate(); | 2040 v8::Isolate* isolate = creator.GetIsolate(); |
2037 { | 2041 { |
2038 v8::HandleScope handle_scope(isolate); | 2042 v8::HandleScope handle_scope(isolate); |
2039 v8::Local<v8::Context> context = v8::Context::New(isolate); | 2043 v8::Local<v8::Context> context = v8::Context::New(isolate); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2135 } | 2139 } |
2136 | 2140 |
2137 TEST(SnapshotCreatorTemplates) { | 2141 TEST(SnapshotCreatorTemplates) { |
2138 DisableAlwaysOpt(); | 2142 DisableAlwaysOpt(); |
2139 v8::StartupData blob; | 2143 v8::StartupData blob; |
2140 | 2144 |
2141 { | 2145 { |
2142 InternalFieldData* a1 = new InternalFieldData{11}; | 2146 InternalFieldData* a1 = new InternalFieldData{11}; |
2143 InternalFieldData* b0 = new InternalFieldData{20}; | 2147 InternalFieldData* b0 = new InternalFieldData{20}; |
2144 InternalFieldData* c0 = new InternalFieldData{30}; | 2148 InternalFieldData* c0 = new InternalFieldData{30}; |
2145 InternalFieldData* c1 = new InternalFieldData{31}; | |
2146 | 2149 |
2147 v8::SnapshotCreator creator(original_external_references); | 2150 v8::SnapshotCreator creator(original_external_references); |
2148 v8::Isolate* isolate = creator.GetIsolate(); | 2151 v8::Isolate* isolate = creator.GetIsolate(); |
2149 { | 2152 { |
2150 v8::HandleScope handle_scope(isolate); | 2153 v8::HandleScope handle_scope(isolate); |
2151 v8::ExtensionConfiguration* no_extension = nullptr; | 2154 v8::ExtensionConfiguration* no_extension = nullptr; |
2152 v8::Local<v8::ObjectTemplate> global_template = | 2155 v8::Local<v8::ObjectTemplate> global_template = |
2153 v8::ObjectTemplate::New(isolate); | 2156 v8::ObjectTemplate::New(isolate); |
2154 v8::Local<v8::FunctionTemplate> callback = | 2157 v8::Local<v8::FunctionTemplate> callback = |
2155 v8::FunctionTemplate::New(isolate, SerializedCallback); | 2158 v8::FunctionTemplate::New(isolate, SerializedCallback); |
2156 global_template->Set(v8_str("f"), callback); | 2159 global_template->Set(v8_str("f"), callback); |
2157 v8::Local<v8::Context> context = | 2160 v8::Local<v8::Context> context = |
2158 v8::Context::New(isolate, no_extension, global_template); | 2161 v8::Context::New(isolate, no_extension, global_template); |
2159 v8::Local<v8::ObjectTemplate> object_template = | 2162 v8::Local<v8::ObjectTemplate> object_template = |
2160 v8::ObjectTemplate::New(isolate); | 2163 v8::ObjectTemplate::New(isolate); |
2161 object_template->SetInternalFieldCount(2); | 2164 object_template->SetInternalFieldCount(3); |
2162 | 2165 |
2163 v8::Context::Scope context_scope(context); | 2166 v8::Context::Scope context_scope(context); |
2164 ExpectInt32("f()", 42); | 2167 ExpectInt32("f()", 42); |
2165 | 2168 |
2166 v8::Local<v8::Object> a = | 2169 v8::Local<v8::Object> a = |
2167 object_template->NewInstance(context).ToLocalChecked(); | 2170 object_template->NewInstance(context).ToLocalChecked(); |
2168 v8::Local<v8::Object> b = | 2171 v8::Local<v8::Object> b = |
2169 object_template->NewInstance(context).ToLocalChecked(); | 2172 object_template->NewInstance(context).ToLocalChecked(); |
2170 v8::Local<v8::Object> c = | 2173 v8::Local<v8::Object> c = |
2171 object_template->NewInstance(context).ToLocalChecked(); | 2174 object_template->NewInstance(context).ToLocalChecked(); |
| 2175 v8::Local<v8::External> null_external = |
| 2176 v8::External::New(isolate, nullptr); |
| 2177 v8::Local<v8::External> field_external = |
| 2178 v8::External::New(isolate, &serialized_static_field); |
2172 a->SetInternalField(0, b); | 2179 a->SetInternalField(0, b); |
2173 a->SetAlignedPointerInInternalField(1, a1); | 2180 a->SetAlignedPointerInInternalField(1, a1); |
2174 b->SetAlignedPointerInInternalField(0, b0); | 2181 b->SetAlignedPointerInInternalField(0, b0); |
2175 b->SetInternalField(1, c); | 2182 b->SetInternalField(1, c); |
2176 c->SetAlignedPointerInInternalField(0, c0); | 2183 c->SetAlignedPointerInInternalField(0, c0); |
2177 c->SetAlignedPointerInInternalField(1, c1); | 2184 c->SetInternalField(1, null_external); |
| 2185 c->SetInternalField(2, field_external); |
2178 CHECK(context->Global()->Set(context, v8_str("a"), a).FromJust()); | 2186 CHECK(context->Global()->Set(context, v8_str("a"), a).FromJust()); |
2179 | 2187 |
2180 CHECK_EQ(0u, creator.AddContext(context)); | 2188 CHECK_EQ(0u, creator.AddContext(context)); |
2181 CHECK_EQ(0u, creator.AddTemplate(callback)); | 2189 CHECK_EQ(0u, creator.AddTemplate(callback)); |
2182 CHECK_EQ(1u, creator.AddTemplate(global_template)); | 2190 CHECK_EQ(1u, creator.AddTemplate(global_template)); |
2183 } | 2191 } |
2184 blob = creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear, | 2192 blob = creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear, |
2185 SerializeInternalFields); | 2193 SerializeInternalFields); |
2186 | 2194 |
2187 delete a1; | 2195 delete a1; |
2188 delete b0; | 2196 delete b0; |
2189 delete c1; | |
2190 delete c0; | 2197 delete c0; |
2191 } | 2198 } |
2192 | 2199 |
2193 { | 2200 { |
2194 v8::Isolate::CreateParams params; | 2201 v8::Isolate::CreateParams params; |
2195 params.snapshot_blob = &blob; | 2202 params.snapshot_blob = &blob; |
2196 params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 2203 params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
2197 params.external_references = original_external_references; | 2204 params.external_references = original_external_references; |
2198 params.deserialize_internal_fields_callback = DeserializeInternalFields; | 2205 params.deserialize_internal_fields_callback = DeserializeInternalFields; |
2199 v8::Isolate* isolate = v8::Isolate::New(params); | 2206 v8::Isolate* isolate = v8::Isolate::New(params); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2232 // Retrieve internal fields. | 2239 // Retrieve internal fields. |
2233 v8::Local<v8::Object> a = context->Global() | 2240 v8::Local<v8::Object> a = context->Global() |
2234 ->Get(context, v8_str("a")) | 2241 ->Get(context, v8_str("a")) |
2235 .ToLocalChecked() | 2242 .ToLocalChecked() |
2236 ->ToObject(context) | 2243 ->ToObject(context) |
2237 .ToLocalChecked(); | 2244 .ToLocalChecked(); |
2238 v8::Local<v8::Object> b = | 2245 v8::Local<v8::Object> b = |
2239 a->GetInternalField(0)->ToObject(context).ToLocalChecked(); | 2246 a->GetInternalField(0)->ToObject(context).ToLocalChecked(); |
2240 InternalFieldData* a1 = reinterpret_cast<InternalFieldData*>( | 2247 InternalFieldData* a1 = reinterpret_cast<InternalFieldData*>( |
2241 a->GetAlignedPointerFromInternalField(1)); | 2248 a->GetAlignedPointerFromInternalField(1)); |
| 2249 v8::Local<v8::Value> a2 = a->GetInternalField(2); |
| 2250 |
2242 InternalFieldData* b0 = reinterpret_cast<InternalFieldData*>( | 2251 InternalFieldData* b0 = reinterpret_cast<InternalFieldData*>( |
2243 b->GetAlignedPointerFromInternalField(0)); | 2252 b->GetAlignedPointerFromInternalField(0)); |
2244 v8::Local<v8::Object> c = | 2253 v8::Local<v8::Object> c = |
2245 b->GetInternalField(1)->ToObject(context).ToLocalChecked(); | 2254 b->GetInternalField(1)->ToObject(context).ToLocalChecked(); |
| 2255 v8::Local<v8::Value> b2 = b->GetInternalField(2); |
| 2256 |
2246 InternalFieldData* c0 = reinterpret_cast<InternalFieldData*>( | 2257 InternalFieldData* c0 = reinterpret_cast<InternalFieldData*>( |
2247 c->GetAlignedPointerFromInternalField(0)); | 2258 c->GetAlignedPointerFromInternalField(0)); |
2248 InternalFieldData* c1 = reinterpret_cast<InternalFieldData*>( | 2259 v8::Local<v8::Value> c1 = c->GetInternalField(1); |
2249 c->GetAlignedPointerFromInternalField(1)); | 2260 v8::Local<v8::Value> c2 = c->GetInternalField(2); |
2250 | 2261 |
2251 CHECK_EQ(11u, a1->data); | 2262 CHECK_EQ(11u, a1->data); |
| 2263 CHECK(a2->IsUndefined()); |
2252 CHECK_EQ(20u, b0->data); | 2264 CHECK_EQ(20u, b0->data); |
| 2265 CHECK(b2->IsUndefined()); |
2253 CHECK_EQ(30u, c0->data); | 2266 CHECK_EQ(30u, c0->data); |
2254 CHECK_EQ(31u, c1->data); | 2267 CHECK(c1->IsExternal()); |
| 2268 CHECK_NULL(v8::Local<v8::External>::Cast(c1)->Value()); |
| 2269 CHECK_EQ(static_cast<void*>(&serialized_static_field), |
| 2270 v8::Local<v8::External>::Cast(c2)->Value()); |
2255 | 2271 |
2256 // Accessing out of bound returns empty MaybeHandle. | 2272 // Accessing out of bound returns empty MaybeHandle. |
2257 CHECK(v8::ObjectTemplate::FromSnapshot(isolate, 2).IsEmpty()); | 2273 CHECK(v8::ObjectTemplate::FromSnapshot(isolate, 2).IsEmpty()); |
2258 CHECK(v8::FunctionTemplate::FromSnapshot(isolate, 2).IsEmpty()); | 2274 CHECK(v8::FunctionTemplate::FromSnapshot(isolate, 2).IsEmpty()); |
2259 CHECK(v8::Context::FromSnapshot(isolate, 2).IsEmpty()); | 2275 CHECK(v8::Context::FromSnapshot(isolate, 2).IsEmpty()); |
2260 | 2276 |
2261 delete a1; | 2277 delete a1; |
2262 delete b0; | 2278 delete b0; |
2263 delete c1; | |
2264 delete c0; | 2279 delete c0; |
2265 } | 2280 } |
2266 | 2281 |
2267 { | 2282 { |
2268 // Create a context with a new object template. It is merged into the | 2283 // Create a context with a new object template. It is merged into the |
2269 // deserialized global object. | 2284 // deserialized global object. |
2270 v8::HandleScope handle_scope(isolate); | 2285 v8::HandleScope handle_scope(isolate); |
2271 v8::ExtensionConfiguration* no_extension = nullptr; | 2286 v8::ExtensionConfiguration* no_extension = nullptr; |
2272 v8::Local<v8::ObjectTemplate> global_template = | 2287 v8::Local<v8::ObjectTemplate> global_template = |
2273 v8::ObjectTemplate::New(isolate); | 2288 v8::ObjectTemplate::New(isolate); |
(...skipping 12 matching lines...) Expand all Loading... |
2286 } | 2301 } |
2287 delete[] blob.data; | 2302 delete[] blob.data; |
2288 } | 2303 } |
2289 | 2304 |
2290 TEST(SerializationMemoryStats) { | 2305 TEST(SerializationMemoryStats) { |
2291 FLAG_profile_deserialization = true; | 2306 FLAG_profile_deserialization = true; |
2292 FLAG_always_opt = false; | 2307 FLAG_always_opt = false; |
2293 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 2308 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
2294 delete[] blob.data; | 2309 delete[] blob.data; |
2295 } | 2310 } |
OLD | NEW |