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

Commit fa3b780

Browse files
committed
chakrashim: implement promise rejection callback
1 parent eed8721 commit fa3b780

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

deps/chakrashim/include/v8.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class PropertyDescriptor;
9999
}
100100

101101
namespace jsrt {
102+
class IsolateShim;
102103
JsErrorCode CreateV8PropertyDescriptor(JsValueRef descriptor,
103104
v8::PropertyDescriptor* result);
104105
}
@@ -377,6 +378,7 @@ class Local {
377378
friend JsErrorCode jsrt::CreateV8PropertyDescriptor(
378379
JsValueRef descriptor,
379380
v8::PropertyDescriptor* result);
381+
friend class jsrt::IsolateShim;
380382
template <class F> friend class FunctionCallbackInfo;
381383
template <class F> friend class MaybeLocal;
382384
template <class F> friend class PersistentBase;

deps/chakrashim/src/jsrtisolateshim.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,24 @@ JsValueRef IsolateShim::GetChakraInspectorShimJsArrayBuffer() {
643643
return chakraInspectorShimArrayBuffer;
644644
}
645645

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

deps/chakrashim/src/jsrtisolateshim.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,16 @@ 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 PromiseRejectionThunk(JsValueRef promise, JsValueRef reason, bool handled, void *callbackState);
171174

172175
JsRuntimeHandle runtime;
173176
JsPropertyIdRef symbolPropertyIdRefs[CachedSymbolPropertyIdRef::SymbolCount];

deps/chakrashim/src/v8isolate.cc

Lines changed: 1 addition & 1 deletion
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) {

0 commit comments

Comments
 (0)