Skip to content

Commit d7e7832

Browse files
committed
Log unhandled promise rejection
1 parent 8d4d72b commit d7e7832

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
.fingerprint = 0xda130f3af836cea0,
66
.dependencies = .{
77
.v8 = .{
8-
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/e62726800663d0397d8766f7185040d8b8b69402.tar.gz",
9-
.hash = "v8-0.0.0-xddH69zDAwD5i0hGhAsv3SPeihlj5fXGpJyO15KqBWOn",
8+
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/efb353230f05c96d5ad96298f8b0b444de615644.tar.gz",
9+
.hash = "v8-0.0.0-xddH6xHEAwCo_OGkWshjXdYHGk18oSG3XZPYtf4tvF0P",
1010
},
1111
//.v8 = .{ .path = "../zig-v8-fork" }
1212
},

src/runtime/js.zig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
197197

198198
// This is the callback that runs whenever a module is dynamically imported.
199199
isolate.setHostImportModuleDynamicallyCallback(JsContext.dynamicModuleCallback);
200+
isolate.setPromiseRejectCallback(promiseRejectCallback);
200201

201202
isolate.enter();
202203
errdefer isolate.exit();
@@ -328,6 +329,20 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
328329
self.isolate.lowMemoryNotification();
329330
}
330331

332+
fn promiseRejectCallback(v8_msg: v8.C_PromiseRejectMessage) callconv(.c) void {
333+
const msg = v8.PromiseRejectMessage.initFromC(v8_msg);
334+
const isolate = msg.getPromise().toObject().getIsolate();
335+
const v8_context = isolate.getCurrentContext();
336+
const context: *JsContext = @ptrFromInt(v8_context.getEmbedderData(1).castTo(v8.BigInt).getUint64());
337+
338+
const value =
339+
if (msg.getValue()) |v8_value| valueToString(context.call_arena, v8_value, isolate, v8_context) catch |err| @errorName(err)
340+
else "no value";
341+
342+
log.debug(.js, "unhandled rejection", .{.value =value});
343+
}
344+
345+
331346
// ExecutionWorld closely models a JS World.
332347
// https://chromium.googlesource.com/chromium/src/+/master/third_party/blink/renderer/bindings/core/v8/V8BindingDesign.md#World
333348
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/ExecutionWorld

0 commit comments

Comments
 (0)