| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 02e3daa commit 198cf41
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,7 +59,8 @@ InternalCallbackScope::InternalCallbackScope(Environment* env, | |||
| 59 | 59 | AsyncWrap::EmitBefore(env, asyncContext.async_id); | |
| 60 | 60 | } | |
| 61 | 61 | ||
| 62 | - if (!IsInnerMakeCallback()) { | ||
| 62 | + CHECK_GE(env->makecallback_depth(), 1); | ||
| 63 | + if (env->makecallback_depth() == 1) { | ||
| 63 | 64 | env->tick_info()->set_has_thrown(false); | |
| 64 | 65 | } | |
| 65 | 66 | ||
@@ -91,7 +92,7 @@ void InternalCallbackScope::Close() { | |||
| 91 | 92 | AsyncWrap::EmitAfter(env_, async_context_.async_id); | |
| 92 | 93 | } | |
| 93 | 94 | ||
| 94 | - if (IsInnerMakeCallback()) { | ||
| 95 | + if (env_->makecallback_depth() > 1) { | ||
| 95 | 96 | return; | |
| 96 | 97 | } | |
| 97 | 98 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -218,8 +218,8 @@ inline Environment::AsyncCallbackScope::~AsyncCallbackScope() { | |||
| 218 | 218 | env_->makecallback_cntr_--; | |
| 219 | 219 | } | |
| 220 | 220 | ||
| 221 | - inline bool Environment::AsyncCallbackScope::in_makecallback() const { | ||
| 222 | - return env_->makecallback_cntr_ > 1; | ||
| 221 | + inline size_t Environment::makecallback_depth() const { | ||
| 222 | + return makecallback_cntr_; | ||
| 223 | 223 | } | |
| 224 | 224 | ||
| 225 | 225 | inline Environment::ImmediateInfo::ImmediateInfo(v8::Isolate* isolate) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -503,14 +503,15 @@ class Environment { | |||
| 503 | 503 | AsyncCallbackScope() = delete; | |
| 504 | 504 | explicit AsyncCallbackScope(Environment* env); | |
| 505 | 505 | ~AsyncCallbackScope(); | |
| 506 | - inline bool in_makecallback() const; | ||
| 507 | 506 | ||
| 508 | 507 | private: | |
| 509 | 508 | Environment* env_; | |
| 510 | 509 | ||
| 511 | 510 | DISALLOW_COPY_AND_ASSIGN(AsyncCallbackScope); | |
| 512 | 511 | }; | |
| 513 | 512 | ||
| 513 | + inline size_t makecallback_depth() const; | ||
| 514 | + | ||
| 514 | 515 | class ImmediateInfo { | |
| 515 | 516 | public: | |
| 516 | 517 | inline AliasedBuffer<uint32_t, v8::Uint32Array>& fields(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -758,7 +758,7 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env, | |||
| 758 | 758 | CHECK(!recv.IsEmpty()); | |
| 759 | 759 | InternalCallbackScope scope(env, recv, asyncContext); | |
| 760 | 760 | if (scope.Failed()) { | |
| 761 | - return Undefined(env->isolate()); | ||
| 761 | + return MaybeLocal<Value>(); | ||
| 762 | 762 | } | |
| 763 | 763 | ||
| 764 | 764 | Local<Function> domain_cb = env->domain_callback(); | |
@@ -773,15 +773,13 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env, | |||
| 773 | 773 | } | |
| 774 | 774 | ||
| 775 | 775 | if (ret.IsEmpty()) { | |
| 776 | - // NOTE: For backwards compatibility with public API we return Undefined() | ||
| 777 | - // if the top level call threw. | ||
| 778 | 776 | scope.MarkAsFailed(); | |
| 779 | - return scope.IsInnerMakeCallback() ? ret : Undefined(env->isolate()); | ||
| 777 | + return MaybeLocal<Value>(); | ||
| 780 | 778 | } | |
| 781 | 779 | ||
| 782 | 780 | scope.Close(); | |
| 783 | 781 | if (scope.Failed()) { | |
| 784 | - return Undefined(env->isolate()); | ||
| 782 | + return MaybeLocal<Value>(); | ||
| 785 | 783 | } | |
| 786 | 784 | ||
| 787 | 785 | return ret; | |
@@ -833,8 +831,14 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate, | |||
| 833 | 831 | // the two contexts need not be the same. | |
| 834 | 832 | Environment* env = Environment::GetCurrent(callback->CreationContext()); | |
| 835 | 833 | Context::Scope context_scope(env->context()); | |
| 836 | - return InternalMakeCallback(env, recv, callback, | ||
| 837 | - argc, argv, asyncContext); | ||
| 834 | + MaybeLocal<Value> ret = InternalMakeCallback(env, recv, callback, | ||
| 835 | + argc, argv, asyncContext); | ||
| 836 | + if (ret.IsEmpty() && env->makecallback_depth() == 0) { | ||
| 837 | + // This is only for legacy compatiblity and we may want to look into | ||
| 838 | + // removing/adjusting it. | ||
| 839 | + return Undefined(env->isolate()); | ||
| 840 | + } | ||
| 841 | + return ret; | ||
| 838 | 842 | } | |
| 839 | 843 | ||
| 840 | 844 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -543,9 +543,6 @@ class InternalCallbackScope { | |||
| 543 | 543 | ||
| 544 | 544 | inline bool Failed() const { return failed_; } | |
| 545 | 545 | inline void MarkAsFailed() { failed_ = true; } | |
| 546 | - inline bool IsInnerMakeCallback() const { | ||
| 547 | - return callback_scope_.in_makecallback(); | ||
| 548 | - } | ||
| 549 | 546 | ||
| 550 | 547 | private: | |
| 551 | 548 | Environment* env_; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,6 +37,7 @@ using v8::FunctionTemplate; | |||
| 37 | 37 | using v8::HandleScope; | |
| 38 | 38 | using v8::Integer; | |
| 39 | 39 | using v8::Local; | |
| 40 | + using v8::MaybeLocal; | ||
| 40 | 41 | using v8::Object; | |
| 41 | 42 | using v8::String; | |
| 42 | 43 | using v8::Value; | |
@@ -138,13 +139,12 @@ class TimerWrap : public HandleWrap { | |||
| 138 | 139 | Environment* env = wrap->env(); | |
| 139 | 140 | HandleScope handle_scope(env->isolate()); | |
| 140 | 141 | Context::Scope context_scope(env->context()); | |
| 141 | - Local<Value> ret; | ||
| 142 | + MaybeLocal<Value> ret; | ||
| 142 | 143 | Local<Value> args[1]; | |
| 143 | 144 | do { | |
| 144 | 145 | args[0] = env->GetNow(); | |
| 145 | - ret = wrap->MakeCallback(env->timers_callback_function(), 1, args) | ||
| 146 | - .ToLocalChecked(); | ||
| 147 | - } while (ret->IsUndefined() && | ||
| 146 | + ret = wrap->MakeCallback(env->timers_callback_function(), 1, args); | ||
| 147 | + } while ((ret.IsEmpty() || ret.ToLocalChecked()->IsUndefined()) && | ||
| 148 | 148 | !env->tick_info()->has_thrown() && | |
| 149 | 149 | env->can_call_into_js() && | |
| 150 | 150 | wrap->object()->Get(env->context(), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments