diff options
author | Bryan English <bryan@bryanenglish.com> | 2021-05-26 06:52:45 +0300 |
---|---|---|
committer | Bryan English <bryan@bryanenglish.com> | 2021-06-02 17:56:29 +0300 |
commit | a172397237af2dbc0c28af45f9edf067c9df544f (patch) | |
tree | 7386305ee0b679da598e088555190777a7a3fa47 /src/env.h | |
parent | 3ec7f300c1633d0cbf081e0366858d373e008fdc (diff) |
src: set PromiseHooks by Environment
The new JS PromiseHooks introduced in the referenced PR are per
v8::Context. This meant that code depending on them, such as
AsyncLocalStorage, wouldn't behave correctly across vm.Context
instances.
PromiseHooks are now synchronized across the main Context and any
Context created via vm.Context.
Refs: https://github.com/nodejs/node/pull/36394
Fixes: https://github.com/nodejs/node/issues/38781
Signed-off-by: Bryan English <bryan@bryanenglish.com>
PR-URL: https://github.com/nodejs/node/pull/38821
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/env.h')
-rw-r--r-- | src/env.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/env.h b/src/env.h index ce88d74355c..4a50227ee8d 100644 --- a/src/env.h +++ b/src/env.h @@ -701,6 +701,11 @@ class AsyncHooks : public MemoryRetainer { // The `js_execution_async_resources` array contains the value in that case. inline v8::Local<v8::Object> native_execution_async_resource(size_t index); + inline void SetJSPromiseHooks(v8::Local<v8::Function> init, + v8::Local<v8::Function> before, + v8::Local<v8::Function> after, + v8::Local<v8::Function> resolve); + inline v8::Local<v8::String> provider_string(int idx); inline void no_force_checks(); @@ -711,6 +716,9 @@ class AsyncHooks : public MemoryRetainer { inline bool pop_async_context(double async_id); inline void clear_async_id_stack(); // Used in fatal exceptions. + inline void AddContext(v8::Local<v8::Context> ctx); + inline void RemoveContext(v8::Local<v8::Context> ctx); + AsyncHooks(const AsyncHooks&) = delete; AsyncHooks& operator=(const AsyncHooks&) = delete; AsyncHooks(AsyncHooks&&) = delete; @@ -770,6 +778,10 @@ class AsyncHooks : public MemoryRetainer { // Non-empty during deserialization const SerializeInfo* info_ = nullptr; + + std::vector<v8::Global<v8::Context>> contexts_; + + std::array<v8::Global<v8::Function>, 4> js_promise_hooks_; }; class ImmediateInfo : public MemoryRetainer { |