diff --git a/src/node.cc b/src/node.cc index 12a746b8b0da42..8259a8c7002417 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1157,10 +1157,10 @@ void OnPromiseGC(const FunctionCallbackInfo& args) { CHECK(args[0]->IsObject()); Local promise = args[0].As(); + Local err = GetPromiseReason(env, promise); - TrackPromise::New(env->isolate(), promise); + TrackPromise::New(env->isolate(), promise, err); - Local err = GetPromiseReason(env, promise); Local unhandled_reject_map = env->promise_unhandled_reject_map(); Local unhandled_reject_keys = @@ -1639,12 +1639,10 @@ void AppendExceptionLine(Environment* env, PrintErrorString("\n%s", arrow); } -void ReportPromiseRejection(Isolate* isolate, Local promise) { +void ReportPromiseRejection(Isolate* isolate, Local reason) { Environment* env = Environment::GetCurrent(isolate); - Local err = GetPromiseReason(env, promise); - - ReportException(env, err, Exception::CreateMessage(isolate, err)); + ReportException(env, reason, Exception::CreateMessage(isolate, reason)); } void ReportException(Environment* env, @@ -4416,7 +4414,9 @@ static void StartNodeInstance(void* arg) { key_iter).ToLocalChecked(); if (unhandled_reject_map->Has(key)) { - ReportPromiseRejection(isolate, unhandled_reject_map->Get(key)); + Local err = GetPromiseReason(env, + unhandled_reject_map->Get(key)); + ReportPromiseRejection(isolate, err); exit(1); } } diff --git a/src/track-promise.cc b/src/track-promise.cc index 26eb0d76cdfb34..1304a9ca5614dc 100644 --- a/src/track-promise.cc +++ b/src/track-promise.cc @@ -5,51 +5,41 @@ namespace node { -using v8::Function; using v8::Isolate; using v8::Local; using v8::Object; using v8::Persistent; using v8::Value; -using v8::WeakCallbackData; - -typedef void (*FreeCallback)(Local object, Local fn); +using v8::WeakCallbackInfo; TrackPromise* TrackPromise::New(Isolate* isolate, - Local object) { - return new TrackPromise(isolate, object); -} - - -Persistent* TrackPromise::persistent() { - return &persistent_; + Local promise, Local reason) { + return new TrackPromise(isolate, promise, reason); } TrackPromise::TrackPromise(Isolate* isolate, - Local object) - : persistent_(isolate, object) { - persistent_.SetWeak(this, WeakCallback); - persistent_.MarkIndependent(); + Local promise, Local reason) + : promise_(isolate, promise), reason_(isolate, reason) { + promise_.SetWeak(this, WeakCallback, v8::WeakCallbackType::kParameter); + promise_.MarkIndependent(); } TrackPromise::~TrackPromise() { - persistent_.Reset(); + promise_.Reset(); + reason_.Reset(); } void TrackPromise::WeakCallback( - const WeakCallbackData& data) { - data.GetParameter()->WeakCallback(data.GetIsolate(), data.GetValue()); + const WeakCallbackInfo& data) { + TrackPromise* self = data.GetParameter(); + node::ReportPromiseRejection(data.GetIsolate(), + PersistentToLocal(data.GetIsolate(), self->reason_)); + delete self; } -void TrackPromise::WeakCallback(Isolate* isolate, Local object) { - node::ReportPromiseRejection(isolate, object.As()); - exit(1); - delete this; -} - } // namespace node diff --git a/src/track-promise.h b/src/track-promise.h index 9e1157c5cc7f2f..04deed17dce146 100644 --- a/src/track-promise.h +++ b/src/track-promise.h @@ -9,21 +9,20 @@ class Environment; class TrackPromise { public: - TrackPromise(v8::Isolate* isolate, v8::Local object); - virtual ~TrackPromise(); - static TrackPromise* New(v8::Isolate* isolate, - v8::Local object); - - inline v8::Persistent* persistent(); + v8::Local promise, + v8::Local reason); static inline void WeakCallback( - const v8::WeakCallbackData& data); + const v8::WeakCallbackInfo& data); private: - inline void WeakCallback(v8::Isolate* isolate, v8::Local object); + TrackPromise(v8::Isolate* isolate, v8::Local promise, + v8::Local reason); + ~TrackPromise(); - v8::Persistent persistent_; + v8::Persistent promise_; + v8::Persistent reason_; }; } // namespace node