aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-15 01:48:31 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-17 07:36:35 -0700
commit6a65631cbdcae75bfa1e64323a6ad613a922cd1a (patch)
treed6a8c56e9455eafbcb944fd29b5ba066ab31bca0 /src
parent382be2cb46eac458e7f619ee1ee05c9efadcce51 (diff)
downloadbun-6a65631cbdcae75bfa1e64323a6ad613a922cd1a.tar.gz
bun-6a65631cbdcae75bfa1e64323a6ad613a922cd1a.tar.zst
bun-6a65631cbdcae75bfa1e64323a6ad613a922cd1a.zip
[bun:ffi] Improve `ptr()` performance and implement code generation for DOMJIT
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/api/bun.zig33
-rw-r--r--src/bun.js/api/ffi.zig29
-rw-r--r--src/bun.js/base.zig374
-rw-r--r--src/bun.js/bindings/JSFFIFunction.cpp6
-rw-r--r--src/bun.js/bindings/ZigGeneratedCode.cpp60
-rw-r--r--src/bun.js/bindings/ZigGlobalObject.cpp2
-rw-r--r--src/bun.js/bindings/ZigLazyStaticFunctions-inlines.h162
-rw-r--r--src/bun.js/bindings/ZigLazyStaticFunctions.h34
-rw-r--r--src/bun.js/bindings/bindings-generator.zig2
-rw-r--r--src/bun.js/bindings/bindings.zig23
-rw-r--r--src/bun.js/bindings/header-gen.zig213
-rw-r--r--src/bun.js/bindings/headers-cpp.h25
-rw-r--r--src/bun.js/bindings/headers-handwritten.h3
-rw-r--r--src/bun.js/bindings/headers.h18
-rw-r--r--src/bun.js/bindings/headers.zig1
-rw-r--r--src/bun.js/bindings/sizes.zig13
-rw-r--r--src/bun.js/bindings/webcore/DOMJITIDLType.h51
-rw-r--r--src/bun.js/ffi.exports.js18
-rw-r--r--src/bun.js/headergen/sizegen.cpp2
-rw-r--r--src/bun.js/javascript.zig1
20 files changed, 739 insertions, 331 deletions
diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig
index 45e7cb1a1..8408ce339 100644
--- a/src/bun.js/api/bun.zig
+++ b/src/bun.js/api/bun.zig
@@ -2392,9 +2392,7 @@ pub const Timer = struct {
pub const FFI = struct {
pub const Class = NewClass(
void,
- .{
- .name = "FFI",
- },
+ .{ .name = "FFI", .has_dom_calls = true },
.{
.viewSource = .{
.rfn = JSC.wrapWithHasContainer(JSC.FFI, "print", false, false, true),
@@ -2408,9 +2406,7 @@ pub const FFI = struct {
.linkSymbols = .{
.rfn = JSC.wrapWithHasContainer(JSC.FFI, "linkSymbols", false, false, false),
},
- .ptr = .{
- .rfn = JSC.wrapWithHasContainer(@This(), "ptr", false, false, true),
- },
+ .ptr = JSC.DOMCall("FFI", @This(), "ptr", f64, JSC.DOMEffect.forRead(.TypedArrayProperties)),
.toBuffer = .{
.rfn = JSC.wrapWithHasContainer(@This(), "toBuffer", false, false, true),
},
@@ -2427,6 +2423,26 @@ pub const FFI = struct {
pub fn ptr(
globalThis: *JSGlobalObject,
+ _: JSValue,
+ arguments: []const JSValue,
+ ) JSValue {
+ return switch (arguments.len) {
+ 0 => ptr_(globalThis, JSValue.zero, null),
+ 1 => ptr_(globalThis, arguments[0], null),
+ else => ptr_(globalThis, arguments[0], arguments[1]),
+ };
+ }
+
+ pub fn ptrWithoutTypeChecks(
+ _: *JSGlobalObject,
+ _: *anyopaque,
+ array: *JSC.JSUint8Array,
+ ) callconv(.C) JSValue {
+ return JSValue.fromPtrAddress(@ptrToInt(array.ptr()));
+ }
+
+ fn ptr_(
+ globalThis: *JSGlobalObject,
value: JSValue,
byteOffset: ?JSValue,
) JSValue {
@@ -2435,7 +2451,7 @@ pub const FFI = struct {
}
const array_buffer = value.asArrayBuffer(globalThis) orelse {
- return JSC.toInvalidArguments("Expected ArrayBufferView", .{}, globalThis.ref());
+ return JSC.toInvalidArguments("Expected ArrayBufferView but received {s}", .{@tagName(value.jsType())}, globalThis.ref());
};
if (array_buffer.len == 0) {
@@ -2443,6 +2459,8 @@ pub const FFI = struct {
}
var addr: usize = @ptrToInt(array_buffer.ptr);
+ // const Sizes = @import("../bindings/sizes.zig");
+ // std.debug.assert(addr == @ptrToInt(value.asEncoded().ptr) + Sizes.Bun_FFI_PointerOffsetToTypedArrayVector);
if (byteOffset) |off| {
if (!off.isEmptyOrUndefinedOrNull()) {
@@ -2687,6 +2705,7 @@ pub const FFI = struct {
var prototype = JSC.C.JSObjectMake(ctx, FFI.Class.get().?[0], null);
var base = JSC.C.JSObjectMake(ctx, null, null);
JSC.C.JSObjectSetPrototype(ctx, base, prototype);
+ FFI.Class.putDOMCalls(ctx, JSC.JSValue.c(base));
return ctx.ptr().putCachedObject(
&ZigString.init("FFI"),
JSValue.fromRef(base),
diff --git a/src/bun.js/api/ffi.zig b/src/bun.js/api/ffi.zig
index 52c086d5b..46a4d20c8 100644
--- a/src/bun.js/api/ffi.zig
+++ b/src/bun.js/api/ffi.zig
@@ -92,6 +92,7 @@ pub const FFI = struct {
);
pub fn callback(globalThis: *JSGlobalObject, interface: JSC.JSValue, js_callback: JSC.JSValue) JSValue {
+ JSC.markBinding();
if (!interface.isObject()) {
return JSC.toInvalidArguments("Expected object", .{}, globalThis.ref());
}
@@ -136,6 +137,7 @@ pub const FFI = struct {
}
pub fn close(this: *FFI) JSValue {
+ JSC.markBinding();
if (this.closed) {
return JSC.JSValue.jsUndefined();
}
@@ -156,6 +158,7 @@ pub const FFI = struct {
}
pub fn printCallback(global: *JSGlobalObject, object: JSC.JSValue) JSValue {
+ JSC.markBinding();
const allocator = VirtualMachine.vm.allocator;
if (object.isEmptyOrUndefinedOrNull() or !object.isObject()) {
@@ -180,6 +183,7 @@ pub const FFI = struct {
}
pub fn print(global: *JSGlobalObject, object: JSC.JSValue, is_callback_val: ?JSC.JSValue) JSValue {
+ JSC.markBinding();
const allocator = VirtualMachine.vm.allocator;
if (is_callback_val) |is_callback| {
if (is_callback.toBoolean()) {
@@ -262,6 +266,7 @@ pub const FFI = struct {
// }
pub fn open(global: *JSGlobalObject, name_str: ZigString, object: JSC.JSValue) JSC.JSValue {
+ JSC.markBinding();
const allocator = VirtualMachine.vm.allocator;
var name_slice = name_str.toSlice(allocator);
defer name_slice.deinit();
@@ -289,7 +294,7 @@ pub const FFI = struct {
}
var dylib = std.DynLib.open(name) catch {
- return JSC.toInvalidArguments("Failed to open library", .{}, global.ref());
+ return JSC.toInvalidArguments("Failed to find or open library", .{}, global.ref());
};
var obj = JSC.JSValue.c(JSC.C.JSObjectMake(global.ref(), null, null));
@@ -376,6 +381,7 @@ pub const FFI = struct {
}
pub fn linkSymbols(global: *JSGlobalObject, object: JSC.JSValue) JSC.JSValue {
+ JSC.markBinding();
const allocator = VirtualMachine.vm.allocator;
if (object.isEmptyOrUndefinedOrNull() or !object.isObject()) {
@@ -467,6 +473,8 @@ pub const FFI = struct {
return JSC.JSValue.createObject2(global, &ZigString.init("close"), &ZigString.init("symbols"), close_object, obj);
}
pub fn generateSymbolForFunction(global: *JSGlobalObject, allocator: std.mem.Allocator, value: JSC.JSValue, function: *Function) !?JSValue {
+ JSC.markBinding();
+
var abi_types = std.ArrayListUnmanaged(ABIType){};
if (value.get(global, "args")) |args| {
@@ -558,6 +566,7 @@ pub const FFI = struct {
return null;
}
pub fn generateSymbols(global: *JSGlobalObject, symbols: *std.StringArrayHashMapUnmanaged(Function), object: JSC.JSValue) !?JSValue {
+ JSC.markBinding();
const allocator = VirtualMachine.vm.allocator;
var symbols_iter = JSC.JSPropertyIterator(.{
@@ -629,6 +638,7 @@ pub const FFI = struct {
pending: void,
compiled: struct {
ptr: *anyopaque,
+ fast_path_ptr: ?*anyopaque = null,
buf: []u8,
js_function: ?*anyopaque = null,
js_context: ?*anyopaque = null,
@@ -687,14 +697,13 @@ pub const FFI = struct {
bun_call: *const @TypeOf(JSC.C.JSObjectCallAsFunction),
};
const headers = @import("../bindings/headers.zig");
-
- var workaround: MyFunctionSStructWorkAround = .{
+ var workaround: MyFunctionSStructWorkAround = if (!JSC.is_bindgen) .{
.JSVALUE_TO_INT64 = headers.JSC__JSValue__toInt64,
.JSVALUE_TO_UINT64 = headers.JSC__JSValue__toUInt64NoTruncate,
.INT64_TO_JSVALUE = headers.JSC__JSValue__fromInt64NoTruncate,
.UINT64_TO_JSVALUE = headers.JSC__JSValue__fromUInt64NoTruncate,
.bun_call = &JSC.C.JSObjectCallAsFunction,
- };
+ } else undefined;
const tcc_options = "-std=c11 -nostdlib -Wl,--export-all-symbols" ++ if (Environment.isDebug) " -g" else "";
@@ -824,6 +833,7 @@ pub const FFI = struct {
}
pub fn inject(state: *TCC.TCCState) void {
+ JSC.markBinding();
_ = TCC.tcc_add_symbol(state, "memset", &memset);
_ = TCC.tcc_add_symbol(state, "memcpy", &memcpy);
@@ -837,10 +847,12 @@ pub const FFI = struct {
"JSVALUE_TO_UINT64_SLOW",
workaround.JSVALUE_TO_UINT64,
);
- std.mem.doNotOptimizeAway(headers.JSC__JSValue__toUInt64NoTruncate);
- std.mem.doNotOptimizeAway(headers.JSC__JSValue__toInt64);
- std.mem.doNotOptimizeAway(headers.JSC__JSValue__fromInt64NoTruncate);
- std.mem.doNotOptimizeAway(headers.JSC__JSValue__fromUInt64NoTruncate);
+ if (!comptime JSC.is_bindgen) {
+ std.mem.doNotOptimizeAway(headers.JSC__JSValue__toUInt64NoTruncate);
+ std.mem.doNotOptimizeAway(headers.JSC__JSValue__toInt64);
+ std.mem.doNotOptimizeAway(headers.JSC__JSValue__fromInt64NoTruncate);
+ std.mem.doNotOptimizeAway(headers.JSC__JSValue__fromUInt64NoTruncate);
+ }
_ = TCC.tcc_add_symbol(
state,
"INT64_TO_JSVALUE_SLOW",
@@ -1203,6 +1215,7 @@ pub const FFI = struct {
}
};
+ // Must be kept in sync with JSFFIFunction.h version
pub const ABIType = enum(i32) {
char = 0,
diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig
index 41454da3c..dd4f2ffc5 100644
--- a/src/bun.js/base.zig
+++ b/src/bun.js/base.zig
@@ -843,6 +843,7 @@ pub const ClassOptions = struct {
no_inheritance: bool = false,
singleton: bool = false,
ts: d.ts.decl = d.ts.decl{ .empty = 0 },
+ has_dom_calls: bool = false,
};
pub fn NewConstructor(
@@ -891,6 +892,7 @@ pub fn NewClassWithInstanceType(
pub const Zig = ZigType;
const ClassDefinitionCreator = @This();
const function_names = std.meta.fieldNames(@TypeOf(staticFunctions));
+ pub const functionDefinitions = staticFunctions;
const function_name_literals = function_names;
var function_name_refs: [function_names.len]js.JSStringRef = undefined;
var function_name_refs_set = false;
@@ -994,6 +996,16 @@ pub fn NewClassWithInstanceType(
return result;
}
+
+ pub fn putDOMCalls(globalThis: *JSC.JSGlobalObject, value: JSValue) void {
+ inline for (function_name_literals) |functionName| {
+ const Function = comptime @field(staticFunctions, functionName);
+ if (@TypeOf(Function) == type and @hasDecl(Function, "is_dom_call")) {
+ Function.put(globalThis, value);
+ }
+ }
+ }
+
pub fn GetClass(comptime ReceiverType: type) type {
const ClassGetter = struct {
get: fn (
@@ -1993,6 +2005,8 @@ pub fn NewClassWithInstanceType(
_ = i;
switch (@typeInfo(@TypeOf(@field(staticFunctions, function_name_literal)))) {
.Struct => {
+ const CtxField = @field(staticFunctions, function_name_literals[i]);
+
if (strings.eqlComptime(function_name_literal, "constructor")) {
def.callAsConstructor = To.JS.Constructor(staticFunctions.constructor.rfn).rfn;
} else if (strings.eqlComptime(function_name_literal, "finalize")) {
@@ -2021,8 +2035,7 @@ pub fn NewClassWithInstanceType(
def.getPropertyNames = @field(staticFunctions, "getPropertyNames").rfn;
} else if (strings.eqlComptime(function_name_literal, "convertToType")) {
def.convertToType = @field(staticFunctions, "convertToType").rfn;
- } else {
- const CtxField = @field(staticFunctions, function_name_literals[i]);
+ } else if (!@hasField(@TypeOf(CtxField), "is_dom_call")) {
if (!@hasField(@TypeOf(CtxField), "rfn")) {
@compileError("Expected " ++ options.name ++ "." ++ function_name_literal ++ " to have .rfn");
}
@@ -2789,6 +2802,363 @@ pub fn wrap(
return wrapWithHasContainer(Container, name, maybe_async, true, true);
}
+pub const DOMEffect = struct {
+ reads: [4]ID = std.mem.zeroes([4]ID),
+ writes: [4]ID = std.mem.zeroes([4]ID),
+
+ pub const top = DOMEffect{
+ .reads = .{ ID.Heap, ID.Heap, ID.Heap, ID.Heap },
+ .writes = .{ ID.Heap, ID.Heap, ID.Heap, ID.Heap },
+ };
+
+ pub fn forRead(read: ID) DOMEffect {
+ return DOMEffect{
+ .reads = .{ read, ID.Heap, ID.Heap, ID.Heap },
+ .writes = .{ ID.Heap, ID.Heap, ID.Heap, ID.Heap },
+ };
+ }
+
+ pub fn forWrite(read: ID) DOMEffect {
+ return DOMEffect{
+ .writes = .{ read, ID.Heap, ID.Heap, ID.Heap },
+ .reads = .{ ID.Heap, ID.Heap, ID.Heap, ID.Heap },
+ };
+ }
+
+ pub const pure = DOMEffect{};
+
+ pub fn isPure(this: DOMEffect) bool {
+ return this.reads[0] == ID.InvalidAbstractHeap and this.writes[0] == ID.InvalidAbstractHeap;
+ }
+
+ pub const ID = enum(u8) {
+ InvalidAbstractHeap = 0,
+ World,
+ Stack,
+ Heap,
+ Butterfly_publicLength,
+ Butterfly_vectorLength,
+ GetterSetter_getter,
+ GetterSetter_setter,
+ JSCell_cellState,
+ JSCell_indexingType,
+ JSCell_structureID,
+ JSCell_typeInfoFlags,
+ JSObject_butterfly,
+ JSPropertyNameEnumerator_cachedPropertyNames,
+ RegExpObject_lastIndex,
+ NamedProperties,
+ IndexedInt32Properties,
+ IndexedDoubleProperties,
+ IndexedContiguousProperties,
+ IndexedArrayStorageProperties,
+ DirectArgumentsProperties,
+ ScopeProperties,
+ TypedArrayProperties,
+ /// Used to reflect the fact that some allocations reveal object identity */
+ HeapObjectCount,
+ RegExpState,
+ MathDotRandomState,
+ JSDateFields,
+ JSMapFields,
+ JSSetFields,
+ JSWeakMapFields,
+ JSWeakSetFields,
+ JSInternalFields,
+ InternalState,
+ CatchLocals,
+ Absolute,
+ /// DOMJIT tells the heap range with the pair of integers. */
+ DOMState,
+ /// Use this for writes only, to indicate that this may fire watchpoints. Usually this is never directly written but instead we test to see if a node clobbers this; it just so happens that you have to write world to clobber it. */
+ Watchpoint_fire,
+ /// Use these for reads only, just to indicate that if the world got clobbered, then this operation will not work. */
+ MiscFields,
+ /// Use this for writes only, just to indicate that hoisting the node is invalid. This works because we don't hoist anything that has any side effects at all. */
+ SideState,
+ };
+};
+
+fn DOMCallArgumentType(comptime Type: type) []const u8 {
+ const ChildType = if (@typeInfo(Type) == .Pointer) std.meta.Child(Type) else Type;
+ return switch (ChildType) {
+ i32 => "JSC::SpecInt32Only",
+ bool => "JSC::SpecBoolean",
+ JSC.JSString => "JSC::SpecString",
+ JSC.JSUint8Array => "JSC::SpecUint8Array",
+ else => @compileError("Unknown DOM type: " ++ @typeName(Type)),
+ };
+}
+
+fn DOMCallArgumentTypeWrapper(comptime Type: type) []const u8 {
+ const ChildType = if (@typeInfo(Type) == .Pointer) std.meta.Child(Type) else Type;
+ return switch (ChildType) {
+ i32 => "int32_t",
+ bool => "bool",
+ JSC.JSString => "JSC::JSString*",
+ JSC.JSUint8Array => "JSC::JSUint8Array*",
+ else => @compileError("Unknown DOM type: " ++ @typeName(Type)),
+ };
+}
+
+fn DOMCallResultType(comptime Type: type) []const u8 {
+ const ChildType = if (@typeInfo(Type) == .Pointer) std.meta.Child(Type) else Type;
+ return switch (ChildType) {
+ i32 => "JSC::SpecInt32Only",
+ bool => "JSC::SpecBoolean",
+ JSC.JSString => "JSC::SpecString",
+ JSC.JSUint8Array => "JSC::SpecUint8Array",
+ JSC.JSCell => "JSC::SpecCell",
+ f64 => "JSC::SpecNonIntAsDouble",
+ else => "JSC::SpecHeapTop",
+ };
+}
+
+pub fn DOMCall(
+ comptime class_name: string,
+ comptime Container: type,
+ comptime functionName: string,
+ comptime ResultType: type,
+ comptime dom_effect: DOMEffect,
+) type {
+ return extern struct {
+ const className = class_name;
+ pub const is_dom_call = true;
+ const Slowpath = @field(Container, functionName);
+ const SlowpathType = @TypeOf(@field(Container, functionName));
+ pub const shim = JSC.Shimmer(className, functionName, @This());
+ pub const name = class_name ++ "__" ++ functionName;
+
+ // Zig doesn't support @frameAddress(1)
+ // so we have to add a small wrapper fujnction
+ pub fn slowpath(
+ globalObject: *JSC.JSGlobalObject,
+ thisValue: JSC.JSValue,
+ arguments_ptr: [*]const JSC.JSValue,
+ arguments_len: usize,
+ ) callconv(.C) JSValue {
+ return @call(.{}, @field(Container, functionName), .{
+ globalObject,
+ thisValue,
+ arguments_ptr[0..arguments_len],
+ });
+ }
+
+ pub const fastpath = @field(Container, functionName ++ "WithoutTypeChecks");
+ pub const Fastpath = @TypeOf(fastpath);
+ pub const Arguments = std.meta.ArgsTuple(Fastpath);
+
+ pub const Export = shim.exportFunctions(.{
+ .@"slowpath" = slowpath,
+ .@"fastpath" = fastpath,
+ });
+
+ pub fn put(globalObject: *JSC.JSGlobalObject, value: JSValue) void {
+ shim.cppFn("put", .{ globalObject, value });
+ }
+
+ pub const effect = dom_effect;
+
+ pub fn printGenerateDOMJITSignature(comptime Writer: type, writer: Writer) !void {
+ const signatureName = "DOMJIT_" ++ shim.name ++ "_signature";
+ const slowPathName = Export[0].symbol_name;
+ const fastPathName = Export[1].symbol_name;
+ const Fields: []const std.builtin.Type.StructField = std.meta.fields(Arguments);
+
+ const options = .{
+ .name = functionName,
+ .exportName = name ++ "__put",
+ .signatureName = signatureName,
+ .IDLResultName = DOMCallResultType(ResultType),
+ .fastPathName = fastPathName,
+ .slowPathName = slowPathName,
+ .argumentsCount = Fields.len - 2,
+ };
+ {
+ const fmt =
+ \\extern "C" JSC_DECLARE_HOST_FUNCTION({[slowPathName]s}Wrapper);
+ \\extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL({[fastPathName]s}Wrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue
+ ;
+ try writer.print(fmt, .{ .fastPathName = options.fastPathName, .slowPathName = options.slowPathName });
+ }
+ {
+ switch (Fields.len - 2) {
+ 0 => @compileError("Must be > 0 arguments"),
+ 1 => {
+ try writer.writeAll(", ");
+ try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[2].field_type));
+ try writer.writeAll("));\n");
+ },
+ 2 => {
+ try writer.writeAll(", ");
+ try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[2].field_type));
+ try writer.writeAll(", ");
+ try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[3].field_type));
+ try writer.writeAll("));\n");
+ },
+ else => @compileError("Must be <= 3 arguments"),
+ }
+ }
+
+ {
+ const fmt =
+ \\
+ \\JSC_DEFINE_JIT_OPERATION({[fastPathName]s}Wrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue
+ ;
+ try writer.print(fmt, .{ .fastPathName = options.fastPathName });
+ }
+ {
+ switch (Fields.len - 2) {
+ 0 => @compileError("Must be > 0 arguments"),
+ 1 => {
+ try writer.writeAll(", ");
+ try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[2].field_type));
+ try writer.writeAll(" arg1)) {\n");
+ },
+ 2 => {
+ try writer.writeAll(", ");
+ try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[2].field_type));
+ try writer.writeAll("arg1, ");
+ try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[3].field_type));
+ try writer.writeAll(" arg2)) {\n");
+ },
+ else => @compileError("Must be <= 3 arguments"),
+ }
+ {
+ const fmt =
+ \\VM& vm = JSC::getVM(lexicalGlobalObject);
+ \\IGNORE_WARNINGS_BEGIN("frame-address")
+ \\CallFrame* callFrame = DECLARE_CALL_FRAME(vm);
+ \\IGNORE_WARNINGS_END
+ \\JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame);
+ \\return {[fastPathName]s}(lexicalGlobalObject, thisValue
+ ;
+ try writer.print(fmt, .{ .fastPathName = options.fastPathName });
+ }
+ {
+ switch (Fields.len - 2) {
+ 0 => @compileError("Must be > 0 arguments"),
+ 1 => {
+ try writer.writeAll(", arg1);\n}\n");
+ },
+ 2 => {
+ try writer.writeAll(", arg1, arg2);\n}\n");
+ },
+ else => @compileError("Must be <= 3 arguments"),
+ }
+ }
+ }
+
+ {
+ const fmt =
+ \\JSC_DEFINE_HOST_FUNCTION({[slowPathName]s}Wrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) {{
+ \\ return {[slowPathName]s}(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount());
+ \\}}
+ \\
+ \\extern "C" void {[exportName]s}(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) {{
+ \\ JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value));
+ \\ static const JSC::DOMJIT::Signature {[signatureName]s}(
+ \\ {[fastPathName]s}Wrapper,
+ \\ thisObject->classInfo(),
+ \\
+ ;
+
+ try writer.print(fmt, .{
+ .slowPathName = options.slowPathName,
+ .exportName = options.exportName,
+ .fastPathName = options.fastPathName,
+ .signatureName = options.signatureName,
+ });
+ }
+ if (effect.isPure()) {
+ try writer.writeAll("JSC::DOMJIT::Effect::forPure(),\n ");
+ } else if (effect.writes[0] == DOMEffect.pure.writes[0]) {
+ try writer.print(
+ "JSC::DOMJIT::Effect::forReadKinds(JSC::DFG::AbstractHeapKind::{s}, JSC::DFG::AbstractHeapKind::{s}, JSC::DFG::AbstractHeapKind::{s}, JSC::DFG::AbstractHeapKind::{s}),\n ",
+ .{
+ @tagName(effect.reads[0]),
+ @tagName(effect.reads[1]),
+ @tagName(effect.reads[2]),
+ @tagName(effect.reads[3]),
+ },
+ );
+ } else if (effect.reads[0] == DOMEffect.pure.reads[0]) {
+ try writer.print(
+ "JSC::DOMJIT::Effect::forWriteKinds(JSC::DFG::AbstractHeapKind::{s}, JSC::DFG::AbstractHeapKind::{s}, JSC::DFG::AbstractHeapKind::{s}, JSC::DFG::AbstractHeapKind::{s}),\n ",
+ .{
+ @tagName(effect.writes[0]),
+ @tagName(effect.writes[1]),
+ @tagName(effect.writes[2]),
+ @tagName(effect.writes[3]),
+ },
+ );
+ } else {
+ try writer.writeAll("JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()),\n ");
+ }
+
+ {
+ try writer.writeAll(DOMCallResultType(ResultType));
+ try writer.writeAll(",\n ");
+ }
+
+ switch (Fields.len - 2) {
+ 0 => @compileError("Must be > 0 arguments"),
+ 1 => {
+ try writer.writeAll(DOMCallArgumentType(Fields[2].field_type));
+ try writer.writeAll("\n ");
+ },
+ 2 => {
+ try writer.writeAll(DOMCallArgumentType(Fields[2].field_type));
+ try writer.writeAll(",\n ");
+ try writer.writeAll(DOMCallArgumentType(Fields[3].field_type));
+ try writer.writeAll("\n ");
+ },
+ else => @compileError("Must be <= 3 arguments"),
+ }
+
+ try writer.writeAll(");\n ");
+
+ {
+ const fmt =
+ \\ JSFunction* function = JSFunction::create(
+ \\ globalObject->vm(),
+ \\ globalObject,
+ \\ {[argumentsCount]d},
+ \\ String("{[name]s}"_s),
+ \\ {[slowPathName]s}Wrapper, ImplementationVisibility::Public, NoIntrinsic, {[slowPathName]s}Wrapper,
+ \\ &{[signatureName]s}
+ \\ );
+ \\ thisObject->putDirect(
+ \\ globalObject->vm(),
+ \\ Identifier::fromString(globalObject->vm(), "{[name]s}"_s),
+ \\ function,
+ \\ JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0
+ \\ );
+ \\}}
+ ;
+ try writer.print(fmt, .{
+ .argumentsCount = options.argumentsCount,
+ .name = options.name,
+ .slowPathName = options.slowPathName,
+ .signatureName = options.signatureName,
+ });
+ }
+ }
+
+ pub const Extern = [_][]const u8{"put"};
+
+ comptime {
+ if (!JSC.is_bindgen) {
+ @export(slowpath, .{ .name = Export[0].symbol_name });
+ @export(fastpath, .{ .name = Export[1].symbol_name });
+ } else {
+ _ = slowpath;
+ _ = fastpath;
+ }
+ }
+ };
+}
+
pub fn wrapWithHasContainer(
comptime Container: type,
comptime name: string,
diff --git a/src/bun.js/bindings/JSFFIFunction.cpp b/src/bun.js/bindings/JSFFIFunction.cpp
index e07f5b819..686cb0250 100644
--- a/src/bun.js/bindings/JSFFIFunction.cpp
+++ b/src/bun.js/bindings/JSFFIFunction.cpp
@@ -30,6 +30,12 @@
#include "JavaScriptCore/VM.h"
#include "ZigGlobalObject.h"
+#include <JavaScriptCore/DOMJITAbstractHeap.h>
+#include "DOMJITIDLConvert.h"
+#include "DOMJITIDLType.h"
+#include "DOMJITIDLTypeFilter.h"
+#include "DOMJITHelpers.h"
+
extern "C" Zig::JSFFIFunction* Bun__CreateFFIFunction(Zig::GlobalObject* globalObject, const ZigString* symbolName, unsigned argCount, Zig::FFIFunction functionPointer)
{
JSC::VM& vm = globalObject->vm();
diff --git a/src/bun.js/bindings/ZigGeneratedCode.cpp b/src/bun.js/bindings/ZigGeneratedCode.cpp
new file mode 100644
index 000000000..e5e377d82
--- /dev/null
+++ b/src/bun.js/bindings/ZigGeneratedCode.cpp
@@ -0,0 +1,60 @@
+#include "root.h"
+
+#include <JavaScriptCore/DOMJITAbstractHeap.h>
+#include "DOMJITIDLConvert.h"
+#include "DOMJITIDLType.h"
+#include "DOMJITIDLTypeFilter.h"
+#include "DOMJITHelpers.h"
+#include <JavaScriptCore/DFGAbstractHeap.h>
+
+#include "JSDOMConvertBufferSource.h"
+
+using namespace JSC;
+using namespace WebCore;
+
+/* -- BEGIN DOMCall DEFINITIONS -- */
+
+extern "C" JSC_DECLARE_HOST_FUNCTION(FFI__ptr__slowpathWrapper);
+extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(FFI__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, JSC::JSUint8Array*));
+
+JSC_DEFINE_JIT_OPERATION(FFI__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, JSC::JSUint8Array* arg1))
+{
+ VM& vm = JSC::getVM(lexicalGlobalObject);
+ IGNORE_WARNINGS_BEGIN("frame-address")
+ CallFrame* callFrame = DECLARE_CALL_FRAME(vm);
+ IGNORE_WARNINGS_END
+ JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame);
+ return FFI__ptr__fastpath(lexicalGlobalObject, thisValue, arg1);
+}
+JSC_DEFINE_HOST_FUNCTION(FFI__ptr__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame))
+{
+ return FFI__ptr__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount());
+}
+
+constexpr JSC::DFG::AbstractHeapKind encodeIntoRead[4] = { JSC::DFG::Absolute, JSC::DFG::MiscFields, JSC::DFG::TypedArrayProperties };
+constexpr JSC::DFG::AbstractHeapKind encodeIntoWrite[4] = { JSC::DFG::Absolute, JSC::DFG::TypedArrayProperties };
+
+extern "C" void FFI__ptr__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value)
+{
+ JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value));
+ static const JSC::DOMJIT::Signature DOMJIT_ptr_signature(
+ FFI__ptr__fastpathWrapper,
+ thisObject->classInfo(),
+ JSC::DOMJIT::Effect::forReadWriteKinds(encodeIntoRead, encodeIntoWrite),
+ JSC::SpecNonIntAsDouble,
+ JSC::SpecUint8Array);
+ JSFunction* function = JSFunction::create(
+ globalObject->vm(),
+ globalObject,
+ 1,
+ String("ptr"_s),
+ FFI__ptr__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, FFI__ptr__slowpathWrapper,
+ &DOMJIT_ptr_signature);
+ thisObject->putDirect(
+ globalObject->vm(),
+ Identifier::fromString(globalObject->vm(), "ptr"_s),
+ function,
+ JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0);
+}
+
+/* -- END DOMCall DEFINITIONS-- */
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp
index 52c25d545..c7c43c523 100644
--- a/src/bun.js/bindings/ZigGlobalObject.cpp
+++ b/src/bun.js/bindings/ZigGlobalObject.cpp
@@ -1020,6 +1020,7 @@ JSC:
obj->putDirectCustomAccessor(vm, JSC::PropertyName(JSC::Identifier::fromString(vm, "getterSetter"_s)), JSC::CustomGetterSetter::create(vm, noop_getter, noop_setter), 0);
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);
return JSC::JSValue::encode(obj);
}
@@ -1524,6 +1525,7 @@ extern "C" {
class JSPerformanceObject;
static JSC_DECLARE_HOST_FUNCTION(functionPerformanceNow);
static JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(functionPerformanceNowWithoutTypeCheck, JSC::EncodedJSValue, (JSC::JSGlobalObject*, JSPerformanceObject*));
+static JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(functionBunNanosecondsWithoutTypeCheck, JSC::EncodedJSValue, (JSC::JSGlobalObject*, JSObject*));
}
class JSPerformanceObject final : public JSC::JSNonFinalObject {
diff --git a/src/bun.js/bindings/ZigLazyStaticFunctions-inlines.h b/src/bun.js/bindings/ZigLazyStaticFunctions-inlines.h
index ebef57b4a..c97393723 100644
--- a/src/bun.js/bindings/ZigLazyStaticFunctions-inlines.h
+++ b/src/bun.js/bindings/ZigLazyStaticFunctions-inlines.h
@@ -3,141 +3,31 @@
namespace Zig {
- template<typename Visitor>
- void LazyStaticFunctions::visit(Visitor& visitor) {
- this->m_Bun__HTTPRequestContext__reject.visit(visitor);
- this->m_Bun__HTTPRequestContext__resolve.visit(visitor);
- this->m_Bun__HTTPRequestContextTLS__reject.visit(visitor);
- this->m_Bun__HTTPRequestContextTLS__resolve.visit(visitor);
- this->m_Bun__HTTPRequestContextDebug__reject.visit(visitor);
- this->m_Bun__HTTPRequestContextDebug__resolve.visit(visitor);
- this->m_Bun__HTTPRequestContextDebugTLS__reject.visit(visitor);
- this->m_Bun__HTTPRequestContextDebugTLS__resolve.visit(visitor);
-
- }
-
- void LazyStaticFunctions::init(Zig::GlobalObject *globalObject) {
-
- m_Bun__HTTPRequestContext__reject.initLater(
- [](const JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction>::Initializer& init) {
- WTF::String functionName = WTF::String("reject"_s);
- Zig::JSFFIFunction* function = Zig::JSFFIFunction::create(
- init.vm,
- init.owner,
- 1,
- functionName,
- Bun__HTTPRequestContext__reject,
- JSC::NoIntrinsic,
- Bun__HTTPRequestContext__reject
- );
- init.set(function);
- });
-
- m_Bun__HTTPRequestContext__resolve.initLater(
- [](const JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction>::Initializer& init) {
- WTF::String functionName = WTF::String("resolve"_s);
- Zig::JSFFIFunction* function = Zig::JSFFIFunction::create(
- init.vm,
- init.owner,
- 1,
- functionName,
- Bun__HTTPRequestContext__resolve,
- JSC::NoIntrinsic,
- Bun__HTTPRequestContext__resolve
- );
- init.set(function);
- });
-
- m_Bun__HTTPRequestContextTLS__reject.initLater(
- [](const JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction>::Initializer& init) {
- WTF::String functionName = WTF::String("reject"_s);
- Zig::JSFFIFunction* function = Zig::JSFFIFunction::create(
- init.vm,
- init.owner,
- 1,
- functionName,
- Bun__HTTPRequestContextTLS__reject,
- JSC::NoIntrinsic,
- Bun__HTTPRequestContextTLS__reject
- );
- init.set(function);
- });
-
- m_Bun__HTTPRequestContextTLS__resolve.initLater(
- [](const JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction>::Initializer& init) {
- WTF::String functionName = WTF::String("resolve"_s);
- Zig::JSFFIFunction* function = Zig::JSFFIFunction::create(
- init.vm,
- init.owner,
- 1,
- functionName,
- Bun__HTTPRequestContextTLS__resolve,
- JSC::NoIntrinsic,
- Bun__HTTPRequestContextTLS__resolve
- );
- init.set(function);
- });
-
- m_Bun__HTTPRequestContextDebug__reject.initLater(
- [](const JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction>::Initializer& init) {
- WTF::String functionName = WTF::String("reject"_s);
- Zig::JSFFIFunction* function = Zig::JSFFIFunction::create(
- init.vm,
- init.owner,
- 1,
- functionName,
- Bun__HTTPRequestContextDebug__reject,
- JSC::NoIntrinsic,
- Bun__HTTPRequestContextDebug__reject
- );
- init.set(function);
- });
-
- m_Bun__HTTPRequestContextDebug__resolve.initLater(
- [](const JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction>::Initializer& init) {
- WTF::String functionName = WTF::String("resolve"_s);
- Zig::JSFFIFunction* function = Zig::JSFFIFunction::create(
- init.vm,
- init.owner,
- 1,
- functionName,
- Bun__HTTPRequestContextDebug__resolve,
- JSC::NoIntrinsic,
- Bun__HTTPRequestContextDebug__resolve
- );
- init.set(function);
- });
-
- m_Bun__HTTPRequestContextDebugTLS__reject.initLater(
- [](const JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction>::Initializer& init) {
- WTF::String functionName = WTF::String("reject"_s);
- Zig::JSFFIFunction* function = Zig::JSFFIFunction::create(
- init.vm,
- init.owner,
- 1,
- functionName,
- Bun__HTTPRequestContextDebugTLS__reject,
- JSC::NoIntrinsic,
- Bun__HTTPRequestContextDebugTLS__reject
- );
- init.set(function);
- });
-
- m_Bun__HTTPRequestContextDebugTLS__resolve.initLater(
- [](const JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction>::Initializer& init) {
- WTF::String functionName = WTF::String("resolve"_s);
- Zig::JSFFIFunction* function = Zig::JSFFIFunction::create(
- init.vm,
- init.owner,
- 1,
- functionName,
- Bun__HTTPRequestContextDebugTLS__resolve,
- JSC::NoIntrinsic,
- Bun__HTTPRequestContextDebugTLS__resolve
- );
- init.set(function);
- });
-
- }
+/* -- BEGIN DOMCall DEFINITIONS -- */
+
+static void DOMCall__FFI__ptr__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value)
+{
+ JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value));
+ static const JSC::DOMJIT::Signature DOMJIT_ptr_signature(
+ FFI__ptr__fastpath,
+ thisObject->classInfo(),
+ JSC::DOMJIT::Effect::forPure(),
+ JSC::SpecHeapTop,
+ JSC::SpecUint8Array);
+ JSFunction* function = JSFunction::create(
+ globalObject->vm(),
+ globalObject,
+ 1,
+ String("ptr"_s),
+ FFI__ptr__slowpath, ImplementationVisibility::Public, NoIntrinsic, FFI__ptr__slowpath,
+ &DOMJIT_ptr_signature);
+ thisObject->putDirect(
+ globalObject->vm(),
+ Identifier::fromString(globalObject->vm(), "ptr"_s),
+ function,
+ JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0);
+}
+
+/* -- END DOMCall DEFINITIONS-- */
} // namespace Zig
diff --git a/src/bun.js/bindings/ZigLazyStaticFunctions.h b/src/bun.js/bindings/ZigLazyStaticFunctions.h
index f262d6ce0..9f7211cd2 100644
--- a/src/bun.js/bindings/ZigLazyStaticFunctions.h
+++ b/src/bun.js/bindings/ZigLazyStaticFunctions.h
@@ -5,7 +5,7 @@
namespace Zig {
class GlobalObject;
class JSFFIFunction;
-
+
class LazyStaticFunctions {
public:
@@ -13,38 +13,10 @@ namespace Zig {
template<typename Visitor>
void visit(Visitor& visitor);
-
-
- /* -- BEGIN FUNCTION DEFINITIONS -- */
-
-#pragma mark HTTPRequestContext
-
- JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction> m_Bun__HTTPRequestContext__reject;
- Zig::JSFFIFunction* get__Bun__HTTPRequestContext__reject(Zig::GlobalObject *globalObject) { return m_Bun__HTTPRequestContext__reject.getInitializedOnMainThread(globalObject); }
- JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction> m_Bun__HTTPRequestContext__resolve;
- Zig::JSFFIFunction* get__Bun__HTTPRequestContext__resolve(Zig::GlobalObject *globalObject) { return m_Bun__HTTPRequestContext__resolve.getInitializedOnMainThread(globalObject); }
-
-#pragma mark HTTPRequestContextTLS
- JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction> m_Bun__HTTPRequestContextTLS__reject;
- Zig::JSFFIFunction* get__Bun__HTTPRequestContextTLS__reject(Zig::GlobalObject *globalObject) { return m_Bun__HTTPRequestContextTLS__reject.getInitializedOnMainThread(globalObject); }
- JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction> m_Bun__HTTPRequestContextTLS__resolve;
- Zig::JSFFIFunction* get__Bun__HTTPRequestContextTLS__resolve(Zig::GlobalObject *globalObject) { return m_Bun__HTTPRequestContextTLS__resolve.getInitializedOnMainThread(globalObject); }
-
-#pragma mark HTTPRequestContextDebug
-
- JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction> m_Bun__HTTPRequestContextDebug__reject;
- Zig::JSFFIFunction* get__Bun__HTTPRequestContextDebug__reject(Zig::GlobalObject *globalObject) { return m_Bun__HTTPRequestContextDebug__reject.getInitializedOnMainThread(globalObject); }
- JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction> m_Bun__HTTPRequestContextDebug__resolve;
- Zig::JSFFIFunction* get__Bun__HTTPRequestContextDebug__resolve(Zig::GlobalObject *globalObject) { return m_Bun__HTTPRequestContextDebug__resolve.getInitializedOnMainThread(globalObject); }
-
-#pragma mark HTTPRequestContextDebugTLS
-
- JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction> m_Bun__HTTPRequestContextDebugTLS__reject;
- Zig::JSFFIFunction* get__Bun__HTTPRequestContextDebugTLS__reject(Zig::GlobalObject *globalObject) { return m_Bun__HTTPRequestContextDebugTLS__reject.getInitializedOnMainThread(globalObject); }
- JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction> m_Bun__HTTPRequestContextDebugTLS__resolve;
- Zig::JSFFIFunction* get__Bun__HTTPRequestContextDebugTLS__resolve(Zig::GlobalObject *globalObject) { return m_Bun__HTTPRequestContextDebugTLS__resolve.getInitializedOnMainThread(globalObject); }
+ /* -- BEGIN FUNCTION DEFINITIONS -- */
+
/* -- END FUNCTION DEFINITIONS-- */
};
diff --git a/src/bun.js/bindings/bindings-generator.zig b/src/bun.js/bindings/bindings-generator.zig
index 75f300b63..3e5eb78cc 100644
--- a/src/bun.js/bindings/bindings-generator.zig
+++ b/src/bun.js/bindings/bindings-generator.zig
@@ -26,7 +26,7 @@ pub fn main() anyerror!void {
const paths = [_][]const u8{ std.fs.path.dirname(src.file) orelse return error.BadPath, "headers.h" };
const paths2 = [_][]const u8{ std.fs.path.dirname(src.file) orelse return error.BadPath, "headers-cpp.h" };
const paths3 = [_][]const u8{ std.fs.path.dirname(src.file) orelse return error.BadPath, "ZigLazyStaticFunctions.h" };
- const paths4 = [_][]const u8{ std.fs.path.dirname(src.file) orelse return error.BadPath, "ZigLazyStaticFunctions-inlines.h" };
+ const paths4 = [_][]const u8{ std.fs.path.dirname(src.file) orelse return error.BadPath, "ZigGeneratedCode.cpp" };
const cpp = try std.fs.createFileAbsolute(try std.fs.path.join(allocator, &paths2), .{});
const file = try std.fs.createFileAbsolute(try std.fs.path.join(allocator, &paths), .{});
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig
index 1c5243336..8a131efe6 100644
--- a/src/bun.js/bindings/bindings.zig
+++ b/src/bun.js/bindings/bindings.zig
@@ -854,6 +854,22 @@ pub const SystemError = extern struct {
};
pub const ReturnableException = *?*Exception;
+pub const Sizes = @import("../bindings/sizes.zig");
+
+pub const JSUint8Array = opaque {
+ pub const name = "Uint8Array_alias";
+ pub fn ptr(this: *JSUint8Array) [*]u8 {
+ return @intToPtr(*[*]u8, @ptrToInt(this) + Sizes.Bun_FFI_PointerOffsetToTypedArrayVector).*;
+ }
+
+ pub fn len(this: *JSUint8Array) usize {
+ return @intToPtr(*usize, @ptrToInt(this) + Sizes.Bun_FFI_PointerOffsetToTypedArrayLength).*;
+ }
+
+ pub fn slice(this: *JSUint8Array) []u8 {
+ return this.ptr()[0..this.len()];
+ }
+};
pub const JSCell = extern struct {
pub const shim = Shimmer("JSC", "JSCell", @This());
@@ -3847,3 +3863,10 @@ pub fn JSPropertyIterator(comptime options: JSPropertyIteratorOptions) type {
}
};
}
+
+// DOMCall Fields
+pub const __DOMCall_ptr = @import("../api/bun.zig").FFI.Class.functionDefinitions.ptr;
+
+pub const DOMCalls = .{
+ @import("../api/bun.zig").FFI,
+};
diff --git a/src/bun.js/bindings/header-gen.zig b/src/bun.js/bindings/header-gen.zig
index ab93fad47..8e79dc5f9 100644
--- a/src/bun.js/bindings/header-gen.zig
+++ b/src/bun.js/bindings/header-gen.zig
@@ -655,14 +655,11 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp
var impl_fourth_buffer = std.ArrayList(u8).init(std.heap.c_allocator);
var impl_fourth_writer = impl_fourth_buffer.writer();
- var lazy_functions_buffer = std.ArrayList(u8).init(std.heap.c_allocator);
- var lazy_functions_buffer_writer = lazy_functions_buffer.writer();
-
var lazy_function_definitions_buffer = std.ArrayList(u8).init(std.heap.c_allocator);
- var lazy_function_definitions_writer = lazy_function_definitions_buffer.writer();
+ // var lazy_function_definitions_writer = lazy_function_definitions_buffer.writer();
- var lazy_function_visitor_buffer = std.ArrayList(u8).init(std.heap.c_allocator);
- var lazy_function_visitor_writer = lazy_function_visitor_buffer.writer();
+ var dom_buffer = std.ArrayList(u8).init(std.heap.c_allocator);
+ var dom_writer = dom_buffer.writer();
// inline for (import.all_static_externs) |static_extern, i| {
// const Type = static_extern.Type;
@@ -689,7 +686,36 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp
var to_get_sizes: usize = 0;
const exclude_from_cpp = comptime [_][]const u8{ "ZigString", "ZigException" };
- const TypesToCheck = [_]type{ first_import, second_import };
+
+ const TypesToCheck: []type = comptime brk: {
+ var all_types: [100]type = undefined;
+ all_types[0] = first_import;
+ all_types[1] = second_import;
+ var counter: usize = 2;
+ inline for (first_import.DOMCalls) |Type| {
+ inline for (std.meta.fieldNames(@TypeOf(Type.Class.functionDefinitions))) |static_function_name| {
+ const static_function = @field(Type.Class.functionDefinitions, static_function_name);
+ if (@TypeOf(static_function) == type and @hasDecl(static_function, "is_dom_call")) {
+ all_types[counter] = static_function;
+ counter += 1;
+ }
+ }
+ }
+
+ break :brk all_types[0..counter];
+ };
+
+ inline for (first_import.DOMCalls) |Type| {
+ inline for (comptime std.meta.fieldNames(@TypeOf(Type.Class.functionDefinitions))) |static_function_name| {
+ const static_function = @field(Type.Class.functionDefinitions, static_function_name);
+ if (comptime @TypeOf(static_function) == type and @hasDecl(static_function, "is_dom_call")) {
+ dom_writer.writeAll("\n\n") catch unreachable;
+ static_function.printGenerateDOMJITSignature(@TypeOf(&dom_writer), &dom_writer) catch unreachable;
+ dom_writer.writeAll("\n\n") catch unreachable;
+ }
+ }
+ }
+
inline for (TypesToCheck) |BaseType| {
const all_decls = comptime std.meta.declarations(BaseType);
inline for (all_decls) |_decls| {
@@ -798,74 +824,74 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp
}
}
- if (@hasDecl(Type, "lazy_static_functions")) {
- const ExportLIst = comptime brk: {
- const Sorder = struct {
- pub fn lessThan(_: @This(), comptime lhs: StaticExport, comptime rhs: StaticExport) bool {
- return std.ascii.orderIgnoreCase(lhs.symbol_name, rhs.symbol_name) == std.math.Order.lt;
- }
- };
- var extern_list = Type.lazy_static_functions;
- std.sort.sort(StaticExport, &extern_list, Sorder{}, Sorder.lessThan);
- break :brk extern_list;
- };
-
- gen.direction = C_Generator.Direction.export_zig;
- if (ExportLIst.len > 0) {
- lazy_function_definitions_writer.writeAll("\n#pragma mark ") catch unreachable;
- lazy_function_definitions_writer.writeAll(Type.shim.name) catch unreachable;
- lazy_function_definitions_writer.writeAll("\n\n") catch unreachable;
-
- inline for (ExportLIst) |static_export| {
- const exp: StaticExport = static_export;
- lazy_function_definitions_writer.print(" JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction> m_{s};", .{exp.symbol_name}) catch unreachable;
- lazy_function_definitions_writer.writeAll("\n") catch unreachable;
-
- lazy_function_definitions_writer.print(
- " Zig::JSFFIFunction* get__{s}(Zig::GlobalObject *globalObject) {{ return m_{s}.getInitializedOnMainThread(globalObject); }}",
- .{ exp.symbol_name, exp.symbol_name },
- ) catch unreachable;
- lazy_function_definitions_writer.writeAll("\n") catch unreachable;
-
- const impl_format =
- \\
- \\ m_{s}.initLater(
- \\ [](const JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction>::Initializer& init) {{
- \\ WTF::String functionName = WTF::String("{s}"_s);
- \\ Zig::JSFFIFunction* function = Zig::JSFFIFunction::create(
- \\ init.vm,
- \\ init.owner,
- \\ 1,
- \\ functionName,
- \\ {s},
- \\ JSC::NoIntrinsic,
- \\ {s}
- \\ );
- \\ init.set(function);
- \\ }});
- \\
- ;
-
- lazy_functions_buffer_writer.print(
- impl_format,
- .{
- exp.symbol_name,
- exp.local_name,
- exp.symbol_name,
- exp.symbol_name,
- },
- ) catch unreachable;
-
- lazy_function_visitor_writer.print(
- \\ this->m_{s}.visit(visitor);
- \\
- ,
- .{exp.symbol_name},
- ) catch unreachable;
- }
- gen.write("\n");
- }
- }
+ // if (@hasDecl(Type, "lazy_static_functions")) {
+ // const ExportLIst = comptime brk: {
+ // const Sorder = struct {
+ // pub fn lessThan(_: @This(), comptime lhs: StaticExport, comptime rhs: StaticExport) bool {
+ // return std.ascii.orderIgnoreCase(lhs.symbol_name, rhs.symbol_name) == std.math.Order.lt;
+ // }
+ // };
+ // var extern_list = Type.lazy_static_functions;
+ // std.sort.sort(StaticExport, &extern_list, Sorder{}, Sorder.lessThan);
+ // break :brk extern_list;
+ // };
+
+ // gen.direction = C_Generator.Direction.export_zig;
+ // if (ExportLIst.len > 0) {
+ // lazy_function_definitions_writer.writeAll("\n#pragma mark ") catch unreachable;
+ // lazy_function_definitions_writer.writeAll(Type.shim.name) catch unreachable;
+ // lazy_function_definitions_writer.writeAll("\n\n") catch unreachable;
+
+ // inline for (ExportLIst) |static_export| {
+ // const exp: StaticExport = static_export;
+ // lazy_function_definitions_writer.print(" JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction> m_{s};", .{exp.symbol_name}) catch unreachable;
+ // lazy_function_definitions_writer.writeAll("\n") catch unreachable;
+
+ // lazy_function_definitions_writer.print(
+ // " Zig::JSFFIFunction* get__{s}(Zig::GlobalObject *globalObject) {{ return m_{s}.getInitializedOnMainThread(globalObject); }}",
+ // .{ exp.symbol_name, exp.symbol_name },
+ // ) catch unreachable;
+ // lazy_function_definitions_writer.writeAll("\n") catch unreachable;
+
+ // const impl_format =
+ // \\
+ // \\ m_{s}.initLater(
+ // \\ [](const JSC::LazyProperty<Zig::GlobalObject, Zig::JSFFIFunction>::Initializer& init) {{
+ // \\ WTF::String functionName = WTF::String("{s}"_s);
+ // \\ Zig::JSFFIFunction* function = Zig::JSFFIFunction::create(
+ // \\ init.vm,
+ // \\ init.owner,
+ // \\ 1,
+ // \\ functionName,
+ // \\ {s},
+ // \\ JSC::NoIntrinsic,
+ // \\ {s}
+ // \\ );
+ // \\ init.set(function);
+ // \\ }});
+ // \\
+ // ;
+
+ // lazy_functions_buffer_writer.print(
+ // impl_format,
+ // .{
+ // exp.symbol_name,
+ // exp.local_name,
+ // exp.symbol_name,
+ // exp.symbol_name,
+ // },
+ // ) catch unreachable;
+
+ // lazy_function_visitor_writer.print(
+ // \\ this->m_{s}.visit(visitor);
+ // \\
+ // ,
+ // .{exp.symbol_name},
+ // ) catch unreachable;
+ // }
+ // gen.write("\n");
+ // }
+ // }
}
}
}
@@ -892,7 +918,7 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp
\\namespace Zig {{
\\ class GlobalObject;
\\ class JSFFIFunction;
- \\
+ \\
\\ class LazyStaticFunctions {{
\\ public:
\\
@@ -900,8 +926,8 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp
\\
\\ template<typename Visitor>
\\ void visit(Visitor& visitor);
- \\
- \\
+ \\
+ \\
\\ /* -- BEGIN FUNCTION DEFINITIONS -- */
\\ {s}
\\ /* -- END FUNCTION DEFINITIONS-- */
@@ -912,25 +938,28 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp
, .{lazy_function_definitions_buffer.items}) catch unreachable;
lazy_functions_impl.writer().print(
- \\// GENERATED FILE
- \\#pragma once
+ \\ #include "root.h"
+ \\
+ \\ #include <JavaScriptCore/DOMJITAbstractHeap.h>
+ \\ #include "DOMJITIDLConvert.h"
+ \\ #include "DOMJITIDLType.h"
+ \\ #include "DOMJITIDLTypeFilter.h"
+ \\ #include "DOMJITHelpers.h"
+ \\ #include <JavaScriptCore/DFGAbstractHeap.h>
+ \\
+ \\ #include "JSDOMConvertBufferSource.h"
+ \\
+ \\ using namespace JSC;
+ \\ using namespace WebCore;
\\
- \\namespace Zig {{
\\
- \\ template<typename Visitor>
- \\ void LazyStaticFunctions::visit(Visitor& visitor) {{
- \\ {s}
- \\ }}
- \\
- \\ void LazyStaticFunctions::init(Zig::GlobalObject *globalObject) {{
- \\ {s}
- \\ }}
+ \\ /* -- BEGIN DOMCall DEFINITIONS -- */
+ \\ {s}
+ \\ /* -- END DOMCall DEFINITIONS-- */
\\
- \\}} // namespace Zig
\\
, .{
- lazy_function_visitor_buffer.items,
- lazy_functions_buffer.items,
+ dom_buffer.items,
}) catch unreachable;
const NamespaceMap = std.StringArrayHashMap(std.BufMap);
diff --git a/src/bun.js/bindings/headers-cpp.h b/src/bun.js/bindings/headers-cpp.h
index bef2b16e4..bd0174d42 100644
--- a/src/bun.js/bindings/headers-cpp.h
+++ b/src/bun.js/bindings/headers-cpp.h
@@ -1,4 +1,4 @@
-//-- AUTOGENERATED FILE -- 1660434151
+//-- AUTOGENERATED FILE -- 1660480861
// clang-format off
#pragma once
@@ -210,38 +210,27 @@ extern "C" const size_t WTF__StringView_object_align_ = alignof(WTF::StringView)
#ifndef INCLUDED__ZigGlobalObject_h_
#define INCLUDED__ZigGlobalObject_h_
-#include ""ZigGlobalObject.h""
+#include "ZigGlobalObject.h"
#endif
extern "C" const size_t Zig__GlobalObject_object_size_ = sizeof(Zig::GlobalObject);
extern "C" const size_t Zig__GlobalObject_object_align_ = alignof(Zig::GlobalObject);
-#ifndef INCLUDED_Path_h
-#define INCLUDED_Path_h
-#include "Path.h"
-#endif
-extern "C" const size_t Bun__Path_object_size_ = sizeof(Bun__Path);
-extern "C" const size_t Bun__Path_object_align_ = alignof(Bun__Path);
#ifndef INCLUDED__ZigConsoleClient_h_
#define INCLUDED__ZigConsoleClient_h_
-#include ""ZigConsoleClient.h""
+#include "ZigConsoleClient.h"
#endif
extern "C" const size_t Zig__ConsoleClient_object_size_ = sizeof(Zig::ConsoleClient);
extern "C" const size_t Zig__ConsoleClient_object_align_ = alignof(Zig::ConsoleClient);
-#ifndef INCLUDED_
-#define INCLUDED_
-#include ""
-#endif
+#include "JSSink.h"
-extern "C" const size_t Bun__Timer_object_size_ = sizeof(Bun__Timer);
-extern "C" const size_t Bun__Timer_object_align_ = alignof(Bun__Timer);
-const size_t sizes[32] = {sizeof(JSC::JSObject), sizeof(WebCore::DOMURL), sizeof(WebCore::FetchHeaders), sizeof(SystemError), sizeof(JSC::JSCell), sizeof(JSC::JSString), sizeof(Inspector::ScriptArguments), sizeof(JSC::JSModuleLoader), sizeof(JSC::JSModuleRecord), sizeof(JSC::JSPromise), sizeof(JSC::JSInternalPromise), sizeof(JSC::SourceOrigin), sizeof(JSC::SourceCode), sizeof(JSC::JSFunction), sizeof(JSC::JSGlobalObject), sizeof(WTF::URL), sizeof(WTF::String), sizeof(JSC::JSValue), sizeof(JSC::PropertyName), sizeof(JSC::Exception), sizeof(JSC::VM), sizeof(JSC::ThrowScope), sizeof(JSC::CatchScope), sizeof(JSC::Identifier), sizeof(WTF::StringImpl), sizeof(WTF::ExternalStringImpl), sizeof(WTF::StringView), sizeof(Zig::GlobalObject), sizeof(Bun__Path), sizeof(ArrayBufferSink), sizeof(HTTPSResponseSink), sizeof(HTTPResponseSink)};
+const size_t sizes[33] = {sizeof(JSC::JSObject), sizeof(WebCore::DOMURL), sizeof(WebCore::FetchHeaders), sizeof(SystemError), sizeof(JSC::JSCell), sizeof(JSC::JSString), sizeof(Inspector::ScriptArguments), sizeof(JSC::JSModuleLoader), sizeof(JSC::JSModuleRecord), sizeof(JSC::JSPromise), sizeof(JSC::JSInternalPromise), sizeof(JSC::SourceOrigin), sizeof(JSC::SourceCode), sizeof(JSC::JSFunction), sizeof(JSC::JSGlobalObject), sizeof(WTF::URL), sizeof(WTF::String), sizeof(JSC::JSValue), sizeof(JSC::PropertyName), sizeof(JSC::Exception), sizeof(JSC::VM), sizeof(JSC::ThrowScope), sizeof(JSC::CatchScope), sizeof(JSC::Identifier), sizeof(WTF::StringImpl), sizeof(WTF::ExternalStringImpl), sizeof(WTF::StringView),sizeof(Zig::GlobalObject), sizeof(WebCore::ArrayBufferSink), sizeof(WebCore::HTTPSResponseSink), sizeof(WebCore::HTTPResponseSink)};
-const char* names[32] = {"JSC__JSObject", "WebCore__DOMURL", "WebCore__FetchHeaders", "SystemError", "JSC__JSCell", "JSC__JSString", "Inspector__ScriptArguments", "JSC__JSModuleLoader", "JSC__JSModuleRecord", "JSC__JSPromise", "JSC__JSInternalPromise", "JSC__SourceOrigin", "JSC__SourceCode", "JSC__JSFunction", "JSC__JSGlobalObject", "WTF__URL", "WTF__String", "JSC__JSValue", "JSC__PropertyName", "JSC__Exception", "JSC__VM", "JSC__ThrowScope", "JSC__CatchScope", "JSC__Identifier", "WTF__StringImpl", "WTF__ExternalStringImpl", "WTF__StringView", "Zig__GlobalObject", "Bun__Path", "ArrayBufferSink", "HTTPSResponseSink", "HTTPResponseSink"};
+const char* names[33] = {"JSC__JSObject", "WebCore__DOMURL", "WebCore__FetchHeaders", "SystemError", "JSC__JSCell", "JSC__JSString", "Inspector__ScriptArguments", "JSC__JSModuleLoader", "JSC__JSModuleRecord", "JSC__JSPromise", "JSC__JSInternalPromise", "JSC__SourceOrigin", "JSC__SourceCode", "JSC__JSFunction", "JSC__JSGlobalObject", "WTF__URL", "WTF__String", "JSC__JSValue", "JSC__PropertyName", "JSC__Exception", "JSC__VM", "JSC__ThrowScope", "JSC__CatchScope", "JSC__Identifier", "WTF__StringImpl", "WTF__ExternalStringImpl", "WTF__StringView", "Zig__GlobalObject", "WebCore__ArrayBufferSink", "WebCore__HTTPSResponseSink", "WebCore__HTTPResponseSink"};
-const size_t aligns[32] = {alignof(JSC::JSObject), alignof(WebCore::DOMURL), alignof(WebCore::FetchHeaders), alignof(SystemError), alignof(JSC::JSCell), alignof(JSC::JSString), alignof(Inspector::ScriptArguments), alignof(JSC::JSModuleLoader), alignof(JSC::JSModuleRecord), alignof(JSC::JSPromise), alignof(JSC::JSInternalPromise), alignof(JSC::SourceOrigin), alignof(JSC::SourceCode), alignof(JSC::JSFunction), alignof(JSC::JSGlobalObject), alignof(WTF::URL), alignof(WTF::String), alignof(JSC::JSValue), alignof(JSC::PropertyName), alignof(JSC::Exception), alignof(JSC::VM), alignof(JSC::ThrowScope), alignof(JSC::CatchScope), alignof(JSC::Identifier), alignof(WTF::StringImpl), alignof(WTF::ExternalStringImpl), alignof(WTF::StringView), alignof(Zig::GlobalObject), alignof(Bun__Path), alignof(ArrayBufferSink), alignof(HTTPSResponseSink), alignof(HTTPResponseSink)};
+const size_t aligns[33] = {alignof(JSC::JSObject), alignof(WebCore::DOMURL), alignof(WebCore::FetchHeaders), alignof(SystemError), alignof(JSC::JSCell), alignof(JSC::JSString), alignof(Inspector::ScriptArguments), alignof(JSC::JSModuleLoader), alignof(JSC::JSModuleRecord), alignof(JSC::JSPromise), alignof(JSC::JSInternalPromise), alignof(JSC::SourceOrigin), alignof(JSC::SourceCode), alignof(JSC::JSFunction), alignof(JSC::JSGlobalObject), alignof(WTF::URL), alignof(WTF::String), alignof(JSC::JSValue), alignof(JSC::PropertyName), alignof(JSC::Exception), alignof(JSC::VM), alignof(JSC::ThrowScope), alignof(JSC::CatchScope), alignof(JSC::Identifier), alignof(WTF::StringImpl), alignof(WTF::ExternalStringImpl), alignof(WTF::StringView),alignof(Zig::GlobalObject), alignof(WebCore::ArrayBufferSink), alignof(WebCore::HTTPSResponseSink), alignof(WebCore::HTTPResponseSink)};
diff --git a/src/bun.js/bindings/headers-handwritten.h b/src/bun.js/bindings/headers-handwritten.h
index 32133c798..eb27088b8 100644
--- a/src/bun.js/bindings/headers-handwritten.h
+++ b/src/bun.js/bindings/headers-handwritten.h
@@ -160,10 +160,13 @@ typedef void WebSocketClientTLS;
#ifndef __cplusplus
typedef struct Bun__ArrayBuffer Bun__ArrayBuffer;
+typedef struct Uint8Array_alias Uint8Array_alias;
#endif
#ifdef __cplusplus
+using Uint8Array_alias = JSC::JSUint8Array;
+
typedef struct {
char* ptr;
uint32_t offset;
diff --git a/src/bun.js/bindings/headers.h b/src/bun.js/bindings/headers.h
index 85781699a..e422d4cb0 100644
--- a/src/bun.js/bindings/headers.h
+++ b/src/bun.js/bindings/headers.h
@@ -1,5 +1,5 @@
// clang-format off
-//-- AUTOGENERATED FILE -- 1660434151
+//-- AUTOGENERATED FILE -- 1660480861
#pragma once
#include <stddef.h>
@@ -88,9 +88,10 @@ typedef void* JSClassRef;
typedef bJSC__JSModuleLoader JSC__JSModuleLoader; // JSC::JSModuleLoader
typedef struct JSC__AsyncGeneratorPrototype JSC__AsyncGeneratorPrototype; // JSC::AsyncGeneratorPrototype
typedef struct JSC__AsyncGeneratorFunctionPrototype JSC__AsyncGeneratorFunctionPrototype; // JSC::AsyncGeneratorFunctionPrototype
- typedef WebSocketClientTLS WebSocketClientTLS;
+ typedef Uint8Array_alias Uint8Array_alias;
typedef bJSC__Identifier JSC__Identifier; // JSC::Identifier
typedef struct JSC__ArrayPrototype JSC__ArrayPrototype; // JSC::ArrayPrototype
+ typedef WebSocketClientTLS WebSocketClientTLS;
typedef struct Zig__JSMicrotaskCallback Zig__JSMicrotaskCallback; // Zig::JSMicrotaskCallback
typedef bJSC__JSPromise JSC__JSPromise; // JSC::JSPromise
typedef WebSocketHTTPClient WebSocketHTTPClient;
@@ -192,6 +193,7 @@ typedef void* JSClassRef;
typedef ErrorableResolvedSource ErrorableResolvedSource;
typedef ErrorableZigString ErrorableZigString;
typedef WebSocketClient WebSocketClient;
+ typedef Uint8Array_alias Uint8Array_alias;
typedef WebSocketClientTLS WebSocketClientTLS;
typedef WebSocketHTTPClient WebSocketHTTPClient;
typedef SystemError SystemError;
@@ -638,6 +640,14 @@ CPP_DECL bool WTF__StringView__is16Bit(const WTF__StringView* arg0);
CPP_DECL bool WTF__StringView__is8Bit(const WTF__StringView* arg0);
CPP_DECL bool WTF__StringView__isEmpty(const WTF__StringView* arg0);
CPP_DECL size_t WTF__StringView__length(const WTF__StringView* arg0);
+CPP_DECL void FFI__ptr__put(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1);
+
+#ifdef __cplusplus
+
+ZIG_DECL JSC__JSValue FFI__ptr__fastpath(JSC__JSGlobalObject* arg0, void* arg1, Uint8Array_alias* arg2);
+ZIG_DECL JSC__JSValue FFI__ptr__slowpath(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1, JSC__JSValue* arg2, size_t arg3);
+
+#endif
#pragma mark - Zig::GlobalObject
@@ -843,7 +853,6 @@ ZIG_DECL void Bun__HTTPRequestContext__resolve(void* arg0, JSC__JSGlobalObject*
#endif
-
#ifdef __cplusplus
ZIG_DECL void Bun__HTTPRequestContextTLS__reject(void* arg0, JSC__JSGlobalObject* arg1, JSC__CallFrame* arg2);
@@ -851,7 +860,6 @@ ZIG_DECL void Bun__HTTPRequestContextTLS__resolve(void* arg0, JSC__JSGlobalObjec
#endif
-
#ifdef __cplusplus
ZIG_DECL void Bun__HTTPRequestContextDebug__reject(void* arg0, JSC__JSGlobalObject* arg1, JSC__CallFrame* arg2);
@@ -859,11 +867,9 @@ ZIG_DECL void Bun__HTTPRequestContextDebug__resolve(void* arg0, JSC__JSGlobalObj
#endif
-
#ifdef __cplusplus
ZIG_DECL void Bun__HTTPRequestContextDebugTLS__reject(void* arg0, JSC__JSGlobalObject* arg1, JSC__CallFrame* arg2);
ZIG_DECL void Bun__HTTPRequestContextDebugTLS__resolve(void* arg0, JSC__JSGlobalObject* arg1, JSC__CallFrame* arg2);
#endif
-
diff --git a/src/bun.js/bindings/headers.zig b/src/bun.js/bindings/headers.zig
index a8379c290..1d563af37 100644
--- a/src/bun.js/bindings/headers.zig
+++ b/src/bun.js/bindings/headers.zig
@@ -404,6 +404,7 @@ pub extern fn WTF__StringView__is16Bit(arg0: [*c]const WTF__StringView) bool;
pub extern fn WTF__StringView__is8Bit(arg0: [*c]const WTF__StringView) bool;
pub extern fn WTF__StringView__isEmpty(arg0: [*c]const WTF__StringView) bool;
pub extern fn WTF__StringView__length(arg0: [*c]const WTF__StringView) usize;
+pub extern fn FFI__ptr__put(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) void;
pub extern fn Zig__GlobalObject__create(arg0: [*c]JSClassRef, arg1: i32, arg2: ?*anyopaque) ?*JSC__JSGlobalObject;
pub extern fn Zig__GlobalObject__getModuleRegistryMap(arg0: ?*JSC__JSGlobalObject) ?*anyopaque;
pub extern fn Zig__GlobalObject__resetModuleRegistryMap(arg0: ?*JSC__JSGlobalObject, arg1: ?*anyopaque) bool;
diff --git a/src/bun.js/bindings/sizes.zig b/src/bun.js/bindings/sizes.zig
index 890d46ee4..385eec012 100644
--- a/src/bun.js/bindings/sizes.zig
+++ b/src/bun.js/bindings/sizes.zig
@@ -1,4 +1,4 @@
-// Auto-generated by src/bun.js/headergen/sizegen.cpp at 2022-08-13 16:15:1660432547.
+// Auto-generated by src/bun.js/headergen/sizegen.cpp at 2022-08-14 21:34:1660538097.
// These are the byte sizes for the different object types with bindings in JavaScriptCore.
// This allows us to safely return stack allocated C++ types to Zig.
// It is only safe to do this when these sizes are correct.
@@ -6,13 +6,13 @@
// 1. We can't dynamically link JavaScriptCore
// 2. It's important that this is run whenever JavaScriptCore is updated or the bindings on the Zig side change.
// Failure to do so will lead to undefined behavior and probably some frustrated people.
-// --- Regenerate this: ---
+// --- Regenerate this: ---
// 1. "make headers"
// 2. "make sizegen"
// 3. "make headers"
// ------------------------
// You can verify the numbers written in this file at runtime via the `extern`d types
-// Run "headers" twice because it uses these values in the output. That's how all the bJSC__.* types are created - from these values.
+// Run "headers" twice because it uses these values in the output. That's how all the bJSC__.* types are created - from these values.
pub const JSC__JSObject = 16;
pub const JSC__JSObject_align = 8;
pub const WebCore__DOMURL = 112;
@@ -69,11 +69,6 @@ pub const WTF__StringView = 16;
pub const WTF__StringView_align = 8;
pub const Zig__GlobalObject = 4672;
pub const Zig__GlobalObject_align = 8;
-pub const ArrayBufferSink = 1;
-pub const ArrayBufferSink_align = 1;
-pub const HTTPSResponseSink = 1;
-pub const HTTPSResponseSink_align = 1;
-pub const HTTPResponseSink = 1;
-pub const HTTPResponseSink_align = 1;
pub const Bun_FFI_PointerOffsetToArgumentsList = 6;
pub const Bun_FFI_PointerOffsetToTypedArrayVector = 16;
+pub const Bun_FFI_PointerOffsetToTypedArrayLength = 24;
diff --git a/src/bun.js/bindings/webcore/DOMJITIDLType.h b/src/bun.js/bindings/webcore/DOMJITIDLType.h
index 219468875..e03de7607 100644
--- a/src/bun.js/bindings/webcore/DOMJITIDLType.h
+++ b/src/bun.js/bindings/webcore/DOMJITIDLType.h
@@ -26,25 +26,50 @@
#pragma once
#include "IDLTypes.h"
+#include "JSDOMConvertBufferSource.h"
-namespace WebCore { namespace DOMJIT {
+namespace WebCore {
+namespace DOMJIT {
template<typename IDLType>
struct IDLJSArgumentTypeSelect;
-template<> struct IDLJSArgumentTypeSelect<IDLBoolean> { typedef bool type; };
-template<> struct IDLJSArgumentTypeSelect<IDLByte> { typedef int32_t type; };
-template<> struct IDLJSArgumentTypeSelect<IDLOctet> { typedef int32_t type; };
-template<> struct IDLJSArgumentTypeSelect<IDLShort> { typedef int32_t type; };
-template<> struct IDLJSArgumentTypeSelect<IDLUnsignedShort> { typedef int32_t type; };
-template<> struct IDLJSArgumentTypeSelect<IDLLong> { typedef int32_t type; };
-template<> struct IDLJSArgumentTypeSelect<IDLDOMString> { typedef JSC::JSString* type; };
-template<> struct IDLJSArgumentTypeSelect<IDLUint8Array> { typedef JSC::JSUint8Array* type; };
-template<> struct IDLJSArgumentTypeSelect<IDLObject> { typedef JSC::JSObject* type; };
-template<> struct IDLJSArgumentTypeSelect<IDLAtomStringAdaptor<IDLDOMString>> { typedef JSC::JSString* type; };
-template<> struct IDLJSArgumentTypeSelect<IDLRequiresExistingAtomStringAdaptor<IDLDOMString>> { typedef JSC::JSString* type; };
+template<> struct IDLJSArgumentTypeSelect<IDLBoolean> {
+ typedef bool type;
+};
+template<> struct IDLJSArgumentTypeSelect<IDLByte> {
+ typedef int32_t type;
+};
+template<> struct IDLJSArgumentTypeSelect<IDLOctet> {
+ typedef int32_t type;
+};
+template<> struct IDLJSArgumentTypeSelect<IDLShort> {
+ typedef int32_t type;
+};
+template<> struct IDLJSArgumentTypeSelect<IDLUnsignedShort> {
+ typedef int32_t type;
+};
+template<> struct IDLJSArgumentTypeSelect<IDLLong> {
+ typedef int32_t type;
+};
+template<> struct IDLJSArgumentTypeSelect<IDLDOMString> {
+ typedef JSC::JSString* type;
+};
+template<> struct IDLJSArgumentTypeSelect<IDLUint8Array> {
+ typedef JSC::JSUint8Array* type;
+};
+template<> struct IDLJSArgumentTypeSelect<IDLObject> {
+ typedef JSC::JSObject* type;
+};
+template<> struct IDLJSArgumentTypeSelect<IDLAtomStringAdaptor<IDLDOMString>> {
+ typedef JSC::JSString* type;
+};
+template<> struct IDLJSArgumentTypeSelect<IDLRequiresExistingAtomStringAdaptor<IDLDOMString>> {
+ typedef JSC::JSString* type;
+};
template<typename IDLType>
using IDLJSArgumentType = typename IDLJSArgumentTypeSelect<IDLType>::type;
-} }
+}
+}
diff --git a/src/bun.js/ffi.exports.js b/src/bun.js/ffi.exports.js
index f24844155..8d5374160 100644
--- a/src/bun.js/ffi.exports.js
+++ b/src/bun.js/ffi.exports.js
@@ -1,12 +1,14 @@
// --- FFIType ---
-export const ptr = globalThis.Bun.FFI.ptr;
-export const toBuffer = globalThis.Bun.FFI.toBuffer;
-export const toArrayBuffer = globalThis.Bun.FFI.toArrayBuffer;
-export const viewSource = globalThis.Bun.FFI.viewSource;
+var ffi = globalThis.Bun.FFI;
+export const ptr = (arg1, arg2) =>
+ typeof arg2 === "undefined" ? ffi.ptr(arg1) : ffi.ptr(arg1, arg2);
+export const toBuffer = ffi.toBuffer;
+export const toArrayBuffer = ffi.toArrayBuffer;
+export const viewSource = ffi.viewSource;
-const BunCString = globalThis.Bun.FFI.CString;
-const nativeLinkSymbols = globalThis.Bun.FFI.linkSymbols;
+const BunCString = ffi.CString;
+const nativeLinkSymbols = ffi.linkSymbols;
export class CString extends String {
constructor(ptr, byteOffset, byteLength) {
@@ -289,8 +291,8 @@ function FFIBuilder(params, returnType, functionToCall, name) {
return wrap;
}
-const nativeDLOpen = globalThis.Bun.FFI.dlopen;
-const nativeCallback = globalThis.Bun.FFI.callback;
+const nativeDLOpen = ffi.dlopen;
+const nativeCallback = ffi.callback;
export const native = {
dlopen: nativeDLOpen,
callback: nativeCallback,
diff --git a/src/bun.js/headergen/sizegen.cpp b/src/bun.js/headergen/sizegen.cpp
index 721f8e652..f12cea820 100644
--- a/src/bun.js/headergen/sizegen.cpp
+++ b/src/bun.js/headergen/sizegen.cpp
@@ -59,5 +59,7 @@ int main() {
<< JSC::CallFrame::argumentOffset(0) << ";\n";
cout << "pub const Bun_FFI_PointerOffsetToTypedArrayVector = "
<< JSC::JSArrayBufferView::offsetOfVector() << ";\n";
+ cout << "pub const Bun_FFI_PointerOffsetToTypedArrayLength = "
+ << JSC::JSArrayBufferView::offsetOfLength() << ";\n";
return 0;
} \ No newline at end of file
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index d480bbac4..3290e2ada 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -2807,6 +2807,7 @@ pub const HardcodedModule = enum {
.{ "http", "node:http" },
.{ "module", "node:module" },
.{ "node:buffer", "node:buffer" },
+ .{ "buffer", "node:buffer" },
.{ "node:fs", "node:fs" },
.{ "node:fs/promises", "node:fs/promises" },
.{ "node:http", "node:http" },