From 6b3d21c66c1a9ab5702e989dff3fecba3b7ad024 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Wed, 17 Mar 2021 22:40:07 +0800 Subject: [PATCH 1/5] patches: add Node.js 16.0.0 Test: manual, node v16.0.0 --- patches/node.v16.0.0.cpp.patch | 497 +++++++++++++++++++++++++++++++++ patches/patches.json | 1 + 2 files changed, 498 insertions(+) create mode 100644 patches/node.v16.0.0.cpp.patch diff --git a/patches/node.v16.0.0.cpp.patch b/patches/node.v16.0.0.cpp.patch new file mode 100644 index 00000000..0f5f08d1 --- /dev/null +++ b/patches/node.v16.0.0.cpp.patch @@ -0,0 +1,497 @@ +--- node/common.gypi ++++ node/common.gypi +@@ -164,7 +164,7 @@ + 'v8_enable_handle_zapping': 0, + 'pgo_generate': ' -fprofile-generate ', + 'pgo_use': ' -fprofile-use -fprofile-correction ', +- 'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ', ++ 'lto': ' -flto=4 -ffat-lto-objects ', + 'conditions': [ + ['node_shared != "true"', { + 'MSVC_runtimeType': 0 # MultiThreaded (/MT) +--- node/deps/v8/include/v8.h ++++ node/deps/v8/include/v8.h +@@ -9934,6 +9934,10 @@ class V8_EXPORT V8 { + 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(); + +--- node/deps/v8/src/api/api.cc ++++ node/deps/v8/src/api/api.cc +@@ -628,6 +628,29 @@ 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) +--- node/deps/v8/src/codegen/compiler.cc ++++ node/deps/v8/src/codegen/compiler.cc +@@ -2840,7 +2840,7 @@ MaybeHandle Compiler::GetSharedFunctionInfoForScript( + source, script_details.name_obj, script_details.line_offset, + script_details.column_offset, origin_options, isolate->native_context(), + language_mode); +- 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(); +--- node/deps/v8/src/objects/js-function.cc ++++ node/deps/v8/src/objects/js-function.cc +@@ -905,6 +905,9 @@ Handle JSFunction::ToString(Handle function) { + Handle maybe_class_positions = JSReceiver::GetDataProperty( + 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(); +--- node/deps/v8/src/objects/shared-function-info-inl.h ++++ node/deps/v8/src/objects/shared-function-info-inl.h +@@ -568,6 +568,14 @@ bool SharedFunctionInfo::ShouldFlushBytecode(BytecodeFlushMode mode) { + Object data = function_data(kAcquireLoad); + 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 (mode == BytecodeFlushMode::kStressFlushBytecode) return true; + + BytecodeArray bytecode = BytecodeArray::cast(data); +--- node/deps/v8/src/parsing/parsing.cc ++++ node/deps/v8/src/parsing/parsing.cc +@@ -42,6 +42,7 @@ bool ParseProgram(ParseInfo* info, Handle