Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(692)

Side by Side Diff: test/cctest/test-serialize.cc

Issue 2066993004: [snapshot] serialize embedder-provided external references. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: address comment Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/isolate.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1929 matching lines...) Expand 10 before | Expand all | Expand 10 after
1940 v8::Context::New(isolate, no_extension, no_template, no_object, 2); 1940 v8::Context::New(isolate, no_extension, no_template, no_object, 2);
1941 v8::Context::Scope context_scope(context); 1941 v8::Context::Scope context_scope(context);
1942 ExpectUndefined("this.f"); 1942 ExpectUndefined("this.f");
1943 } 1943 }
1944 } 1944 }
1945 1945
1946 isolate->Dispose(); 1946 isolate->Dispose();
1947 delete[] blob.data; 1947 delete[] blob.data;
1948 } 1948 }
1949 1949
1950 static void SerializedCallback(
1951 const v8::FunctionCallbackInfo<v8::Value>& args) {
1952 args.GetReturnValue().Set(v8_num(42));
1953 }
1954
1955 static void SerializedCallbackReplacement(
1956 const v8::FunctionCallbackInfo<v8::Value>& args) {
1957 args.GetReturnValue().Set(v8_num(1337));
1958 }
1959
1960 intptr_t original_external_references[] = {
1961 reinterpret_cast<intptr_t>(SerializedCallback), 0};
1962
1963 intptr_t replaced_external_references[] = {
1964 reinterpret_cast<intptr_t>(SerializedCallbackReplacement), 0};
1965
1966 TEST(SnapshotCreatorExternalReferences) {
1967 DisableTurbofan();
1968 v8::StartupData blob;
1969 {
1970 v8::SnapshotCreator creator(original_external_references);
1971 v8::Isolate* isolate = creator.GetIsolate();
1972 {
1973 v8::HandleScope handle_scope(isolate);
1974 v8::Local<v8::Context> context = v8::Context::New(isolate);
1975 v8::Context::Scope context_scope(context);
1976 v8::Local<v8::FunctionTemplate> callback =
1977 v8::FunctionTemplate::New(isolate, SerializedCallback);
1978 v8::Local<v8::Value> function =
1979 callback->GetFunction(context).ToLocalChecked();
1980 CHECK(context->Global()->Set(context, v8_str("f"), function).FromJust());
1981 ExpectInt32("f()", 42);
1982 CHECK_EQ(0, creator.AddContext(context));
1983 }
1984 blob =
1985 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
1986 }
1987
1988 // Deserialize with the original external reference.
1989 {
1990 v8::Isolate::CreateParams params;
1991 params.snapshot_blob = &blob;
1992 params.array_buffer_allocator = CcTest::array_buffer_allocator();
1993 params.external_references = original_external_references;
1994 v8::Isolate* isolate = v8::Isolate::New(params);
1995 {
1996 v8::Isolate::Scope isolate_scope(isolate);
1997 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 =
2003 v8::Context::New(isolate, no_extension, no_template, no_object, 0);
2004 v8::Context::Scope context_scope(context);
2005 ExpectInt32("f()", 42);
2006 }
2007 isolate->Dispose();
2008 }
2009
2010 // Deserialize with the some other external reference.
2011 {
2012 v8::Isolate::CreateParams params;
2013 params.snapshot_blob = &blob;
2014 params.array_buffer_allocator = CcTest::array_buffer_allocator();
2015 params.external_references = replaced_external_references;
2016 v8::Isolate* isolate = v8::Isolate::New(params);
2017 {
2018 v8::Isolate::Scope isolate_scope(isolate);
2019 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 =
2025 v8::Context::New(isolate, no_extension, no_template, no_object, 0);
2026 v8::Context::Scope context_scope(context);
2027 ExpectInt32("f()", 1337);
2028 }
2029 isolate->Dispose();
2030 }
2031 delete[] blob.data;
2032 }
2033
2034 TEST(SnapshotCreatorGlobalTemplate) {
2035 DisableTurbofan();
2036 v8::StartupData blob;
2037 {
2038 v8::SnapshotCreator creator(original_external_references);
2039 v8::Isolate* isolate = creator.GetIsolate();
2040 {
2041 v8::HandleScope handle_scope(isolate);
2042 v8::ExtensionConfiguration* no_extension = nullptr;
2043 v8::Local<v8::ObjectTemplate> global_template =
2044 v8::ObjectTemplate::New(isolate);
2045 global_template->Set(
2046 v8_str("f"), v8::FunctionTemplate::New(isolate, SerializedCallback));
2047 v8::Local<v8::Context> context =
2048 v8::Context::New(isolate, no_extension, global_template);
2049 v8::Context::Scope context_scope(context);
2050 ExpectInt32("f()", 42);
2051 CHECK_EQ(0, creator.AddContext(context));
2052 }
2053 blob =
2054 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
2055 }
2056
2057 {
2058 v8::Isolate::CreateParams params;
2059 params.snapshot_blob = &blob;
2060 params.array_buffer_allocator = CcTest::array_buffer_allocator();
2061 params.external_references = original_external_references;
2062 v8::Isolate* isolate = v8::Isolate::New(params);
2063 {
2064 v8::Isolate::Scope isolate_scope(isolate);
2065 {
2066 // Create a new context without a new object template.
2067 v8::HandleScope handle_scope(isolate);
2068 v8::ExtensionConfiguration* no_extension = nullptr;
2069 v8::Local<v8::ObjectTemplate> no_template =
2070 v8::Local<v8::ObjectTemplate>();
2071 v8::Local<v8::Value> no_object = v8::Local<v8::Value>();
2072 v8::Local<v8::Context> context =
2073 v8::Context::New(isolate, no_extension, no_template, no_object, 0);
2074 v8::Context::Scope context_scope(context);
2075 ExpectInt32("f()", 42);
2076 }
2077
2078 {
2079 // Create a context with a new object template. It is merged into the
2080 // deserialized global object.
2081 v8::HandleScope handle_scope(isolate);
2082 v8::ExtensionConfiguration* no_extension = nullptr;
2083 v8::Local<v8::ObjectTemplate> global_template =
2084 v8::ObjectTemplate::New(isolate);
2085 global_template->Set(
2086 v8_str("g"),
2087 v8::FunctionTemplate::New(isolate, SerializedCallbackReplacement));
2088 v8::Local<v8::Value> no_object = v8::Local<v8::Value>();
2089 v8::Local<v8::Context> context = v8::Context::New(
2090 isolate, no_extension, global_template, no_object, 0);
2091 v8::Context::Scope context_scope(context);
2092 ExpectInt32("g()", 1337);
2093 ExpectInt32("f()", 42);
2094 }
2095 }
2096 isolate->Dispose();
2097 }
2098 delete[] blob.data;
2099 }
2100
1950 TEST(SerializationMemoryStats) { 2101 TEST(SerializationMemoryStats) {
1951 FLAG_profile_deserialization = true; 2102 FLAG_profile_deserialization = true;
1952 FLAG_always_opt = false; 2103 FLAG_always_opt = false;
1953 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); 2104 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob();
1954 delete[] blob.data; 2105 delete[] blob.data;
1955 } 2106 }
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698