diff --git a/src/bake/FrameworkRouter.zig b/src/bake/FrameworkRouter.zig index 8824e851d7..010c60b202 100644 --- a/src/bake/FrameworkRouter.zig +++ b/src/bake/FrameworkRouter.zig @@ -1166,7 +1166,7 @@ pub const JSFrameworkRouter = struct { pub fn getBindings(global: *jsc.JSGlobalObject) bun.JSError!jsc.JSValue { return (try jsc.JSObject.create(.{ - .parseRoutePattern = global.createHostFunction("parseRoutePattern", parseRoutePattern, 1), + .parseRoutePattern = jsc.JSFunction.create(global, "parseRoutePattern", jsc.host_fn.toJSHostFn(parseRoutePattern), 1, .{}), .FrameworkRouter = js.getConstructor(global), }, global)).toJS(); } @@ -1313,7 +1313,7 @@ pub const JSFrameworkRouter = struct { bun.destroy(this); } - pub fn parseRoutePattern(global: *JSGlobalObject, frame: *CallFrame) !JSValue { + pub fn parseRoutePattern(global: *JSGlobalObject, frame: *CallFrame) bun.JSError!JSValue { var arena = std.heap.ArenaAllocator.init(bun.default_allocator); defer arena.deinit(); const alloc = arena.allocator(); diff --git a/src/bun.js/api/BunObject.zig b/src/bun.js/api/BunObject.zig index 8eb64a3126..e45ff6a664 100644 --- a/src/bun.js/api/BunObject.zig +++ b/src/bun.js/api/BunObject.zig @@ -508,10 +508,10 @@ export fn Bun__inspect_singleline(globalThis: *JSGlobalObject, value: JSValue) b } pub fn getInspect(globalObject: *jsc.JSGlobalObject, _: *jsc.JSObject) jsc.JSValue { - const fun = jsc.createCallback(globalObject, ZigString.static("inspect"), 2, inspect); + const fun = jsc.JSFunction.create(globalObject, "inspect", inspect, 2, .{}); var str = ZigString.init("nodejs.util.inspect.custom"); fun.put(globalObject, ZigString.static("custom"), jsc.JSValue.symbolFor(globalObject, &str)); - fun.put(globalObject, ZigString.static("table"), jsc.createCallback(globalObject, ZigString.static("table"), 3, inspectTable)); + fun.put(globalObject, ZigString.static("table"), jsc.JSFunction.create(globalObject, "table", inspectTable, 3, .{})); return fun; } @@ -1375,13 +1375,13 @@ const CSRFObject = struct { object.put( globalThis, ZigString.static("generate"), - jsc.createCallback(globalThis, ZigString.static("generate"), 1, @import("../../csrf.zig").csrf__generate), + jsc.JSFunction.create(globalThis, "generate", @import("../../csrf.zig").csrf__generate, 1, .{}), ); object.put( globalThis, ZigString.static("verify"), - jsc.createCallback(globalThis, ZigString.static("verify"), 1, @import("../../csrf.zig").csrf__verify), + jsc.JSFunction.create(globalThis, "verify", @import("../../csrf.zig").csrf__verify, 1, .{}), ); return object; diff --git a/src/bun.js/api/FFIObject.zig b/src/bun.js/api/FFIObject.zig index d45da78d31..f7e2b0a3b8 100644 --- a/src/bun.js/api/FFIObject.zig +++ b/src/bun.js/api/FFIObject.zig @@ -19,7 +19,7 @@ pub fn toJS(globalObject: *jsc.JSGlobalObject) jsc.JSValue { object.put( globalObject, comptime ZigString.static(field), - jsc.createCallback(globalObject, comptime ZigString.static(field), 1, comptime @field(fields, field)), + jsc.JSFunction.create(globalObject, field, @field(fields, field), 1, .{}), ); } diff --git a/src/bun.js/api/HashObject.zig b/src/bun.js/api/HashObject.zig index 3d547a1a62..05256cf581 100644 --- a/src/bun.js/api/HashObject.zig +++ b/src/bun.js/api/HashObject.zig @@ -32,7 +32,7 @@ pub const murmur64v2 = hashWrap(std.hash.murmur.Murmur2_64); pub const rapidhash = hashWrap(bun.deprecated.RapidHash); pub fn create(globalThis: *jsc.JSGlobalObject) jsc.JSValue { - const function = jsc.createCallback(globalThis, ZigString.static("hash"), 1, wyhash); + const function = jsc.JSFunction.create(globalThis, "hash", wyhash, 1, .{}); const fns = comptime .{ "wyhash", "adler32", @@ -48,12 +48,7 @@ pub fn create(globalThis: *jsc.JSGlobalObject) jsc.JSValue { "rapidhash", }; inline for (fns) |name| { - const value = jsc.createCallback( - globalThis, - ZigString.static(name), - 1, - @field(HashObject, name), - ); + const value = jsc.JSFunction.create(globalThis, name, @field(HashObject, name), 1, .{}); function.put(globalThis, comptime ZigString.static(name), value); } diff --git a/src/bun.js/api/TOMLObject.zig b/src/bun.js/api/TOMLObject.zig index 8b3d414d9e..419d0579de 100644 --- a/src/bun.js/api/TOMLObject.zig +++ b/src/bun.js/api/TOMLObject.zig @@ -3,11 +3,12 @@ pub fn create(globalThis: *jsc.JSGlobalObject) jsc.JSValue { object.put( globalThis, ZigString.static("parse"), - jsc.createCallback( + jsc.JSFunction.create( globalThis, - ZigString.static("parse"), - 1, + "parse", parse, + 1, + .{}, ), ); diff --git a/src/bun.js/api/UnsafeObject.zig b/src/bun.js/api/UnsafeObject.zig index f42fcb29a2..7ab191b9c3 100644 --- a/src/bun.js/api/UnsafeObject.zig +++ b/src/bun.js/api/UnsafeObject.zig @@ -9,7 +9,7 @@ pub fn create(globalThis: *jsc.JSGlobalObject) jsc.JSValue { object.put( globalThis, comptime ZigString.static(name), - jsc.createCallback(globalThis, comptime ZigString.static(name), 1, comptime @field(fields, name)), + jsc.JSFunction.create(globalThis, name, @field(fields, name), 1, .{}), ); } return object; diff --git a/src/bun.js/api/YAMLObject.zig b/src/bun.js/api/YAMLObject.zig index 6862e2e6dd..043352e793 100644 --- a/src/bun.js/api/YAMLObject.zig +++ b/src/bun.js/api/YAMLObject.zig @@ -3,21 +3,23 @@ pub fn create(globalThis: *jsc.JSGlobalObject) jsc.JSValue { object.put( globalThis, ZigString.static("parse"), - jsc.createCallback( + jsc.JSFunction.create( globalThis, - ZigString.static("parse"), - 1, + "parse", parse, + 1, + .{}, ), ); object.put( globalThis, ZigString.static("stringify"), - jsc.createCallback( + jsc.JSFunction.create( globalThis, - ZigString.static("stringify"), - 3, + "stringify", stringify, + 3, + .{}, ), ); diff --git a/src/bun.js/api/crypto/PasswordObject.zig b/src/bun.js/api/crypto/PasswordObject.zig index 8f8d7a1fde..0a7753b1c9 100644 --- a/src/bun.js/api/crypto/PasswordObject.zig +++ b/src/bun.js/api/crypto/PasswordObject.zig @@ -324,10 +324,10 @@ pub const JSPasswordObject = struct { pub export fn JSPasswordObject__create(globalObject: *jsc.JSGlobalObject) jsc.JSValue { var object = JSValue.createEmptyObject(globalObject, 4); - object.put(globalObject, ZigString.static("hash"), jsc.createCallback(globalObject, ZigString.static("hash"), 2, JSPasswordObject__hash)); - object.put(globalObject, ZigString.static("hashSync"), jsc.createCallback(globalObject, ZigString.static("hashSync"), 2, JSPasswordObject__hashSync)); - object.put(globalObject, ZigString.static("verify"), jsc.createCallback(globalObject, ZigString.static("verify"), 2, JSPasswordObject__verify)); - object.put(globalObject, ZigString.static("verifySync"), jsc.createCallback(globalObject, ZigString.static("verifySync"), 2, JSPasswordObject__verifySync)); + object.put(globalObject, ZigString.static("hash"), jsc.JSFunction.create(globalObject, "hash", JSPasswordObject__hash, 2, .{})); + object.put(globalObject, ZigString.static("hashSync"), jsc.JSFunction.create(globalObject, "hashSync", JSPasswordObject__hashSync, 2, .{})); + object.put(globalObject, ZigString.static("verify"), jsc.JSFunction.create(globalObject, "verify", JSPasswordObject__verify, 2, .{})); + object.put(globalObject, ZigString.static("verifySync"), jsc.JSFunction.create(globalObject, "verifySync", JSPasswordObject__verifySync, 2, .{})); return object; } diff --git a/src/bun.js/api/ffi.zig b/src/bun.js/api/ffi.zig index d1127e4e15..94e736920b 100644 --- a/src/bun.js/api/ffi.zig +++ b/src/bun.js/api/ffi.zig @@ -780,7 +780,6 @@ pub const FFI = struct { &str, @as(u32, @intCast(function.arg_types.items.len)), bun.cast(*const jsc.JSHostFn, compiled.ptr), - false, true, function.symbol_from_dynamic_library, ); @@ -1134,7 +1133,6 @@ pub const FFI = struct { &str, @as(u32, @intCast(function.arg_types.items.len)), bun.cast(*const jsc.JSHostFn, compiled.ptr), - false, true, function.symbol_from_dynamic_library, ); @@ -1237,7 +1235,6 @@ pub const FFI = struct { name, @as(u32, @intCast(function.arg_types.items.len)), bun.cast(*jsc.JSHostFn, compiled.ptr), - false, true, function.symbol_from_dynamic_library, ); @@ -1449,7 +1446,6 @@ pub const FFI = struct { // val.allocator.free(val.step.compiled.buf); if (val.step.compiled.js_function != .zero) { _ = globalThis; - // _ = jsc.untrackFunction(globalThis, val.step.compiled.js_function); val.step.compiled.js_function = .zero; } diff --git a/src/bun.js/bindings/JSFFIFunction.cpp b/src/bun.js/bindings/JSFFIFunction.cpp index ee99be8c8e..0a66f73665 100644 --- a/src/bun.js/bindings/JSFFIFunction.cpp +++ b/src/bun.js/bindings/JSFFIFunction.cpp @@ -71,24 +71,17 @@ extern "C" FFICallbackFunctionWrapper* Bun__createFFICallbackFunction( return wrapper; } -extern "C" Zig::JSFFIFunction* Bun__CreateFFIFunctionWithData(Zig::GlobalObject* globalObject, const ZigString* symbolName, unsigned argCount, Zig::FFIFunction functionPointer, bool strong, void* data) +extern "C" Zig::JSFFIFunction* Bun__CreateFFIFunctionWithData(Zig::GlobalObject* globalObject, const ZigString* symbolName, unsigned argCount, Zig::FFIFunction functionPointer, void* data) { auto& vm = JSC::getVM(globalObject); Zig::JSFFIFunction* function = Zig::JSFFIFunction::create(vm, globalObject, argCount, symbolName != nullptr ? Zig::toStringCopy(*symbolName) : String(), functionPointer, JSC::NoIntrinsic); - if (strong) - globalObject->trackFFIFunction(function); function->dataPtr = data; return function; } -extern "C" JSC::EncodedJSValue Bun__CreateFFIFunctionWithDataValue(Zig::GlobalObject* globalObject, const ZigString* symbolName, unsigned argCount, Zig::FFIFunction functionPointer, bool strong, void* data) +extern "C" JSC::EncodedJSValue Bun__CreateFFIFunctionWithDataValue(Zig::GlobalObject* globalObject, const ZigString* symbolName, unsigned argCount, Zig::FFIFunction functionPointer, void* data) { - return JSC::JSValue::encode(Bun__CreateFFIFunctionWithData(globalObject, symbolName, argCount, functionPointer, strong, data)); -} - -extern "C" Zig::JSFFIFunction* Bun__CreateFFIFunction(Zig::GlobalObject* globalObject, const ZigString* symbolName, unsigned argCount, Zig::FFIFunction functionPointer, bool strong) -{ - return Bun__CreateFFIFunctionWithData(globalObject, symbolName, argCount, functionPointer, strong, nullptr); + return JSC::JSValue::encode(Bun__CreateFFIFunctionWithData(globalObject, symbolName, argCount, functionPointer, data)); } extern "C" void* Bun__FFIFunction_getDataPtr(JSC::EncodedJSValue jsValue) @@ -110,11 +103,8 @@ extern "C" void Bun__FFIFunction_setDataPtr(JSC::EncodedJSValue jsValue, void* p function->dataPtr = ptr; } -extern "C" void Bun__untrackFFIFunction(Zig::GlobalObject* globalObject, JSC::EncodedJSValue function) -{ - globalObject->untrackFFIFunction(JSC::jsCast(JSC::JSValue::decode(function))); -} -extern "C" JSC::EncodedJSValue Bun__CreateFFIFunctionValue(Zig::GlobalObject* globalObject, const ZigString* symbolName, unsigned argCount, Zig::FFIFunction functionPointer, bool strong, bool addPtrField, void* symbolFromDynamicLibrary) + +extern "C" JSC::EncodedJSValue Bun__CreateFFIFunctionValue(Zig::GlobalObject* globalObject, const ZigString* symbolName, unsigned argCount, Zig::FFIFunction functionPointer, bool addPtrField, void* symbolFromDynamicLibrary) { if (addPtrField) { auto* function = Zig::JSFFIFunction::createForFFI(globalObject->vm(), globalObject, argCount, symbolName != nullptr ? Zig::toStringCopy(*symbolName) : String(), reinterpret_cast(functionPointer)); @@ -127,7 +117,7 @@ extern "C" JSC::EncodedJSValue Bun__CreateFFIFunctionValue(Zig::GlobalObject* gl return JSC::JSValue::encode(function); } - return Bun__CreateFFIFunctionWithDataValue(globalObject, symbolName, argCount, functionPointer, strong, nullptr); + return Bun__CreateFFIFunctionWithDataValue(globalObject, symbolName, argCount, functionPointer, nullptr); } namespace Zig { diff --git a/src/bun.js/bindings/JSFFIFunction.h b/src/bun.js/bindings/JSFFIFunction.h index 4b7cc250e9..6eccae7b61 100644 --- a/src/bun.js/bindings/JSFFIFunction.h +++ b/src/bun.js/bindings/JSFFIFunction.h @@ -98,5 +98,3 @@ private: }; } // namespace JSC - -extern "C" Zig::JSFFIFunction* Bun__CreateFFIFunction(Zig::GlobalObject* globalObject, const ZigString* symbolName, unsigned argCount, Zig::FFIFunction functionPointer, bool strong); diff --git a/src/bun.js/bindings/JSFunction.zig b/src/bun.js/bindings/JSFunction.zig index 9e4ede4e1a..4cb565da6a 100644 --- a/src/bun.js/bindings/JSFunction.zig +++ b/src/bun.js/bindings/JSFunction.zig @@ -30,7 +30,7 @@ pub const JSFunction = opaque { pub fn create( global: *JSGlobalObject, fn_name: anytype, - comptime implementation: jsc.JSHostFnZig, + comptime implementation: anytype, function_length: u32, options: CreateJSFunctionOptions, ) JSValue { @@ -40,7 +40,11 @@ pub const JSFunction = opaque { bun.String => fn_name, else => bun.String.init(fn_name), }, - jsc.toJSHostFn(implementation), + switch (@TypeOf(implementation)) { + jsc.JSHostFnZig => jsc.toJSHostFn(implementation), + jsc.JSHostFn => implementation, + else => @compileError("unexpected function type"), + }, function_length, options.implementation_visibility, options.intrinsic, diff --git a/src/bun.js/bindings/JSGlobalObject.zig b/src/bun.js/bindings/JSGlobalObject.zig index e882f8de98..fa2a092018 100644 --- a/src/bun.js/bindings/JSGlobalObject.zig +++ b/src/bun.js/bindings/JSGlobalObject.zig @@ -776,17 +776,6 @@ pub const JSGlobalObject = opaque { return default; } - pub inline fn createHostFunction( - global: *JSGlobalObject, - comptime display_name: [:0]const u8, - // when querying from JavaScript, 'func.name' - comptime function: anytype, - // when querying from JavaScript, 'func.len' - comptime argument_count: u32, - ) JSValue { - return jsc.host_fn.NewRuntimeFunction(global, ZigString.static(display_name), argument_count, jsc.toJSHostFn(function), false, false, null); - } - /// Get a lazily-initialized `JSC::String` from `BunCommonStrings.h`. pub inline fn commonStrings(this: *jsc.JSGlobalObject) CommonStrings { jsc.markBinding(@src()); diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 7e22705369..c2d3b64f8a 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -2995,7 +2995,6 @@ void GlobalObject::visitAdditionalChildren(Visitor& visitor) thisObject->globalEventScope->visitJSEventListeners(visitor); thisObject->m_aboutToBeNotifiedRejectedPromises.visit(thisObject, visitor); - thisObject->m_ffiFunctions.visit(thisObject, visitor); ScriptExecutionContext* context = thisObject->scriptExecutionContext(); visitor.addOpaqueRoot(context); @@ -3558,17 +3557,6 @@ bool GlobalObject::hasNapiFinalizers() const void GlobalObject::setNodeWorkerEnvironmentData(JSMap* data) { m_nodeWorkerEnvironmentData.set(vm(), this, data); } -void GlobalObject::trackFFIFunction(JSC::JSFunction* function) -{ - this->m_ffiFunctions.append(vm(), this, function); -} -bool GlobalObject::untrackFFIFunction(JSC::JSFunction* function) -{ - return this->m_ffiFunctions.removeFirstMatching(this, [&](JSC::WriteBarrier& untrackedFunction) -> bool { - return untrackedFunction.get() == function; - }); -} - extern "C" void Zig__GlobalObject__destructOnExit(Zig::GlobalObject* globalObject) { auto& vm = JSC::getVM(globalObject); diff --git a/src/bun.js/bindings/ZigGlobalObject.h b/src/bun.js/bindings/ZigGlobalObject.h index 937da8c906..ffbc145c0e 100644 --- a/src/bun.js/bindings/ZigGlobalObject.h +++ b/src/bun.js/bindings/ZigGlobalObject.h @@ -672,9 +672,6 @@ public: String agentClusterID() const; static String defaultAgentClusterID(); - void trackFFIFunction(JSC::JSFunction* function); - bool untrackFFIFunction(JSC::JSFunction* function); - BunPlugin::OnLoad onLoadPlugins {}; BunPlugin::OnResolve onResolvePlugins {}; @@ -734,7 +731,6 @@ private: WebCore::SubtleCrypto* m_subtleCrypto = nullptr; Bun::WriteBarrierList m_aboutToBeNotifiedRejectedPromises; - Bun::WriteBarrierList m_ffiFunctions; }; class EvalGlobalObject : public GlobalObject { diff --git a/src/bun.js/jsc.zig b/src/bun.js/jsc.zig index 61adcd7564..b4f8cc51ab 100644 --- a/src/bun.js/jsc.zig +++ b/src/bun.js/jsc.zig @@ -37,7 +37,6 @@ pub const toJSHostFnWithContext = host_fn.toJSHostFnWithContext; pub const toJSHostCall = host_fn.toJSHostCall; pub const fromJSHostCall = host_fn.fromJSHostCall; pub const fromJSHostCallGeneric = host_fn.fromJSHostCallGeneric; -pub const createCallback = host_fn.createCallback; // JSC Classes Bindings pub const AnyPromise = @import("./bindings/AnyPromise.zig").AnyPromise; diff --git a/src/bun.js/jsc/host_fn.zig b/src/bun.js/jsc/host_fn.zig index 1cc4d1b904..738080a0f5 100644 --- a/src/bun.js/jsc/host_fn.zig +++ b/src/bun.js/jsc/host_fn.zig @@ -271,72 +271,32 @@ const private = struct { ?*const ZigString, argCount: u32, function: *const JSHostFn, - strong: bool, data: *anyopaque, ) JSValue; - pub extern fn Bun__CreateFFIFunction( - globalObject: *JSGlobalObject, - symbolName: ?*const ZigString, - argCount: u32, - function: *const JSHostFn, - strong: bool, - ) *anyopaque; pub extern fn Bun__CreateFFIFunctionValue( globalObject: *JSGlobalObject, symbolName: ?*const ZigString, argCount: u32, function: *const JSHostFn, - strong: bool, add_ptr_field: bool, inputFunctionPtr: ?*anyopaque, ) JSValue; - pub extern fn Bun__untrackFFIFunction( - globalObject: *JSGlobalObject, - function: JSValue, - ) bool; - pub extern fn Bun__FFIFunction_getDataPtr(JSValue) ?*anyopaque; pub extern fn Bun__FFIFunction_setDataPtr(JSValue, ?*anyopaque) void; }; -pub fn NewFunction( - globalObject: *JSGlobalObject, - symbolName: ?*const ZigString, - argCount: u32, - comptime function: anytype, - strong: bool, -) JSValue { - if (@TypeOf(function) == JSHostFn) { - return NewRuntimeFunction(globalObject, symbolName, argCount, function, strong, false, null); - } - return NewRuntimeFunction(globalObject, symbolName, argCount, toJSHostFn(function), strong, false, null); -} - -pub fn createCallback( - globalObject: *JSGlobalObject, - symbolName: ?*const ZigString, - argCount: u32, - comptime function: anytype, -) JSValue { - if (@TypeOf(function) == JSHostFn) { - return NewRuntimeFunction(globalObject, symbolName, argCount, function, false, false, null); - } - return NewRuntimeFunction(globalObject, symbolName, argCount, toJSHostFn(function), false, false, null); -} - pub fn NewRuntimeFunction( globalObject: *JSGlobalObject, symbolName: ?*const ZigString, argCount: u32, functionPointer: *const JSHostFn, - strong: bool, add_ptr_property: bool, inputFunctionPtr: ?*anyopaque, ) JSValue { jsc.markBinding(@src()); - return private.Bun__CreateFFIFunctionValue(globalObject, symbolName, argCount, functionPointer, strong, add_ptr_property, inputFunctionPtr); + return private.Bun__CreateFFIFunctionValue(globalObject, symbolName, argCount, functionPointer, add_ptr_property, inputFunctionPtr); } pub fn getFunctionData(function: JSValue) ?*anyopaque { @@ -354,7 +314,6 @@ pub fn NewFunctionWithData( symbolName: ?*const ZigString, argCount: u32, comptime function: JSHostFnZig, - strong: bool, data: *anyopaque, ) JSValue { jsc.markBinding(@src()); @@ -363,19 +322,10 @@ pub fn NewFunctionWithData( symbolName, argCount, toJSHostFn(function), - strong, data, ); } -pub fn untrackFunction( - globalObject: *JSGlobalObject, - value: JSValue, -) bool { - jsc.markBinding(@src()); - return private.Bun__untrackFFIFunction(globalObject, value); -} - pub const DOMEffect = struct { reads: [4]ID = std.mem.zeroes([4]ID), writes: [4]ID = std.mem.zeroes([4]ID), diff --git a/src/bun.js/test/DoneCallback.zig b/src/bun.js/test/DoneCallback.zig index 7c1c4e49a3..f9bb8e3619 100644 --- a/src/bun.js/test/DoneCallback.zig +++ b/src/bun.js/test/DoneCallback.zig @@ -29,7 +29,7 @@ pub fn createUnbound(globalThis: *JSGlobalObject) JSValue { } pub fn bind(value: JSValue, globalThis: *JSGlobalObject) bun.JSError!JSValue { - const callFn = jsc.host_fn.NewFunction(globalThis, bun.ZigString.static("done"), 1, BunTest.bunTestDoneCallback, false); + const callFn = jsc.JSFunction.create(globalThis, "done", BunTest.bunTestDoneCallback, 1, .{}); return try callFn.bind(globalThis, value, &bun.String.static("done"), 1, &.{}); } diff --git a/src/bun.js/test/ScopeFunctions.zig b/src/bun.js/test/ScopeFunctions.zig index 9c44d3b388..715c334505 100644 --- a/src/bun.js/test/ScopeFunctions.zig +++ b/src/bun.js/test/ScopeFunctions.zig @@ -450,9 +450,9 @@ pub fn createUnbound(globalThis: *JSGlobalObject, mode: Mode, each: jsc.JSValue, return value; } -pub fn bind(value: JSValue, globalThis: *JSGlobalObject, name: *const bun.String) bun.JSError!JSValue { - const callFn = jsc.host_fn.NewFunction(globalThis, &name.toZigString(), 1, callAsFunction, false); - const bound = try callFn.bind(globalThis, value, name, 1, &.{}); +pub fn bind(value: JSValue, globalThis: *JSGlobalObject, name: bun.String) bun.JSError!JSValue { + const callFn = jsc.JSFunction.create(globalThis, name, callAsFunction, 1, .{}); + const bound = try callFn.bind(globalThis, value, &name, 1, &.{}); try bound.setPrototypeDirect(value.getPrototype(globalThis), globalThis); return bound; } @@ -462,7 +462,7 @@ pub fn createBound(globalThis: *JSGlobalObject, mode: Mode, each: jsc.JSValue, c defer groupLog.end(); const value = createUnbound(globalThis, mode, each, cfg); - return bind(value, globalThis, &name); + return bind(value, globalThis, name); } const bun = @import("bun"); diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index a2add25650..3725a5d5cd 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -195,12 +195,12 @@ pub const Jest = struct { const xdescribe_scope_functions = bun_test.ScopeFunctions.createBound(globalObject, .describe, .zero, .{ .self_mode = .skip }, bun_test.ScopeFunctions.strings.xdescribe) catch return .zero; module.put(globalObject, ZigString.static("xdescribe"), xdescribe_scope_functions); - module.put(globalObject, ZigString.static("beforeEach"), jsc.host_fn.NewFunction(globalObject, ZigString.static("beforeEach"), 1, bun_test.js_fns.genericHook(.beforeEach).hookFn, false)); - module.put(globalObject, ZigString.static("beforeAll"), jsc.host_fn.NewFunction(globalObject, ZigString.static("beforeAll"), 1, bun_test.js_fns.genericHook(.beforeAll).hookFn, false)); - module.put(globalObject, ZigString.static("afterAll"), jsc.host_fn.NewFunction(globalObject, ZigString.static("afterAll"), 1, bun_test.js_fns.genericHook(.afterAll).hookFn, false)); - module.put(globalObject, ZigString.static("afterEach"), jsc.host_fn.NewFunction(globalObject, ZigString.static("afterEach"), 1, bun_test.js_fns.genericHook(.afterEach).hookFn, false)); - module.put(globalObject, ZigString.static("onTestFinished"), jsc.host_fn.NewFunction(globalObject, ZigString.static("onTestFinished"), 1, bun_test.js_fns.genericHook(.onTestFinished).hookFn, false)); - module.put(globalObject, ZigString.static("setDefaultTimeout"), jsc.host_fn.NewFunction(globalObject, ZigString.static("setDefaultTimeout"), 1, jsSetDefaultTimeout, false)); + module.put(globalObject, ZigString.static("beforeEach"), jsc.JSFunction.create(globalObject, "beforeEach", bun_test.js_fns.genericHook(.beforeEach).hookFn, 1, .{})); + module.put(globalObject, ZigString.static("beforeAll"), jsc.JSFunction.create(globalObject, "beforeAll", bun_test.js_fns.genericHook(.beforeAll).hookFn, 1, .{})); + module.put(globalObject, ZigString.static("afterAll"), jsc.JSFunction.create(globalObject, "afterAll", bun_test.js_fns.genericHook(.afterAll).hookFn, 1, .{})); + module.put(globalObject, ZigString.static("afterEach"), jsc.JSFunction.create(globalObject, "afterEach", bun_test.js_fns.genericHook(.afterEach).hookFn, 1, .{})); + module.put(globalObject, ZigString.static("onTestFinished"), jsc.JSFunction.create(globalObject, "onTestFinished", bun_test.js_fns.genericHook(.onTestFinished).hookFn, 1, .{})); + module.put(globalObject, ZigString.static("setDefaultTimeout"), jsc.JSFunction.create(globalObject, "setDefaultTimeout", jsSetDefaultTimeout, 1, .{})); module.put(globalObject, ZigString.static("expect"), Expect.js.getConstructor(globalObject)); module.put(globalObject, ZigString.static("expectTypeOf"), ExpectTypeOf.js.getConstructor(globalObject)); @@ -211,20 +211,20 @@ pub const Jest = struct { } fn createMockObjects(globalObject: *JSGlobalObject, module: JSValue) void { - const setSystemTime = jsc.host_fn.NewFunction(globalObject, ZigString.static("setSystemTime"), 0, JSMock__jsSetSystemTime, false); + const setSystemTime = jsc.JSFunction.create(globalObject, "setSystemTime", JSMock__jsSetSystemTime, 0, .{}); module.put( globalObject, ZigString.static("setSystemTime"), setSystemTime, ); - const useFakeTimers = jsc.host_fn.NewFunction(globalObject, ZigString.static("useFakeTimers"), 0, JSMock__jsUseFakeTimers, false); - const useRealTimers = jsc.host_fn.NewFunction(globalObject, ZigString.static("useRealTimers"), 0, JSMock__jsUseRealTimers, false); + const useFakeTimers = jsc.JSFunction.create(globalObject, "useFakeTimers", JSMock__jsUseFakeTimers, 0, .{}); + const useRealTimers = jsc.JSFunction.create(globalObject, "useRealTimers", JSMock__jsUseRealTimers, 0, .{}); - const mockFn = jsc.host_fn.NewFunction(globalObject, ZigString.static("fn"), 1, JSMock__jsMockFn, false); - const spyOn = jsc.host_fn.NewFunction(globalObject, ZigString.static("spyOn"), 2, JSMock__jsSpyOn, false); - const restoreAllMocks = jsc.host_fn.NewFunction(globalObject, ZigString.static("restoreAllMocks"), 2, JSMock__jsRestoreAllMocks, false); - const clearAllMocks = jsc.host_fn.NewFunction(globalObject, ZigString.static("clearAllMocks"), 2, JSMock__jsClearAllMocks, false); - const mockModuleFn = jsc.host_fn.NewFunction(globalObject, ZigString.static("module"), 2, JSMock__jsModuleMock, false); + const mockFn = jsc.JSFunction.create(globalObject, "fn", JSMock__jsMockFn, 1, .{}); + const spyOn = jsc.JSFunction.create(globalObject, "spyOn", JSMock__jsSpyOn, 2, .{}); + const restoreAllMocks = jsc.JSFunction.create(globalObject, "restoreAllMocks", JSMock__jsRestoreAllMocks, 2, .{}); + const clearAllMocks = jsc.JSFunction.create(globalObject, "clearAllMocks", JSMock__jsClearAllMocks, 2, .{}); + const mockModuleFn = jsc.JSFunction.create(globalObject, "module", JSMock__jsModuleMock, 2, .{}); module.put(globalObject, ZigString.static("mock"), mockFn); mockFn.put(globalObject, ZigString.static("module"), mockModuleFn); mockFn.put(globalObject, ZigString.static("restore"), restoreAllMocks); @@ -252,8 +252,8 @@ pub const Jest = struct { ZigString.static("useRealTimers"), useRealTimers, ); - jest.put(globalObject, ZigString.static("now"), jsc.host_fn.NewFunction(globalObject, ZigString.static("now"), 0, JSMock__jsNow, false)); - jest.put(globalObject, ZigString.static("setTimeout"), jsc.host_fn.NewFunction(globalObject, ZigString.static("setTimeout"), 1, jsSetDefaultTimeout, false)); + jest.put(globalObject, ZigString.static("now"), jsc.JSFunction.create(globalObject, "now", JSMock__jsNow, 0, .{})); + jest.put(globalObject, ZigString.static("setTimeout"), jsc.JSFunction.create(globalObject, "setTimeout", jsSetDefaultTimeout, 1, .{})); module.put(globalObject, ZigString.static("jest"), jest); module.put(globalObject, ZigString.static("spyOn"), spyOn); diff --git a/src/cli/upgrade_command.zig b/src/cli/upgrade_command.zig index cf9dc91427..9252782e01 100644 --- a/src/cli/upgrade_command.zig +++ b/src/cli/upgrade_command.zig @@ -903,9 +903,9 @@ pub const upgrade_js_bindings = struct { pub fn generate(global: *jsc.JSGlobalObject) jsc.JSValue { const obj = JSValue.createEmptyObject(global, 2); const open = ZigString.static("openTempDirWithoutSharingDelete"); - obj.put(global, open, jsc.createCallback(global, open, 1, jsOpenTempDirWithoutSharingDelete)); + obj.put(global, open, jsc.JSFunction.create(global, "openTempDirWithoutSharingDelete", jsOpenTempDirWithoutSharingDelete, 1, .{})); const close = ZigString.static("closeTempDirHandle"); - obj.put(global, close, jsc.createCallback(global, close, 1, jsCloseTempDirHandle)); + obj.put(global, close, jsc.JSFunction.create(global, "closeTempDirHandle", jsCloseTempDirHandle, 1, .{})); return obj; } diff --git a/src/codegen/bindgen.ts b/src/codegen/bindgen.ts index 6e9fd9d408..0ab0708612 100644 --- a/src/codegen/bindgen.ts +++ b/src/codegen/bindgen.ts @@ -1455,7 +1455,7 @@ for (const [filename, { functions, typedefs }] of files) { const minArgCount = fn.variants.reduce((acc, vari) => Math.min(acc, vari.args.length), Number.MAX_SAFE_INTEGER); zig.line(`pub fn ${wrapperName}(global: *jsc.JSGlobalObject) callconv(jsc.conv) jsc.JSValue {`); zig.line( - ` return jsc.host_fn.NewRuntimeFunction(global, jsc.ZigString.static(${str(fn.name)}), ${minArgCount}, js${cap(fn.name)}, false, false, null);`, + ` return jsc.host_fn.NewRuntimeFunction(global, jsc.ZigString.static(${str(fn.name)}), ${minArgCount}, js${cap(fn.name)}, false, null);`, ); zig.line(`}`); } diff --git a/src/crash_handler.zig b/src/crash_handler.zig index 3bc18b642b..d902410444 100644 --- a/src/crash_handler.zig +++ b/src/crash_handler.zig @@ -1858,7 +1858,7 @@ pub const js_bindings = struct { .{ "raiseIgnoringPanicHandler", jsRaiseIgnoringPanicHandler }, }) |tuple| { const name = jsc.ZigString.static(tuple[0]); - obj.put(global, name, jsc.createCallback(global, name, 1, tuple[1])); + obj.put(global, name, jsc.JSFunction.create(global, tuple[0], tuple[1], 1, .{})); } return obj; } diff --git a/src/csrf.zig b/src/csrf.zig index d78756a83f..45a204c92a 100644 --- a/src/csrf.zig +++ b/src/csrf.zig @@ -291,7 +291,7 @@ pub fn csrf__generate_impl(globalObject: *jsc.JSGlobalObject, callframe: *jsc.Ca return encoding.toNodeEncoding().encodeWithMaxSize(globalObject, boring.EVP_MAX_MD_SIZE + 32, token_bytes); } -pub const csrf__generate = jsc.toJSHostFn(csrf__generate_impl); +pub const csrf__generate = csrf__generate_impl; /// JS binding function for verifying CSRF tokens /// First argument is token (required), second is options (optional) @@ -377,7 +377,7 @@ pub fn csrf__verify_impl(globalObject: *jsc.JSGlobalObject, call_frame: *jsc.Cal return jsc.JSValue.jsBoolean(is_valid); } -pub const csrf__verify = jsc.toJSHostFn(csrf__verify_impl); +pub const csrf__verify = csrf__verify_impl; const hmac = @import("./hmac.zig"); const std = @import("std"); diff --git a/src/deps/uws/UpgradedDuplex.zig b/src/deps/uws/UpgradedDuplex.zig index 26204293e5..419c03b690 100644 --- a/src/deps/uws/UpgradedDuplex.zig +++ b/src/deps/uws/UpgradedDuplex.zig @@ -270,7 +270,6 @@ pub fn getJSHandlers(this: *UpgradedDuplex, globalThis: *jsc.JSGlobalObject) bun null, 0, onReceivedData, - false, this, ); dataCallback.ensureStillAlive(); @@ -290,7 +289,6 @@ pub fn getJSHandlers(this: *UpgradedDuplex, globalThis: *jsc.JSGlobalObject) bun null, 0, onReceivedData, - false, this, ); endCallback.ensureStillAlive(); @@ -310,7 +308,6 @@ pub fn getJSHandlers(this: *UpgradedDuplex, globalThis: *jsc.JSGlobalObject) bun null, 0, onWritable, - false, this, ); writableCallback.ensureStillAlive(); @@ -329,7 +326,6 @@ pub fn getJSHandlers(this: *UpgradedDuplex, globalThis: *jsc.JSGlobalObject) bun null, 0, onCloseJS, - false, this, ); closeCallback.ensureStillAlive(); diff --git a/src/install/install_binding.zig b/src/install/install_binding.zig index fc937f4529..504c2391d3 100644 --- a/src/install/install_binding.zig +++ b/src/install/install_binding.zig @@ -6,7 +6,7 @@ pub const bun_install_js_bindings = struct { pub fn generate(global: *JSGlobalObject) JSValue { const obj = JSValue.createEmptyObject(global, 1); const parseLockfile = ZigString.static("parseLockfile"); - obj.put(global, parseLockfile, jsc.createCallback(global, parseLockfile, 1, jsParseLockfile)); + obj.put(global, parseLockfile, jsc.JSFunction.create(global, "parseLockfile", jsParseLockfile, 1, .{})); return obj; } diff --git a/src/install/npm.zig b/src/install/npm.zig index 11ca8fa72d..b79fb89cbb 100644 --- a/src/install/npm.zig +++ b/src/install/npm.zig @@ -1337,7 +1337,7 @@ pub const PackageManifest = struct { pub fn generate(global: *JSGlobalObject) JSValue { const obj = JSValue.createEmptyObject(global, 1); const parseManifestString = ZigString.static("parseManifest"); - obj.put(global, parseManifestString, jsc.createCallback(global, parseManifestString, 2, jsParseManifest)); + obj.put(global, parseManifestString, jsc.JSFunction.create(global, "parseManifest", jsParseManifest, 2, .{})); return obj; } diff --git a/src/semver/SemverObject.zig b/src/semver/SemverObject.zig index 91c7d90ee2..7fbc12bc5a 100644 --- a/src/semver/SemverObject.zig +++ b/src/semver/SemverObject.zig @@ -6,24 +6,24 @@ pub fn create(globalThis: *jsc.JSGlobalObject) jsc.JSValue { object.put( globalThis, jsc.ZigString.static("satisfies"), - jsc.host_fn.NewFunction( + jsc.JSFunction.create( globalThis, - jsc.ZigString.static("satisfies"), - 2, + "satisfies", SemverObject.satisfies, - false, + 2, + .{}, ), ); object.put( globalThis, jsc.ZigString.static("order"), - jsc.host_fn.NewFunction( + jsc.JSFunction.create( globalThis, - jsc.ZigString.static("order"), - 2, + "order", SemverObject.order, - false, + 2, + .{}, ), ); diff --git a/test/js/bun/util/hash.test.js b/test/js/bun/util/hash.test.js index 9dd290439f..c680649b01 100644 --- a/test/js/bun/util/hash.test.js +++ b/test/js/bun/util/hash.test.js @@ -74,3 +74,15 @@ it(`Bun.hash.rapidhash()`, () => { gcTick(); expect(Bun.hash.rapidhash(new TextEncoder().encode("hello world"))).toBe(0x58a89bdcee89c08cn); }); +it("does not crash when changing Int32Array constructor with Bun.hash.xxHash32 as species", () => { + const arr = new Int32Array(); + function foo(a4) { + return a4; + } + foo[Symbol.species] = Bun.hash.xxHash32; + arr.constructor = foo; + + expect(() => { + arr.map(Bun.hash.xxHash32); + }).toThrow("species is not a constructor"); +});