Skip to content

Commit

Permalink
chore: upgrade to Node.js v20 (electron#40545)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Samuel Attard <[email protected]>
  • Loading branch information
3 people authored and MrHuangJser committed Dec 11, 2023
1 parent e21259b commit 34651d1
Show file tree
Hide file tree
Showing 76 changed files with 1,604 additions and 1,787 deletions.
14 changes: 10 additions & 4 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import("filenames.gni")
import("filenames.hunspell.gni")
import("filenames.libcxx.gni")
import("filenames.libcxxabi.gni")
import("js2c_toolchain.gni")

if (is_mac) {
import("//build/config/mac/rules.gni")
Expand Down Expand Up @@ -237,6 +238,7 @@ action("electron_js2c") {
":electron_sandboxed_renderer_bundle",
":electron_utility_bundle",
":electron_worker_bundle",
"//third_party/electron_node:node_js2c($electron_js2c_toolchain)",
]

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

inputs = sources + [ "//third_party/electron_node/tools/js2c.py" ]
inputs = sources
outputs = [ "$root_gen_dir/electron_natives.cc" ]

script = "build/js2c.py"
args = [ rebase_path("//third_party/electron_node") ] +
rebase_path(outputs, root_build_dir) +
rebase_path(sources, root_build_dir)
out_dir =
get_label_info(":anything($electron_js2c_toolchain)", "root_out_dir")
args = [
rebase_path("$out_dir/node_js2c"),
rebase_path("$root_gen_dir"),
] + rebase_path(outputs, root_gen_dir) +
rebase_path(sources, root_gen_dir)
}

action("generate_config_gypi") {
Expand Down
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ vars = {
'chromium_version':
'121.0.6147.0',
'node_version':
'v18.18.2',
'v20.9.0',
'nan_version':
'e14bdcd1f72d62bca1d541b66da43130384ec213',
'squirrel.mac_version':
Expand Down
30 changes: 6 additions & 24 deletions build/js2c.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,14 @@
import subprocess
import sys

TEMPLATE = """
#include "node_native_module.h"
#include "node_internals.h"
namespace node::native_module {{
{definitions}
void NativeModuleLoader::LoadEmbedderJavaScriptSource() {{
{initializers}
}}
}} // namespace node::native_module
"""

def main():
node_path = os.path.abspath(sys.argv[1])
natives = os.path.abspath(sys.argv[2])
js_source_files = sys.argv[3:]
js2c = sys.argv[1]
root = sys.argv[2]
natives = sys.argv[3]
js_source_files = sys.argv[4:]

js2c = os.path.join(node_path, 'tools', 'js2c.py')
subprocess.check_call(
[sys.executable, js2c] +
js_source_files +
['--only-js', '--target', natives])

[js2c, natives] + js_source_files + ['--only-js', "--root", root])

if __name__ == '__main__':
sys.exit(main())
sys.exit(main())
9 changes: 5 additions & 4 deletions build/run-in-dir.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import sys
import os
import subprocess

def main(argv):
cwd = argv[1]
os.chdir(cwd)
os.execv(sys.executable, [sys.executable] + argv[2:])
os.chdir(argv[1])
p = subprocess.Popen(argv[2:])
return p.wait()

if __name__ == '__main__':
main(sys.argv)
sys.exit(main(sys.argv))
71 changes: 71 additions & 0 deletions js2c_toolchain.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright (c) 2023 Microsoft, GmbH
# Use of this source code is governed by the MIT license that can be
# found in the LICENSE file.

declare_args() {
electron_js2c_toolchain = ""
}

if (electron_js2c_toolchain == "") {
if (current_os == host_os && current_cpu == host_cpu) {
# This is not a cross-compile, so build the snapshot with the current
# toolchain.
electron_js2c_toolchain = current_toolchain
} else if (current_os == host_os && current_cpu == "x86" &&
host_cpu == "x64") {
# This is an x64 -> x86 cross-compile, but x64 hosts can usually run x86
# binaries built for the same OS, so build the snapshot with the current
# toolchain here, too.
electron_js2c_toolchain = current_toolchain
} else if (current_os == host_os && host_cpu == "arm64" &&
current_cpu == "arm") {
# Trying to compile 32-bit arm on arm64. Good luck!
electron_js2c_toolchain = current_toolchain
} else if (host_cpu == current_cpu) {
# Cross-build from same ISA on one OS to another. For example:
# * targeting win/x64 on a linux/x64 host
# * targeting win/arm64 on a mac/arm64 host
electron_js2c_toolchain = host_toolchain
} else if (host_cpu == "arm64" && current_cpu == "x64") {
# Cross-build from arm64 to intel (likely on an Apple Silicon mac).
electron_js2c_toolchain =
"//build/toolchain/${host_os}:clang_arm64_v8_$current_cpu"
} else if (host_cpu == "x64") {
# This is a cross-compile from an x64 host to either a non-Intel target
# cpu or to 32-bit x86 on a different target OS.

assert(current_cpu != "x64", "handled by host_cpu == current_cpu branch")
if (current_cpu == "x86") {
_cpus = current_cpu
} else if (current_cpu == "arm64") {
if (is_win) {
# set _cpus to blank for Windows ARM64 so host_toolchain could be
# selected as snapshot toolchain later.
_cpus = ""
} else {
_cpus = "x64_v8_${current_cpu}"
}
} else if (current_cpu == "arm") {
_cpus = "x86_v8_${current_cpu}"
} else {
# This branch should not be reached; leave _cpus blank so the assert
# below will fail.
_cpus = ""
}

if (_cpus != "") {
electron_js2c_toolchain = "//build/toolchain/${host_os}:clang_${_cpus}"
} else if (is_win && current_cpu == "arm64") {
# cross compile Windows arm64 with host toolchain.
electron_js2c_toolchain = host_toolchain
}
} else if (host_cpu == "arm64" && current_cpu == "arm64" &&
host_os == "mac") {
# cross compile iOS arm64 with host_toolchain
electron_js2c_toolchain = host_toolchain
}
}

assert(electron_js2c_toolchain != "",
"Do not know how to build js2c for $current_toolchain " +
"on $host_os $host_cpu")
2 changes: 1 addition & 1 deletion lib/renderer/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ require('@electron/internal/renderer/common-init');

if (nodeIntegration) {
// Export node bindings to global.
const { makeRequireFunction } = __non_webpack_require__('internal/modules/cjs/helpers');
const { makeRequireFunction } = __non_webpack_require__('internal/modules/helpers');
global.module = new Module('electron/js2c/renderer_init');
global.require = makeRequireFunction(global.module);

Expand Down
2 changes: 1 addition & 1 deletion lib/worker/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require('@electron/internal/common/init');
const { hasSwitch, getSwitchValue } = process._linkedBinding('electron_common_command_line');

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

Expand Down
2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"@electron/get": "^2.0.0",
"@types/node": "^18.11.18",
"@types/node": "^20.9.0",
"extract-zip": "^2.0.1"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@types/klaw": "^3.0.1",
"@types/minimist": "^1.2.0",
"@types/mocha": "^7.0.2",
"@types/node": "^18.11.18",
"@types/node": "^20.9.0",
"@types/semver": "^7.3.3",
"@types/send": "^0.14.5",
"@types/split": "^1.0.0",
Expand Down
18 changes: 5 additions & 13 deletions patches/node/.patches
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ fix_suppress_clang_-wdeprecated-declarations_in_libuv.patch
fix_serdes_test.patch
feat_add_knostartdebugsignalhandler_to_environment_to_prevent.patch
feat_add_uv_loop_interrupt_on_io_change_option_to_uv_loop_configure.patch
json_parse_errors_made_user-friendly.patch
support_v8_sandboxed_pointers.patch
build_ensure_v8_pointer_compression_sandbox_is_enabled_on_64bit.patch
build_ensure_native_module_compilation_fails_if_not_using_a_new.patch
fix_override_createjob_in_node_platform.patch
v8_api_advance_api_deprecation.patch
fix_parallel_test-v8-stats.patch
fix_expose_the_built-in_electron_module_via_the_esm_loader.patch
api_pass_oomdetails_to_oomerrorcallback.patch
fix_expose_lookupandcompile_with_parameters.patch
enable_crashpad_linux_node_processes.patch
fix_lazyload_fs_in_esm_loaders_to_apply_asar_patches.patch
Expand All @@ -38,21 +33,18 @@ fix_wunreachable-code_warning_in_ares_init_rand_engine.patch
fix_-wshadow_warning.patch
fix_do_not_resolve_electron_entrypoints.patch
fix_ftbfs_werror_wextra-semi.patch
fix_isurl_implementation.patch
ci_ensure_node_tests_set_electron_run_as_node.patch
fix_assert_module_in_the_renderer_process.patch
src_cast_v8_object_getinternalfield_return_value_to_v8_value.patch
fix_add_trusted_space_and_trusted_lo_space_to_the_v8_heap.patch
tls_ensure_tls_sockets_are_closed_if_the_underlying_wrap_closes.patch
test_deflake_test-tls-socket-close.patch
net_fix_crash_due_to_simultaneous_close_shutdown_on_js_stream.patch
net_use_asserts_in_js_socket_stream_to_catch_races_in_future.patch
lib_fix_broadcastchannel_initialization_location.patch
src_adapt_to_v8_exception_api_change.patch
lib_test_do_not_hardcode_buffer_kmaxlength.patch
fix_handle_possible_disabled_sharedarraybuffer.patch
win_process_avoid_assert_after_spawning_store_app_4152.patch
test_fix_edge_snapshot_stack_traces.patch
chore_remove_use_of_deprecated_kmaxlength.patch
api_remove_allcan_read_write.patch
fix_avx_detection.patch
src_avoid_copying_string_in_fs_permission.patch
fix_missing_include_for_node_extern.patch
feat_optionally_prevent_calling_v8_enablewebassemblytraphandler.patch
build_only_create_cppgc_heap_on_non-32_bit_platforms.patch
src_fix_compatility_with_upcoming_v8_12_1_apis.patch
38 changes: 0 additions & 38 deletions patches/node/api_pass_oomdetails_to_oomerrorcallback.patch

This file was deleted.

22 changes: 0 additions & 22 deletions patches/node/api_remove_allcan_read_write.patch

This file was deleted.

Loading

0 comments on commit 34651d1

Please sign in to comment.