Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit 219bf8c

Browse files
committed
chakrashim: implement promise rejection callback
* Enabled some unhandled rejection tests (but not the Symbol one due to an unrelated issue) * Added a new chakracore baseline for `unhandled_promise_trace_warnings` * Fixed `test-inspector-debug-brk-flag` which had unhandled rejections * Skipped `test-inspector-bindings` which had unhandled rejections PR-URL: #469 Reviewed-By: Taylor Woll <[email protected]> Reviewed-By: Jimmy Thomson <[email protected]>
1 parent a4d7cd5 commit 219bf8c

10 files changed

+89
-12
lines changed

Diff for: deps/chakrashim/include/v8.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ class PropertyDescriptor;
9999
}
100100

101101
namespace jsrt {
102-
JsErrorCode CreateV8PropertyDescriptor(JsValueRef descriptor,
103-
v8::PropertyDescriptor* result);
102+
class IsolateShim;
103+
104+
JsErrorCode CreateV8PropertyDescriptor(JsValueRef descriptor,
105+
v8::PropertyDescriptor* result);
104106
}
105107

106108
namespace v8 {
@@ -377,6 +379,7 @@ class Local {
377379
friend JsErrorCode jsrt::CreateV8PropertyDescriptor(
378380
JsValueRef descriptor,
379381
v8::PropertyDescriptor* result);
382+
friend class jsrt::IsolateShim;
380383
template <class F> friend class FunctionCallbackInfo;
381384
template <class F> friend class MaybeLocal;
382385
template <class F> friend class PersistentBase;

Diff for: deps/chakrashim/src/jsrtisolateshim.cc

+21
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,27 @@ JsValueRef IsolateShim::GetChakraInspectorShimJsArrayBuffer() {
643643
return chakraInspectorShimArrayBuffer;
644644
}
645645

646+
void CHAKRA_CALLBACK IsolateShim::PromiseRejectionCallback(
647+
JsValueRef promise, JsValueRef reason, bool handled, void *callbackState) {
648+
CHAKRA_VERIFY(callbackState != nullptr);
649+
v8::PromiseRejectCallback callback =
650+
reinterpret_cast<v8::PromiseRejectCallback>(callbackState);
651+
652+
v8::PromiseRejectMessage message(
653+
promise,
654+
handled ? v8::kPromiseHandlerAddedAfterReject :
655+
v8::kPromiseRejectWithNoHandler,
656+
reason,
657+
v8::Local<v8::StackTrace>());
658+
659+
callback(message);
660+
}
661+
662+
void IsolateShim::SetPromiseRejectCallback(v8::PromiseRejectCallback callback) {
663+
JsSetHostPromiseRejectionTracker(IsolateShim::PromiseRejectionCallback,
664+
reinterpret_cast<void*>(callback));
665+
}
666+
646667
/*static*/
647668
bool IsolateShim::RunSingleStepOfReverseMoveLoop(v8::Isolate* isolate,
648669
uint64_t* moveMode,

Diff for: deps/chakrashim/src/jsrtisolateshim.h

+4
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,17 @@ class IsolateShim {
161161
return isIdleGcScheduled;
162162
}
163163

164+
void SetPromiseRejectCallback(v8::PromiseRejectCallback callback);
165+
164166
private:
165167
// Construction/Destruction should go thru New/Dispose
166168
explicit IsolateShim(JsRuntimeHandle runtime);
167169
~IsolateShim();
168170
static v8::Isolate * ToIsolate(IsolateShim * isolate);
169171
static void CHAKRA_CALLBACK JsContextBeforeCollectCallback(JsRef contextRef,
170172
void *data);
173+
static void CHAKRA_CALLBACK PromiseRejectionCallback(
174+
JsValueRef promise, JsValueRef reason, bool handled, void *callbackState);
171175

172176
JsRuntimeHandle runtime;
173177
JsPropertyIdRef symbolPropertyIdRefs[CachedSymbolPropertyIdRef::SymbolCount];

Diff for: deps/chakrashim/src/v8isolate.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Local<Context> Isolate::GetCurrentContext() {
112112
}
113113

114114
void Isolate::SetPromiseRejectCallback(PromiseRejectCallback callback) {
115-
// CHAKRA does not support this explicit callback
115+
jsrt::IsolateShim::FromIsolate(this)->SetPromiseRejectCallback(callback);
116116
}
117117

118118
void Isolate::SetPromiseHook(PromiseHook hook) {

Diff for: test/message/message.status

-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ esm_display_syntax_error : SKIP
2323
esm_display_syntax_error_import : SKIP
2424
esm_display_syntax_error_import_module : SKIP
2525
esm_display_syntax_error_module : SKIP
26-
unhandled_promise_trace_warnings : SKIP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
(node:*) UnhandledPromiseRejectionWarning: Error: This was rejected
2+
at * (*test*message*unhandled_promise_trace_warnings.js:*)
3+
at *
4+
at *
5+
at *
6+
at *
7+
at *
8+
at *
9+
at *
10+
at *
11+
at *
12+
at *
13+
at *
14+
at *
15+
at *
16+
at *
17+
at *
18+
(node:*) Error: This was rejected
19+
at * (*test*message*unhandled_promise_trace_warnings.js:*)
20+
at *
21+
at *
22+
at *
23+
at *
24+
at *
25+
at *
26+
at *
27+
at *
28+
(node:*) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
29+
at *
30+
at *
31+
at *
32+
at *
33+
at *
34+
at *
35+
at *
36+
at *
37+
(node:*) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)
38+
at *
39+
at handledRejection (internal/process/promises.js:*)
40+
at Promise.prototype.then (native code:0:0)
41+
at Promise.prototype.catch (native code:0:0)
42+
at Anonymous function (*test*message*unhandled_promise_trace_warnings.js:*)
43+
at *
44+
at *
45+
at *

Diff for: test/parallel/parallel.status

-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ test-performance-function : SKIP
6363
test-performance-gc : SKIP
6464
test-process-env-symbols : SKIP
6565
test-promise-internal-creation : SKIP
66-
test-promises-unhandled-rejections : SKIP
6766
test-promises-unhandled-symbol-rejections : SKIP
68-
test-promises-warning-on-unhandled-rejection : SKIP
6967
test-regress-GH-12371 : SKIP
7068
test-repl : SKIP
7169
test-repl-inspector : SKIP

Diff for: test/sequential/sequential.status

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ test-inspector-async-call-stack-abort : SKIP
3434
test-inspector-async-hook-setup-at-inspect-brk : SKIP
3535
test-inspector-async-stack-traces-promise-then : SKIP
3636
test-inspector-async-stack-traces-set-interval : SKIP
37+
test-inspector-bindings : SKIP
3738
test-inspector-break-when-eval : SKIP
3839
test-inspector-contexts : SKIP
3940
test-inspector-scriptparsed-context : SKIP

Diff for: test/sequential/test-inspector-debug-brk-flag.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@ async function testBreakpointOnStart(session) {
1414
{ 'method': 'Debugger.setPauseOnExceptions',
1515
'params': { 'state': 'none' } },
1616
{ 'method': 'Debugger.setAsyncCallStackDepth',
17-
'params': { 'maxDepth': 0 } },
18-
{ 'method': 'Profiler.enable' },
19-
{ 'method': 'Profiler.setSamplingInterval',
20-
'params': { 'interval': 100 } },
17+
'params': { 'maxDepth': 0 } }
18+
];
19+
20+
if (process.jsEngine !== 'chakracore') {
21+
commands.push(
22+
{ 'method': 'Profiler.enable' },
23+
{ 'method': 'Profiler.setSamplingInterval',
24+
'params': { 'interval': 100 } });
25+
}
26+
27+
commands.push(
2128
{ 'method': 'Debugger.setBlackboxPatterns',
2229
'params': { 'patterns': [] } },
23-
{ 'method': 'Runtime.runIfWaitingForDebugger' }
24-
];
30+
{ 'method': 'Runtime.runIfWaitingForDebugger' });
2531

2632
session.send(commands);
2733
await session.waitForBreakOnLine(0, session.scriptPath());

0 commit comments

Comments
 (0)