Browse Source

chore: cherry-pick 1fe571a from node (#28108)

* chore: cherry-pick 1fe571a from node

Backports https://github.com/nodejs/node/pull/37000

* Fix merge error

* update patches

Co-authored-by: deepak1556 <[email protected]>
Co-authored-by: Cheng Zhao <[email protected]>
Co-authored-by: Electron Bot <[email protected]>
trop[bot] 4 years ago
parent
commit
43b9988c57

+ 1 - 0
patches/node/.patches

@@ -47,3 +47,4 @@ fix_add_v8_enable_reverse_jsargs_defines_in_common_gypi.patch
 chore_expose_v8_initialization_isolate_callbacks.patch
 fix_add_safeforterminationscopes_for_sigint_interruptions.patch
 allow_preventing_preparestacktracecallback.patch
+src_inline_asynccleanuphookhandle_in_headers.patch

+ 73 - 0
patches/node/src_inline_asynccleanuphookhandle_in_headers.patch

@@ -0,0 +1,73 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Tyler Ang-Wanek <[email protected]>
+Date: Tue, 19 Jan 2021 07:39:14 -0700
+Subject: src: inline AsyncCleanupHookHandle in headers
+
+Fixes: https://github.com/nodejs/node/issues/36349
+
+PR-URL: https://github.com/nodejs/node/pull/37000
+Reviewed-By: Anna Henningsen <[email protected]>
+Reviewed-By: Rich Trott <[email protected]>
+Reviewed-By: James M Snell <[email protected]>
+
+diff --git a/src/api/hooks.cc b/src/api/hooks.cc
+index 3b16c0350d8a8494202144407664af41d338fe04..8b6f209cc8f167173a957049dec96dbec7ccc8d1 100644
+--- a/src/api/hooks.cc
++++ b/src/api/hooks.cc
+@@ -131,7 +131,7 @@ static void RunAsyncCleanupHook(void* arg) {
+   info->fun(info->arg, FinishAsyncCleanupHook, info);
+ }
+ 
+-AsyncCleanupHookHandle AddEnvironmentCleanupHook(
++ACHHandle* AddEnvironmentCleanupHookInternal(
+     Isolate* isolate,
+     AsyncCleanupHook fun,
+     void* arg) {
+@@ -143,11 +143,11 @@ AsyncCleanupHookHandle AddEnvironmentCleanupHook(
+   info->arg = arg;
+   info->self = info;
+   env->AddCleanupHook(RunAsyncCleanupHook, info.get());
+-  return AsyncCleanupHookHandle(new ACHHandle { info });
++  return new ACHHandle { info };
+ }
+ 
+-void RemoveEnvironmentCleanupHook(
+-    AsyncCleanupHookHandle handle) {
++void RemoveEnvironmentCleanupHookInternal(
++    ACHHandle* handle) {
+   if (handle->info->started) return;
+   handle->info->self.reset();
+   handle->info->env->RemoveCleanupHook(RunAsyncCleanupHook, handle->info.get());
+diff --git a/src/node.h b/src/node.h
+index 0917daec298229a942c1790becfbefd19d01fb8d..8e52f9e8065750b48ddb36f447e4af54f993acfa 100644
+--- a/src/node.h
++++ b/src/node.h
+@@ -747,12 +747,26 @@ struct ACHHandle;
+ struct NODE_EXTERN DeleteACHHandle { void operator()(ACHHandle*) const; };
+ typedef std::unique_ptr<ACHHandle, DeleteACHHandle> AsyncCleanupHookHandle;
+ 
+-NODE_EXTERN AsyncCleanupHookHandle AddEnvironmentCleanupHook(
++/* This function is not intended to be used externally, it exists to aid in
++ * keeping ABI compatibility between Node and Electron. */
++NODE_EXTERN ACHHandle* AddEnvironmentCleanupHookInternal(
+     v8::Isolate* isolate,
+     void (*fun)(void* arg, void (*cb)(void*), void* cbarg),
+     void* arg);
++inline AsyncCleanupHookHandle AddEnvironmentCleanupHook(
++    v8::Isolate* isolate,
++    void (*fun)(void* arg, void (*cb)(void*), void* cbarg),
++    void* arg) {
++  return AsyncCleanupHookHandle(AddEnvironmentCleanupHookInternal(isolate, fun,
++      arg));
++}
+ 
+-NODE_EXTERN void RemoveEnvironmentCleanupHook(AsyncCleanupHookHandle holder);
++/* This function is not intended to be used externally, it exists to aid in
++ * keeping ABI compatibility between Node and Electron. */
++NODE_EXTERN void RemoveEnvironmentCleanupHookInternal(ACHHandle* holder);
++inline void RemoveEnvironmentCleanupHook(AsyncCleanupHookHandle holder) {
++  RemoveEnvironmentCleanupHookInternal(holder.get());
++}
+ 
+ /* Returns the id of the current execution context. If the return value is
+  * zero then no execution has been set. This will happen if the user handles