electron/patches/common/v8/cherry-pick_a440efb27f.patch
Jeremy Apthorp 76c5f5cc8a
build: move libcc patches to electron repo (#14104)
In the GN build, libchromiumcontent is no longer a distinct library, but
merely a container for a set of scripts and patches. Maintaining those
patches in a separate repository is tedious and error-prone, so merge
them into the main repo.

Once this is merged and GN is the default way to build Electron, the
libchromiumcontent repository can be archived.
2018-09-13 22:02:16 -07:00

225 lines
9.5 KiB
Diff

diff --git a/include/v8.h b/include/v8.h
index 29566f4303..07a500f7ff 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -1578,6 +1578,9 @@ class V8_EXPORT ScriptCompiler {
* This will return nullptr if the script cannot be serialized. The
* CachedData returned by this function should be owned by the caller.
*/
+ static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script);
+
+ // Deprecated.
static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script,
Local<String> source);
@@ -1587,6 +1590,9 @@ class V8_EXPORT ScriptCompiler {
* This will return nullptr if the script cannot be serialized. The
* CachedData returned by this function should be owned by the caller.
*/
+ static CachedData* CreateCodeCacheForFunction(Local<Function> function);
+
+ // Deprecated.
static CachedData* CreateCodeCacheForFunction(Local<Function> function,
Local<String> source);
diff --git a/src/api.cc b/src/api.cc
index 27e7598bfa..61b1be1401 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -2628,21 +2628,29 @@ uint32_t ScriptCompiler::CachedDataVersionTag() {
ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCache(
Local<UnboundScript> unbound_script, Local<String> source) {
+ return CreateCodeCache(unbound_script);
+}
+
+ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCache(
+ Local<UnboundScript> unbound_script) {
i::Handle<i::SharedFunctionInfo> shared =
i::Handle<i::SharedFunctionInfo>::cast(
Utils::OpenHandle(*unbound_script));
- i::Handle<i::String> source_str = Utils::OpenHandle(*source);
DCHECK(shared->is_toplevel());
- return i::CodeSerializer::Serialize(shared, source_str);
+ return i::CodeSerializer::Serialize(shared);
}
ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCacheForFunction(
Local<Function> function, Local<String> source) {
+ return CreateCodeCacheForFunction(function);
+}
+
+ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCacheForFunction(
+ Local<Function> function) {
i::Handle<i::SharedFunctionInfo> shared(
i::Handle<i::JSFunction>::cast(Utils::OpenHandle(*function))->shared());
- i::Handle<i::String> source_str = Utils::OpenHandle(*source);
CHECK(shared->is_wrapped());
- return i::CodeSerializer::Serialize(shared, source_str);
+ return i::CodeSerializer::Serialize(shared);
}
MaybeLocal<Script> Script::Compile(Local<Context> context, Local<String> source,
diff --git a/src/d8.cc b/src/d8.cc
index b338dfbb2d..e6ba022795 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -636,7 +636,7 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
ShellOptions::CodeCacheOptions::kProduceCache) {
// Serialize and store it in memory for the next execution.
ScriptCompiler::CachedData* cached_data =
- ScriptCompiler::CreateCodeCache(script->GetUnboundScript(), source);
+ ScriptCompiler::CreateCodeCache(script->GetUnboundScript());
StoreInCodeCache(isolate, source, cached_data);
delete cached_data;
}
@@ -645,7 +645,7 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
ShellOptions::CodeCacheOptions::kProduceCacheAfterExecute) {
// Serialize and store it in memory for the next execution.
ScriptCompiler::CachedData* cached_data =
- ScriptCompiler::CreateCodeCache(script->GetUnboundScript(), source);
+ ScriptCompiler::CreateCodeCache(script->GetUnboundScript());
StoreInCodeCache(isolate, source, cached_data);
delete cached_data;
}
diff --git a/src/snapshot/code-serializer.cc b/src/snapshot/code-serializer.cc
index 2697e9dce4..823d8dc9af 100644
--- a/src/snapshot/code-serializer.cc
+++ b/src/snapshot/code-serializer.cc
@@ -32,7 +32,7 @@ ScriptData::ScriptData(const byte* data, int length)
// static
ScriptCompiler::CachedData* CodeSerializer::Serialize(
- Handle<SharedFunctionInfo> info, Handle<String> source) {
+ Handle<SharedFunctionInfo> info) {
Isolate* isolate = info->GetIsolate();
TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
HistogramTimerScope histogram_timer(isolate->counters()->compile_serialize());
@@ -45,8 +45,7 @@ ScriptCompiler::CachedData* CodeSerializer::Serialize(
Handle<Script> script(Script::cast(info->script()), isolate);
if (FLAG_trace_serializer) {
PrintF("[Serializing from");
- Object* script = info->script();
- Script::cast(script)->name()->ShortPrint();
+ script->name()->ShortPrint();
PrintF("]\n");
}
// TODO(7110): Enable serialization of Asm modules once the AsmWasmData is
@@ -55,10 +54,11 @@ ScriptCompiler::CachedData* CodeSerializer::Serialize(
if (isolate->debug()->is_loaded()) return nullptr;
// Serialize code object.
+ Handle<String> source(String::cast(script->source()), isolate);
CodeSerializer cs(isolate, SerializedCodeData::SourceHash(source));
DisallowHeapAllocation no_gc;
cs.reference_map()->AddAttachedReference(*source);
- ScriptData* script_data = cs.Serialize(info);
+ ScriptData* script_data = cs.SerializeSharedFunctionInfo(info);
if (FLAG_profile_deserialization) {
double ms = timer.Elapsed().InMillisecondsF();
@@ -75,11 +75,12 @@ ScriptCompiler::CachedData* CodeSerializer::Serialize(
return result;
}
-ScriptData* CodeSerializer::Serialize(Handle<HeapObject> obj) {
+ScriptData* CodeSerializer::SerializeSharedFunctionInfo(
+ Handle<SharedFunctionInfo> info) {
DisallowHeapAllocation no_gc;
VisitRootPointer(Root::kHandleScope, nullptr,
- Handle<Object>::cast(obj).location());
+ Handle<Object>::cast(info).location());
SerializeDeferredObjects();
Pad();
diff --git a/src/snapshot/code-serializer.h b/src/snapshot/code-serializer.h
index 8e97f47f2f..f6b51bf9b1 100644
--- a/src/snapshot/code-serializer.h
+++ b/src/snapshot/code-serializer.h
@@ -45,10 +45,9 @@ class ScriptData {
class CodeSerializer : public Serializer<> {
public:
- static ScriptCompiler::CachedData* Serialize(Handle<SharedFunctionInfo> info,
- Handle<String> source);
+ static ScriptCompiler::CachedData* Serialize(Handle<SharedFunctionInfo> info);
- ScriptData* Serialize(Handle<HeapObject> obj);
+ ScriptData* SerializeSharedFunctionInfo(Handle<SharedFunctionInfo> info);
V8_WARN_UNUSED_RESULT static MaybeHandle<SharedFunctionInfo> Deserialize(
Isolate* isolate, ScriptData* cached_data, Handle<String> source);
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index f242262cf0..fbcc12190e 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -25428,8 +25428,7 @@ TEST(CodeCache) {
v8::ScriptCompiler::kNoCompileOptions;
v8::Local<v8::Script> script =
v8::ScriptCompiler::Compile(context, &source, option).ToLocalChecked();
- cache = v8::ScriptCompiler::CreateCodeCache(script->GetUnboundScript(),
- source_string);
+ cache = v8::ScriptCompiler::CreateCodeCache(script->GetUnboundScript());
}
isolate1->Dispose();
diff --git a/test/cctest/test-serialize.cc b/test/cctest/test-serialize.cc
index 370791f6c2..817561c68a 100644
--- a/test/cctest/test-serialize.cc
+++ b/test/cctest/test-serialize.cc
@@ -1240,8 +1240,7 @@ static Handle<SharedFunctionInfo> CompileScriptAndProduceCache(
NOT_NATIVES_CODE)
.ToHandleChecked();
std::unique_ptr<ScriptCompiler::CachedData> cached_data(
- ScriptCompiler::CreateCodeCache(ToApiHandle<UnboundScript>(sfi),
- Utils::ToLocal(source)));
+ ScriptCompiler::CreateCodeCache(ToApiHandle<UnboundScript>(sfi)));
uint8_t* buffer = NewArray<uint8_t>(cached_data->length);
MemCopy(buffer, cached_data->data, cached_data->length);
*script_data = new i::ScriptData(buffer, cached_data->length);
@@ -1895,7 +1894,7 @@ v8::ScriptCompiler::CachedData* CompileRunAndProduceCache(
.ToLocalChecked();
if (cacheType != CodeCacheType::kAfterExecute) {
- cache = ScriptCompiler::CreateCodeCache(script, source_str);
+ cache = ScriptCompiler::CreateCodeCache(script);
}
v8::Local<v8::Value> result = script->BindToCurrentContext()
@@ -1907,7 +1906,7 @@ v8::ScriptCompiler::CachedData* CompileRunAndProduceCache(
.FromJust());
if (cacheType == CodeCacheType::kAfterExecute) {
- cache = ScriptCompiler::CreateCodeCache(script, source_str);
+ cache = ScriptCompiler::CreateCodeCache(script);
}
CHECK(cache);
}
@@ -2153,7 +2152,7 @@ TEST(CodeSerializerWithHarmonyScoping) {
v8::ScriptCompiler::CompileUnboundScript(
isolate1, &source, v8::ScriptCompiler::kNoCompileOptions)
.ToLocalChecked();
- cache = v8::ScriptCompiler::CreateCodeCache(script, source_str);
+ cache = v8::ScriptCompiler::CreateCodeCache(script);
CHECK(cache);
v8::Local<v8::Value> result = script->BindToCurrentContext()
@@ -2218,7 +2217,7 @@ TEST(Regress503552) {
heap::SimulateIncrementalMarking(isolate->heap());
v8::ScriptCompiler::CachedData* cache_data =
- CodeSerializer::Serialize(shared, source);
+ CodeSerializer::Serialize(shared);
delete cache_data;
}
@@ -3447,7 +3446,7 @@ TEST(CachedCompileFunctionInContext) {
env.local(), &script_source, 1, &arg_str, 0, nullptr,
v8::ScriptCompiler::kEagerCompile)
.ToLocalChecked();
- cache = v8::ScriptCompiler::CreateCodeCacheForFunction(fun, source);
+ cache = v8::ScriptCompiler::CreateCodeCacheForFunction(fun);
}
{