diff --git a/DEPS b/DEPS index 16efd55bf4fe1..97e874d6b0ab0 100644 --- a/DEPS +++ b/DEPS @@ -14,7 +14,7 @@ vars = { 'chromium_version': 'ddac4c3cc1528254008f9e7a2aea5d4426906bfd', 'node_version': - 'v12.15.0', + 'v12.16.1', 'nan_version': '2ee313aaca52e2b478965ac50eb5082520380d1b', diff --git a/patches/node/.patches b/patches/node/.patches index eeb7a98dd7678..1f09fc30ef70c 100644 --- a/patches/node/.patches +++ b/patches/node/.patches @@ -31,6 +31,11 @@ fix_include_libuv_header_in_node_binding.patch remove_deprecated_task_api_override_removed_in_latest_v8.patch remove_serialization_deserialization_of_wasmmoduleobject.patch 64bit_bump_typedarray_max_length_to_2_32-1_elements.patch -test_use_tmpdir_refresh_in_test-esm-windows_js.patch override_existing_v8_reallocate.patch -feat_enable_passing_cli_flags.patch +fix_use_hex_not_decimal_for_clarity.patch +fix_use_crypto_impls_for_compat.patch +fix_ensure_clocks_header_included_in_impl.patch +fix_remove_implicit_type_conversions.patch +fix_include_io_h_in_uvwasi_for_win.patch +fix_--perf-prof_only_works_on_linux.patch +fix_we_need_to_eager-load_cjs_modules.patch diff --git a/patches/node/build_add_gn_build_files.patch b/patches/node/build_add_gn_build_files.patch index 2565f04f6875a..bed5a6c0080b3 100644 --- a/patches/node/build_add_gn_build_files.patch +++ b/patches/node/build_add_gn_build_files.patch @@ -7,10 +7,10 @@ This adds GN build files for Node, so we don't have to build with GYP. diff --git a/BUILD.gn b/BUILD.gn new file mode 100644 -index 0000000000000000000000000000000000000000..ec06e14dd327cdf89dc6fd584b6972ae64311ea0 +index 0000000000000000000000000000000000000000..e4aab62b85e6ea1eac68cc21056081b4ff4bd1d6 --- /dev/null +++ b/BUILD.gn -@@ -0,0 +1,370 @@ +@@ -0,0 +1,358 @@ +import("//electron/build/asar.gni") +import("//v8/gni/v8.gni") + @@ -88,28 +88,15 @@ index 0000000000000000000000000000000000000000..ec06e14dd327cdf89dc6fd584b6972ae + ":generate_config_gypi", + ":node_js2c_inputs", + ] -+ -+ macro_inputs = [] -+ if (!node_use_dtrace && !node_use_etw) { -+ macro_inputs += [ "tools/js2c_macros/notrace_macros.py" ] -+ } -+ if (node_debug_lib) { -+ macro_inputs += [ "tools/js2c_macros/nodcheck_macros.py" ] -+ } else { -+ macro_inputs += [ "tools/js2c_macros/dcheck_macros.py" ] -+ } -+ macro_inputs += [ "tools/js2c_macros/check_macros.py" ] -+ + config_gypi = [ "$target_gen_dir/config.gypi" ] -+ -+ inputs = library_files + macro_inputs + config_gypi ++ inputs = library_files + config_gypi + outputs = [ + "$target_gen_dir/node_javascript.cc", + ] + + cwd = "$target_gen_dir/js2c_inputs" + script = "tools/js2c.py" -+ args = library_files + rebase_path(macro_inputs + config_gypi) + ["--target"] + rebase_path(outputs) ++ args = library_files + rebase_path(config_gypi) + ["--target"] + rebase_path(outputs) +} + +config("node_features") { @@ -221,6 +208,7 @@ index 0000000000000000000000000000000000000000..ec06e14dd327cdf89dc6fd584b6972ae + "deps/http_parser", + "deps/llhttp", + "deps/nghttp2", ++ "deps/uvwasi", + "deps/zlib", + "//third_party/brotli:dec", + "//third_party/brotli:enc", @@ -628,10 +616,10 @@ index 0000000000000000000000000000000000000000..66af819990b338caa49ca59d1fe6c5ad +} diff --git a/deps/uv/BUILD.gn b/deps/uv/BUILD.gn new file mode 100644 -index 0000000000000000000000000000000000000000..4674bdd48b4bfc9b7152377b8cd0984d1cf42562 +index 0000000000000000000000000000000000000000..510d86194ed71d78b2c89c7a77422afc0ef614ad --- /dev/null +++ b/deps/uv/BUILD.gn -@@ -0,0 +1,185 @@ +@@ -0,0 +1,190 @@ +config("libuv_config") { + include_dirs = [ "include" ] + @@ -691,6 +679,7 @@ index 0000000000000000000000000000000000000000..4674bdd48b4bfc9b7152377b8cd0984d + "src/idna.c", + "src/idna.h", + "src/inet.c", ++ "src/random.c", + "src/queue.h", + "src/strscpy.c", + "src/strscpy.h", @@ -769,6 +758,7 @@ index 0000000000000000000000000000000000000000..4674bdd48b4bfc9b7152377b8cd0984d + "src/unix/pipe.c", + "src/unix/poll.c", + "src/unix/process.c", ++ "src/unix/random-devurandom.c", + "src/unix/pthread-fixes.c", + "src/unix/signal.c", + "src/unix/spinlock.h", @@ -787,6 +777,7 @@ index 0000000000000000000000000000000000000000..4674bdd48b4bfc9b7152377b8cd0984d + if (is_mac) { + sources += [ + "src/unix/darwin-proctitle.c", ++ "src/unix/random-getentropy.c", + "src/unix/darwin.c", + "src/unix/fsevents.c", + ] @@ -803,6 +794,8 @@ index 0000000000000000000000000000000000000000..4674bdd48b4bfc9b7152377b8cd0984d + "src/unix/linux-syscalls.c", + "src/unix/linux-syscalls.h", + "src/unix/procfs-exepath.c", ++ "src/unix/random-getrandom.c", ++ "src/unix/random-sysctl-linux.c", + "src/unix/sysinfo-loadavg.c", + ] + libs += [ @@ -817,6 +810,46 @@ index 0000000000000000000000000000000000000000..4674bdd48b4bfc9b7152377b8cd0984d + ] + } +} +diff --git a/deps/uvwasi/BUILD.gn b/deps/uvwasi/BUILD.gn +new file mode 100644 +index 0000000000000000000000000000000000000000..52d0c08bd9818b9436175ea8157e462e4d0fbafe +--- /dev/null ++++ b/deps/uvwasi/BUILD.gn +@@ -0,0 +1,34 @@ ++config("uvwasi_config") { ++ include_dirs = [ "include" ] ++} ++ ++static_library("uvwasi") { ++ include_dirs = [ ++ "include", ++ "src", ++ ] ++ ++ defines = [] ++ if (is_linux) { ++ defines += [ ++ "_GNU_SOURCE", ++ "_POSIX_C_SOURCE=200112" ++ ] ++ } ++ ++ deps = [ "../../deps/uv" ] ++ ++ public_configs = [ ":uvwasi_config" ] ++ ++ cflags_c = [] ++ if (!is_win) { ++ cflags_c += [ "-fvisibility=hidden" ] ++ } ++ ++ sources = [ ++ "src/clocks.c", ++ "src/fd_table.c", ++ "src/uv_mapping.c", ++ "src/uvwasi.c", ++ ] ++} diff --git a/deps/zlib/BUILD.gn b/deps/zlib/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f13b471d17128468bed06e66bd03a2eaaea76280 @@ -883,10 +916,10 @@ index 0000000000000000000000000000000000000000..f13b471d17128468bed06e66bd03a2ea +} diff --git a/filenames.json b/filenames.json new file mode 100644 -index 0000000000000000000000000000000000000000..db73a7699cdb1925c723fd1708d6ce1fad1cc946 +index 0000000000000000000000000000000000000000..147561938788aac7021fe340f64fd8b4303603e6 --- /dev/null +++ b/filenames.json -@@ -0,0 +1,448 @@ +@@ -0,0 +1,461 @@ +// This file is automatically generated by generate_gn_filenames_json.py +// DO NOT EDIT +{ @@ -959,6 +992,10 @@ index 0000000000000000000000000000000000000000..db73a7699cdb1925c723fd1708d6ce1f + "lib/internal/bootstrap/loaders.js", + "lib/internal/bootstrap/node.js", + "lib/internal/bootstrap/pre_execution.js", ++ "lib/internal/bootstrap/switches/does_own_process_state.js", ++ "lib/internal/bootstrap/switches/does_not_own_process_state.js", ++ "lib/internal/bootstrap/switches/is_main_thread.js", ++ "lib/internal/bootstrap/switches/is_not_main_thread.js", + "lib/internal/per_context/primordials.js", + "lib/internal/per_context/domexception.js", + "lib/async_hooks.js", @@ -1013,6 +1050,7 @@ index 0000000000000000000000000000000000000000..db73a7699cdb1925c723fd1708d6ce1f + "lib/util.js", + "lib/v8.js", + "lib/vm.js", ++ "lib/wasi.js", + "lib/worker_threads.js", + "lib/zlib.js", + "lib/internal/assert.js", @@ -1021,6 +1059,7 @@ index 0000000000000000000000000000000000000000..db73a7699cdb1925c723fd1708d6ce1f + "lib/internal/buffer.js", + "lib/internal/cli_table.js", + "lib/internal/child_process.js", ++ "lib/internal/child_process/serialization.js", + "lib/internal/cluster/child.js", + "lib/internal/cluster/master.js", + "lib/internal/cluster/round_robin_handle.js", @@ -1068,20 +1107,23 @@ index 0000000000000000000000000000000000000000..db73a7699cdb1925c723fd1708d6ce1f + "lib/internal/main/eval_string.js", + "lib/internal/main/eval_stdin.js", + "lib/internal/main/inspect.js", -+ "lib/internal/main/print_bash_completion.js", + "lib/internal/main/print_help.js", + "lib/internal/main/prof_process.js", + "lib/internal/main/repl.js", + "lib/internal/main/run_main_module.js", + "lib/internal/main/run_third_party_main.js", + "lib/internal/main/worker_thread.js", ++ "lib/internal/modules/run_main.js", + "lib/internal/modules/cjs/helpers.js", + "lib/internal/modules/cjs/loader.js", + "lib/internal/modules/esm/loader.js", + "lib/internal/modules/esm/create_dynamic_module.js", -+ "lib/internal/modules/esm/default_resolve.js", ++ "lib/internal/modules/esm/get_format.js", ++ "lib/internal/modules/esm/get_source.js", + "lib/internal/modules/esm/module_job.js", + "lib/internal/modules/esm/module_map.js", ++ "lib/internal/modules/esm/resolve.js", ++ "lib/internal/modules/esm/transform_source.js", + "lib/internal/modules/esm/translators.js", + "lib/internal/net.js", + "lib/internal/options.js", @@ -1090,14 +1132,13 @@ index 0000000000000000000000000000000000000000..db73a7699cdb1925c723fd1708d6ce1f + "lib/internal/priority_queue.js", + "lib/internal/process/esm_loader.js", + "lib/internal/process/execution.js", -+ "lib/internal/process/main_thread_only.js", + "lib/internal/process/per_thread.js", + "lib/internal/process/policy.js", + "lib/internal/process/promises.js", -+ "lib/internal/process/stdio.js", + "lib/internal/process/warning.js", + "lib/internal/process/worker_thread_only.js", + "lib/internal/process/report.js", ++ "lib/internal/process/signal.js", + "lib/internal/process/task_queues.js", + "lib/internal/querystring.js", + "lib/internal/readline/utils.js", @@ -1128,19 +1169,19 @@ index 0000000000000000000000000000000000000000..db73a7699cdb1925c723fd1708d6ce1f + "lib/internal/v8_prof_processor.js", + "lib/internal/validators.js", + "lib/internal/stream_base_commons.js", -+ "lib/internal/vm/source_text_module.js", ++ "lib/internal/vm/module.js", + "lib/internal/worker.js", + "lib/internal/worker/io.js", + "lib/internal/streams/lazy_transform.js", + "lib/internal/streams/async_iterator.js", + "lib/internal/streams/buffer_list.js", + "lib/internal/streams/duplexpair.js", ++ "lib/internal/streams/from.js", + "lib/internal/streams/legacy.js", + "lib/internal/streams/destroy.js", + "lib/internal/streams/state.js", + "lib/internal/streams/pipeline.js", + "lib/internal/streams/end-of-stream.js", -+ "lib/internal/streams/from.js", + "deps/v8/tools/splaytree.js", + "deps/v8/tools/codemap.js", + "deps/v8/tools/consarray.js", @@ -1226,6 +1267,7 @@ index 0000000000000000000000000000000000000000..db73a7699cdb1925c723fd1708d6ce1f + "src/node_url.cc", + "src/node_util.cc", + "src/node_v8.cc", ++ "src/node_wasi.cc", + "src/node_watchdog.cc", + "src/node_worker.cc", + "src/node_zlib.cc", @@ -1280,12 +1322,15 @@ index 0000000000000000000000000000000000000000..db73a7699cdb1925c723fd1708d6ce1f + "src/node_dir.h", + "src/node_errors.h", + "src/node_file.h", ++ "src/node_file-inl.h", + "src/node_http_parser_impl.h", + "src/node_http2.h", + "src/node_http2_state.h", + "src/node_i18n.h", + "src/node_internals.h", + "src/node_main_instance.h", ++ "src/node_mem.h", ++ "src/node_mem-inl.h", + "src/node_messaging.h", + "src/node_metadata.h", + "src/node_mutex.h", @@ -1305,6 +1350,7 @@ index 0000000000000000000000000000000000000000..db73a7699cdb1925c723fd1708d6ce1f + "src/node_url.h", + "src/node_version.h", + "src/node_v8_platform-inl.h", ++ "src/node_wasi.h", + "src/node_watchdog.h", + "src/node_worker.h", + "src/pipe_wrap.h", @@ -1541,7 +1587,7 @@ index 0000000000000000000000000000000000000000..f3c5c798c0aefcb8cf9b1570a7b4817c + args = rebase_path(inputs + outputs, root_build_dir) +} diff --git a/src/node_version.h b/src/node_version.h -index 8a6fb55a5a3824b40d2c744a0ed1e8d84e6bbc4a..c68a60d7b0a818b25ce3bd44037d52abe57769f2 100644 +index 489dff631e51d1e93ed79acc48e52d33cd9c66d1..3f7349a4fa77aaae258ed32f378384165260c5b0 100644 --- a/src/node_version.h +++ b/src/node_version.h @@ -89,7 +89,10 @@ @@ -1697,18 +1743,14 @@ index 655802980a6ea94d1d4ca1dc63c8c8e905fbb83a..ab1a18a215cb7393310324c6dbcacc66 if 'false' == variables.get('node_shared_libuv'): subdir_files('deps/uv/include', 'include/node/', action) diff --git a/tools/js2c.py b/tools/js2c.py -index 1346b2a87046d3472577875c887b3b44a63280ed..752344d68c3f63b4c5e491b33d4576ed48f8b74f 100755 +index 4594694a2cab0d878d86127a72714ed60c251b6e..9e9883129bed62c591d23f71d139514c5034ac8d 100755 --- a/tools/js2c.py +++ b/tools/js2c.py -@@ -261,10 +261,18 @@ def NormalizeFileName(filename): - split = ['internal'] + split - else: # `lib/**/*.js` so drop the 'lib' part +@@ -130,6 +130,14 @@ def NormalizeFileName(filename): split = split[1:] -+ if len(split): filename = '/'.join(split) -- return os.path.splitext(filename)[0] - ++ + # Electron-specific: when driving the node build from Electron, we generate + # config.gypi in a separate directory and pass the absolute path to js2c. + # This overrides the absolute path so that the variable names in the @@ -1716,10 +1758,9 @@ index 1346b2a87046d3472577875c887b3b44a63280ed..752344d68c3f63b4c5e491b33d4576ed + if filename.endswith("/config.gypi"): + filename = "config.gypi" + -+ return os.path.splitext(filename)[0] + return os.path.splitext(filename)[0] + - def JS2C(source_files, target): - # Process input from all *macro.py files diff --git a/tools/tar.py b/tools/tar.py new file mode 100644 index 0000000000000000000000000000000000000000..eb697be25779db62c829aac45a509804e9fff331 diff --git a/patches/node/build_bring_back_node_with_ltcg_configuration.patch b/patches/node/build_bring_back_node_with_ltcg_configuration.patch index 5cd712c2bf428..6c4e2248b94e4 100644 --- a/patches/node/build_bring_back_node_with_ltcg_configuration.patch +++ b/patches/node/build_bring_back_node_with_ltcg_configuration.patch @@ -23,8 +23,8 @@ index f07e65f719a1a5939997dfcae7bc787ee6391f4d..f4d03a2fdfd47a4e6a71c7146d92ce7c 'node_tag%': '', @@ -240,6 +240,26 @@ - 'cflags': [ '-fPIE' ], - 'ldflags': [ '-fPIE', '-pie' ] + 'cflags': [ '-fPIC' ], + 'ldflags': [ '-fPIC' ] }], + ['node_with_ltcg=="true"', { + 'msvs_settings': { diff --git a/patches/node/build_modify_js2c_py_to_allow_injection_of_original-fs_and_custom_embedder_js.patch b/patches/node/build_modify_js2c_py_to_allow_injection_of_original-fs_and_custom_embedder_js.patch index a977d06e2ea2c..e319bdb1a5fb9 100644 --- a/patches/node/build_modify_js2c_py_to_allow_injection_of_original-fs_and_custom_embedder_js.patch +++ b/patches/node/build_modify_js2c_py_to_allow_injection_of_original-fs_and_custom_embedder_js.patch @@ -59,18 +59,7 @@ index 752344d68c3f63b4c5e491b33d4576ed48f8b74f..a6f0805048e3c3f4dd81ce6e90b684c4 }} // namespace native_module -@@ -243,8 +245,8 @@ def GetDefinition(var, source, step=30): - return definition, len(code_points) - - --def AddModule(filename, consts, macros, definitions, initializers): -- code = ReadFile(filename) -+def AddModule(filename, consts, macros, definitions, initializers, FileReadFn=ReadFile): -+ code = FileReadFn(filename) - code = ExpandConstants(code, consts) - code = ExpandMacros(code, macros) - name = NormalizeFileName(filename) -@@ -256,7 +258,7 @@ def AddModule(filename, consts, macros, definitions, initializers): +@@ -256,7 +258,7 @@ def AddModule(filename, definitions, initializers): initializers.append(initializer) def NormalizeFileName(filename): @@ -79,23 +68,30 @@ index 752344d68c3f63b4c5e491b33d4576ed48f8b74f..a6f0805048e3c3f4dd81ce6e90b684c4 if split[0] == 'deps': split = ['internal'] + split else: # `lib/**/*.js` so drop the 'lib' part -@@ -274,9 +276,9 @@ def NormalizeFileName(filename): +@@ -114,8 +114,8 @@ def GetDefinition(var, source, step=30): + return definition, len(code_points) + +-def AddModule(filename, definitions, initializers): +- code = ReadFile(filename) ++def AddModule(filename, definitions, initializers, ReadFileFn=ReadFile): ++ code = ReadFileFn(filename) + name = NormalizeFileName(filename) + slug = SLUGGER_RE.sub('_', name) + var = slug + '_raw' +@@ -141,7 +141,7 @@ def NormalizeFileName(filename): return os.path.splitext(filename)[0] + -def JS2C(source_files, target): +def JS2C(source_files, target, only_js): - # Process input from all *macro.py files -- consts, macros = ReadMacros(source_files['.py']) -+ consts, macros = ReadMacros([] if only_js else source_files['.py']) - # Build source code lines definitions = [] -@@ -284,14 +286,26 @@ def JS2C(source_files, target): - + initializers = [] +@@ -149,13 +149,26 @@ def JS2C(source_files, target): for filename in source_files['.js']: - AddModule(filename, consts, macros, definitions, initializers) -- + AddModule(filename, definitions, initializers) + - config_def, config_size = handle_config_gypi(source_files['config.gypi']) - definitions.append(config_def) + # Electron: Expose fs module without asar support. @@ -105,9 +101,9 @@ index 752344d68c3f63b4c5e491b33d4576ed48f8b74f..a6f0805048e3c3f4dd81ce6e90b684c4 + # we have to copy both 'fs' *and* 'internal/fs/streams' and modify the + # copies to depend on each other instead of on our asarified 'fs' code. + # See https://github.com/electron/electron/pull/16028 for more. -+ AddModule('lib/original-fs.js', consts, macros, definitions, initializers, lambda _: ReadFile(filename).replace("require('internal/fs/streams')", "require('internal/original-fs/streams')")) ++ AddModule('lib/original-fs.js', definitions, initializers, lambda _: ReadFile(filename).replace("require('internal/fs/streams')", "require('internal/original-fs/streams')")) + elif filename == 'lib/internal/fs/streams.js': -+ AddModule('lib/internal/original-fs/streams.js', consts, macros, definitions, initializers, lambda _: ReadFile(filename).replace("require('fs')", "require('original-fs')")) ++ AddModule('lib/internal/original-fs/streams.js', definitions, initializers, lambda _: ReadFile(filename).replace("require('fs')", "require('original-fs')")) + + config_size = 0 + if not only_js: @@ -132,8 +128,8 @@ index 752344d68c3f63b4c5e491b33d4576ed48f8b74f..a6f0805048e3c3f4dd81ce6e90b684c4 global is_verbose is_verbose = options.verbose source_files = functools.reduce(SourceFileByExt, options.sources, {}) - # Should have exactly 3 types: `.js`, `.py`, and `.gypi` -- assert len(source_files) == 3 + # Should have exactly 2 types: `.js`, and `.gypi` +- assert len(source_files) == 2 - # Currently config.gypi is the only `.gypi` file allowed - assert source_files['.gypi'] == ['config.gypi'] - source_files['config.gypi'] = source_files.pop('.gypi')[0] @@ -141,7 +137,7 @@ index 752344d68c3f63b4c5e491b33d4576ed48f8b74f..a6f0805048e3c3f4dd81ce6e90b684c4 + if options.only_js: + assert len(source_files) == 1 + else: -+ assert len(source_files) == 3 ++ assert len(source_files) == 2 + # Currently config.gypi is the only `.gypi` file allowed + assert source_files['.gypi'][0].endswith('config.gypi') + source_files['config.gypi'] = source_files.pop('.gypi')[0] diff --git a/patches/node/call_process_log_from_fallback_stream_on_windows.patch b/patches/node/call_process_log_from_fallback_stream_on_windows.patch index be7a586e2eccf..98c32f16d0fd4 100644 --- a/patches/node/call_process_log_from_fallback_stream_on_windows.patch +++ b/patches/node/call_process_log_from_fallback_stream_on_windows.patch @@ -5,11 +5,11 @@ Subject: Call process.log from fallback stream on Windows (cherry picked from commit d31e629b4f2daf3500a485caab2b2990a41e3ad4) -diff --git a/lib/internal/process/stdio.js b/lib/internal/process/stdio.js -index 2491f14cdf01409e4625d6793279ef87dbcc6942..54d3fb23dc1b51fec206e8989e4873d95884583f 100644 ---- a/lib/internal/process/stdio.js -+++ b/lib/internal/process/stdio.js -@@ -192,6 +192,11 @@ function createWritableStdioStream(fd) { +diff --git a/lib/internal/bootstrap/switches/is_main_thread.js b/lib/internal/bootstrap/switches/is_main_thread.js +index ac8336fb6229e7f44eb00f43abb07bea83a9463c..2005e8ef9ebd090c1be19ff320f48b9cd365239e 100644 +--- a/lib/internal/bootstrap/switches/is_main_thread.js ++++ b/lib/internal/bootstrap/switches/is_main_thread.js +@@ -80,6 +80,11 @@ function createWritableStdioStream(fd) { const { Writable } = require('stream'); stream = new Writable({ write(buf, enc, cb) { diff --git a/patches/node/chore_prevent_warn_non_context-aware_native_modules_being_loaded.patch b/patches/node/chore_prevent_warn_non_context-aware_native_modules_being_loaded.patch index 2d04fade4133b..d602f40c61c4e 100644 --- a/patches/node/chore_prevent_warn_non_context-aware_native_modules_being_loaded.patch +++ b/patches/node/chore_prevent_warn_non_context-aware_native_modules_being_loaded.patch @@ -23,10 +23,10 @@ index e7bd18855fb98a822833b4366bfb595dccfc1b6f..a96f891f675cc598e912a5e010c24938 // TODO(joyeecheung): most of these should be deprecated and removed, diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js -index 2fddd3766ffb28dc9176ed1b7a4b01361dd72fcd..c14cbe0279bbce98ea875bc3487996da679b4f40 100644 +index 38f4d277a51e3c3ff6d1fe37128e975b888207f0..b21a3e12e7b9dd49e0ffb7ef6495443ecb1d156f 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js -@@ -932,6 +932,13 @@ Module.prototype._compile = function(content, filename) { +@@ -1128,6 +1128,13 @@ Module.prototype._compile = function(content, filename) { if (getOptionValue('--inspect-brk') && process._eval == null) { if (!resolvedArgv) { // We enter the repl if we're not given a filename argument. @@ -38,8 +38,8 @@ index 2fddd3766ffb28dc9176ed1b7a4b01361dd72fcd..c14cbe0279bbce98ea875bc3487996da + delete process._firstFileName + } else if (process.argv[1]) { - resolvedArgv = Module._resolveFilename(process.argv[1], null, false); - } else { + try { + resolvedArgv = Module._resolveFilename(process.argv[1], null, false); diff --git a/src/env.h b/src/env.h index 60cb1b6d113e7e0687d96806f8940b5a715144cf..eef7b7bc244b4231419b4ec3013fa1cf700c97ef 100644 --- a/src/env.h diff --git a/patches/node/expose_get_builtin_module_function.patch b/patches/node/expose_get_builtin_module_function.patch index 01dcb2ae70012..042b3eeeb65e4 100644 --- a/patches/node/expose_get_builtin_module_function.patch +++ b/patches/node/expose_get_builtin_module_function.patch @@ -1,13 +1,28 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Mon, 6 Mar 2017 10:42:34 -0300 -Subject: Expose `get_builtin_module` function +Subject: Expose `get_linked_module` function -This is a requirement for electron/electron#8815, which exposes some builtin -modules to sandboxed renderers. +This is a requirement for electron/electron#8815, which exposes some linked +modules to sandboxed renderers. -(cherry picked from commit 4c058a6cb5331eef1c7f51c042dd074a2d4f9234) +TODO(codebytere): remove and replace with a public facing API. +diff --git a/src/node_binding.cc b/src/node_binding.cc +index 0facfc36cbcb784cd0a1802a7748dff3366710fd..db60617cebee83ac09371aa1e2200280e29bd772 100644 +--- a/src/node_binding.cc ++++ b/src/node_binding.cc +@@ -611,6 +611,10 @@ void GetInternalBinding(const FunctionCallbackInfo& args) { + args.GetReturnValue().Set(exports); + } + ++node_module* get_linked_module(const char* name) { ++ return FindModule(modlist_linked, name, NM_F_LINKED); ++} ++ + void GetLinkedBinding(const FunctionCallbackInfo& args) { + Environment* env = Environment::GetCurrent(args); + diff --git a/src/node_binding.h b/src/node_binding.h index 42f3c5b8d00880588f442a4e724e080128c56dfe..cefb6419ebb7f5c5c79927d179eef0a790e234ad 100644 --- a/src/node_binding.h diff --git a/patches/node/feat_add_flags_for_low-level_hooks_and_exceptions.patch b/patches/node/feat_add_flags_for_low-level_hooks_and_exceptions.patch index 59c8fbf34112d..ec54bd6fbd8a5 100644 --- a/patches/node/feat_add_flags_for_low-level_hooks_and_exceptions.patch +++ b/patches/node/feat_add_flags_for_low-level_hooks_and_exceptions.patch @@ -87,25 +87,23 @@ index 9d182d2aeb48c8b600bace036df868fb695dfa7c..38c467c7d49589ef5d985ad999fe22d9 #ifdef NODE_REPORT // Cache the original command line to be -@@ -811,6 +824,9 @@ int InitializeNodeWithArgs(std::vector* argv, +@@ -849,6 +849,8 @@ int InitializeNodeWithArgs(std::vector* argv, + if (exit_code != 0) return exit_code; } #endif - + if (g_upstream_node_mode) { + // NOTE(jeremy): indentation is intentionally wrong here, to ease rebasing. -+ - const int exit_code = ProcessGlobalArgs(argv, exec_argv, errors, false); - if (exit_code != 0) return exit_code; -@@ -833,6 +849,8 @@ int InitializeNodeWithArgs(std::vector* argv, + const int exit_code = ProcessGlobalArgs(argv, + exec_argv, +@@ -893,6 +895,7 @@ int InitializeNodeWithArgs(std::vector* argv, + } per_process::metadata.versions.InitializeIntlVersions(); #endif - + } // g_upstream_node_mode -+ + NativeModuleEnv::InitializeCodeCache(); - // We should set node_is_initialized here instead of in node::Start, diff --git a/src/node.h b/src/node.h index 025c6b949dc438a98a960d3630c723376f731ca7..892dafd8031533d23a88298406356107409cbd0a 100644 --- a/src/node.h diff --git a/patches/node/feat_enable_passing_cli_flags.patch b/patches/node/feat_enable_passing_cli_flags.patch deleted file mode 100644 index f865d68b22b4f..0000000000000 --- a/patches/node/feat_enable_passing_cli_flags.patch +++ /dev/null @@ -1,108 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Shelley Vohr -Date: Wed, 13 Nov 2019 15:39:48 +0000 -Subject: feat: enable passing cli flags - -This patches enables passing safelisted cli flags to Node.js. -Upstreamed in https://github.com/nodejs/node/pull/30466. - -diff --git a/src/node.cc b/src/node.cc -index 461f736beacec67b35c89a42319f99178a1e38e9..c00bfb6ccbe603604fca29268d15d67b208b2e6a 100644 ---- a/src/node.cc -+++ b/src/node.cc -@@ -113,8 +113,6 @@ - namespace node { - - using native_module::NativeModuleEnv; --using options_parser::kAllowedInEnvironment; --using options_parser::kDisallowedInEnvironment; - - using v8::Boolean; - using v8::EscapableHandleScope; -@@ -670,7 +668,7 @@ void ResetStdio() { - int ProcessGlobalArgs(std::vector* args, - std::vector* exec_args, - std::vector* errors, -- bool is_env) { -+ OptionEnvvarSettings settings) { - // Parse a few arguments which are specific to Node. - std::vector v8_args; - -@@ -680,7 +678,7 @@ int ProcessGlobalArgs(std::vector* args, - exec_args, - &v8_args, - per_process::cli_options.get(), -- is_env ? kAllowedInEnvironment : kDisallowedInEnvironment, -+ settings, - errors); - - if (!errors->empty()) return 9; -@@ -851,7 +849,7 @@ int InitializeNodeWithArgs(std::vector* argv, - return 9; - } - -- const int exit_code = ProcessGlobalArgs(&env_argv, nullptr, errors, true); -+ const int exit_code = ProcessGlobalArgs(&env_argv, nullptr, errors, kAllowedInEnvironment); - if (exit_code != 0) return exit_code; - } - #endif -@@ -859,7 +857,7 @@ int InitializeNodeWithArgs(std::vector* argv, - if (g_upstream_node_mode) { - // NOTE(jeremy): indentation is intentionally wrong here, to ease rebasing. - -- const int exit_code = ProcessGlobalArgs(argv, exec_argv, errors, false); -+ const int exit_code = ProcessGlobalArgs(argv, exec_argv, errors, kDisallowedInEnvironment); - if (exit_code != 0) return exit_code; - - // Set the process.title immediately after processing argv if --title is set. -diff --git a/src/node.h b/src/node.h -index 9c6dcbf7014f7cf87f7f66886cbf255978c244fa..4f2da9a46966199465a33c1fa275d0116d395a56 100644 ---- a/src/node.h -+++ b/src/node.h -@@ -223,6 +223,16 @@ NODE_EXTERN void Init(int* argc, - int* exec_argc, - const char*** exec_argv); - -+enum OptionEnvvarSettings { -+ kAllowedInEnvironment, -+ kDisallowedInEnvironment -+}; -+ -+NODE_EXTERN int ProcessGlobalArgs(std::vector* args, -+ std::vector* exec_args, -+ std::vector* errors, -+ OptionEnvvarSettings settings); -+ - class NodeArrayBufferAllocator; - - // An ArrayBuffer::Allocator class with some Node.js-specific tweaks. If you do -diff --git a/src/node_options.h b/src/node_options.h -index 4ce5551284bb5b1b4194905a9fe619f852933405..404cb72536cdaf8f0320770392e02ac75c303cae 100644 ---- a/src/node_options.h -+++ b/src/node_options.h -@@ -248,11 +248,6 @@ HostPort NODE_EXTERN SplitHostPort(const std::string& arg, - std::vector* errors); - void GetOptions(const v8::FunctionCallbackInfo& args); - --enum OptionEnvvarSettings { -- kAllowedInEnvironment, -- kDisallowedInEnvironment --}; -- - enum OptionType { - kNoOp, - kV8Option, -diff --git a/src/node_worker.cc b/src/node_worker.cc -index c8b2e1699f26ac9bfeb373653d35271f9b6c841f..a4db86ad99c75e07960a95247a41ed78e5bf55ca 100644 ---- a/src/node_worker.cc -+++ b/src/node_worker.cc -@@ -16,7 +16,7 @@ - #include - #include - --using node::options_parser::kDisallowedInEnvironment; -+using node::kDisallowedInEnvironment; - using v8::Array; - using v8::Boolean; - using v8::Context; - \ No newline at end of file diff --git a/patches/node/feat_initialize_asar_support.patch b/patches/node/feat_initialize_asar_support.patch index 052bfb799e094..685630b31ef0d 100644 --- a/patches/node/feat_initialize_asar_support.patch +++ b/patches/node/feat_initialize_asar_support.patch @@ -3,34 +3,21 @@ From: Shelley Vohr Date: Thu, 13 Sep 2018 08:56:07 -0700 Subject: feat: initialize asar support -This patch initializies asar support in Node.js. +This patch initializes asar support in Node.js. -diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js -index 0cad5209c4ff4e68d7c400af1d2b4c234210ddb4..918bc8c0c4e78bad5a3372e8a5522da00aa9073e 100644 ---- a/lib/internal/bootstrap/loaders.js -+++ b/lib/internal/bootstrap/loaders.js -@@ -192,6 +192,8 @@ function nativeModuleRequire(id) { - return mod.compile(); - } - -+NativeModule.require = nativeModuleRequire -+ - NativeModule.exists = function(id) { - return NativeModule.map.has(id); - }; diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js -index 2aa2a3b46c5fc12d22e0e74e304d2d55ca02c3b5..c86b5851ca9332ca440443e5feab2e65c7ac30b9 100644 +index 1b05d6e30a0ba004ac3c1113da3ad649a6e74dcc..2fc1151251571db91e01725353af2c8ff41af018 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js -@@ -61,6 +61,7 @@ function prepareMainThreadExecution(expandArgv1 = false) { - initializeESMLoader(); +@@ -67,6 +67,7 @@ function prepareMainThreadExecution(expandArgv1 = false) { + assert(!CJSLoader.hasLoadedAnyUserCJSModule); loadPreloadModules(); initializeFrozenIntrinsics(); + setupAsarSupport(); } function patchProcessObject(expandArgv1) { -@@ -444,6 +445,10 @@ function loadPreloadModules() { +@@ -445,6 +446,10 @@ function loadPreloadModules() { } } diff --git a/patches/node/fix_--perf-prof_only_works_on_linux.patch b/patches/node/fix_--perf-prof_only_works_on_linux.patch new file mode 100644 index 0000000000000..c713ff55b5235 --- /dev/null +++ b/patches/node/fix_--perf-prof_only_works_on_linux.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Shelley Vohr +Date: Thu, 20 Feb 2020 17:22:58 -0800 +Subject: fix: --perf-prof only works on Linux + +`--perf-prof`-related flags have been removed in V8 on non-linux devices. + +See: +* https://chromium-review.googlesource.com/c/v8/v8/+/1993969 +* https://chromium-review.googlesource.com/c/v8/v8/+/1993978 + +Upstreamed in https://github.com/nodejs/node/pull/31892. + +diff --git a/test/parallel/test-cli-node-options.js b/test/parallel/test-cli-node-options.js +index 698f463b627644a85db0fcddfcd471ebd91934e5..63cb22c8693447da94f4ba2f8c4082ea6bf49d6a 100644 +--- a/test/parallel/test-cli-node-options.js ++++ b/test/parallel/test-cli-node-options.js +@@ -41,15 +41,14 @@ expect('--trace-event-file-pattern {pid}-${rotation}.trace_events ' + + '--trace-event-categories node.async_hooks', 'B\n'); + expect('--unhandled-rejections=none', 'B\n'); + +-if (!common.isWindows) { ++if (common.isLinux) { + expect('--perf-basic-prof', 'B\n'); + expect('--perf-basic-prof-only-functions', 'B\n'); +-} + +-if (common.isLinux && ['arm', 'x64'].includes(process.arch)) { +- // PerfJitLogger is only implemented in Linux. +- expect('--perf-prof', 'B\n'); +- expect('--perf-prof-unwinding-info', 'B\n'); ++ if (['arm', 'x64'].includes(process.arch)) { ++ expect('--perf-prof', 'B\n'); ++ expect('--perf-prof-unwinding-info', 'B\n'); ++ } + } + + if (common.hasCrypto) { diff --git a/patches/node/fix_ensure_clocks_header_included_in_impl.patch b/patches/node/fix_ensure_clocks_header_included_in_impl.patch new file mode 100644 index 0000000000000..75240731dbc3d --- /dev/null +++ b/patches/node/fix_ensure_clocks_header_included_in_impl.patch @@ -0,0 +1,20 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Shelley Vohr +Date: Fri, 14 Feb 2020 14:05:33 -0800 +Subject: fix: ensure clocks header included in impl + +Fixes some build errors in uvwasi like: `error: no previous prototype for function 'uvwasi__clock_gettime_realtime'` +This fix will be upstreamed to uvwasi if possible. + +diff --git a/deps/uvwasi/src/clocks.c b/deps/uvwasi/src/clocks.c +index e1fbc696b62f058cb0007e77bdd2e52a3c26d765..d2ca006530f50a0e8d77e8223b8191fb8e35ff2b 100644 +--- a/deps/uvwasi/src/clocks.c ++++ b/deps/uvwasi/src/clocks.c +@@ -1,3 +1,7 @@ ++#ifdef _WIN32 ++#include "clocks.h" ++#endif /* _WIN32 */ ++ + #ifndef _WIN32 + # include + # include diff --git a/patches/node/fix_expose_internalcallbackscope.patch b/patches/node/fix_expose_internalcallbackscope.patch index 51269ce086bbd..c901f9e47dc06 100644 --- a/patches/node/fix_expose_internalcallbackscope.patch +++ b/patches/node/fix_expose_internalcallbackscope.patch @@ -6,7 +6,7 @@ Subject: fix: expose InternalCallbackScope This commit exposes InternalCallbackScope in order to allow us access to kAllowEmptyResource for usage https://github.com/electron/electron/blob/master/atom/common/api/atom_bindings.cc\#L108. We should look to accomplish this another way so we no longer need to do this, as in verbose mode the regular CallBack Scope doesn't swallow errors and so we can otherwise use it. diff --git a/src/node_internals.h b/src/node_internals.h -index 0fff2e6111e53f99ca8e92d6966d9847570d01bd..e8d6705e0197aad55b931910bb5221dd33b37fb0 100644 +index 114498458a9fd69e636a8e68c30e4b93937406d7..c5b4a084e85b48d5e2121a1ebcfd0c4e4b081852 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -203,7 +203,7 @@ v8::MaybeLocal InternalMakeCallback( @@ -16,5 +16,5 @@ index 0fff2e6111e53f99ca8e92d6966d9847570d01bd..e8d6705e0197aad55b931910bb5221dd -class InternalCallbackScope { +class NODE_EXTERN InternalCallbackScope { public: - // Tell the constructor whether its `object` parameter may be empty or not. - enum ResourceExpectation { kRequireResource, kAllowEmptyResource }; + enum Flags { + kNoFlags = 0, diff --git a/patches/node/fix_include_io_h_in_uvwasi_for_win.patch b/patches/node/fix_include_io_h_in_uvwasi_for_win.patch new file mode 100644 index 0000000000000..4b32c2b19e473 --- /dev/null +++ b/patches/node/fix_include_io_h_in_uvwasi_for_win.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Shelley Vohr +Date: Tue, 18 Feb 2020 16:42:14 -0800 +Subject: fix: include io.h in uvwasi for win + +io.h must be explicitly included, or '_lseeki64' will error +as undefined. + +Already fixed upstream in https://github.com/cjihrig/uvwasi/pull/81. + +diff --git a/deps/uvwasi/src/uvwasi.c b/deps/uvwasi/src/uvwasi.c +index 28c6dcc26104c928f132117b790ee63d17bad805..44b353caaf3966fa5cc1d5b7ae8ba9f47c6ea057 100644 +--- a/deps/uvwasi/src/uvwasi.c ++++ b/deps/uvwasi/src/uvwasi.c +@@ -3,6 +3,7 @@ + + #ifndef _WIN32 + # include ++# include + # include + # include + # include +@@ -11,6 +12,7 @@ + # define SLASH_STR "/" + # define IS_SLASH(c) ((c) == '/') + #else ++# include + # define SLASH '\\' + # define SLASH_STR "\\" + # define IS_SLASH(c) ((c) == '/' || (c) == '\\') diff --git a/patches/node/fix_remove_implicit_type_conversions.patch b/patches/node/fix_remove_implicit_type_conversions.patch new file mode 100644 index 0000000000000..d76892f34c4b3 --- /dev/null +++ b/patches/node/fix_remove_implicit_type_conversions.patch @@ -0,0 +1,58 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Shelley Vohr +Date: Fri, 14 Feb 2020 18:54:44 -0800 +Subject: fix: remove implicit type conversions + +This PR removes some implicit type conversions from uvwasi. It will be upstreamed. + +diff --git a/deps/uvwasi/src/fd_table.c b/deps/uvwasi/src/fd_table.c +index f3855d4da54dbe5cbcaf0b2e5d56aa8c4f06902b..7ec19bfb38f6772e88a08a370372cd41f2b16108 100644 +--- a/deps/uvwasi/src/fd_table.c ++++ b/deps/uvwasi/src/fd_table.c +@@ -190,7 +190,7 @@ static uvwasi_errno_t uvwasi__fd_table_insert(uvwasi_t* uvwasi, + struct uvwasi_fd_wrap_t** new_fds; + uvwasi_errno_t err; + uint32_t new_size; +- int index; ++ uint32_t index; + uint32_t i; + int r; + size_t mp_len; +@@ -231,16 +231,17 @@ static uvwasi_errno_t uvwasi__fd_table_insert(uvwasi_t* uvwasi, + table->size = new_size; + } else { + /* The table is big enough, so find an empty slot for the new data. */ +- index = -1; ++ int valid_slot = 0; + for (i = 0; i < table->size; ++i) { + if (table->fds[i] == NULL) { ++ valid_slot = 1; + index = i; + break; + } + } + + /* index should never be -1. */ +- if (index == -1) { ++ if (!valid_slot) { + uvwasi__free(uvwasi, entry); + err = UVWASI_ENOSPC; + goto exit; +@@ -283,7 +284,7 @@ uvwasi_errno_t uvwasi_fd_table_init(uvwasi_t* uvwasi, + uvwasi_rights_t base; + uvwasi_rights_t inheriting; + uvwasi_errno_t err; +- uvwasi_fd_t i; ++ int i; + int r; + + /* Require an initial size of at least three to store the stdio FDs. */ +@@ -335,7 +336,7 @@ uvwasi_errno_t uvwasi_fd_table_init(uvwasi_t* uvwasi, + if (err != UVWASI_ESUCCESS) + goto error_exit; + +- if (wrap->id != i || wrap->id != (uvwasi_fd_t) wrap->fd) { ++ if ((int) wrap->id != i || wrap->id != (uvwasi_fd_t) wrap->fd) { + err = UVWASI_EBADF; + goto error_exit; + } diff --git a/patches/node/fix_use_crypto_impls_for_compat.patch b/patches/node/fix_use_crypto_impls_for_compat.patch new file mode 100644 index 0000000000000..15b573bfa70f0 --- /dev/null +++ b/patches/node/fix_use_crypto_impls_for_compat.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Shelley Vohr +Date: Wed, 12 Feb 2020 15:08:04 -0800 +Subject: fix: use crypto impls for compat + +BoringSSL does not export DSA_get0_q, ECDSA_SIG_get0_r, or ECDSA_SIG_get0_s. This +patch works around that problem by using the implementations of those functions as +found in the OpenSSL repo. I plan to upstream a version of this. + +diff --git a/src/node_crypto.cc b/src/node_crypto.cc +index 41b72d010824234c567586524d22cae6ac849edb..b2403821bb3cab4aa4587fcb757eeb101c8a7e03 100644 +--- a/src/node_crypto.cc ++++ b/src/node_crypto.cc +@@ -5027,7 +5027,7 @@ static unsigned int GetBytesOfRS(const ManagedEVPPKey& pkey) { + if (base_id == EVP_PKEY_DSA) { + DSA* dsa_key = EVP_PKEY_get0_DSA(pkey.get()); + // Both r and s are computed mod q, so their width is limited by that of q. +- bits = BN_num_bits(DSA_get0_q(dsa_key)); ++ bits = BN_num_bits(dsa_key->q); + } else if (base_id == EVP_PKEY_EC) { + EC_KEY* ec_key = EVP_PKEY_get0_EC_KEY(pkey.get()); + const EC_GROUP* ec_group = EC_KEY_get0_group(ec_key); +@@ -5056,8 +5056,8 @@ static AllocatedBuffer ConvertSignatureToP1363(Environment* env, + AllocatedBuffer buf = env->AllocateManaged(2 * n); + unsigned char* data = reinterpret_cast(buf.data()); + +- const BIGNUM* r = ECDSA_SIG_get0_r(asn1_sig.get()); +- const BIGNUM* s = ECDSA_SIG_get0_s(asn1_sig.get()); ++ const BIGNUM* r = asn1_sig.get()->r; ++ const BIGNUM* s = asn1_sig.get()->s; + CHECK_EQ(n, static_cast(BN_bn2binpad(r, data, n))); + CHECK_EQ(n, static_cast(BN_bn2binpad(s, data + n, n))); + diff --git a/patches/node/fix_use_hex_not_decimal_for_clarity.patch b/patches/node/fix_use_hex_not_decimal_for_clarity.patch new file mode 100644 index 0000000000000..0bc79bdf7a200 --- /dev/null +++ b/patches/node/fix_use_hex_not_decimal_for_clarity.patch @@ -0,0 +1,23 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Shelley Vohr +Date: Wed, 12 Feb 2020 14:19:11 -0800 +Subject: fix: use hex not decimal for clarity + +In Electron, clang enforces -Wxor-used-as-pow, so we should use hex +here to clarify intent for the compiler. + +Upstreamed at https://github.com/nodejs/node/pull/31758. + +diff --git a/src/module_wrap.cc b/src/module_wrap.cc +index b53aab6dc16c7ae42530998c94ddc845035b1256..c6aa5751a1bbaa693b915e418de8eb69ea8139f8 100644 +--- a/src/module_wrap.cc ++++ b/src/module_wrap.cc +@@ -923,7 +923,7 @@ bool IsArrayIndex(Environment* env, Local p) { + if (!n->ToInteger(context).ToLocal(&cmp_integer)) { + return false; + } +- return n_dbl > 0 && n_dbl < (2 ^ 32) - 1; ++ return n_dbl > 0 && n_dbl < (1LL << 32) - 1; + } + + Maybe ResolveExportsTarget(Environment* env, diff --git a/patches/node/fix_we_need_to_eager-load_cjs_modules.patch b/patches/node/fix_we_need_to_eager-load_cjs_modules.patch new file mode 100644 index 0000000000000..8d6bc1c2e5a3d --- /dev/null +++ b/patches/node/fix_we_need_to_eager-load_cjs_modules.patch @@ -0,0 +1,36 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Shelley Vohr +Date: Thu, 20 Feb 2020 19:04:18 -0800 +Subject: fix: we need to eager-load cjs modules + +Node.js added a check to prevent commonjs modules being loaded before prepareMainThreadExecution, +but Electron needs to do that in our asar logic in order to override child_process. I plan to +either tweak this logic and upstream it to Nodejs, or to find an alternate approach in Electron +for overriding the child_process apis. + +diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js +index 35ad9ee1a685177894bb5c13c58c16af2ccee362..865ade2b6917321e16ef3b5f12121e8bfcc25b07 100644 +--- a/lib/internal/bootstrap/pre_execution.js ++++ b/lib/internal/bootstrap/pre_execution.js +@@ -64,7 +64,7 @@ function prepareMainThreadExecution(expandArgv1 = false) { + initializeESMLoader(); + + const CJSLoader = require('internal/modules/cjs/loader'); +- assert(!CJSLoader.hasLoadedAnyUserCJSModule); ++ // assert(!CJSLoader.hasLoadedAnyUserCJSModule); + loadPreloadModules(); + initializeFrozenIntrinsics(); + setupAsarSupport(); +diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js +index 56ccd9df5e9b539297856a31691f577a5ab56bf0..abc1efcef3822c84f5f70ed64e1e9a80a16be98c 100644 +--- a/lib/internal/main/worker_thread.js ++++ b/lib/internal/main/worker_thread.js +@@ -115,7 +115,7 @@ port.on('message', (message) => { + initializeESMLoader(); + + const CJSLoader = require('internal/modules/cjs/loader'); +- assert(!CJSLoader.hasLoadedAnyUserCJSModule); ++ // assert(!CJSLoader.hasLoadedAnyUserCJSModule); + loadPreloadModules(); + initializeFrozenIntrinsics(); + if (argv !== undefined) { diff --git a/patches/node/pass_all_globals_through_require.patch b/patches/node/pass_all_globals_through_require.patch index 25edebe12be9f..2472abcfd2c21 100644 --- a/patches/node/pass_all_globals_through_require.patch +++ b/patches/node/pass_all_globals_through_require.patch @@ -6,10 +6,10 @@ Subject: Pass all globals through "require" (cherry picked from commit 7d015419cb7a0ecfe6728431a4ed2056cd411d62) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js -index 4bd467849ccf98ba17e0f4615d1df5febf878173..112a35280391ac85665f119ded9c78e88f868542 100644 +index 7b1c1c5f16e6cc68be6a7188572c0a502ba73148..0265ce3f06405d4df5128ce1918be228d6eaa451 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js -@@ -83,6 +83,13 @@ const { +@@ -101,6 +101,13 @@ const { CHAR_COLON } = require('internal/constants'); @@ -22,19 +22,19 @@ index 4bd467849ccf98ba17e0f4615d1df5febf878173..112a35280391ac85665f119ded9c78e8 + const isWindows = process.platform === 'win32'; - const relativeResolveCache = Object.create(null); -@@ -950,10 +957,12 @@ Module.prototype._compile = function(content, filename) { + const relativeResolveCache = ObjectCreate(null); +@@ -1152,10 +1159,12 @@ Module.prototype._compile = function(content, filename) { if (requireDepth === 0) statCache = new Map(); if (inspectorWrapper) { result = inspectorWrapper(compiledWrapper, thisValue, exports, - require, module, filename, dirname); -+ require, module, filename, dirname, process, -+ localGlobal, localBuffer); ++ require, module, filename, dirname, ++ process, localGlobal, localBuffer); } else { result = compiledWrapper.call(thisValue, exports, require, module, - filename, dirname); + filename, dirname, process, localGlobal, + localBuffer); } + hasLoadedAnyUserCJSModule = true; if (requireDepth === 0) statCache = null; - return result; diff --git a/patches/node/refactor_allow_embedder_overriding_of_internal_fs_calls.patch b/patches/node/refactor_allow_embedder_overriding_of_internal_fs_calls.patch index 914eec444f732..4aa1e7a39bf12 100644 --- a/patches/node/refactor_allow_embedder_overriding_of_internal_fs_calls.patch +++ b/patches/node/refactor_allow_embedder_overriding_of_internal_fs_calls.patch @@ -10,16 +10,16 @@ diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 18acd9d2b64774efdb9261e69923a5ba320a7f0e..0f36697ce5ed0b5bb6df74ceca219574da7eea53 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js -@@ -63,6 +63,10 @@ if (ownsProcessState) { - ); - } +@@ -57,6 +57,10 @@ setupBuffer(); + process.domain = null; + process._exiting = false; +// NOTE: Electron deletes this references before user code runs so that +// internalBinding is not leaked to user code +process.internalBinding = internalBinding; + // process.config is serialized config.gypi - process.config = JSON.parse(internalBinding('native_module').config); + process.config = JSONParse(internalBinding('native_module').config); diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index fc0f953820fa6222ff8cca2e27d3087e05288ff5..2fddd3766ffb28dc9176ed1b7a4b01361dd72fcd 100644 diff --git a/patches/node/revert_crypto_add_oaeplabel_option.patch b/patches/node/revert_crypto_add_oaeplabel_option.patch index bdd7483c14bb0..70f1a2d542f38 100644 --- a/patches/node/revert_crypto_add_oaeplabel_option.patch +++ b/patches/node/revert_crypto_add_oaeplabel_option.patch @@ -8,10 +8,10 @@ The BoringSSL incompatibilities (OPENSSL_memdup) will be shimmed in and this sho be removed when the associated update is rolled into Chromium. diff --git a/src/node_crypto.cc b/src/node_crypto.cc -index 861d321d6170b25e874080d4c70dda201cab3248..ef96843c820a5361056022cea5546e94e5572918 100644 +index 7950c68f52050b7c9a6798b653a9c831256b21b5..41b72d010824234c567586524d22cae6ac849edb 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc -@@ -5365,17 +5365,6 @@ bool PublicKeyCipher::Cipher(Environment* env, +@@ -5514,18 +5514,6 @@ bool PublicKeyCipher::Cipher(Environment* env, return false; } @@ -19,8 +19,9 @@ index 861d321d6170b25e874080d4c70dda201cab3248..ef96843c820a5361056022cea5546e94 - // OpenSSL takes ownership of the label, so we need to create a copy. - void* label = OPENSSL_memdup(oaep_label, oaep_label_len); - CHECK_NOT_NULL(label); -- if (0 >= EVP_PKEY_CTX_set0_rsa_oaep_label(ctx.get(), label, -- oaep_label_len)) { +- if (0 >= EVP_PKEY_CTX_set0_rsa_oaep_label(ctx.get(), +- reinterpret_cast(label), +- oaep_label_len)) { - OPENSSL_free(label); - return false; - } diff --git a/patches/node/test_use_tmpdir_refresh_in_test-esm-windows_js.patch b/patches/node/test_use_tmpdir_refresh_in_test-esm-windows_js.patch deleted file mode 100644 index 43bcd6811ac4f..0000000000000 --- a/patches/node/test_use_tmpdir_refresh_in_test-esm-windows_js.patch +++ /dev/null @@ -1,33 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Richard Lau -Date: Mon, 16 Dec 2019 16:25:31 -0500 -Subject: test: use tmpdir.refresh() in test-esm-windows.js - -Use `tmpdir.refresh()` in `test/es-module/test-esm-windows.js` so -that the temporary directory is cleaned before use and when the test -exits. - -PR-URL: https://github.com/nodejs/node/pull/30997 -Reviewed-By: Denys Otrishko -Reviewed-By: Colin Ihrig -Reviewed-By: Rich Trott -Reviewed-By: Luigi Pinca -Reviewed-By: James M Snell -(cherry picked from commit e23aebc684a45f725811211f9740bcee3bcdbe26) - -diff --git a/test/es-module/test-esm-windows.js b/test/es-module/test-esm-windows.js -index 64ba1249a76c06ee3461b56f7ac69a650e6fbfcc..44af65d6a4e0315b31508cab3183c0142ff0d17c 100644 ---- a/test/es-module/test-esm-windows.js -+++ b/test/es-module/test-esm-windows.js -@@ -15,9 +15,8 @@ const imp = (file) => { - }; - - (async () => { -- const tmp = tmpdir.path; -- await fs.mkdir(tmp).catch(() => {}); -- const rel = (file) => path.join(tmp, file); -+ tmpdir.refresh(); -+ const rel = (file) => path.join(tmpdir.path, file); - - { // Load a single script - const file = rel('con.mjs'); diff --git a/script/node-disabled-tests.json b/script/node-disabled-tests.json index a90d2b3a9b0fe..c1b06f94c81f8 100644 --- a/script/node-disabled-tests.json +++ b/script/node-disabled-tests.json @@ -36,6 +36,8 @@ "message/esm_display_syntax_error_import", "message/esm_display_syntax_error_import_module", "message/esm_display_syntax_error_module", + "message/esm_loader_not_found", + "message/esm_loader_syntax_error", "message/source_map_throw_catch", "message/source_map_throw_first_tick", "message/source_map_throw_set_immediate", @@ -104,6 +106,7 @@ "parallel/test-inspector-heap-allocation-tracker", "parallel/test-module-loading-globalpaths", "parallel/test-module-version", + "parallel/test-module-run-main-monkey-patch", "parallel/test-openssl-ca-options", "parallel/test-policy-integrity", "parallel/test-preload", @@ -160,6 +163,8 @@ "parallel/test-tls-multi-pfx", "parallel/test-tls-no-cert-required", "parallel/test-tls-options-boolean-check", + "parallel/test-tls-psk-circuit", + "parallel/test-tls-handshake-exception", "parallel/test-tls-passphrase", "parallel/test-tls-peer-certificate", "parallel/test-tls-pfx-authorizationerror", diff --git a/shell/app/node_main.cc b/shell/app/node_main.cc index e124f511718a2..7d7c087315ac8 100644 --- a/shell/app/node_main.cc +++ b/shell/app/node_main.cc @@ -74,6 +74,17 @@ void SetNodeCliFlags() { ProcessGlobalArgs(&args, nullptr, &errors, node::kDisallowedInEnvironment); } +// TODO(codebytere): expose this from Node.js itself? +void HostCleanupFinalizationGroupCallback( + v8::Local context, + v8::Local group) { + node::Environment* env = node::Environment::GetCurrent(context); + if (env == nullptr) { + return; + } + env->RegisterFinalizationGroupForCleanup(group); +} + } // namespace namespace electron { @@ -142,6 +153,14 @@ int NodeMain(int argc, char* argv[]) { node::BootstrapEnvironment(env); + // TODO(codebytere): we shouldn't have to call this - upstream? + env->InitializeDiagnostics(); + + // This is needed in order to enable v8 host weakref hooks. + // TODO(codebytere): we shouldn't have to call this - upstream? + gin_env.isolate()->SetHostCleanupFinalizationGroupCallback( + HostCleanupFinalizationGroupCallback); + gin_helper::Dictionary process(gin_env.isolate(), env->process_object()); #if defined(OS_WIN) process.SetMethod("log", &ElectronBindings::Log); @@ -165,7 +184,15 @@ int NodeMain(int argc, char* argv[]) { versions.SetReadOnly(ELECTRON_PROJECT_NAME, ELECTRON_VERSION_STRING); } - node::LoadEnvironment(env); + // TODO(codebytere): we should try to handle this upstream. + { + node::InternalCallbackScope callback_scope( + env, v8::Local(), {1, 0}, + node::InternalCallbackScope::kAllowEmptyResource | + node::InternalCallbackScope::kSkipAsyncHooks); + node::LoadEnvironment(env); + } + v8::Isolate* isolate = env->isolate(); {