Skip to content

Commit

Permalink
fix: use allocationtype kold in v8 scriptormodule legacy lifetime (#3…
Browse files Browse the repository at this point in the history
…2355)

Co-authored-by: VerteDinde <khammond@slack-corp.com>
  • Loading branch information
trop[bot] and VerteDinde committed Jan 5, 2022
1 parent 6ea5f92 commit 1d70429
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions patches/v8/.patches
Expand Up @@ -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
@@ -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);

0 comments on commit 1d70429

Please sign in to comment.