chore: bump node to v14.11.0 (master) (#25489)

This commit is contained in:
Electron Bot 2020-09-22 07:11:56 -07:00 коммит произвёл GitHub
Родитель dae60e01d4
Коммит d2a82dbd1d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
19 изменённых файлов: 97 добавлений и 491 удалений

2
DEPS
Просмотреть файл

@ -16,7 +16,7 @@ vars = {
'chromium_version':
'b943d006a33ec5bc1743792d64724693eb357083',
'node_version':
'v14.9.0',
'v14.11.0',
'nan_version':
'2c4ee8a32a299eada3cd6e468bbd0a473bfea96d',
'squirrel.mac_version':

Просмотреть файл

@ -28,9 +28,7 @@ fix_window_c-ares_incompatibilities.patch
fix_comment_out_incompatible_crypto_modules.patch
update_tests_after_increasing_typed_array_size.patch
feat_add_implementation_of_v8_platform_postjob.patch
n-api_src_provide_asynchronous_cleanup_hooks.patch
crypto_update_certdata_to_nss_3_56.patch
fix_-wincompatible-pointer-types-discards-qualifiers_error.patch
fix_allow_preventing_initializeinspector_in_env.patch
test_make_some_tests_embedder_agnostic.patch
fix_add_v8_enable_reverse_jsargs_defines_in_common_gypi.patch

Просмотреть файл

@ -846,10 +846,10 @@ index 0000000000000000000000000000000000000000..2c9d2826c85bdd033f1df1d6188df636
+}
diff --git a/filenames.json b/filenames.json
new file mode 100644
index 0000000000000000000000000000000000000000..b09510a6048f6cff3905240e3c969f143a382047
index 0000000000000000000000000000000000000000..d3315d9150ac674e06948d72ae02179a9151d74c
--- /dev/null
+++ b/filenames.json
@@ -0,0 +1,527 @@
@@ -0,0 +1,526 @@
+// This file is automatically generated by generate_gn_filenames_json.py
+// DO NOT EDIT
+{
@ -1136,7 +1136,6 @@ index 0000000000000000000000000000000000000000..b09510a6048f6cff3905240e3c969f14
+ "lib/internal/url.js",
+ "lib/internal/util.js",
+ "lib/internal/util/comparisons.js",
+ "lib/internal/util/compositekey.js",
+ "lib/internal/util/debuglog.js",
+ "lib/internal/util/inspect.js",
+ "lib/internal/util/inspector.js",
@ -1583,7 +1582,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 49e4e9d16f8732641248fd3ab15be1a74d9fd45f..35f90fcae715c5421c672a9397a8e25d93f80cd6 100644
index 0d7ffd57452c95c2f1008ffe6ff74a46342974b7..28000c9629496ef79433fa4041a1c6ef54e09f8c 100644
--- a/src/node_version.h
+++ b/src/node_version.h
@@ -89,7 +89,10 @@

Просмотреть файл

@ -10,7 +10,7 @@ THe fix for this should land in node-gyp as discussed in above issue,
landing this as temporary patch.
diff --git a/common.gypi b/common.gypi
index 2fda2d685edc6b8f45441cda017f7cabfe60d91f..bd42d6cfa6006630d316faf2cddd93bea57102ba 100644
index 8a8fcfa8c2479ff34df97320f7d7d0ef6ca15997..cde383f5a2d652dffe1c58c7f6de8399b967b441 100644
--- a/common.gypi
+++ b/common.gypi
@@ -19,7 +19,7 @@

Просмотреть файл

@ -29,10 +29,10 @@ index f947c6bf27e80c534a8f72265d0139a8b5b3f13a..d7e56d9c3fe5a56897989915984cb823
// 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 c633daa2b3557c98b05cca5f428d87775ef8a02a..4846370adb5206c53d57deef303b2c3f02342d24 100644
index 7067737952a5002899071bb4a434a93ec92103ce..3430cac5bb858c9abfe094b458f590096fc36dce 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -1049,6 +1049,13 @@ Module.prototype._compile = function(content, filename) {
@@ -1050,6 +1050,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.
@ -46,38 +46,40 @@ index c633daa2b3557c98b05cca5f428d87775ef8a02a..4846370adb5206c53d57deef303b2c3f
if (process.argv[1]) {
try {
resolvedArgv = Module._resolveFilename(process.argv[1], null, false);
diff --git a/src/env-inl.h b/src/env-inl.h
index c1853f81b68bd22d20fb99877f4c500a384e9545..623e9d4e429c03bb267539a318166f3ef3b9c501 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -550,6 +550,14 @@ inline bool Environment::force_context_aware() const {
return options_->force_context_aware;
}
+inline void Environment::set_warn_context_aware(bool value) {
+ options_->warn_context_aware = value;
+}
+
+inline bool Environment::warn_context_aware() const {
+ return options_->warn_context_aware;
+}
+
inline void Environment::set_abort_on_uncaught_exception(bool value) {
options_->abort_on_uncaught_exception = value;
}
diff --git a/src/env.h b/src/env.h
index bc222804010a035333cf6d7becc9a0a8f385af85..dea62b38cb20a0a0913128e17e8904c4ca71ac1a 100644
index f89365a1aa7ffacbb423e01a68f484992751f76f..38d17f4e18aa38fde2c2f59a9816c8fb0f65fd51 100644
--- a/src/env.h
+++ b/src/env.h
@@ -885,6 +885,15 @@ class Environment : public MemoryRetainer {
ThreadId thread_id);
~Environment() override;
@@ -949,6 +949,8 @@ class Environment : public MemoryRetainer {
+ void ForceOnlyContextAwareNativeModules() {
+ force_context_aware_ = true;
+ }
+ void WarnNonContextAwareNativeModules() {
+ warn_non_context_aware_ = true;
+ }
+ bool force_context_aware() { return force_context_aware_; }
+ bool warn_non_context_aware() { return warn_non_context_aware_; }
+
void InitializeLibuv();
inline const std::vector<std::string>& exec_argv();
inline const std::vector<std::string>& argv();
@@ -1235,6 +1244,9 @@ class Environment : public MemoryRetainer {
inline void ThrowError(v8::Local<v8::Value> (*fun)(v8::Local<v8::String>),
const char* errmsg);
inline void set_force_context_aware(bool value);
inline bool force_context_aware() const;
+ inline void set_warn_context_aware(bool value);
+ inline bool warn_context_aware() const;
+ bool force_context_aware_ = false;
+ bool warn_non_context_aware_ = false;
+
std::list<binding::DLib> loaded_addons_;
v8::Isolate* const isolate_;
IsolateData* const isolate_data_;
// This stores whether the --abort-on-uncaught-exception flag was passed
// to Node.
diff --git a/src/node_binding.cc b/src/node_binding.cc
index 0ab18f7aeda3511338cbf115a4b636a6c72437b2..51ae4c89a61a176a9629e537f9409b38c3397aa2 100644
index ca5a01f925a2ae69ba4295d82316e546f45c60cd..928afa04f4312db23ef4de8c32e0705784ccee7f 100644
--- a/src/node_binding.cc
+++ b/src/node_binding.cc
@@ -3,6 +3,7 @@
@ -88,22 +90,19 @@ index 0ab18f7aeda3511338cbf115a4b636a6c72437b2..51ae4c89a61a176a9629e537f9409b38
#include "util.h"
#if HAVE_OPENSSL
@@ -461,10 +462,22 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
if (mp != nullptr) {
@@ -463,8 +464,19 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
if (mp->nm_context_register_func == nullptr) {
- if (env->options()->force_context_aware) {
+ if (env->force_context_aware()) {
if (env->force_context_aware()) {
dlib->Close();
- THROW_ERR_NON_CONTEXT_AWARE_DISABLED(env);
- return false;
+ char errmsg[1024];
+ snprintf(errmsg,
+ sizeof(errmsg),
+ "Loading non-context-aware native module in renderer: '%s', but app.allowRendererProcessReuse is true. See https://github.com/electron/electron/issues/18397.",
+ *filename);
+ env->ThrowError(errmsg);
return false;
+ } else if (env->warn_non_context_aware()) {
+ } else if (env->warn_context_aware()) {
+ char errmsg[1024];
+ snprintf(errmsg,
+ sizeof(errmsg),
@ -113,3 +112,30 @@ index 0ab18f7aeda3511338cbf115a4b636a6c72437b2..51ae4c89a61a176a9629e537f9409b38
}
}
mp->nm_dso_handle = dlib->handle_;
diff --git a/src/node_options.cc b/src/node_options.cc
index 2854ec072bf1c68810373c61673269f86fad442b..7319d7ec4541211571f0e60d94d0d28788f0631b 100644
--- a/src/node_options.cc
+++ b/src/node_options.cc
@@ -386,6 +386,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"disable loading non-context-aware addons",
&EnvironmentOptions::force_context_aware,
kAllowedInEnvironment);
+ AddOption("--warn-context-aware",
+ "warn when loading non-context-aware addons",
+ &EnvironmentOptions::warn_context_aware,
+ kAllowedInEnvironment);
AddOption("--pending-deprecation",
"emit pending deprecation warnings",
&EnvironmentOptions::pending_deprecation,
diff --git a/src/node_options.h b/src/node_options.h
index 3258d4b3f0df0c57b055c652d3391c2196ad5075..734e80aa7d35235ffe503056e14205b94f807d60 100644
--- a/src/node_options.h
+++ b/src/node_options.h
@@ -122,6 +122,7 @@ class EnvironmentOptions : public Options {
bool no_force_async_hooks_checks = false;
bool no_warnings = false;
bool force_context_aware = false;
+ bool warn_context_aware = false;
bool pending_deprecation = false;
bool preserve_symlinks = false;
bool preserve_symlinks_main = false;

Просмотреть файл

@ -8,7 +8,7 @@ node modules will have different (wrong) ideas about how v8 structs are laid
out in memory on 64-bit machines, and will summarily fail to work.
diff --git a/common.gypi b/common.gypi
index bd42d6cfa6006630d316faf2cddd93bea57102ba..734c2917535c50e260192abe6acb4726104b7b6a 100644
index cde383f5a2d652dffe1c58c7f6de8399b967b441..547186692b8035cbc03556336729dc3fe631e260 100644
--- a/common.gypi
+++ b/common.gypi
@@ -64,7 +64,7 @@

Просмотреть файл

@ -9,7 +9,7 @@ modules to sandboxed renderers.
TODO(codebytere): remove and replace with a public facing API.
diff --git a/src/node_binding.cc b/src/node_binding.cc
index 1072ed34667262d7ef729c3235766f056acd659c..0ab18f7aeda3511338cbf115a4b636a6c72437b2 100644
index 8665b2827583d3ac7cfbfde661878026caba15ca..ca5a01f925a2ae69ba4295d82316e546f45c60cd 100644
--- a/src/node_binding.cc
+++ b/src/node_binding.cc
@@ -608,6 +608,10 @@ void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {

Просмотреть файл

@ -24,7 +24,7 @@ Environment on the V8 context of blink, so no new V8 context is created.
As a result, a renderer process may have multiple Node Environments in it.
diff --git a/src/node.cc b/src/node.cc
index 0dc7040381889541d9b5257158c2564ef0e728a2..cda0220071196fb7eced326985002bf0588aa23f 100644
index c5a406062c48dd00d411e3d1d26e4c6f40c30513..0be31f4e02513682fc742e7a71c11a115245e3d8 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -134,6 +134,8 @@ using v8::Undefined;

Просмотреть файл

@ -8,7 +8,7 @@ common.gypi is a file that's included in the node header bundle, despite
the fact that we do not build node with gyp.
diff --git a/common.gypi b/common.gypi
index 0025a6782f36a2643416bf015fff66503216e403..2fda2d685edc6b8f45441cda017f7cabfe60d91f 100644
index 46b4633f5d7e853144d78870f694a34f9fcb497c..8a8fcfa8c2479ff34df97320f7d7d0ef6ca15997 100644
--- a/common.gypi
+++ b/common.gypi
@@ -81,6 +81,22 @@

Просмотреть файл

@ -6,7 +6,7 @@ Subject: fix: add v8_enable_reverse_jsargs defines in common.gypi
This can be removed once node upgrades V8 and inevitably has to do this exact same thing. Also hi node people if you are looking at this.
diff --git a/common.gypi b/common.gypi
index 734c2917535c50e260192abe6acb4726104b7b6a..f2f4f2011ace475840b84f2a48b3d036b7350409 100644
index 547186692b8035cbc03556336729dc3fe631e260..7b4dfa4f8fd166bd2259136fe6ea0c2842793603 100644
--- a/common.gypi
+++ b/common.gypi
@@ -65,6 +65,7 @@

Просмотреть файл

@ -12,7 +12,7 @@ EnvironmentFlags option which allows preventing that invocation.
This will be upstreamed.
diff --git a/src/api/environment.cc b/src/api/environment.cc
index ac6b47e0f327ca0ffe28e97f747c72ebaa5d7005..97610a12be47cdbf0d39d61e5982bab09ff09e95 100644
index 4fa2d4175fb318f560b7b9a8ed8baa091d3ed6a2..7bd899c5933ac2e6178d650632699e19e85c00c9 100644
--- a/src/api/environment.cc
+++ b/src/api/environment.cc
@@ -358,12 +358,14 @@ Environment* CreateEnvironment(
@ -37,10 +37,10 @@ index ac6b47e0f327ca0ffe28e97f747c72ebaa5d7005..97610a12be47cdbf0d39d61e5982bab0
#endif
diff --git a/src/env-inl.h b/src/env-inl.h
index ddae5766127119f727f52212d5147d29eb72ebc0..a4f48dd1f7e5f765858dbce4a080a775c0d6a124 100644
index 623e9d4e429c03bb267539a318166f3ef3b9c501..8fc5f720764dd4ca536ae01ca78b2c7e3e9fd007 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -817,6 +817,10 @@ inline bool Environment::owns_inspector() const {
@@ -833,6 +833,10 @@ inline bool Environment::owns_inspector() const {
return flags_ & EnvironmentFlags::kOwnsInspector;
}
@ -52,10 +52,10 @@ index ddae5766127119f727f52212d5147d29eb72ebc0..a4f48dd1f7e5f765858dbce4a080a775
return flags_ & EnvironmentFlags::kTrackUnmanagedFds;
}
diff --git a/src/env.h b/src/env.h
index dea62b38cb20a0a0913128e17e8904c4ca71ac1a..18305853a4f0da3382f827e38f3b120d807a67c6 100644
index 38d17f4e18aa38fde2c2f59a9816c8fb0f65fd51..4b9c2780f9736cb8bde60f40abb9aac9d53160a1 100644
--- a/src/env.h
+++ b/src/env.h
@@ -1023,6 +1023,7 @@ class Environment : public MemoryRetainer {
@@ -1019,6 +1019,7 @@ class Environment : public MemoryRetainer {
inline bool is_main_thread() const;
inline bool should_not_register_esm_loader() const;

Просмотреть файл

@ -5,7 +5,7 @@ Subject: fix: expose tracing::Agent and use tracing::TracingController instead
of v8::TracingController
diff --git a/src/api/environment.cc b/src/api/environment.cc
index ea2be2c5c0bad66fbc70124c72aa6fa36de6ea60..ac6b47e0f327ca0ffe28e97f747c72ebaa5d7005 100644
index bc1ab0bfcf87936b8d8156172319283704b05da8..4fa2d4175fb318f560b7b9a8ed8baa091d3ed6a2 100644
--- a/src/api/environment.cc
+++ b/src/api/environment.cc
@@ -472,6 +472,10 @@ MultiIsolatePlatform* GetMultiIsolatePlatform(IsolateData* env) {

Просмотреть файл

@ -10,10 +10,10 @@ node's module code.
(cherry picked from commit 76ba048c37588ee32636817fa7b8dffc64330cbf)
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index a7fa93b9cfa9468f068fcfb950bade8137483121..a24ab3c2ee7d664700a6c4c8e17c9ef2b74efa5a 100644
index 0f8647a5f2299237a1c61dc30bd3ff5c391d69fc..efe537fca514c3d558527c9f4fc8ebb8a4de367c 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -1198,8 +1198,8 @@ Module._initPaths = function() {
@@ -1199,8 +1199,8 @@ Module._initPaths = function() {
modulePaths = paths;

Просмотреть файл

@ -1,345 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Gabriel Schulhof <gabriel.schulhof@intel.com>
Date: Mon, 17 Aug 2020 10:13:00 -0700
Subject: n-api: re-implement async env cleanup hooks
* Avoid passing core `void*` and function pointers into add-on.
* Document `napi_async_cleanup_hook_handle` type.
* Render receipt of the handle mandatory from the point where the
hook gets called. Removal of the handle remains mandatory.
Fixes: https://github.com/nodejs/node/issues/34715
Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com>
Co-authored-by: Anna Henningsen <github@addaleax.net>
PR-URL: https://github.com/nodejs/node/pull/34819
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
diff --git a/doc/api/n-api.md b/doc/api/n-api.md
index d9b757721c880388664f11cc5c0425379e105e2b..161f61308e5e5faa1ddf68802fdafacf1e5c1613 100644
--- a/doc/api/n-api.md
+++ b/doc/api/n-api.md
@@ -623,6 +623,15 @@ typedef struct {
} napi_type_tag;
```
+#### napi_async_cleanup_hook_handle
+<!-- YAML
+added: REPLACEME
+-->
+
+An opaque value returned by [`napi_add_async_cleanup_hook`][]. It must be passed
+to [`napi_remove_async_cleanup_hook`][] when the chain of asynchronous cleanup
+events completes.
+
### N-API callback types
#### napi_callback_info
@@ -751,6 +760,30 @@ typedef void (*napi_threadsafe_function_call_js)(napi_env env,
Unless for reasons discussed in [Object Lifetime Management][], creating a
handle and/or callback scope inside the function body is not necessary.
+#### napi_async_cleanup_hook
+<!-- YAML
+added: REPLACEME
+-->
+
+Function pointer used with [`napi_add_async_cleanup_hook`][]. It will be called
+when the environment is being torn down.
+
+Callback functions must satisfy the following signature:
+
+```c
+typedef void (*napi_async_cleanup_hook)(napi_async_cleanup_hook_handle handle,
+ void* data);
+```
+
+* `[in] handle`: The handle that must be passed to
+[`napi_remove_async_cleanup_hook`][] after completion of the asynchronous
+cleanup.
+* `[in] data`: The data that was passed to [`napi_add_async_cleanup_hook`][].
+
+The body of the function should initiate the asynchronous cleanup actions at the
+end of which `handle` must be passed in a call to
+[`napi_remove_async_cleanup_hook`][].
+
## Error handling
N-API uses both return values and JavaScript exceptions for error handling.
@@ -1580,6 +1613,10 @@ with `napi_add_env_cleanup_hook`, otherwise the process will abort.
#### napi_add_async_cleanup_hook
<!-- YAML
added: v14.8.0
+changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/34819
+ description: Changed signature of the `hook` callback.
-->
> Stability: 1 - Experimental
@@ -1587,15 +1624,22 @@ added: v14.8.0
```c
NAPI_EXTERN napi_status napi_add_async_cleanup_hook(
napi_env env,
- void (*fun)(void* arg, void(* cb)(void*), void* cbarg),
+ napi_async_cleanup_hook hook,
void* arg,
napi_async_cleanup_hook_handle* remove_handle);
```
-Registers `fun` as a function to be run with the `arg` parameter once the
-current Node.js environment exits. Unlike [`napi_add_env_cleanup_hook`][],
-the hook is allowed to be asynchronous in this case, and must invoke the passed
-`cb()` function with `cbarg` once all asynchronous activity is finished.
+* `[in] env`: The environment that the API is invoked under.
+* `[in] hook`: The function pointer to call at environment teardown.
+* `[in] arg`: The pointer to pass to `hook` when it gets called.
+* `[out] remove_handle`: Optional handle that refers to the asynchronous cleanup
+hook.
+
+Registers `hook`, which is a function of type [`napi_async_cleanup_hook`][], as
+a function to be run with the `remove_handle` and `arg` parameters once the
+current Node.js environment exits.
+
+Unlike [`napi_add_env_cleanup_hook`][], the hook is allowed to be asynchronous.
Otherwise, behavior generally matches that of [`napi_add_env_cleanup_hook`][].
@@ -1608,19 +1652,25 @@ is being torn down anyway.
#### napi_remove_async_cleanup_hook
<!-- YAML
added: v14.8.0
+changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/34819
+ description: Removed `env` parameter.
-->
> Stability: 1 - Experimental
```c
NAPI_EXTERN napi_status napi_remove_async_cleanup_hook(
- napi_env env,
napi_async_cleanup_hook_handle remove_handle);
```
+* `[in] remove_handle`: The handle to an asynchronous cleanup hook that was
+created with [`napi_add_async_cleanup_hook`][].
+
Unregisters the cleanup hook corresponding to `remove_handle`. This will prevent
the hook from being executed, unless it has already started executing.
-This must be called on any `napi_async_cleanup_hook_handle` value retrieved
+This must be called on any `napi_async_cleanup_hook_handle` value obtained
from [`napi_add_async_cleanup_hook`][].
## Module registration
@@ -5757,6 +5807,7 @@ This API may only be called from the main thread.
[`napi_add_async_cleanup_hook`]: #n_api_napi_add_async_cleanup_hook
[`napi_add_env_cleanup_hook`]: #n_api_napi_add_env_cleanup_hook
[`napi_add_finalizer`]: #n_api_napi_add_finalizer
+[`napi_async_cleanup_hook`]: #n_api_napi_async_cleanup_hook
[`napi_async_complete_callback`]: #n_api_napi_async_complete_callback
[`napi_async_init`]: #n_api_napi_async_init
[`napi_callback`]: #n_api_napi_callback
diff --git a/src/node_api.cc b/src/node_api.cc
index 4fbab771d5840004a303094c87981409d8bac848..93488146d56690c27c56a21f2795796d027cfa02 100644
--- a/src/node_api.cc
+++ b/src/node_api.cc
@@ -519,41 +519,68 @@ napi_status napi_remove_env_cleanup_hook(napi_env env,
}
struct napi_async_cleanup_hook_handle__ {
- node::AsyncCleanupHookHandle handle;
+ napi_async_cleanup_hook_handle__(napi_env env,
+ napi_async_cleanup_hook user_hook,
+ void* user_data):
+ env_(env),
+ user_hook_(user_hook),
+ user_data_(user_data) {
+ handle_ = node::AddEnvironmentCleanupHook(env->isolate, Hook, this);
+ env->Ref();
+ }
+
+ ~napi_async_cleanup_hook_handle__() {
+ node::RemoveEnvironmentCleanupHook(std::move(handle_));
+ if (done_cb_ != nullptr)
+ done_cb_(done_data_);
+
+ // Release the `env` handle asynchronously since it would be surprising if
+ // a call to a N-API function would destroy `env` synchronously.
+ static_cast<node_napi_env>(env_)->node_env()
+ ->SetImmediate([env = env_](node::Environment*) { env->Unref(); });
+ }
+
+ static void Hook(void* data, void (*done_cb)(void*), void* done_data) {
+ auto handle = static_cast<napi_async_cleanup_hook_handle__*>(data);
+ handle->done_cb_ = done_cb;
+ handle->done_data_ = done_data;
+ handle->user_hook_(handle, handle->user_data_);
+ }
+
+ node::AsyncCleanupHookHandle handle_;
+ napi_env env_ = nullptr;
+ napi_async_cleanup_hook user_hook_ = nullptr;
+ void* user_data_ = nullptr;
+ void (*done_cb_)(void*) = nullptr;
+ void* done_data_ = nullptr;
};
napi_status napi_add_async_cleanup_hook(
napi_env env,
- void (*fun)(void* arg, void(* cb)(void*), void* cbarg),
+ napi_async_cleanup_hook hook,
void* arg,
napi_async_cleanup_hook_handle* remove_handle) {
CHECK_ENV(env);
- CHECK_ARG(env, fun);
+ CHECK_ARG(env, hook);
- auto handle = node::AddEnvironmentCleanupHook(env->isolate, fun, arg);
- if (remove_handle != nullptr) {
- *remove_handle = new napi_async_cleanup_hook_handle__ { std::move(handle) };
- env->Ref();
- }
+ napi_async_cleanup_hook_handle__* handle =
+ new napi_async_cleanup_hook_handle__(env, hook, arg);
+
+ if (remove_handle != nullptr)
+ *remove_handle = handle;
return napi_clear_last_error(env);
}
napi_status napi_remove_async_cleanup_hook(
- napi_env env,
napi_async_cleanup_hook_handle remove_handle) {
- CHECK_ENV(env);
- CHECK_ARG(env, remove_handle);
- node::RemoveEnvironmentCleanupHook(std::move(remove_handle->handle));
- delete remove_handle;
+ if (remove_handle == nullptr)
+ return napi_invalid_arg;
- // Release the `env` handle asynchronously since it would be surprising if
- // a call to a N-API function would destroy `env` synchronously.
- static_cast<node_napi_env>(env)->node_env()
- ->SetImmediate([env](node::Environment*) { env->Unref(); });
+ delete remove_handle;
- return napi_clear_last_error(env);
+ return napi_ok;
}
napi_status napi_fatal_exception(napi_env env, napi_value err) {
diff --git a/src/node_api.h b/src/node_api.h
index 4f3eb8f2caae6375d5334486d75be76bf912d4e3..577a1dcd94987202819e7a36a2d9674f13d13614 100644
--- a/src/node_api.h
+++ b/src/node_api.h
@@ -254,12 +254,11 @@ napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func);
NAPI_EXTERN napi_status napi_add_async_cleanup_hook(
napi_env env,
- void (*fun)(void* arg, void(* cb)(void*), void* cbarg),
+ napi_async_cleanup_hook hook,
void* arg,
napi_async_cleanup_hook_handle* remove_handle);
NAPI_EXTERN napi_status napi_remove_async_cleanup_hook(
- napi_env env,
napi_async_cleanup_hook_handle remove_handle);
#endif // NAPI_EXPERIMENTAL
diff --git a/src/node_api_types.h b/src/node_api_types.h
index b8711d3eddc408bc239a964528c23d71555a5d72..0e400e9676df5ba09d350fe7a2a70a1dc9e4d3d6 100644
--- a/src/node_api_types.h
+++ b/src/node_api_types.h
@@ -43,6 +43,8 @@ typedef struct {
#ifdef NAPI_EXPERIMENTAL
typedef struct napi_async_cleanup_hook_handle__* napi_async_cleanup_hook_handle;
+typedef void (*napi_async_cleanup_hook)(napi_async_cleanup_hook_handle handle,
+ void* data);
#endif // NAPI_EXPERIMENTAL
#endif // SRC_NODE_API_TYPES_H_
diff --git a/test/node-api/test_async_cleanup_hook/binding.c b/test/node-api/test_async_cleanup_hook/binding.c
index f0c9cd97a26c48c3f7323930dc856e49e1755f35..7bbde56bb0ec888a97926f36425f7a1dca719514 100644
--- a/test/node-api/test_async_cleanup_hook/binding.c
+++ b/test/node-api/test_async_cleanup_hook/binding.c
@@ -5,7 +5,7 @@
#include <stdlib.h>
#include "../../js-native-api/common.h"
-void MustNotCall(void* arg, void(*cb)(void*), void* cbarg) {
+static void MustNotCall(napi_async_cleanup_hook_handle hook, void* arg) {
assert(0);
}
@@ -13,36 +13,26 @@ struct AsyncData {
uv_async_t async;
napi_env env;
napi_async_cleanup_hook_handle handle;
- void (*done_cb)(void*);
- void* done_arg;
};
-struct AsyncData* CreateAsyncData() {
+static struct AsyncData* CreateAsyncData() {
struct AsyncData* data = (struct AsyncData*) malloc(sizeof(struct AsyncData));
data->handle = NULL;
return data;
}
-void AfterCleanupHookTwo(uv_handle_t* handle) {
+static void AfterCleanupHookTwo(uv_handle_t* handle) {
struct AsyncData* data = (struct AsyncData*) handle->data;
- data->done_cb(data->done_arg);
+ napi_status status = napi_remove_async_cleanup_hook(data->handle);
+ assert(status == napi_ok);
free(data);
}
-void AfterCleanupHookOne(uv_async_t* async) {
- struct AsyncData* data = (struct AsyncData*) async->data;
- if (data->handle != NULL) {
- // Verify that removing the hook is okay between starting and finishing
- // of its execution.
- napi_status status =
- napi_remove_async_cleanup_hook(data->env, data->handle);
- assert(status == napi_ok);
- }
-
+static void AfterCleanupHookOne(uv_async_t* async) {
uv_close((uv_handle_t*) async, AfterCleanupHookTwo);
}
-void AsyncCleanupHook(void* arg, void(*cb)(void*), void* cbarg) {
+static void AsyncCleanupHook(napi_async_cleanup_hook_handle handle, void* arg) {
struct AsyncData* data = (struct AsyncData*) arg;
uv_loop_t* loop;
napi_status status = napi_get_uv_event_loop(data->env, &loop);
@@ -51,12 +41,11 @@ void AsyncCleanupHook(void* arg, void(*cb)(void*), void* cbarg) {
assert(err == 0);
data->async.data = data;
- data->done_cb = cb;
- data->done_arg = cbarg;
+ data->handle = handle;
uv_async_send(&data->async);
}
-napi_value Init(napi_env env, napi_value exports) {
+static napi_value Init(napi_env env, napi_value exports) {
{
struct AsyncData* data = CreateAsyncData();
data->env = env;
@@ -73,7 +62,7 @@ napi_value Init(napi_env env, napi_value exports) {
napi_async_cleanup_hook_handle must_not_call_handle;
napi_add_async_cleanup_hook(
env, MustNotCall, NULL, &must_not_call_handle);
- napi_remove_async_cleanup_hook(env, must_not_call_handle);
+ napi_remove_async_cleanup_hook(must_not_call_handle);
}
return NULL;

Просмотреть файл

@ -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 a24ab3c2ee7d664700a6c4c8e17c9ef2b74efa5a..cab75bce3624cc74a87283d86c30277c82292982 100644
index efe537fca514c3d558527c9f4fc8ebb8a4de367c..edd5972002d7ad4d6932dfbed591a96d5b3f6fab 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -105,6 +105,13 @@ const {
@@ -106,6 +106,13 @@ const {
CHAR_COLON
} = require('internal/constants');
@ -23,7 +23,7 @@ index a24ab3c2ee7d664700a6c4c8e17c9ef2b74efa5a..cab75bce3624cc74a87283d86c30277c
const {
isProxy
} = require('internal/util/types');
@@ -1070,10 +1077,12 @@ Module.prototype._compile = function(content, filename) {
@@ -1071,10 +1078,12 @@ Module.prototype._compile = function(content, filename) {
if (requireDepth === 0) statCache = new Map();
if (inspectorWrapper) {
result = inspectorWrapper(compiledWrapper, thisValue, exports,

Просмотреть файл

@ -22,7 +22,7 @@ index 6d6ca2af629c41df68fe1a4652cf94fef30be038..e1f70addc28e4fe31d3a7089ecec3b58
process.config = JSONParse(internalBinding('native_module').config);
require('internal/worker/js_transferable').setup();
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index cab75bce3624cc74a87283d86c30277c82292982..c633daa2b3557c98b05cca5f428d87775ef8a02a 100644
index edd5972002d7ad4d6932dfbed591a96d5b3f6fab..7067737952a5002899071bb4a434a93ec92103ce 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -67,7 +67,7 @@ const internalFS = require('internal/fs/utils');
@ -34,7 +34,7 @@ index cab75bce3624cc74a87283d86c30277c82292982..c633daa2b3557c98b05cca5f428d8777
const packageJsonReader = require('internal/modules/package_json_reader');
const { safeGetenv } = internalBinding('credentials');
const {
@@ -159,7 +159,7 @@ function stat(filename) {
@@ -160,7 +160,7 @@ function stat(filename) {
const result = statCache.get(filename);
if (result !== undefined) return result;
}
@ -44,7 +44,7 @@ index cab75bce3624cc74a87283d86c30277c82292982..c633daa2b3557c98b05cca5f428d8777
return result;
}
diff --git a/lib/internal/modules/package_json_reader.js b/lib/internal/modules/package_json_reader.js
index 25edfee027c35baba9d8add054895d0aa48bbafa..d545e24e72b2a6fb91b7aa35a576712e831ff937 100644
index 4a2b0e6ddb3ed8881f896c6f556c9debaf778b81..209df9033a26c29c6e60bd173f71055884a0db89 100644
--- a/lib/internal/modules/package_json_reader.js
+++ b/lib/internal/modules/package_json_reader.js
@@ -1,7 +1,7 @@
@ -56,7 +56,7 @@ index 25edfee027c35baba9d8add054895d0aa48bbafa..d545e24e72b2a6fb91b7aa35a576712e
const { pathToFileURL } = require('url');
const { toNamespacedPath } = require('path');
@@ -16,7 +16,7 @@ function read(jsonPath) {
@@ -18,7 +18,7 @@ function read(jsonPath) {
return cache.get(jsonPath);
}

Просмотреть файл

@ -1,80 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Thu, 3 Sep 2020 13:35:35 -0700
Subject: test: make some tests embedder agnostic
Make the .out checks process-agnostic.
Upstreamed at https://github.com/nodejs/node/pull/35040.
diff --git a/test/message/esm_loader_not_found.out b/test/message/esm_loader_not_found.out
index 60abb529a3c87152087f4a2c52f79ac5dfdf7f25..26292512d9b00225100d2af91f0f7507072099e2 100644
--- a/test/message/esm_loader_not_found.out
+++ b/test/message/esm_loader_not_found.out
@@ -1,5 +1,5 @@
(node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
-(Use `node --trace-warnings ...` to show where the warning was created)
+(Use `* --trace-warnings ...` to show where the warning was created)
internal/process/esm_loader.js:*
internalBinding('errors').triggerUncaughtException(
^
diff --git a/test/message/esm_loader_not_found_cjs_hint_relative.out b/test/message/esm_loader_not_found_cjs_hint_relative.out
index f7460c31416dc97ca971d5a88cc8d424276f6d42..1c43c0d3a2eb31e31fbb2cf2496e2bd0ef3bea1d 100644
--- a/test/message/esm_loader_not_found_cjs_hint_relative.out
+++ b/test/message/esm_loader_not_found_cjs_hint_relative.out
@@ -1,5 +1,5 @@
(node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
-(Use `node --trace-warnings ...` to show where the warning was created)
+(Use `* --trace-warnings ...` to show where the warning was created)
internal/process/esm_loader.js:*
internalBinding('errors').triggerUncaughtException(
^
diff --git a/test/message/esm_loader_syntax_error.out b/test/message/esm_loader_syntax_error.out
index 6201de95208ff3e08c58cfe2cab5bcda2218fbf3..d6c6df0a338c848127ba0cfa11a98d13b0326848 100644
--- a/test/message/esm_loader_syntax_error.out
+++ b/test/message/esm_loader_syntax_error.out
@@ -1,5 +1,5 @@
(node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
-(Use `node --trace-warnings ...` to show where the warning was created)
+(Use `* --trace-warnings ...` to show where the warning was created)
file://*/test/fixtures/es-module-loaders/syntax-error.mjs:2
await async () => 0;
^^^^^^^^^^^^^
diff --git a/test/message/promise_unhandled_warn_with_error.out b/test/message/promise_unhandled_warn_with_error.out
index b539adb2d1e76931a41f73b606c6e1611b998883..66c98c57f71717046d26e6672897030dfd770da6 100644
--- a/test/message/promise_unhandled_warn_with_error.out
+++ b/test/message/promise_unhandled_warn_with_error.out
@@ -6,5 +6,5 @@
at *
at *
at *
-(Use `node --trace-warnings ...` to show where the warning was created)
+(Use `* --trace-warnings ...` to show where the warning was created)
*UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
\ No newline at end of file
diff --git a/test/pseudo-tty/test-tty-color-support-warning-2.out b/test/pseudo-tty/test-tty-color-support-warning-2.out
index d17fa99b96974a54ad443a37b5f828fe7bd33152..37b470a5f108f9cffc8a08cfb15bf04bbea4d9d5 100644
--- a/test/pseudo-tty/test-tty-color-support-warning-2.out
+++ b/test/pseudo-tty/test-tty-color-support-warning-2.out
@@ -1,3 +1,3 @@
(node:*) Warning: The 'NODE_DISABLE_COLORS' env is ignored due to the 'FORCE_COLOR' env being set.
-(Use `node --trace-warnings ...` to show where the warning was created)
+(Use `* --trace-warnings ...` to show where the warning was created)
diff --git a/test/pseudo-tty/test-tty-color-support-warning.out b/test/pseudo-tty/test-tty-color-support-warning.out
index 7a9df4725486d28062ebbcfa4269bf543a051c00..b25d2e42cf7244a6513de2f29c2f647d91983782 100644
--- a/test/pseudo-tty/test-tty-color-support-warning.out
+++ b/test/pseudo-tty/test-tty-color-support-warning.out
@@ -1,3 +1,3 @@
(node:*) Warning: The 'NODE_DISABLE_COLORS' and 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
-(Use `node --trace-warnings ...` to show where the warning was created)
+(Use `* --trace-warnings ...` to show where the warning was created)
diff --git a/test/pseudo-tty/test-tty-color-support.out b/test/pseudo-tty/test-tty-color-support.out
index 86ed488ee8c1b292c43434f869e19d190e19cf66..df5831c555be1914e28986df62bbb4421a29d68a 100644
--- a/test/pseudo-tty/test-tty-color-support.out
+++ b/test/pseudo-tty/test-tty-color-support.out
@@ -1,2 +1,2 @@
(node:*) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set.
-(Use `node --trace-warnings ...` to show where the warning was created)
+(Use `* --trace-warnings ...` to show where the warning was created)

Просмотреть файл

@ -180,9 +180,13 @@ int NodeMain(int argc, char* argv[]) {
gin::V8Initializer::LoadV8Snapshot(
gin::V8Initializer::V8SnapshotFileType::kWithAdditionalContext);
// V8 requires a task scheduler apparently
// V8 requires a task scheduler.
base::ThreadPoolInstance::CreateAndStartWithDefaultParams("Electron");
// Allow Node.js to track the amount of time the event loop has spent
// idle in the kernels event provider .
uv_loop_configure(loop, UV_METRICS_IDLE_TIME);
// Initialize gin::IsolateHolder.
JavascriptEnvironment gin_env(loop);
@ -261,6 +265,8 @@ int NodeMain(int argc, char* argv[]) {
{
v8::SealHandleScope seal(isolate);
bool more;
env->performance_state()->Mark(
node::performance::NODE_PERFORMANCE_MILESTONE_LOOP_START);
do {
uv_run(env->event_loop(), UV_RUN_DEFAULT);
@ -278,6 +284,8 @@ int NodeMain(int argc, char* argv[]) {
// event, or after running some callbacks.
more = uv_loop_alive(env->event_loop());
} while (more && !env->is_stopping());
env->performance_state()->Mark(
node::performance::NODE_PERFORMANCE_MILESTONE_LOOP_EXIT);
}
node_debugger.Stop();

Просмотреть файл

@ -130,8 +130,8 @@ void ElectronRendererClient::DidCreateScriptContext(
// If we have disabled the site instance overrides we should prevent loading
// any non-context aware native module
if (command_line->HasSwitch(switches::kDisableElectronSiteInstanceOverrides))
env->ForceOnlyContextAwareNativeModules();
env->WarnNonContextAwareNativeModules();
env->set_force_context_aware(true);
env->set_warn_context_aware(true);
environments_.insert(env);