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 1992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2003 v8::Context::FromSnapshot(isolate, 2).ToLocalChecked(); | 2003 v8::Context::FromSnapshot(isolate, 2).ToLocalChecked(); |
2004 v8::Context::Scope context_scope(context); | 2004 v8::Context::Scope context_scope(context); |
2005 ExpectUndefined("this.f"); | 2005 ExpectUndefined("this.f"); |
2006 } | 2006 } |
2007 } | 2007 } |
2008 | 2008 |
2009 isolate->Dispose(); | 2009 isolate->Dispose(); |
2010 delete[] blob.data; | 2010 delete[] blob.data; |
2011 } | 2011 } |
2012 | 2012 |
2013 void SerializedCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { | 2013 static void SerializedCallback( |
| 2014 const v8::FunctionCallbackInfo<v8::Value>& args) { |
2014 args.GetReturnValue().Set(v8_num(42)); | 2015 args.GetReturnValue().Set(v8_num(42)); |
2015 } | 2016 } |
2016 | 2017 |
2017 void SerializedCallbackReplacement( | 2018 static void SerializedCallbackReplacement( |
2018 const v8::FunctionCallbackInfo<v8::Value>& args) { | 2019 const v8::FunctionCallbackInfo<v8::Value>& args) { |
2019 args.GetReturnValue().Set(v8_num(1337)); | 2020 args.GetReturnValue().Set(v8_num(1337)); |
2020 } | 2021 } |
2021 | 2022 |
2022 intptr_t original_external_references[] = { | 2023 intptr_t original_external_references[] = { |
2023 reinterpret_cast<intptr_t>(SerializedCallback), 0}; | 2024 reinterpret_cast<intptr_t>(SerializedCallback), 0}; |
2024 | 2025 |
2025 intptr_t replaced_external_references[] = { | 2026 intptr_t replaced_external_references[] = { |
2026 reinterpret_cast<intptr_t>(SerializedCallbackReplacement), 0}; | 2027 reinterpret_cast<intptr_t>(SerializedCallbackReplacement), 0}; |
2027 | 2028 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2078 v8::Local<v8::Context> context = | 2079 v8::Local<v8::Context> context = |
2079 v8::Context::FromSnapshot(isolate, 0).ToLocalChecked(); | 2080 v8::Context::FromSnapshot(isolate, 0).ToLocalChecked(); |
2080 v8::Context::Scope context_scope(context); | 2081 v8::Context::Scope context_scope(context); |
2081 ExpectInt32("f()", 1337); | 2082 ExpectInt32("f()", 1337); |
2082 } | 2083 } |
2083 isolate->Dispose(); | 2084 isolate->Dispose(); |
2084 } | 2085 } |
2085 delete[] blob.data; | 2086 delete[] blob.data; |
2086 } | 2087 } |
2087 | 2088 |
2088 TEST(SnapshotCreatorUnknownExternalReferences) { | |
2089 DisableTurbofan(); | |
2090 v8::SnapshotCreator creator; | |
2091 v8::Isolate* isolate = creator.GetIsolate(); | |
2092 { | |
2093 v8::HandleScope handle_scope(isolate); | |
2094 v8::Local<v8::Context> context = v8::Context::New(isolate); | |
2095 v8::Context::Scope context_scope(context); | |
2096 | |
2097 v8::Local<v8::FunctionTemplate> callback = | |
2098 v8::FunctionTemplate::New(isolate, SerializedCallback); | |
2099 v8::Local<v8::Value> function = | |
2100 callback->GetFunction(context).ToLocalChecked(); | |
2101 CHECK(context->Global()->Set(context, v8_str("f"), function).FromJust()); | |
2102 ExpectInt32("f()", 42); | |
2103 | |
2104 CHECK_EQ(0, creator.AddContext(context)); | |
2105 } | |
2106 v8::StartupData blob = | |
2107 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); | |
2108 | |
2109 delete[] blob.data; | |
2110 } | |
2111 | |
2112 TEST(SnapshotCreatorTemplates) { | 2089 TEST(SnapshotCreatorTemplates) { |
2113 DisableTurbofan(); | 2090 DisableTurbofan(); |
2114 v8::StartupData blob; | 2091 v8::StartupData blob; |
2115 { | 2092 { |
2116 v8::SnapshotCreator creator(original_external_references); | 2093 v8::SnapshotCreator creator(original_external_references); |
2117 v8::Isolate* isolate = creator.GetIsolate(); | 2094 v8::Isolate* isolate = creator.GetIsolate(); |
2118 { | 2095 { |
2119 v8::HandleScope handle_scope(isolate); | 2096 v8::HandleScope handle_scope(isolate); |
2120 v8::ExtensionConfiguration* no_extension = nullptr; | 2097 v8::ExtensionConfiguration* no_extension = nullptr; |
2121 v8::Local<v8::ObjectTemplate> global_template = | 2098 v8::Local<v8::ObjectTemplate> global_template = |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2201 } | 2178 } |
2202 delete[] blob.data; | 2179 delete[] blob.data; |
2203 } | 2180 } |
2204 | 2181 |
2205 TEST(SerializationMemoryStats) { | 2182 TEST(SerializationMemoryStats) { |
2206 FLAG_profile_deserialization = true; | 2183 FLAG_profile_deserialization = true; |
2207 FLAG_always_opt = false; | 2184 FLAG_always_opt = false; |
2208 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 2185 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
2209 delete[] blob.data; | 2186 delete[] blob.data; |
2210 } | 2187 } |
OLD | NEW |