-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib,src: throw on unhanded promise rejections
Refs: #5292 Refs: nodejs/promises#26 Refs: #6355
- Loading branch information
1 parent
3ee68f7
commit 7e2a08c
Showing
16 changed files
with
321 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "track-promise.h" | ||
#include "env.h" | ||
#include "env-inl.h" | ||
#include "node_internals.h" | ||
|
||
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> object, Local<Function> fn); | ||
|
||
|
||
TrackPromise* TrackPromise::New(Isolate* isolate, | ||
Local<Object> object) { | ||
return new TrackPromise(isolate, object); | ||
} | ||
|
||
|
||
Persistent<Object>* TrackPromise::persistent() { | ||
return &persistent_; | ||
} | ||
|
||
|
||
TrackPromise::TrackPromise(Isolate* isolate, | ||
Local<Object> object) | ||
: persistent_(isolate, object) { | ||
persistent_.SetWeak(this, WeakCallback); | ||
persistent_.MarkIndependent(); | ||
} | ||
|
||
|
||
TrackPromise::~TrackPromise() { | ||
persistent_.Reset(); | ||
} | ||
|
||
|
||
void TrackPromise::WeakCallback( | ||
const WeakCallbackData<Object, TrackPromise>& data) { | ||
data.GetParameter()->WeakCallback(data.GetIsolate(), data.GetValue()); | ||
} | ||
|
||
|
||
void TrackPromise::WeakCallback(Isolate* isolate, Local<Object> object) { | ||
node::ReportPromiseRejection(isolate, object.As<Value>()); | ||
exit(1); | ||
delete this; | ||
} | ||
|
||
} // namespace node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef SRC_TRACK_PROMISE_H_ | ||
#define SRC_TRACK_PROMISE_H_ | ||
|
||
#include "v8.h" | ||
|
||
namespace node { | ||
|
||
class Environment; | ||
|
||
class TrackPromise { | ||
public: | ||
TrackPromise(v8::Isolate* isolate, v8::Local<v8::Object> object); | ||
virtual ~TrackPromise(); | ||
|
||
static TrackPromise* New(v8::Isolate* isolate, | ||
v8::Local<v8::Object> object); | ||
|
||
inline v8::Persistent<v8::Object>* persistent(); | ||
|
||
static inline void WeakCallback( | ||
const v8::WeakCallbackData<v8::Object, TrackPromise>& data); | ||
|
||
private: | ||
inline void WeakCallback(v8::Isolate* isolate, v8::Local<v8::Object> object); | ||
|
||
v8::Persistent<v8::Object> persistent_; | ||
}; | ||
|
||
} // namespace node | ||
|
||
#endif // SRC_TRACK_PROMISE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
const p1 = new Promise(function(res, rej) { | ||
consol.log('One'); // eslint-disable-line no-undef | ||
}); | ||
|
||
new Promise(function(res, rej) { | ||
consol.log('Two'); // eslint-disable-line no-undef | ||
}); | ||
|
||
const p3 = new Promise(function(res, rej) { | ||
consol.log('Three'); // eslint-disable-line no-undef | ||
}); | ||
|
||
new Promise(function(res, rej) { | ||
setTimeout(common.mustCall(() => { | ||
p1.catch(() => {}); | ||
p3.catch(() => {}); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*test*message*promise_fast_handled_reject.js:* | ||
consol.log('Two'); // eslint-disable-line no-undef | ||
^ | ||
|
||
ReferenceError: consol is not defined | ||
at *test*message*promise_fast_handled_reject.js:*:* | ||
at Object.<anonymous> (*test*message*promise_fast_handled_reject.js:*:*) | ||
at Module._compile (module.js:*:*) | ||
at Object.Module._extensions..js (module.js:*:*) | ||
at Module.load (module.js:*:*) | ||
at tryModuleLoad (module.js:*:*) | ||
at Function.Module._load (module.js:*:*) | ||
at Function.Module.runMain (module.js:*:*) | ||
at startup (node.js:*:*) | ||
at node.js:*:* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
require('../common'); | ||
|
||
new Promise(function(res, rej) { | ||
consol.log('One'); // eslint-disable-line no-undef | ||
}); | ||
|
||
new Promise(function(res, rej) { | ||
consol.log('Two'); // eslint-disable-line no-undef | ||
}); |
Oops, something went wrong.