Skip to content

Commit 34651d1

Browse files
codebytereVerteDindeMarshallOfSound
authored and
MrHuangJser
committed
chore: upgrade to Node.js v20 (electron#40545)
* chore: upgrade to Node.js v20 * src: allow embedders to override NODE_MODULE_VERSION nodejs/node#49279 * src: fix missing trailing , nodejs/node#46909 * src,tools: initialize cppgc nodejs/node#45704 * tools: allow passing absolute path of config.gypi in js2c nodejs/node#49162 * tools: port js2c.py to C++ nodejs/node#46997 * doc,lib: disambiguate the old term, NativeModule nodejs/node#45673 * chore: fixup Node.js BSSL tests * nodejs/node#49492 * nodejs/node#44498 * deps: upgrade to libuv 1.45.0 nodejs/node#48078 * deps: update V8 to 10.7 nodejs/node#44741 * test: use gcUntil() in test-v8-serialize-leak nodejs/node#49168 * module: make CJS load from ESM loader nodejs/node#47999 * src: make BuiltinLoader threadsafe and non-global nodejs/node#45942 * chore: address changes to CJS/ESM loading * module: make CJS load from ESM loader (nodejs/node#47999) * lib: improve esm resolve performance (nodejs/node#46652) * bootstrap: optimize modules loaded in the built-in snapshot nodejs/node#45849 * test: mark test-runner-output as flaky nodejs/node#49854 * lib: lazy-load deps in modules/run_main.js nodejs/node#45849 * url: use private properties for brand check nodejs/node#46904 * test: refactor `test-node-output-errors` nodejs/node#48992 * assert: deprecate callTracker nodejs/node#47740 * src: cast v8::Object::GetInternalField() return value to v8::Value nodejs/node#48943 * test: adapt test-v8-stats for V8 update nodejs/node#45230 * tls: ensure TLS Sockets are closed if the underlying wrap closes nodejs/node#49327 * test: deflake test-tls-socket-close nodejs/node#49575 * net: fix crash due to simultaneous close/shutdown on JS Stream Sockets nodejs/node#49400 * net: use asserts in JS Socket Stream to catch races in future nodejs/node#49400 * lib: fix BroadcastChannel initialization location nodejs/node#46864 * src: create BaseObject with node::Realm nodejs/node#44348 * src: implement DataQueue and non-memory resident Blob nodejs/node#45258 * sea: add support for V8 bytecode-only caching nodejs/node#48191 * chore: fixup patch indices * gyp: put filenames in variables nodejs/node#46965 * build: modify js2c.py into GN executable * fix: (WIP) handle string replacement of fs -> original-fs * [v20.x] backport vm-related memory fixes nodejs/node#49874 * src: make BuiltinLoader threadsafe and non-global nodejs/node#45942 * src: avoid copying string in fs_permission nodejs/node#47746 * look upon my works ye mighty and dispair * chore: patch cleanup * [api] Remove AllCan Read/Write https://chromium-review.googlesource.com/c/v8/v8/+/5006387 * fix: missing include for NODE_EXTERN * chore: fixup patch indices * fix: fail properly when js2c fails in Node.js * build: fix js2c root_gen_dir * fix: lib/fs.js -> lib/original-fs.js * build: fix original-fs file xforms * fixup! module: make CJS load from ESM loader * build: get rid of CppHeap for now * build: add patch to prevent extra fs lookup on esm load * build: greatly simplify js2c modifications Moves our original-fs modifications back into a super simple python script action, wires up the output of that action into our call to js2c * chore: update to handle moved internal/modules/helpers file * test: update @types/node test * feat: enable preventing cppgc heap creation * feat: optionally prevent calling V8::EnableWebAssemblyTrapHandler * fix: no cppgc initialization in the renderer * gyp: put filenames in variables nodejs/node#46965 * test: disable single executable tests * fix: nan tests failing on node headers missing file * tls,http2: send fatal alert on ALPN mismatch nodejs/node#44031 * test: disable snapshot tests * nodejs/node#47887 * nodejs/node#49684 * nodejs/node#44193 * build: use deps/v8 for v8/tools Node.js hard depends on these in their builtins * test: fix edge snapshot stack traces nodejs/node#49659 * build: remove js2c //base dep * build: use electron_js2c_toolchain to build node_js2c * fix: don't create SafeSet outside packageResolve Fixes failure in parallel/test-require-delete-array-iterator: === release test-require-delete-array-iterator === Path: parallel/test-require-delete-array-iterator node:internal/per_context/primordials:426 constructor(i) { super(i); } // eslint-disable-line no-useless-constructor ^ TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator)) at new Set (<anonymous>) at new SafeSet (node:internal/per_context/primordials:426:22) * fix: failing crashReporter tests on Linux These were failing because our change from node::InitializeNodeWithArgs to node::InitializeOncePerProcess meant that we now inadvertently called PlatformInit, which reset signal handling. This meant that our intentional crash function ElectronBindings::Crash no longer worked and the renderer process no longer crashed when process.crash() was called. We don't want to use Node.js' default signal handling in the renderer process, so we disable it by passing kNoDefaultSignalHandling to node::InitializeOncePerProcess. * build: only create cppgc heap on non-32 bit platforms * chore: clean up util:CompileAndCall * src: fix compatility with upcoming V8 12.1 APIs nodejs/node#50709 * fix: use thread_local BuiltinLoader * chore: fixup v8 patch indices --------- Co-authored-by: Keeley Hammond <vertedinde@electronjs.org> Co-authored-by: Samuel Attard <marshallofsound@electronjs.org>
1 parent e21259b commit 34651d1

File tree

76 files changed

+1604
-1787
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1604
-1787
lines changed

BUILD.gn

+10-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import("filenames.gni")
2929
import("filenames.hunspell.gni")
3030
import("filenames.libcxx.gni")
3131
import("filenames.libcxxabi.gni")
32+
import("js2c_toolchain.gni")
3233

3334
if (is_mac) {
3435
import("//build/config/mac/rules.gni")
@@ -237,6 +238,7 @@ action("electron_js2c") {
237238
":electron_sandboxed_renderer_bundle",
238239
":electron_utility_bundle",
239240
":electron_worker_bundle",
241+
"//third_party/electron_node:node_js2c($electron_js2c_toolchain)",
240242
]
241243

242244
sources = [
@@ -249,13 +251,17 @@ action("electron_js2c") {
249251
"$target_gen_dir/js2c/worker_init.js",
250252
]
251253

252-
inputs = sources + [ "//third_party/electron_node/tools/js2c.py" ]
254+
inputs = sources
253255
outputs = [ "$root_gen_dir/electron_natives.cc" ]
254256

255257
script = "build/js2c.py"
256-
args = [ rebase_path("//third_party/electron_node") ] +
257-
rebase_path(outputs, root_build_dir) +
258-
rebase_path(sources, root_build_dir)
258+
out_dir =
259+
get_label_info(":anything($electron_js2c_toolchain)", "root_out_dir")
260+
args = [
261+
rebase_path("$out_dir/node_js2c"),
262+
rebase_path("$root_gen_dir"),
263+
] + rebase_path(outputs, root_gen_dir) +
264+
rebase_path(sources, root_gen_dir)
259265
}
260266

261267
action("generate_config_gypi") {

DEPS

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ vars = {
44
'chromium_version':
55
'121.0.6147.0',
66
'node_version':
7-
'v18.18.2',
7+
'v20.9.0',
88
'nan_version':
99
'e14bdcd1f72d62bca1d541b66da43130384ec213',
1010
'squirrel.mac_version':

build/js2c.py

100755100644
+6-24
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,14 @@
44
import subprocess
55
import sys
66

7-
TEMPLATE = """
8-
#include "node_native_module.h"
9-
#include "node_internals.h"
10-
11-
namespace node::native_module {{
12-
13-
{definitions}
14-
15-
void NativeModuleLoader::LoadEmbedderJavaScriptSource() {{
16-
{initializers}
17-
}}
18-
19-
}} // namespace node::native_module
20-
"""
21-
227
def main():
23-
node_path = os.path.abspath(sys.argv[1])
24-
natives = os.path.abspath(sys.argv[2])
25-
js_source_files = sys.argv[3:]
8+
js2c = sys.argv[1]
9+
root = sys.argv[2]
10+
natives = sys.argv[3]
11+
js_source_files = sys.argv[4:]
2612

27-
js2c = os.path.join(node_path, 'tools', 'js2c.py')
2813
subprocess.check_call(
29-
[sys.executable, js2c] +
30-
js_source_files +
31-
['--only-js', '--target', natives])
32-
14+
[js2c, natives] + js_source_files + ['--only-js', "--root", root])
3315

3416
if __name__ == '__main__':
35-
sys.exit(main())
17+
sys.exit(main())

build/run-in-dir.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import sys
22
import os
3+
import subprocess
34

45
def main(argv):
5-
cwd = argv[1]
6-
os.chdir(cwd)
7-
os.execv(sys.executable, [sys.executable] + argv[2:])
6+
os.chdir(argv[1])
7+
p = subprocess.Popen(argv[2:])
8+
return p.wait()
89

910
if __name__ == '__main__':
10-
main(sys.argv)
11+
sys.exit(main(sys.argv))

js2c_toolchain.gni

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright (c) 2023 Microsoft, GmbH
2+
# Use of this source code is governed by the MIT license that can be
3+
# found in the LICENSE file.
4+
5+
declare_args() {
6+
electron_js2c_toolchain = ""
7+
}
8+
9+
if (electron_js2c_toolchain == "") {
10+
if (current_os == host_os && current_cpu == host_cpu) {
11+
# This is not a cross-compile, so build the snapshot with the current
12+
# toolchain.
13+
electron_js2c_toolchain = current_toolchain
14+
} else if (current_os == host_os && current_cpu == "x86" &&
15+
host_cpu == "x64") {
16+
# This is an x64 -> x86 cross-compile, but x64 hosts can usually run x86
17+
# binaries built for the same OS, so build the snapshot with the current
18+
# toolchain here, too.
19+
electron_js2c_toolchain = current_toolchain
20+
} else if (current_os == host_os && host_cpu == "arm64" &&
21+
current_cpu == "arm") {
22+
# Trying to compile 32-bit arm on arm64. Good luck!
23+
electron_js2c_toolchain = current_toolchain
24+
} else if (host_cpu == current_cpu) {
25+
# Cross-build from same ISA on one OS to another. For example:
26+
# * targeting win/x64 on a linux/x64 host
27+
# * targeting win/arm64 on a mac/arm64 host
28+
electron_js2c_toolchain = host_toolchain
29+
} else if (host_cpu == "arm64" && current_cpu == "x64") {
30+
# Cross-build from arm64 to intel (likely on an Apple Silicon mac).
31+
electron_js2c_toolchain =
32+
"//build/toolchain/${host_os}:clang_arm64_v8_$current_cpu"
33+
} else if (host_cpu == "x64") {
34+
# This is a cross-compile from an x64 host to either a non-Intel target
35+
# cpu or to 32-bit x86 on a different target OS.
36+
37+
assert(current_cpu != "x64", "handled by host_cpu == current_cpu branch")
38+
if (current_cpu == "x86") {
39+
_cpus = current_cpu
40+
} else if (current_cpu == "arm64") {
41+
if (is_win) {
42+
# set _cpus to blank for Windows ARM64 so host_toolchain could be
43+
# selected as snapshot toolchain later.
44+
_cpus = ""
45+
} else {
46+
_cpus = "x64_v8_${current_cpu}"
47+
}
48+
} else if (current_cpu == "arm") {
49+
_cpus = "x86_v8_${current_cpu}"
50+
} else {
51+
# This branch should not be reached; leave _cpus blank so the assert
52+
# below will fail.
53+
_cpus = ""
54+
}
55+
56+
if (_cpus != "") {
57+
electron_js2c_toolchain = "//build/toolchain/${host_os}:clang_${_cpus}"
58+
} else if (is_win && current_cpu == "arm64") {
59+
# cross compile Windows arm64 with host toolchain.
60+
electron_js2c_toolchain = host_toolchain
61+
}
62+
} else if (host_cpu == "arm64" && current_cpu == "arm64" &&
63+
host_os == "mac") {
64+
# cross compile iOS arm64 with host_toolchain
65+
electron_js2c_toolchain = host_toolchain
66+
}
67+
}
68+
69+
assert(electron_js2c_toolchain != "",
70+
"Do not know how to build js2c for $current_toolchain " +
71+
"on $host_os $host_cpu")

lib/renderer/init.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ require('@electron/internal/renderer/common-init');
5858

5959
if (nodeIntegration) {
6060
// Export node bindings to global.
61-
const { makeRequireFunction } = __non_webpack_require__('internal/modules/cjs/helpers');
61+
const { makeRequireFunction } = __non_webpack_require__('internal/modules/helpers');
6262
global.module = new Module('electron/js2c/renderer_init');
6363
global.require = makeRequireFunction(global.module);
6464

lib/worker/init.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require('@electron/internal/common/init');
1616
const { hasSwitch, getSwitchValue } = process._linkedBinding('electron_common_command_line');
1717

1818
// Export node bindings to global.
19-
const { makeRequireFunction } = __non_webpack_require__('internal/modules/cjs/helpers');
19+
const { makeRequireFunction } = __non_webpack_require__('internal/modules/helpers');
2020
global.module = new Module('electron/js2c/worker_init');
2121
global.require = makeRequireFunction(global.module);
2222

npm/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"dependencies": {
1111
"@electron/get": "^2.0.0",
12-
"@types/node": "^18.11.18",
12+
"@types/node": "^20.9.0",
1313
"extract-zip": "^2.0.1"
1414
},
1515
"engines": {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@types/klaw": "^3.0.1",
2424
"@types/minimist": "^1.2.0",
2525
"@types/mocha": "^7.0.2",
26-
"@types/node": "^18.11.18",
26+
"@types/node": "^20.9.0",
2727
"@types/semver": "^7.3.3",
2828
"@types/send": "^0.14.5",
2929
"@types/split": "^1.0.0",

patches/node/.patches

+5-13
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@ fix_suppress_clang_-wdeprecated-declarations_in_libuv.patch
1717
fix_serdes_test.patch
1818
feat_add_knostartdebugsignalhandler_to_environment_to_prevent.patch
1919
feat_add_uv_loop_interrupt_on_io_change_option_to_uv_loop_configure.patch
20-
json_parse_errors_made_user-friendly.patch
2120
support_v8_sandboxed_pointers.patch
2221
build_ensure_v8_pointer_compression_sandbox_is_enabled_on_64bit.patch
2322
build_ensure_native_module_compilation_fails_if_not_using_a_new.patch
24-
fix_override_createjob_in_node_platform.patch
25-
v8_api_advance_api_deprecation.patch
26-
fix_parallel_test-v8-stats.patch
2723
fix_expose_the_built-in_electron_module_via_the_esm_loader.patch
28-
api_pass_oomdetails_to_oomerrorcallback.patch
2924
fix_expose_lookupandcompile_with_parameters.patch
3025
enable_crashpad_linux_node_processes.patch
3126
fix_lazyload_fs_in_esm_loaders_to_apply_asar_patches.patch
@@ -38,21 +33,18 @@ fix_wunreachable-code_warning_in_ares_init_rand_engine.patch
3833
fix_-wshadow_warning.patch
3934
fix_do_not_resolve_electron_entrypoints.patch
4035
fix_ftbfs_werror_wextra-semi.patch
41-
fix_isurl_implementation.patch
4236
ci_ensure_node_tests_set_electron_run_as_node.patch
4337
fix_assert_module_in_the_renderer_process.patch
44-
src_cast_v8_object_getinternalfield_return_value_to_v8_value.patch
4538
fix_add_trusted_space_and_trusted_lo_space_to_the_v8_heap.patch
46-
tls_ensure_tls_sockets_are_closed_if_the_underlying_wrap_closes.patch
47-
test_deflake_test-tls-socket-close.patch
48-
net_fix_crash_due_to_simultaneous_close_shutdown_on_js_stream.patch
49-
net_use_asserts_in_js_socket_stream_to_catch_races_in_future.patch
50-
lib_fix_broadcastchannel_initialization_location.patch
5139
src_adapt_to_v8_exception_api_change.patch
5240
lib_test_do_not_hardcode_buffer_kmaxlength.patch
5341
fix_handle_possible_disabled_sharedarraybuffer.patch
5442
win_process_avoid_assert_after_spawning_store_app_4152.patch
5543
test_fix_edge_snapshot_stack_traces.patch
5644
chore_remove_use_of_deprecated_kmaxlength.patch
57-
api_remove_allcan_read_write.patch
5845
fix_avx_detection.patch
46+
src_avoid_copying_string_in_fs_permission.patch
47+
fix_missing_include_for_node_extern.patch
48+
feat_optionally_prevent_calling_v8_enablewebassemblytraphandler.patch
49+
build_only_create_cppgc_heap_on_non-32_bit_platforms.patch
50+
src_fix_compatility_with_upcoming_v8_12_1_apis.patch

patches/node/api_pass_oomdetails_to_oomerrorcallback.patch

-38
This file was deleted.

patches/node/api_remove_allcan_read_write.patch

-22
This file was deleted.

0 commit comments

Comments
 (0)