diff options
author | Anna Henningsen <anna@addaleax.net> | 2017-09-15 15:03:48 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-09-21 02:03:02 +0200 |
commit | f27b5e4bdaafc73a830a0451ee3c641b8bcd08fe (patch) | |
tree | 09e8fccc815d2a27db433ce233e80bbcbeb0579a /src/node_internals.h | |
parent | 01c680b92aed62e128aa2abd4ad923f9a6a0331a (diff) | |
download | android-node-v8-f27b5e4bdaafc73a830a0451ee3c641b8bcd08fe.tar.gz android-node-v8-f27b5e4bdaafc73a830a0451ee3c641b8bcd08fe.tar.bz2 android-node-v8-f27b5e4bdaafc73a830a0451ee3c641b8bcd08fe.zip |
src: prepare platform for upstream V8 changes
V8 platform tasks may schedule other tasks (both background and
foreground), and may perform asynchronous operations like
resolving Promises.
To address that:
- Run the task queue drain call inside a callback scope.
This makes sure asynchronous operations inside it, like
resolving promises, lead to the microtask queue and any
subsequent operations not being silently forgotten.
- Move the task queue drain call before `EmitBeforeExit()`
and only run `EmitBeforeExit()` if there is no new event
loop work.
- Account for possible new foreground tasks scheduled by
background tasks in `DrainBackgroundTasks()`.
PR-URL: https://github.com/nodejs/node/pull/15428
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matthew Loring <mattloring@google.com>
Diffstat (limited to 'src/node_internals.h')
-rw-r--r-- | src/node_internals.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/node_internals.h b/src/node_internals.h index 9371d442ad..fd8cc26a28 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -294,8 +294,36 @@ v8::MaybeLocal<v8::Value> InternalMakeCallback( v8::Local<v8::Value> argv[], async_context asyncContext); +class InternalCallbackScope { + public: + // Tell the constructor whether its `object` parameter may be empty or not. + enum ResourceExpectation { kRequireResource, kAllowEmptyResource }; + InternalCallbackScope(Environment* env, + v8::Local<v8::Object> object, + const async_context& asyncContext, + ResourceExpectation expect = kRequireResource); + ~InternalCallbackScope(); + void Close(); + + inline bool Failed() const { return failed_; } + inline void MarkAsFailed() { failed_ = true; } + inline bool IsInnerMakeCallback() const { + return callback_scope_.in_makecallback(); + } + + private: + Environment* env_; + async_context async_context_; + v8::Local<v8::Object> object_; + Environment::AsyncCallbackScope callback_scope_; + bool failed_ = false; + bool pushed_ids_ = false; + bool closed_ = false; +}; + } // namespace node + #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #endif // SRC_NODE_INTERNALS_H_ |