diff options
-rw-r--r-- | bench/snippets/noop.js | 13 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 8 |
2 files changed, 20 insertions, 1 deletions
diff --git a/bench/snippets/noop.js b/bench/snippets/noop.js index 789e6abbb..d4fc03680 100644 --- a/bench/snippets/noop.js +++ b/bench/snippets/noop.js @@ -1,9 +1,20 @@ import { bench, run } from "mitata"; var noop = globalThis[Symbol.for("Bun.lazy")]("noop"); +var { function: noopFn, callback } = noop; +const noop2 = () => {}; bench("function", function () { - noop.function(); + noopFn(); +}); + +bench("JSC::call(() => {})", () => { + callback(noop2); +}); + +const bound = noop2.bind(null); +bench("bound call", () => { + bound(); }); bench("setter", function () { diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 3d038955d..c4b63869e 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -1067,6 +1067,13 @@ JSC_DEFINE_HOST_FUNCTION(functionNoop, (JSC::JSGlobalObject*, JSC::CallFrame*)) return JSC::JSValue::encode(JSC::jsUndefined()); } +JSC_DEFINE_HOST_FUNCTION(functionCallback, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) +{ + JSFunction* callback = jsCast<JSFunction*>(callFrame->uncheckedArgument(0)); + JSC::CallData callData = JSC::getCallData(callback); + return JSC::JSValue::encode(JSC::call(globalObject, callback, callData, JSC::jsUndefined(), JSC::MarkedArgumentBuffer())); +} + JSC_DECLARE_HOST_FUNCTION(functionPathToFileURL); JSC_DECLARE_HOST_FUNCTION(functionFileURLToPath); @@ -1263,6 +1270,7 @@ JSC: Zig::JSFFIFunction* function = Zig::JSFFIFunction::create(vm, reinterpret_cast<Zig::GlobalObject*>(globalObject), 0, String(), functionNoop, JSC::NoIntrinsic); obj->putDirect(vm, JSC::PropertyName(JSC::Identifier::fromString(vm, "function"_s)), function, JSC::PropertyAttribute::Function | 0); obj->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "functionRegular"_s), 1, functionNoop, ImplementationVisibility::Public, NoIntrinsic, PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::Function); + obj->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, "callback"_s), 1, functionCallback, ImplementationVisibility::Public, NoIntrinsic, PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::Function); return JSC::JSValue::encode(obj); } |