allow zig js host functions to return JSError (#15120)

This commit is contained in:
Meghan Denny
2024-11-13 21:11:56 -08:00
committed by GitHub
parent 32ddf343ee
commit fdd8d35845
70 changed files with 827 additions and 876 deletions

View File

@@ -14,7 +14,7 @@ const NodeFSFunction = fn (
this: *JSC.Node.NodeJSFS,
globalObject: *JSC.JSGlobalObject,
callframe: *JSC.CallFrame,
) JSC.JSValue;
) bun.JSError!JSC.JSValue;
const NodeFSFunctionEnum = std.meta.DeclEnum(JSC.Node.NodeFS);
@@ -34,14 +34,14 @@ fn callSync(comptime FunctionEnum: NodeFSFunctionEnum) NodeFSFunction {
this: *JSC.Node.NodeJSFS,
globalObject: *JSC.JSGlobalObject,
callframe: *JSC.CallFrame,
) JSC.JSValue {
) bun.JSError!JSC.JSValue {
var arguments = callframe.arguments(8);
var slice = ArgumentsSlice.init(globalObject.bunVM(), arguments.slice());
defer slice.deinit();
const args = if (comptime Arguments != void)
(Arguments.fromJS(globalObject, &slice) catch return .zero)
(try Arguments.fromJS(globalObject, &slice))
else
Arguments{};
defer {
@@ -79,7 +79,7 @@ fn call(comptime FunctionEnum: NodeFSFunctionEnum) NodeFSFunction {
comptime if (function.params.len != 3) @compileError("Expected 3 arguments");
const Arguments = comptime function.params[1].type.?;
const NodeBindingClosure = struct {
pub fn bind(this: *JSC.Node.NodeJSFS, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) JSC.JSValue {
pub fn bind(this: *JSC.Node.NodeJSFS, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue {
var arguments = callframe.arguments(8);
var slice = ArgumentsSlice.init(globalObject.bunVM(), arguments.slice());
@@ -244,7 +244,7 @@ pub fn createBinding(globalObject: *JSC.JSGlobalObject) JSC.JSValue {
return module.toJS(globalObject);
}
pub fn createMemfdForTesting(globalObject: *JSC.JSGlobalObject, callFrame: *JSC.CallFrame) JSC.JSValue {
pub fn createMemfdForTesting(globalObject: *JSC.JSGlobalObject, callFrame: *JSC.CallFrame) bun.JSError!JSC.JSValue {
const arguments = callFrame.arguments(1);
if (arguments.len < 1) {