mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Expose some no-ops (#16125)
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
@@ -1,20 +1,14 @@
|
||||
import { noOpForTesting as noop } from "bun:internal-for-testing";
|
||||
import { bench, run } from "../runner.mjs";
|
||||
|
||||
// These are no-op C++ functions that are exported to JS.
|
||||
const lazy = globalThis[Symbol.for("Bun.lazy")];
|
||||
const noop = lazy("noop");
|
||||
const fn = noop.function;
|
||||
const regular = noop.functionRegular;
|
||||
const callback = noop.callback;
|
||||
|
||||
bench("C++ callback into JS", () => {
|
||||
callback(() => {});
|
||||
});
|
||||
|
||||
bench("C++ fn regular", () => {
|
||||
regular();
|
||||
});
|
||||
|
||||
bench("C++ fn", () => {
|
||||
fn();
|
||||
});
|
||||
|
||||
47
src/bun.js/bindings/NoOpForTesting.cpp
Normal file
47
src/bun.js/bindings/NoOpForTesting.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
|
||||
#include "root.h"
|
||||
|
||||
#include "JavaScriptCore/CustomGetterSetter.h"
|
||||
#include "JavaScriptCore/ObjectConstructor.h"
|
||||
#include "JavaScriptCore/JSObject.h"
|
||||
#include <JavaScriptCore/JSFunction.h>
|
||||
|
||||
namespace Bun {
|
||||
using namespace JSC;
|
||||
|
||||
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))
|
||||
{
|
||||
JSObject* callback = jsCast<JSObject*>(callFrame->uncheckedArgument(0));
|
||||
JSC::CallData callData = JSC::getCallData(callback);
|
||||
return JSC::JSValue::encode(JSC::profiledCall(globalObject, ProfilingReason::API, callback, callData, JSC::jsUndefined(), JSC::MarkedArgumentBuffer()));
|
||||
}
|
||||
|
||||
JSC_DEFINE_CUSTOM_GETTER(noop_getter, (JSGlobalObject*, EncodedJSValue, PropertyName))
|
||||
{
|
||||
return JSC::JSValue::encode(JSC::jsUndefined());
|
||||
}
|
||||
|
||||
JSC_DEFINE_CUSTOM_SETTER(noop_setter,
|
||||
(JSC::JSGlobalObject*, JSC::EncodedJSValue,
|
||||
JSC::EncodedJSValue, JSC::PropertyName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
JSC::JSObject* createNoOpForTesting(JSC::JSGlobalObject* globalObject)
|
||||
{
|
||||
auto& vm = globalObject->vm();
|
||||
JSC::JSObject* object = JSC::constructEmptyObject(vm, globalObject->nullPrototypeObjectStructure());
|
||||
object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, String("function"_s)), 0, functionNoop, ImplementationVisibility::Public, JSC::NoIntrinsic, 0);
|
||||
object->putDirectNativeFunction(vm, globalObject, JSC::Identifier::fromString(vm, String("callback"_s)), 0, functionCallback, ImplementationVisibility::Public, JSC::NoIntrinsic, 0);
|
||||
object->putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, String("getterSetter"_s)), JSC::CustomGetterSetter::create(vm, noop_getter, noop_setter), 0);
|
||||
return object;
|
||||
}
|
||||
|
||||
}
|
||||
3
src/bun.js/bindings/NoOpForTesting.h
Normal file
3
src/bun.js/bindings/NoOpForTesting.h
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace Bun {
|
||||
JSC::JSObject* createNoOpForTesting(JSC::JSGlobalObject* globalObject);
|
||||
}
|
||||
@@ -1883,30 +1883,6 @@ JSC_DEFINE_HOST_FUNCTION(functionCreateUninitializedArrayBuffer,
|
||||
RELEASE_AND_RETURN(scope, JSValue::encode(JSC::JSArrayBuffer::create(globalObject->vm(), globalObject->arrayBufferStructure(JSC::ArrayBufferSharingMode::Default), WTFMove(arrayBuffer))));
|
||||
}
|
||||
|
||||
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::profiledCall(globalObject, ProfilingReason::API, callback, callData, JSC::jsUndefined(), JSC::MarkedArgumentBuffer()));
|
||||
}
|
||||
|
||||
JSC_DEFINE_CUSTOM_GETTER(noop_getter, (JSGlobalObject*, EncodedJSValue, PropertyName))
|
||||
{
|
||||
return JSC::JSValue::encode(JSC::jsUndefined());
|
||||
}
|
||||
|
||||
JSC_DEFINE_CUSTOM_SETTER(noop_setter,
|
||||
(JSC::JSGlobalObject*, JSC::EncodedJSValue,
|
||||
JSC::EncodedJSValue, JSC::PropertyName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline JSC::EncodedJSValue jsFunctionAddEventListenerBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, Zig::GlobalObject* castedThis)
|
||||
{
|
||||
auto& vm = JSC::getVM(lexicalGlobalObject);
|
||||
|
||||
@@ -149,3 +149,5 @@ export const bindgen = $zig("bindgen_test.zig", "getBindgenTestFunctions") as {
|
||||
add: (a: any, b: any) => number;
|
||||
requiredAndOptionalArg: (a: any, b?: any, c?: any, d?: any) => number;
|
||||
};
|
||||
|
||||
export const noOpForTesting = $cpp("NoOpForTesting.cpp", "createNoOpForTesting");
|
||||
|
||||
Reference in New Issue
Block a user