Skip to content

Commit

Permalink
Implement process.hasUncaughtExceptionCaptureCallback() (#10937)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored May 9, 2024
1 parent 13c6f46 commit 75420ba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/runtime/nodejs-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ The table below lists all globals implemented by Node.js and Bun's current compa

### [`process`](https://nodejs.org/api/process.html)

🟡 Missing `domain` `hasUncaughtExceptionCaptureCallback` `initgroups` `setUncaughtExceptionCaptureCallback` `setegid` `seteuid` `setgid` `setgroups` `setuid` `allowedNodeEnvironmentFlags` `getActiveResourcesInfo` `setActiveResourcesInfo` `moduleLoadList` `setSourceMapsEnabled` `channel`. `process.binding` is partially implemented.
🟡 Missing `domain` `hasUncaughtExceptionCaptureCallback` `initgroups` `setegid` `seteuid` `setgid` `setgroups` `setuid` `allowedNodeEnvironmentFlags` `getActiveResourcesInfo` `setActiveResourcesInfo` `moduleLoadList` `setSourceMapsEnabled` `channel`. `process.binding` is partially implemented.

### [`queueMicrotask()`](https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask)

Expand Down
16 changes: 16 additions & 0 deletions src/bun.js/bindings/BunProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,21 @@ JSC_DEFINE_HOST_FUNCTION(Process_setUncaughtExceptionCaptureCallback,
return JSC::JSValue::encode(jsUndefined());
}

JSC_DEFINE_HOST_FUNCTION(Process_hasUncaughtExceptionCaptureCallback,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
auto* zigGlobal = jsDynamicCast<Zig::GlobalObject*>(globalObject);
if (UNLIKELY(!zigGlobal)) {
zigGlobal = Bun__getDefaultGlobal();
}
JSValue cb = jsCast<Process*>(zigGlobal->processObject())->getUncaughtExceptionCaptureCallback();
if (cb.isEmpty() || !cb.isCell()) {
return JSValue::encode(jsBoolean(false));
}

return JSValue::encode(jsBoolean(true));
}

extern "C" uint64_t Bun__readOriginTimer(void*);

JSC_DEFINE_HOST_FUNCTION(Process_functionHRTime,
Expand Down Expand Up @@ -2787,6 +2802,7 @@ extern "C" void Process__emitDisconnectEvent(Zig::GlobalObject* global)
exitCode processExitCode CustomAccessor
features constructFeatures PropertyCallback
getActiveResourcesInfo Process_stubFunctionReturningArray Function 0
hasUncaughtExceptionCaptureCallback Process_hasUncaughtExceptionCaptureCallback Function 0
hrtime constructProcessHrtimeObject PropertyCallback
isBun constructIsBun PropertyCallback
kill Process_functionKill Function 2
Expand Down
8 changes: 8 additions & 0 deletions test/js/node/process/process.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,3 +603,11 @@ it("aborts when the uncaughtExceptionCaptureCallback throws", async () => {
expect(await proc.exited).toBe(1);
expect(await new Response(proc.stderr).text()).toContain("bar");
});

it("process.hasUncaughtExceptionCaptureCallback", () => {
process.setUncaughtExceptionCaptureCallback(null);
expect(process.hasUncaughtExceptionCaptureCallback()).toBe(false);
process.setUncaughtExceptionCaptureCallback(() => {});
expect(process.hasUncaughtExceptionCaptureCallback()).toBe(true);
process.setUncaughtExceptionCaptureCallback(null);
});

0 comments on commit 75420ba

Please sign in to comment.