aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--integration/bunjs-only-snippets/reportError.test.js5
-rw-r--r--src/javascript/jsc/api/bun.zig33
-rw-r--r--src/javascript/jsc/bindings/ZigGlobalObject.cpp25
3 files changed, 39 insertions, 24 deletions
diff --git a/integration/bunjs-only-snippets/reportError.test.js b/integration/bunjs-only-snippets/reportError.test.js
new file mode 100644
index 000000000..ed25bd743
--- /dev/null
+++ b/integration/bunjs-only-snippets/reportError.test.js
@@ -0,0 +1,5 @@
+import { it } from "bun:test";
+
+it("reportError", () => {
+ reportError(new Error("reportError Test!"));
+});
diff --git a/src/javascript/jsc/api/bun.zig b/src/javascript/jsc/api/bun.zig
index c66c5f0f1..fef810c97 100644
--- a/src/javascript/jsc/api/bun.zig
+++ b/src/javascript/jsc/api/bun.zig
@@ -823,29 +823,6 @@ pub fn getPublicPathJS(
return ZigString.init(stream.buffer[0..stream.pos]).toValueGC(ctx.ptr()).asObjectRef();
}
-// pub fn resolvePath(
-// _: void,
-// ctx: js.JSContextRef,
-// _: js.JSObjectRef,
-// _: js.JSObjectRef,
-// arguments: []const js.JSValueRef,
-// _: js.ExceptionRef,
-// ) js.JSValueRef {
-// if (arguments.len == 0) return ZigString.Empty.toValue(ctx.ptr()).asObjectRef();
-// var zig_str: ZigString = ZigString.Empty;
-// JSValue.toZigString(JSValue.fromRef(arguments[0]), &zig_str, ctx.ptr());
-// var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
-// var stack = std.heap.stackFallback(32 * @sizeOf(string), VirtualMachine.vm.allocator);
-// var allocator = stack.get();
-// var parts = allocator.alloc(string, arguments.len) catch {};
-// defer allocator.free(parts);
-
-// const to = zig_str.slice();
-// var parts = .{to};
-// const value = ZigString.init(VirtualMachine.vm.bundler.fs.absBuf(&parts, &buf)).toValueGC(ctx.ptr());
-// return value.asObjectRef();
-// }
-
pub const Class = NewClass(
void,
.{
@@ -1610,3 +1587,13 @@ pub const EnvironmentVariables = struct {
}
}
};
+
+export fn Bun__reportError(_: *JSGlobalObject, err: JSC.JSValue) void {
+ JSC.VirtualMachine.vm.defaultErrorHandler(err, null);
+}
+
+comptime {
+ if (!is_bindgen) {
+ _ = Bun__reportError;
+ }
+}
diff --git a/src/javascript/jsc/bindings/ZigGlobalObject.cpp b/src/javascript/jsc/bindings/ZigGlobalObject.cpp
index 16d4786a3..6dca86aa6 100644
--- a/src/javascript/jsc/bindings/ZigGlobalObject.cpp
+++ b/src/javascript/jsc/bindings/ZigGlobalObject.cpp
@@ -540,13 +540,30 @@ static JSC_DEFINE_HOST_FUNCTION(functionImportMeta__resolve,
}
}
+extern "C" void Bun__reportError(JSC::JSGlobalObject*, JSC__JSValue);
+static JSC_DECLARE_HOST_FUNCTION(functionReportError);
+static JSC_DEFINE_HOST_FUNCTION(functionReportError,
+ (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
+{
+ switch (callFrame->argumentCount()) {
+ case 0: {
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+ default: {
+ Bun__reportError(globalObject, JSC::JSValue::encode(callFrame->argument(0)));
+ }
+ }
+
+ return JSC::JSValue::encode(JSC::jsUndefined());
+}
+
// This is not a publicly exposed API currently.
// This is used by the bundler to make Response, Request, FetchEvent,
// and any other objects available globally.
void GlobalObject::installAPIGlobals(JSClassRef* globals, int count)
{
WTF::Vector<GlobalPropertyInfo> extraStaticGlobals;
- extraStaticGlobals.reserveCapacity((size_t)count + 3 + 7);
+ extraStaticGlobals.reserveCapacity((size_t)count + 3 + 9);
int i = 0;
for (; i < count - 1; i++) {
@@ -629,6 +646,12 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count)
JSC::JSFunction::create(vm(), JSC::jsCast<JSC::JSGlobalObject*>(this), 0,
"btoa", functionBTOA),
JSC::PropertyAttribute::DontDelete | 0 });
+ JSC::Identifier reportErrorIdentifier = JSC::Identifier::fromString(vm(), "reportError"_s);
+ extraStaticGlobals.uncheckedAppend(
+ GlobalPropertyInfo { reportErrorIdentifier,
+ JSC::JSFunction::create(vm(), JSC::jsCast<JSC::JSGlobalObject*>(this), 0,
+ "reportError", functionReportError),
+ JSC::PropertyAttribute::DontDelete | 0 });
auto clientData = Bun::clientData(vm());