diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-12-23 00:02:14 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2019-01-06 10:28:44 +0800 |
commit | bf566718b29a6fae8cef8d0fecd7e77948726d5a (patch) | |
tree | 2388b6a0ece578d891487c1c1657aeee31b60e51 /src | |
parent | f6a1d88c5d1c813c8d55933436b4b834a29f449f (diff) | |
download | android-node-v8-bf566718b29a6fae8cef8d0fecd7e77948726d5a.tar.gz android-node-v8-bf566718b29a6fae8cef8d0fecd7e77948726d5a.tar.bz2 android-node-v8-bf566718b29a6fae8cef8d0fecd7e77948726d5a.zip |
src: refactor tickInfo access
- Wrap access to tickInfo fields in functions
- Rename `kHasScheduled` to `kHasTickScheduled` and
`kHasPromiseRejections` to `kHasRejectionToWarn` for clarity - note
the latter will be set to false if the rejection does not lead to
a warning so the previous description is not accurate.
- Set `kHasRejectionToWarn` in JS land of relying on C++ to use
an implict contract (return value of the promise rejection handler)
to set it, as the decision is made entirely in JS land.
- Destructure promise reject event constants.
PR-URL: https://github.com/nodejs/node/pull/25200
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/callback_scope.cc | 4 | ||||
-rw-r--r-- | src/env-inl.h | 12 | ||||
-rw-r--r-- | src/env.h | 10 | ||||
-rw-r--r-- | src/node_task_queue.cc | 10 |
4 files changed, 12 insertions, 24 deletions
diff --git a/src/callback_scope.cc b/src/callback_scope.cc index 0757b61061..89fd4d6dd4 100644 --- a/src/callback_scope.cc +++ b/src/callback_scope.cc @@ -95,7 +95,7 @@ void InternalCallbackScope::Close() { Environment::TickInfo* tick_info = env_->tick_info(); if (!env_->can_call_into_js()) return; - if (!tick_info->has_scheduled()) { + if (!tick_info->has_tick_scheduled()) { env_->isolate()->RunMicrotasks(); } @@ -106,7 +106,7 @@ void InternalCallbackScope::Close() { CHECK_EQ(env_->trigger_async_id(), 0); } - if (!tick_info->has_scheduled() && !tick_info->has_promise_rejections()) { + if (!tick_info->has_tick_scheduled() && !tick_info->has_rejection_to_warn()) { return; } diff --git a/src/env-inl.h b/src/env-inl.h index 0555e79c81..7c643539ad 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -265,16 +265,12 @@ inline AliasedBuffer<uint8_t, v8::Uint8Array>& Environment::TickInfo::fields() { return fields_; } -inline bool Environment::TickInfo::has_scheduled() const { - return fields_[kHasScheduled] == 1; +inline bool Environment::TickInfo::has_tick_scheduled() const { + return fields_[kHasTickScheduled] == 1; } -inline bool Environment::TickInfo::has_promise_rejections() const { - return fields_[kHasPromiseRejections] == 1; -} - -inline void Environment::TickInfo::promise_rejections_toggle_on() { - fields_[kHasPromiseRejections] = 1; +inline bool Environment::TickInfo::has_rejection_to_warn() const { + return fields_[kHasRejectionToWarn] == 1; } inline void Environment::AssignToContext(v8::Local<v8::Context> context, @@ -575,18 +575,16 @@ class Environment { class TickInfo { public: inline AliasedBuffer<uint8_t, v8::Uint8Array>& fields(); - inline bool has_scheduled() const; - inline bool has_promise_rejections() const; - - inline void promise_rejections_toggle_on(); + inline bool has_tick_scheduled() const; + inline bool has_rejection_to_warn() const; private: friend class Environment; // So we can call the constructor. inline explicit TickInfo(v8::Isolate* isolate); enum Fields { - kHasScheduled, - kHasPromiseRejections, + kHasTickScheduled = 0, + kHasRejectionToWarn, kFieldsCount }; diff --git a/src/node_task_queue.cc b/src/node_task_queue.cc index f65f420081..5bfa281068 100644 --- a/src/node_task_queue.cc +++ b/src/node_task_queue.cc @@ -17,7 +17,6 @@ using v8::kPromiseRejectAfterResolved; using v8::kPromiseRejectWithNoHandler; using v8::kPromiseResolveAfterResolved; using v8::Local; -using v8::MaybeLocal; using v8::Number; using v8::Object; using v8::Promise; @@ -80,13 +79,8 @@ static void PromiseRejectCallback(PromiseRejectMessage message) { } Local<Value> args[] = { type, promise, value }; - MaybeLocal<Value> ret = callback->Call(env->context(), - Undefined(isolate), - arraysize(args), - args); - - if (!ret.IsEmpty() && ret.ToLocalChecked()->IsTrue()) - env->tick_info()->promise_rejections_toggle_on(); + USE(callback->Call( + env->context(), Undefined(isolate), arraysize(args), args)); } static void InitializePromiseRejectCallback( |