chore: upgrade to Node.js v18 (#35999)

* chore: update to Node.js v18

* child_process: improve argument validation

https://github.com/nodejs/node/pull/41305

* bootstrap: support configure-time user-land snapshot

https://github.com/nodejs/node/pull/42466

* chore: update GN patch

* src: disambiguate terms used to refer to builtins and addons

https://github.com/nodejs/node/pull/44135

* src: use a typed array internally for process._exiting

https://github.com/nodejs/node/pull/43883

* chore: lib/internal/bootstrap -> lib/internal/process

* src: disambiguate terms used to refer to builtins and addons

https://github.com/nodejs/node/pull/44135

* chore: remove redudant browserGlobals patch

* chore: update BoringSSL patch

* src: allow embedder-provided PageAllocator in NodePlatform

https://github.com/nodejs/node/pull/38362

* chore: fixup Node.js crypto tests

- https://github.com/nodejs/node/pull/44171
- https://github.com/nodejs/node/pull/41600

* lib: add Promise methods to avoid-prototype-pollution lint rule

https://github.com/nodejs/node/pull/43849

* deps: update V8 to 10.1

https://github.com/nodejs/node/pull/42657

* src: add kNoBrowserGlobals flag for Environment

https://github.com/nodejs/node/pull/40532

* chore: consolidate asar initialization patches

* deps: update V8 to 10.1

https://github.com/nodejs/node/pull/42657

* deps: update V8 to 9.8

https://github.com/nodejs/node/pull/41610

* src,crypto: remove AllocatedBuffers from crypto_spkac

https://github.com/nodejs/node/pull/40752

* build: enable V8's shared read-only heap

https://github.com/nodejs/node/pull/42809

* src: fix ssize_t error from nghttp2.h

https://github.com/nodejs/node/pull/44393

* chore: fixup ESM patch

* chore: fixup patch indices

* src: merge NativeModuleEnv into NativeModuleLoader

https://github.com/nodejs/node/pull/43824

* [API] Pass OOMDetails to OOMErrorCallback

https://chromium-review.googlesource.com/c/v8/v8/+/3647827

* src: iwyu in cleanup_queue.cc

* src: return Maybe from a couple of functions

https://github.com/nodejs/node/pull/39603

* src: clean up embedder API

https://github.com/nodejs/node/pull/35897

* src: refactor DH groups to delete crypto_groups.h

https://github.com/nodejs/node/pull/43896

* deps,src: use SIMD for normal base64 encoding

https://github.com/nodejs/node/pull/39775

* chore: remove deleted source file

* chore: update patches

* chore: remove deleted source file

* lib: add fetch

https://github.com/nodejs/node/pull/41749

* chore: remove nonexistent node specs

* test: split report OOM tests

https://github.com/nodejs/node/pull/44389

* src: trace fs async api

https://github.com/nodejs/node/pull/44057

* http: trace http request / response

https://github.com/nodejs/node/pull/44102

* test: split test-crypto-dh.js

https://github.com/nodejs/node/pull/40451

* crypto: introduce X509Certificate API

https://github.com/nodejs/node/pull/36804

* src: split property helpers from node::Environment

https://github.com/nodejs/node/pull/44056

* https://github.com/nodejs/node/pull/38905

bootstrap: implement run-time user-land snapshots via --build-snapshot and --snapshot-blob

* lib,src: implement WebAssembly Web API

https://github.com/nodejs/node/pull/42701

* fixup! deps,src: use SIMD for normal base64 encoding

* fixup! src: refactor DH groups to delete crypto_groups.h

* chore: fixup base64 GN file

* fix: check that node::InitializeContext() returns true

* chore: delete _noBrowserGlobals usage

* chore: disable fetch in renderer procceses

* dns: default to verbatim=true in dns.lookup()

https://github.com/nodejs/node/pull/39987

Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
This commit is contained in:
Shelley Vohr
2022-11-10 22:31:20 +01:00
committed by GitHub
parent 1b1609aa0f
commit 75d2caf451
50 changed files with 792 additions and 1134 deletions

View File

@@ -262,11 +262,11 @@ v8::Isolate* JavascriptEnvironment::Initialize(uv_loop_t* event_loop) {
auto* tracing_agent = node::CreateAgent();
auto* tracing_controller = new TracingControllerImpl();
node::tracing::TraceEventHelper::SetAgent(tracing_agent);
platform_ = node::CreatePlatform(
platform_ = node::MultiIsolatePlatform::Create(
base::RecommendedMaxNumberOfThreadsInThreadGroup(3, 8, 0.1, 0),
tracing_controller, gin::V8Platform::PageAllocator());
v8::V8::InitializePlatform(platform_);
v8::V8::InitializePlatform(platform_.get());
gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode,
gin::ArrayBufferAllocator::SharedInstance(),
nullptr /* external_reference_table */,

View File

@@ -32,7 +32,7 @@ class JavascriptEnvironment {
void CreateMicrotasksRunner();
void DestroyMicrotasksRunner();
node::MultiIsolatePlatform* platform() const { return platform_; }
node::MultiIsolatePlatform* platform() const { return platform_.get(); }
v8::Isolate* isolate() const { return isolate_; }
v8::Local<v8::Context> context() const {
return v8::Local<v8::Context>::New(isolate_, context_);
@@ -42,8 +42,7 @@ class JavascriptEnvironment {
private:
v8::Isolate* Initialize(uv_loop_t* event_loop);
// Leaked on exit.
node::MultiIsolatePlatform* platform_;
std::unique_ptr<node::MultiIsolatePlatform> platform_;
v8::Isolate* isolate_;
gin::IsolateHolder isolate_holder_;

View File

@@ -210,46 +210,6 @@ GetAllowedDebugOptions() {
return {};
}
// Initialize Node.js cli options to pass to Node.js
// See https://nodejs.org/api/cli.html#cli_options
void SetNodeCliFlags() {
const std::unordered_set<base::StringPiece, base::StringPieceHash> allowed =
GetAllowedDebugOptions();
const auto argv = base::CommandLine::ForCurrentProcess()->argv();
std::vector<std::string> args;
// TODO(codebytere): We need to set the first entry in args to the
// process name owing to src/node_options-inl.h#L286-L290 but this is
// redundant and so should be refactored upstream.
args.reserve(argv.size() + 1);
args.emplace_back("electron");
for (const auto& arg : argv) {
#if BUILDFLAG(IS_WIN)
const auto& option = base::WideToUTF8(arg);
#else
const auto& option = arg;
#endif
const auto stripped = base::StringPiece(option).substr(0, option.find('='));
// Only allow in no-op (--) option or DebugOptions
if (allowed.count(stripped) != 0 || stripped == "--")
args.push_back(option);
}
std::vector<std::string> errors;
const int exit_code = ProcessGlobalArgs(&args, nullptr, &errors,
node::kDisallowedInEnvironment);
const std::string err_str = "Error parsing Node.js cli flags ";
if (exit_code != 0) {
LOG(ERROR) << err_str;
} else if (!errors.empty()) {
LOG(ERROR) << err_str << base::JoinString(errors, " ");
}
}
// Initialize NODE_OPTIONS to pass to Node.js
// See https://nodejs.org/api/cli.html#cli_node_options_options
void SetNodeOptions(base::Environment* env) {
@@ -370,6 +330,53 @@ bool NodeBindings::IsInitialized() {
return g_is_initialized;
}
// Initialize Node.js cli options to pass to Node.js
// See https://nodejs.org/api/cli.html#cli_options
void NodeBindings::SetNodeCliFlags() {
const std::unordered_set<base::StringPiece, base::StringPieceHash> allowed =
GetAllowedDebugOptions();
const auto argv = base::CommandLine::ForCurrentProcess()->argv();
std::vector<std::string> args;
// TODO(codebytere): We need to set the first entry in args to the
// process name owing to src/node_options-inl.h#L286-L290 but this is
// redundant and so should be refactored upstream.
args.reserve(argv.size() + 1);
args.emplace_back("electron");
for (const auto& arg : argv) {
#if BUILDFLAG(IS_WIN)
const auto& option = base::WideToUTF8(arg);
#else
const auto& option = arg;
#endif
const auto stripped = base::StringPiece(option).substr(0, option.find('='));
// Only allow in no-op (--) option or DebugOptions
if (allowed.count(stripped) != 0 || stripped == "--")
args.push_back(option);
}
// We need to disable Node.js' fetch implementation to prevent
// conflict with Blink's in renderer and worker processes.
if (browser_env_ == BrowserEnvironment::kRenderer ||
browser_env_ == BrowserEnvironment::kWorker) {
args.push_back("--no-experimental-fetch");
}
std::vector<std::string> errors;
const int exit_code = ProcessGlobalArgs(&args, nullptr, &errors,
node::kDisallowedInEnvironment);
const std::string err_str = "Error parsing Node.js cli flags ";
if (exit_code != 0) {
LOG(ERROR) << err_str;
} else if (!errors.empty()) {
LOG(ERROR) << err_str << base::JoinString(errors, " ");
}
}
void NodeBindings::Initialize() {
TRACE_EVENT0("electron", "NodeBindings::Initialize");
// Open node's error reporting system for browser process.
@@ -445,14 +452,6 @@ node::Environment* NodeBindings::CreateEnvironment(
v8::Isolate* isolate = context->GetIsolate();
gin_helper::Dictionary global(isolate, context->Global());
// Avoids overriding globals like setImmediate, clearImmediate
// queueMicrotask etc during the bootstrap phase of Node.js
// for processes that already have these defined by DOM.
// Check //third_party/electron_node/lib/internal/bootstrap/node.js
// for the list of overrides on globalThis.
if (browser_env_ == BrowserEnvironment::kRenderer ||
browser_env_ == BrowserEnvironment::kWorker)
global.Set("_noBrowserGlobals", true);
if (browser_env_ == BrowserEnvironment::kBrowser) {
const std::vector<std::string> search_paths = {"app.asar", "app",
@@ -487,7 +486,13 @@ node::Environment* NodeBindings::CreateEnvironment(
// Only one ESM loader can be registered per isolate -
// in renderer processes this should be blink. We need to tell Node.js
// not to register its handler (overriding blinks) in non-browser processes.
// We also avoid overriding globals like setImmediate, clearImmediate
// queueMicrotask etc during the bootstrap phase of Node.js
// for processes that already have these defined by DOM.
// Check //third_party/electron_node/lib/internal/bootstrap/node.js
// for the list of overrides on globalThis.
flags |= node::EnvironmentFlags::kNoRegisterESMLoader |
node::EnvironmentFlags::kNoBrowserGlobals |
node::EnvironmentFlags::kNoCreateInspector;
}
@@ -517,15 +522,6 @@ node::Environment* NodeBindings::CreateEnvironment(
DCHECK(env);
// Clean up the global _noBrowserGlobals that we unironically injected into
// the global scope
if (browser_env_ == BrowserEnvironment::kRenderer ||
browser_env_ == BrowserEnvironment::kWorker) {
// We need to bootstrap the env in non-browser processes so that
// _noBrowserGlobals is read correctly before we remove it
global.Delete("_noBrowserGlobals");
}
node::IsolateSettings is;
// Use a custom fatal error callback to allow us to add

View File

@@ -87,6 +87,8 @@ class NodeBindings {
// Setup V8, libuv.
void Initialize();
void SetNodeCliFlags();
// Create the environment and load node.js.
node::Environment* CreateEnvironment(v8::Handle<v8::Context> context,
node::MultiIsolatePlatform* platform,

View File

@@ -20,9 +20,9 @@
#include "env.h"
#include "node.h"
#include "node_buffer.h"
#include "node_builtins.h"
#include "node_errors.h"
#include "node_internals.h"
#include "node_native_module_env.h"
#include "node_object_wrap.h"
#include "node_options-inl.h"
#include "node_options.h"

View File

@@ -18,8 +18,8 @@ v8::MaybeLocal<v8::Value> CompileAndCall(
v8::Isolate* isolate = context->GetIsolate();
v8::TryCatch try_catch(isolate);
v8::MaybeLocal<v8::Function> compiled =
node::native_module::NativeModuleEnv::LookupAndCompile(
context, id, parameters, optional_env);
node::builtins::BuiltinLoader::LookupAndCompile(context, id, parameters,
optional_env);
if (compiled.IsEmpty()) {
return v8::MaybeLocal<v8::Value>();
}

View File

@@ -85,8 +85,8 @@ void ElectronRendererClient::DidCreateScriptContext(
node::tracing::TraceEventHelper::SetAgent(node::CreateAgent());
// Setup node environment for each window.
bool initialized = node::InitializeContext(renderer_context);
CHECK(initialized);
v8::Maybe<bool> initialized = node::InitializeContext(renderer_context);
CHECK(!initialized.IsNothing() && initialized.FromJust());
node::Environment* env =
node_bindings_->CreateEnvironment(renderer_context, nullptr);

View File

@@ -63,8 +63,8 @@ void WebWorkerObserver::WorkerScriptReadyForEvaluation(
node::tracing::TraceEventHelper::SetAgent(node::CreateAgent());
// Setup node environment for each window.
bool initialized = node::InitializeContext(worker_context);
CHECK(initialized);
v8::Maybe<bool> initialized = node::InitializeContext(worker_context);
CHECK(!initialized.IsNothing() && initialized.FromJust());
node::Environment* env =
node_bindings_->CreateEnvironment(worker_context, nullptr);