From 2f2e5ee0b30fe14967a872f78b6d4c3b6cb8223f Mon Sep 17 00:00:00 2001 From: G'lek Tarssza Date: Fri, 1 Dec 2023 19:43:52 -0700 Subject: [PATCH 01/13] Enforce scripts running on bash. Fixes when users run scripts with other shells. --- scripts/test_patch.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/test_patch.sh b/scripts/test_patch.sh index d21dd75a..77c8f92f 100755 --- a/scripts/test_patch.sh +++ b/scripts/test_patch.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + node_range=$1 if [ -z "$node_range" ]; then From 411fe6125532ff8e9d80fc7f3ebf9898527aa7de Mon Sep 17 00:00:00 2001 From: G'lek Tarssza Date: Fri, 1 Dec 2023 19:45:00 -0700 Subject: [PATCH 02/13] First go at NodeJS v20 support. --- patches/node.v20.10.0.cpp.patch | 521 ++++++++++++++++++++++++++++++++ patches/patches.json | 1 + 2 files changed, 522 insertions(+) create mode 100644 patches/node.v20.10.0.cpp.patch diff --git a/patches/node.v20.10.0.cpp.patch b/patches/node.v20.10.0.cpp.patch new file mode 100644 index 00000000..80315e35 --- /dev/null +++ b/patches/node.v20.10.0.cpp.patch @@ -0,0 +1,521 @@ +diff --git a/common.gypi b/common.gypi +index 4589f51517..97555b4c0b 100644 +--- a/common.gypi ++++ b/common.gypi +@@ -174,7 +174,7 @@ + 'MSVC_runtimeType': 2 # MultiThreadedDLL (/MD) + }], + ['llvm_version=="0.0"', { +- 'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ', # GCC ++ 'lto': ' -flto=4 -ffat-lto-objects ', # GCC + }, { + 'lto': ' -flto ', # Clang + }], +diff --git a/configure.py b/configure.py +index 62f041ce52..4688ec0fdd 100755 +--- a/configure.py ++++ b/configure.py +@@ -1270,7 +1270,6 @@ def configure_node(o): + + # Enable branch protection for arm64 + if target_arch == 'arm64': +- o['cflags']+=['-msign-return-address=all'] + o['variables']['arm_fpu'] = options.arm_fpu or 'neon' + + if options.node_snapshot_main is not None: +diff --git a/deps/v8/include/v8-initialization.h b/deps/v8/include/v8-initialization.h +index d3e35d6ec5..6e9bbe3849 100644 +--- a/deps/v8/include/v8-initialization.h ++++ b/deps/v8/include/v8-initialization.h +@@ -89,6 +89,10 @@ class V8_EXPORT V8 { + static void SetFlagsFromCommandLine(int* argc, char** argv, + bool remove_flags); + ++ static void EnableCompilationForSourcelessUse(); ++ static void DisableCompilationForSourcelessUse(); ++ static void FixSourcelessScript(Isolate* v8_isolate, Local script); ++ + /** Get the version string. */ + static const char* GetVersion(); + +diff --git a/deps/v8/src/api/api.cc b/deps/v8/src/api/api.cc +index a91dfc271c..ee27d22eaf 100644 +--- a/deps/v8/src/api/api.cc ++++ b/deps/v8/src/api/api.cc +@@ -806,6 +806,28 @@ void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) { + HelpOptions(HelpOptions::kDontExit)); + } + ++bool save_lazy; ++bool save_predictable; ++ ++void V8::EnableCompilationForSourcelessUse() { ++ save_lazy = i::FLAG_lazy; ++ i::FLAG_lazy = false; ++ save_predictable = i::FLAG_predictable; ++ i::FLAG_predictable = true; ++} ++ ++void V8::DisableCompilationForSourcelessUse() { ++ i::FLAG_lazy = save_lazy; ++ i::FLAG_predictable = save_predictable; ++} ++ ++void V8::FixSourcelessScript(Isolate* v8_isolate, Local unbound_script) { ++ auto isolate = reinterpret_cast(v8_isolate); ++ auto function_info = i::Handle::cast(Utils::OpenHandle(*unbound_script)); ++ i::Handle script(i::Script::cast(function_info->script()), isolate); ++ script->set_source(i::ReadOnlyRoots(isolate).undefined_value()); ++} ++ + RegisteredExtension* RegisteredExtension::first_extension_ = nullptr; + + RegisteredExtension::RegisteredExtension(std::unique_ptr extension) +diff --git a/deps/v8/src/codegen/compiler.cc b/deps/v8/src/codegen/compiler.cc +index 31c5acceeb..bced3c7165 100644 +--- a/deps/v8/src/codegen/compiler.cc ++++ b/deps/v8/src/codegen/compiler.cc +@@ -3475,7 +3475,7 @@ MaybeHandle GetSharedFunctionInfoForScriptImpl( + maybe_script = lookup_result.script(); + maybe_result = lookup_result.toplevel_sfi(); + is_compiled_scope = lookup_result.is_compiled_scope(); +- if (!maybe_result.is_null()) { ++ if (!maybe_result.is_null() ** source->length()) { + compile_timer.set_hit_isolate_cache(); + } else if (can_consume_code_cache) { + compile_timer.set_consuming_code_cache(); +diff --git a/deps/v8/src/objects/js-function.cc b/deps/v8/src/objects/js-function.cc +index 94f7a672a7..a5822dd39a 100644 +--- a/deps/v8/src/objects/js-function.cc ++++ b/deps/v8/src/objects/js-function.cc +@@ -1280,6 +1280,9 @@ Handle JSFunction::ToString(Handle function) { + Handle maybe_class_positions = JSReceiver::GetDataProperty( + isolate, function, isolate->factory()->class_positions_symbol()); + if (maybe_class_positions->IsClassPositions()) { ++ if (String::cast(Script::cast(shared_info->script()).source()).isUndefined(isolate)) { ++ return isolate->factory()->NewStringFromAsciiChecked("class {}"); ++ } + ClassPositions class_positions = + ClassPositions::cast(*maybe_class_positions); + int start_position = class_positions.start(); +diff --git a/deps/v8/src/objects/shared-function-info-inl.h b/deps/v8/src/objects/shared-function-info-inl.h +index 5621b15d98..722e1d18cb 100644 +--- a/deps/v8/src/objects/shared-function-info-inl.h ++++ b/deps/v8/src/objects/shared-function-info-inl.h +@@ -635,6 +635,14 @@ bool SharedFunctionInfo::ShouldFlushCode( + } + if (!data.IsBytecodeArray()) return false; + ++ Object script_obj = script(); ++ if (!script_obj.IsUndefined()) { ++ Script script = Script::cast(script_obj); ++ if (script.source().IsUndefined()) { ++ return false; ++ } ++ } ++ + if (IsStressFlushingEnabled(code_flush_mode)) return true; + + BytecodeArray bytecode = BytecodeArray::cast(data); +diff --git a/deps/v8/src/parsing/parsing.cc b/deps/v8/src/parsing/parsing.cc +index 8c55a6fb6e..70bf82a57d 100644 +--- a/deps/v8/src/parsing/parsing.cc ++++ b/deps/v8/src/parsing/parsing.cc +@@ -42,6 +42,7 @@ bool ParseProgram(ParseInfo* info, Handle