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 1899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1910 blob = | 1910 blob = |
1911 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); | 1911 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); |
1912 } | 1912 } |
1913 | 1913 |
1914 v8::Isolate::CreateParams params; | 1914 v8::Isolate::CreateParams params; |
1915 params.snapshot_blob = &blob; | 1915 params.snapshot_blob = &blob; |
1916 params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 1916 params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
1917 v8::Isolate* isolate = v8::Isolate::New(params); | 1917 v8::Isolate* isolate = v8::Isolate::New(params); |
1918 { | 1918 { |
1919 v8::Isolate::Scope isolate_scope(isolate); | 1919 v8::Isolate::Scope isolate_scope(isolate); |
1920 v8::ExtensionConfiguration* no_extension = nullptr; | |
1921 v8::Local<v8::ObjectTemplate> no_template = v8::Local<v8::ObjectTemplate>(); | |
1922 v8::Local<v8::Value> no_object = v8::Local<v8::Value>(); | |
1923 { | 1920 { |
1924 v8::HandleScope handle_scope(isolate); | 1921 v8::HandleScope handle_scope(isolate); |
1925 v8::Local<v8::Context> context = | 1922 v8::Local<v8::Context> context = |
1926 v8::Context::New(isolate, no_extension, no_template, no_object, 0); | 1923 v8::Context::FromSnapshot(isolate, 0).ToLocalChecked(); |
1927 v8::Context::Scope context_scope(context); | 1924 v8::Context::Scope context_scope(context); |
1928 ExpectInt32("f()", 1); | 1925 ExpectInt32("f()", 1); |
1929 } | 1926 } |
1930 { | 1927 { |
1931 v8::HandleScope handle_scope(isolate); | 1928 v8::HandleScope handle_scope(isolate); |
1932 v8::Local<v8::Context> context = | 1929 v8::Local<v8::Context> context = |
1933 v8::Context::New(isolate, no_extension, no_template, no_object, 1); | 1930 v8::Context::FromSnapshot(isolate, 1).ToLocalChecked(); |
1934 v8::Context::Scope context_scope(context); | 1931 v8::Context::Scope context_scope(context); |
1935 ExpectInt32("f()", 2); | 1932 ExpectInt32("f()", 2); |
1936 } | 1933 } |
1937 { | 1934 { |
1938 v8::HandleScope handle_scope(isolate); | 1935 v8::HandleScope handle_scope(isolate); |
1939 v8::Local<v8::Context> context = | 1936 v8::Local<v8::Context> context = |
1940 v8::Context::New(isolate, no_extension, no_template, no_object, 2); | 1937 v8::Context::FromSnapshot(isolate, 2).ToLocalChecked(); |
1941 v8::Context::Scope context_scope(context); | 1938 v8::Context::Scope context_scope(context); |
1942 ExpectUndefined("this.f"); | 1939 ExpectUndefined("this.f"); |
1943 } | 1940 } |
1944 } | 1941 } |
1945 | 1942 |
1946 isolate->Dispose(); | 1943 isolate->Dispose(); |
1947 delete[] blob.data; | 1944 delete[] blob.data; |
1948 } | 1945 } |
1949 | 1946 |
1950 static void SerializedCallback( | 1947 static void SerializedCallback( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1988 // Deserialize with the original external reference. | 1985 // Deserialize with the original external reference. |
1989 { | 1986 { |
1990 v8::Isolate::CreateParams params; | 1987 v8::Isolate::CreateParams params; |
1991 params.snapshot_blob = &blob; | 1988 params.snapshot_blob = &blob; |
1992 params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 1989 params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
1993 params.external_references = original_external_references; | 1990 params.external_references = original_external_references; |
1994 v8::Isolate* isolate = v8::Isolate::New(params); | 1991 v8::Isolate* isolate = v8::Isolate::New(params); |
1995 { | 1992 { |
1996 v8::Isolate::Scope isolate_scope(isolate); | 1993 v8::Isolate::Scope isolate_scope(isolate); |
1997 v8::HandleScope handle_scope(isolate); | 1994 v8::HandleScope handle_scope(isolate); |
1998 v8::ExtensionConfiguration* no_extension = nullptr; | |
1999 v8::Local<v8::ObjectTemplate> no_template = | |
2000 v8::Local<v8::ObjectTemplate>(); | |
2001 v8::Local<v8::Value> no_object = v8::Local<v8::Value>(); | |
2002 v8::Local<v8::Context> context = | 1995 v8::Local<v8::Context> context = |
2003 v8::Context::New(isolate, no_extension, no_template, no_object, 0); | 1996 v8::Context::FromSnapshot(isolate, 0).ToLocalChecked(); |
2004 v8::Context::Scope context_scope(context); | 1997 v8::Context::Scope context_scope(context); |
2005 ExpectInt32("f()", 42); | 1998 ExpectInt32("f()", 42); |
2006 } | 1999 } |
2007 isolate->Dispose(); | 2000 isolate->Dispose(); |
2008 } | 2001 } |
2009 | 2002 |
2010 // Deserialize with the some other external reference. | 2003 // Deserialize with the some other external reference. |
2011 { | 2004 { |
2012 v8::Isolate::CreateParams params; | 2005 v8::Isolate::CreateParams params; |
2013 params.snapshot_blob = &blob; | 2006 params.snapshot_blob = &blob; |
2014 params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 2007 params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
2015 params.external_references = replaced_external_references; | 2008 params.external_references = replaced_external_references; |
2016 v8::Isolate* isolate = v8::Isolate::New(params); | 2009 v8::Isolate* isolate = v8::Isolate::New(params); |
2017 { | 2010 { |
2018 v8::Isolate::Scope isolate_scope(isolate); | 2011 v8::Isolate::Scope isolate_scope(isolate); |
2019 v8::HandleScope handle_scope(isolate); | 2012 v8::HandleScope handle_scope(isolate); |
2020 v8::ExtensionConfiguration* no_extension = nullptr; | |
2021 v8::Local<v8::ObjectTemplate> no_template = | |
2022 v8::Local<v8::ObjectTemplate>(); | |
2023 v8::Local<v8::Value> no_object = v8::Local<v8::Value>(); | |
2024 v8::Local<v8::Context> context = | 2013 v8::Local<v8::Context> context = |
2025 v8::Context::New(isolate, no_extension, no_template, no_object, 0); | 2014 v8::Context::FromSnapshot(isolate, 0).ToLocalChecked(); |
2026 v8::Context::Scope context_scope(context); | 2015 v8::Context::Scope context_scope(context); |
2027 ExpectInt32("f()", 1337); | 2016 ExpectInt32("f()", 1337); |
2028 } | 2017 } |
2029 isolate->Dispose(); | 2018 isolate->Dispose(); |
2030 } | 2019 } |
2031 delete[] blob.data; | 2020 delete[] blob.data; |
2032 } | 2021 } |
2033 | 2022 |
2034 TEST(SnapshotCreatorTemplates) { | 2023 TEST(SnapshotCreatorTemplates) { |
2035 DisableTurbofan(); | 2024 DisableTurbofan(); |
(...skipping 25 matching lines...) Expand all Loading... |
2061 v8::Isolate::CreateParams params; | 2050 v8::Isolate::CreateParams params; |
2062 params.snapshot_blob = &blob; | 2051 params.snapshot_blob = &blob; |
2063 params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 2052 params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
2064 params.external_references = original_external_references; | 2053 params.external_references = original_external_references; |
2065 v8::Isolate* isolate = v8::Isolate::New(params); | 2054 v8::Isolate* isolate = v8::Isolate::New(params); |
2066 { | 2055 { |
2067 v8::Isolate::Scope isolate_scope(isolate); | 2056 v8::Isolate::Scope isolate_scope(isolate); |
2068 { | 2057 { |
2069 // Create a new context without a new object template. | 2058 // Create a new context without a new object template. |
2070 v8::HandleScope handle_scope(isolate); | 2059 v8::HandleScope handle_scope(isolate); |
2071 v8::ExtensionConfiguration* no_extension = nullptr; | |
2072 v8::Local<v8::ObjectTemplate> no_template = | |
2073 v8::Local<v8::ObjectTemplate>(); | |
2074 v8::Local<v8::Value> no_object = v8::Local<v8::Value>(); | |
2075 v8::Local<v8::Context> context = | 2060 v8::Local<v8::Context> context = |
2076 v8::Context::New(isolate, no_extension, no_template, no_object, 0); | 2061 v8::Context::FromSnapshot(isolate, 0).ToLocalChecked(); |
2077 v8::Context::Scope context_scope(context); | 2062 v8::Context::Scope context_scope(context); |
2078 ExpectInt32("f()", 42); | 2063 ExpectInt32("f()", 42); |
2079 | 2064 |
2080 // Retrieve the snapshotted object template. | 2065 // Retrieve the snapshotted object template. |
2081 v8::Local<v8::ObjectTemplate> obj_template = | 2066 v8::Local<v8::ObjectTemplate> obj_template = |
2082 v8::ObjectTemplate::FromSnapshot(isolate, 1); | 2067 v8::ObjectTemplate::FromSnapshot(isolate, 1).ToLocalChecked(); |
2083 CHECK(!obj_template.IsEmpty()); | 2068 CHECK(!obj_template.IsEmpty()); |
2084 v8::Local<v8::Object> object = | 2069 v8::Local<v8::Object> object = |
2085 obj_template->NewInstance(context).ToLocalChecked(); | 2070 obj_template->NewInstance(context).ToLocalChecked(); |
2086 CHECK(context->Global()->Set(context, v8_str("o"), object).FromJust()); | 2071 CHECK(context->Global()->Set(context, v8_str("o"), object).FromJust()); |
2087 ExpectInt32("o.f()", 42); | 2072 ExpectInt32("o.f()", 42); |
2088 // Check that it instantiates to the same prototype. | 2073 // Check that it instantiates to the same prototype. |
2089 ExpectTrue("o.f.prototype === f.prototype"); | 2074 ExpectTrue("o.f.prototype === f.prototype"); |
2090 | 2075 |
2091 // Retrieve the snapshotted function template. | 2076 // Retrieve the snapshotted function template. |
2092 v8::Local<v8::FunctionTemplate> fun_template = | 2077 v8::Local<v8::FunctionTemplate> fun_template = |
2093 v8::FunctionTemplate::FromSnapshot(isolate, 0); | 2078 v8::FunctionTemplate::FromSnapshot(isolate, 0).ToLocalChecked(); |
2094 CHECK(!fun_template.IsEmpty()); | 2079 CHECK(!fun_template.IsEmpty()); |
2095 v8::Local<v8::Function> fun = | 2080 v8::Local<v8::Function> fun = |
2096 fun_template->GetFunction(context).ToLocalChecked(); | 2081 fun_template->GetFunction(context).ToLocalChecked(); |
2097 CHECK(context->Global()->Set(context, v8_str("g"), fun).FromJust()); | 2082 CHECK(context->Global()->Set(context, v8_str("g"), fun).FromJust()); |
2098 ExpectInt32("g()", 42); | 2083 ExpectInt32("g()", 42); |
2099 // Check that it instantiates to the same prototype. | 2084 // Check that it instantiates to the same prototype. |
2100 ExpectTrue("g.prototype === f.prototype"); | 2085 ExpectTrue("g.prototype === f.prototype"); |
| 2086 |
| 2087 // Accessing out of bound returns empty MaybeHandle. |
| 2088 CHECK(v8::ObjectTemplate::FromSnapshot(isolate, 2).IsEmpty()); |
| 2089 CHECK(v8::FunctionTemplate::FromSnapshot(isolate, 2).IsEmpty()); |
| 2090 CHECK(v8::Context::FromSnapshot(isolate, 2).IsEmpty()); |
2101 } | 2091 } |
2102 | 2092 |
2103 { | 2093 { |
2104 // Create a context with a new object template. It is merged into the | 2094 // Create a context with a new object template. It is merged into the |
2105 // deserialized global object. | 2095 // deserialized global object. |
2106 v8::HandleScope handle_scope(isolate); | 2096 v8::HandleScope handle_scope(isolate); |
2107 v8::ExtensionConfiguration* no_extension = nullptr; | 2097 v8::ExtensionConfiguration* no_extension = nullptr; |
2108 v8::Local<v8::ObjectTemplate> global_template = | 2098 v8::Local<v8::ObjectTemplate> global_template = |
2109 v8::ObjectTemplate::New(isolate); | 2099 v8::ObjectTemplate::New(isolate); |
2110 global_template->Set( | 2100 global_template->Set( |
2111 v8_str("g"), | 2101 v8_str("g"), |
2112 v8::FunctionTemplate::New(isolate, SerializedCallbackReplacement)); | 2102 v8::FunctionTemplate::New(isolate, SerializedCallbackReplacement)); |
2113 v8::Local<v8::Value> no_object = v8::Local<v8::Value>(); | 2103 v8::Local<v8::Context> context = |
2114 v8::Local<v8::Context> context = v8::Context::New( | 2104 v8::Context::FromSnapshot(isolate, 0, no_extension, global_template) |
2115 isolate, no_extension, global_template, no_object, 0); | 2105 .ToLocalChecked(); |
2116 v8::Context::Scope context_scope(context); | 2106 v8::Context::Scope context_scope(context); |
2117 ExpectInt32("g()", 1337); | 2107 ExpectInt32("g()", 1337); |
2118 ExpectInt32("f()", 42); | 2108 ExpectInt32("f()", 42); |
2119 } | 2109 } |
2120 } | 2110 } |
2121 isolate->Dispose(); | 2111 isolate->Dispose(); |
2122 } | 2112 } |
2123 delete[] blob.data; | 2113 delete[] blob.data; |
2124 } | 2114 } |
2125 | 2115 |
2126 TEST(SerializationMemoryStats) { | 2116 TEST(SerializationMemoryStats) { |
2127 FLAG_profile_deserialization = true; | 2117 FLAG_profile_deserialization = true; |
2128 FLAG_always_opt = false; | 2118 FLAG_always_opt = false; |
2129 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 2119 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
2130 delete[] blob.data; | 2120 delete[] blob.data; |
2131 } | 2121 } |
OLD | NEW |