fix: use allocationtype kold in v8 scriptormodule legacy lifetime (#32339)

This commit is contained in:
Keeley Hammond 2022-01-05 11:43:28 -08:00 committed by GitHub
parent dd4eae8a3b
commit b61805b63a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 0 deletions

View file

@ -6,3 +6,4 @@ workaround_an_undefined_symbol_error.patch
do_not_export_private_v8_symbols_on_windows.patch
fix_build_deprecated_attirbute_for_older_msvc_versions.patch
fix_disable_implies_dcheck_for_node_stream_array_buffers.patch
fix_use_allocationtype_kold_in_v8_scriptormodule_legacy_lifetime.patch

View file

@ -0,0 +1,56 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: VerteDinde <khammond@slack-corp.com>
Date: Tue, 4 Jan 2022 14:55:00 -0800
Subject: fix: use allocationtype kold in v8 scriptormodule legacy lifetime
Changed in this CL: https://chromium-review.googlesource.com/c/v8/v8/+/3211575
Upstream proposed fix: https://chromium-review.googlesource.com/c/v8/v8/+/3354087
Enabling V8_SCRIPTORMODULE_LEGACY_LIFETIME is necessary to fix ESM in
Node.js, but Blink expects old allocations so we change this in the
interim while Node.js works to remove their usage of WeakRefs to
ScriptOrModule.
This patch can be removed when the upsteam fix is merged, or
when support is added in Node.js
diff --git a/src/heap/factory-base.cc b/src/heap/factory-base.cc
index 89eb0defc2c1f1d2f6f59c3fb107d844e0c7f986..509cc193f339fc2d44ee493c6fe6c17c024b55fb 100644
--- a/src/heap/factory-base.cc
+++ b/src/heap/factory-base.cc
@@ -247,7 +247,7 @@ Handle<Script> FactoryBase<Impl>::NewScriptWithId(
// Create and initialize script object.
ReadOnlyRoots roots = read_only_roots();
#ifdef V8_SCRIPTORMODULE_LEGACY_LIFETIME
- Handle<ArrayList> list = NewArrayList(0);
+ Handle<ArrayList> list = NewArrayList(0, AllocationType::kOld);
#endif
Handle<Script> script = handle(
NewStructInternal<Script>(SCRIPT_TYPE, AllocationType::kOld), isolate());
@@ -283,8 +283,10 @@ Handle<Script> FactoryBase<Impl>::NewScriptWithId(
}
template <typename Impl>
-Handle<ArrayList> FactoryBase<Impl>::NewArrayList(int size) {
- Handle<FixedArray> fixed_array = NewFixedArray(size + ArrayList::kFirstIndex);
+Handle<ArrayList> FactoryBase<Impl>::NewArrayList(int size,
+ AllocationType allocation) {
+ Handle<FixedArray> fixed_array =
+ NewFixedArray(size + ArrayList::kFirstIndex, allocation);
fixed_array->set_map_no_write_barrier(read_only_roots().array_list_map());
Handle<ArrayList> result = Handle<ArrayList>::cast(fixed_array);
result->SetLength(0);
diff --git a/src/heap/factory-base.h b/src/heap/factory-base.h
index 9e45c00a6c7d3dbc44d8f13383a22a40f757d5a7..23bd405d5d660556e23bff23986013fe3b0c627d 100644
--- a/src/heap/factory-base.h
+++ b/src/heap/factory-base.h
@@ -157,7 +157,8 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase
Handle<Script> NewScriptWithId(Handle<PrimitiveHeapObject> source,
int script_id);
- Handle<ArrayList> NewArrayList(int size);
+ Handle<ArrayList> NewArrayList(
+ int size, AllocationType allocation = AllocationType::kYoung);
Handle<SharedFunctionInfo> NewSharedFunctionInfoForLiteral(
FunctionLiteral* literal, Handle<Script> script, bool is_toplevel);