| 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 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2024 v8::Local<v8::Context> context = | 2024 v8::Local<v8::Context> context = |
| 2025 v8::Context::New(isolate, no_extension, no_template, no_object, 0); | 2025 v8::Context::New(isolate, no_extension, no_template, no_object, 0); |
| 2026 v8::Context::Scope context_scope(context); | 2026 v8::Context::Scope context_scope(context); |
| 2027 ExpectInt32("f()", 1337); | 2027 ExpectInt32("f()", 1337); |
| 2028 } | 2028 } |
| 2029 isolate->Dispose(); | 2029 isolate->Dispose(); |
| 2030 } | 2030 } |
| 2031 delete[] blob.data; | 2031 delete[] blob.data; |
| 2032 } | 2032 } |
| 2033 | 2033 |
| 2034 TEST(SnapshotCreatorGlobalTemplate) { | 2034 TEST(SnapshotCreatorTemplates) { |
| 2035 DisableTurbofan(); | 2035 DisableTurbofan(); |
| 2036 v8::StartupData blob; | 2036 v8::StartupData blob; |
| 2037 { | 2037 { |
| 2038 v8::SnapshotCreator creator(original_external_references); | 2038 v8::SnapshotCreator creator(original_external_references); |
| 2039 v8::Isolate* isolate = creator.GetIsolate(); | 2039 v8::Isolate* isolate = creator.GetIsolate(); |
| 2040 { | 2040 { |
| 2041 v8::HandleScope handle_scope(isolate); | 2041 v8::HandleScope handle_scope(isolate); |
| 2042 v8::ExtensionConfiguration* no_extension = nullptr; | 2042 v8::ExtensionConfiguration* no_extension = nullptr; |
| 2043 v8::Local<v8::ObjectTemplate> global_template = | 2043 v8::Local<v8::ObjectTemplate> global_template = |
| 2044 v8::ObjectTemplate::New(isolate); | 2044 v8::ObjectTemplate::New(isolate); |
| 2045 global_template->Set( | 2045 v8::Local<v8::FunctionTemplate> callback = |
| 2046 v8_str("f"), v8::FunctionTemplate::New(isolate, SerializedCallback)); | 2046 v8::FunctionTemplate::New(isolate, SerializedCallback); |
| 2047 global_template->Set(v8_str("f"), callback); |
| 2047 v8::Local<v8::Context> context = | 2048 v8::Local<v8::Context> context = |
| 2048 v8::Context::New(isolate, no_extension, global_template); | 2049 v8::Context::New(isolate, no_extension, global_template); |
| 2049 v8::Context::Scope context_scope(context); | 2050 v8::Context::Scope context_scope(context); |
| 2050 ExpectInt32("f()", 42); | 2051 ExpectInt32("f()", 42); |
| 2051 CHECK_EQ(0, creator.AddContext(context)); | 2052 CHECK_EQ(0, creator.AddContext(context)); |
| 2053 CHECK_EQ(0, creator.AddTemplate(callback)); |
| 2054 CHECK_EQ(1, creator.AddTemplate(global_template)); |
| 2052 } | 2055 } |
| 2053 blob = | 2056 blob = |
| 2054 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); | 2057 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); |
| 2055 } | 2058 } |
| 2056 | 2059 |
| 2057 { | 2060 { |
| 2058 v8::Isolate::CreateParams params; | 2061 v8::Isolate::CreateParams params; |
| 2059 params.snapshot_blob = &blob; | 2062 params.snapshot_blob = &blob; |
| 2060 params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 2063 params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 2061 params.external_references = original_external_references; | 2064 params.external_references = original_external_references; |
| 2062 v8::Isolate* isolate = v8::Isolate::New(params); | 2065 v8::Isolate* isolate = v8::Isolate::New(params); |
| 2063 { | 2066 { |
| 2064 v8::Isolate::Scope isolate_scope(isolate); | 2067 v8::Isolate::Scope isolate_scope(isolate); |
| 2065 { | 2068 { |
| 2066 // Create a new context without a new object template. | 2069 // Create a new context without a new object template. |
| 2067 v8::HandleScope handle_scope(isolate); | 2070 v8::HandleScope handle_scope(isolate); |
| 2068 v8::ExtensionConfiguration* no_extension = nullptr; | 2071 v8::ExtensionConfiguration* no_extension = nullptr; |
| 2069 v8::Local<v8::ObjectTemplate> no_template = | 2072 v8::Local<v8::ObjectTemplate> no_template = |
| 2070 v8::Local<v8::ObjectTemplate>(); | 2073 v8::Local<v8::ObjectTemplate>(); |
| 2071 v8::Local<v8::Value> no_object = v8::Local<v8::Value>(); | 2074 v8::Local<v8::Value> no_object = v8::Local<v8::Value>(); |
| 2072 v8::Local<v8::Context> context = | 2075 v8::Local<v8::Context> context = |
| 2073 v8::Context::New(isolate, no_extension, no_template, no_object, 0); | 2076 v8::Context::New(isolate, no_extension, no_template, no_object, 0); |
| 2074 v8::Context::Scope context_scope(context); | 2077 v8::Context::Scope context_scope(context); |
| 2075 ExpectInt32("f()", 42); | 2078 ExpectInt32("f()", 42); |
| 2079 |
| 2080 // Retrieve the snapshotted object template. |
| 2081 v8::Local<v8::ObjectTemplate> obj_template = |
| 2082 v8::ObjectTemplate::FromSnapshot(isolate, 1); |
| 2083 CHECK(!obj_template.IsEmpty()); |
| 2084 v8::Local<v8::Object> object = |
| 2085 obj_template->NewInstance(context).ToLocalChecked(); |
| 2086 CHECK(context->Global()->Set(context, v8_str("o"), object).FromJust()); |
| 2087 ExpectInt32("o.f()", 42); |
| 2088 // Check that it instantiates to the same prototype. |
| 2089 ExpectTrue("o.f.prototype === f.prototype"); |
| 2090 |
| 2091 // Retrieve the snapshotted function template. |
| 2092 v8::Local<v8::FunctionTemplate> fun_template = |
| 2093 v8::FunctionTemplate::FromSnapshot(isolate, 0); |
| 2094 CHECK(!fun_template.IsEmpty()); |
| 2095 v8::Local<v8::Function> fun = |
| 2096 fun_template->GetFunction(context).ToLocalChecked(); |
| 2097 CHECK(context->Global()->Set(context, v8_str("g"), fun).FromJust()); |
| 2098 ExpectInt32("g()", 42); |
| 2099 // Check that it instantiates to the same prototype. |
| 2100 ExpectTrue("g.prototype === f.prototype"); |
| 2076 } | 2101 } |
| 2077 | 2102 |
| 2078 { | 2103 { |
| 2079 // Create a context with a new object template. It is merged into the | 2104 // Create a context with a new object template. It is merged into the |
| 2080 // deserialized global object. | 2105 // deserialized global object. |
| 2081 v8::HandleScope handle_scope(isolate); | 2106 v8::HandleScope handle_scope(isolate); |
| 2082 v8::ExtensionConfiguration* no_extension = nullptr; | 2107 v8::ExtensionConfiguration* no_extension = nullptr; |
| 2083 v8::Local<v8::ObjectTemplate> global_template = | 2108 v8::Local<v8::ObjectTemplate> global_template = |
| 2084 v8::ObjectTemplate::New(isolate); | 2109 v8::ObjectTemplate::New(isolate); |
| 2085 global_template->Set( | 2110 global_template->Set( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2097 } | 2122 } |
| 2098 delete[] blob.data; | 2123 delete[] blob.data; |
| 2099 } | 2124 } |
| 2100 | 2125 |
| 2101 TEST(SerializationMemoryStats) { | 2126 TEST(SerializationMemoryStats) { |
| 2102 FLAG_profile_deserialization = true; | 2127 FLAG_profile_deserialization = true; |
| 2103 FLAG_always_opt = false; | 2128 FLAG_always_opt = false; |
| 2104 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 2129 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
| 2105 delete[] blob.data; | 2130 delete[] blob.data; |
| 2106 } | 2131 } |
| OLD | NEW |