aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--integration/bunjs-only-snippets/ffi.test.fixture.callback.c34
-rw-r--r--integration/bunjs-only-snippets/ffi.test.fixture.receiver.c34
-rw-r--r--integration/bunjs-only-snippets/ffi.test.js113
-rw-r--r--src/javascript/jsc/api/FFI.h34
-rw-r--r--src/javascript/jsc/api/ffi.zig56
-rw-r--r--src/javascript/jsc/bindings/bindings.cpp31
-rw-r--r--src/javascript/jsc/bindings/bindings.zig14
-rw-r--r--src/javascript/jsc/bindings/headers-cpp.h12
-rw-r--r--src/javascript/jsc/bindings/headers.h11
-rw-r--r--src/javascript/jsc/bindings/headers.zig3
-rw-r--r--src/javascript/jsc/ffi.exports.js14
11 files changed, 212 insertions, 144 deletions
diff --git a/integration/bunjs-only-snippets/ffi.test.fixture.callback.c b/integration/bunjs-only-snippets/ffi.test.fixture.callback.c
index a0da35f62..bc31d8b1c 100644
--- a/integration/bunjs-only-snippets/ffi.test.fixture.callback.c
+++ b/integration/bunjs-only-snippets/ffi.test.fixture.callback.c
@@ -38,28 +38,6 @@ typedef _Bool bool;
#define true 1
#define false 0
-#ifdef USES_FLOAT
-// https://git.musl-libc.org/cgit/musl/tree/src/math/trunc.c
-double trunc(double x);
-double trunc(double x)
-{
- union {double f; uint64_t i;} u = {x};
- int e = (int)(u.i >> 52 & 0x7ff) - 0x3ff + 12;
- uint64_t m;
-
- if (e >= 52 + 12)
- return x;
- if (e < 12)
- e = 1;
- m = -1ULL >> e;
- if ((u.i & m) == 0)
- return x;
- x + 0x1p120f;
- u.i &= ~m;
- return u.f;
-}
-#endif
-
// This value is 2^49, used to encode doubles such that the encoded value will
// begin with a 15-bit pattern within the range 0x0002..0xFFFC.
@@ -82,7 +60,6 @@ typedef void* JSCell;
typedef union EncodedJSValue {
int64_t asInt64;
#if USE_JSVALUE32_64
- double asDouble;
#elif USE_JSVALUE64
JSCell *ptr;
#endif
@@ -117,6 +94,11 @@ JSContext cachedJSContext;
void* cachedCallbackFunction;
#endif
+uint64_t JSVALUE_TO_UINT64(void* globalObject, EncodedJSValue value);
+int64_t JSVALUE_TO_INT64(EncodedJSValue value);
+
+EncodedJSValue UINT64_TO_JSVALUE(void* globalObject, uint64_t val);
+EncodedJSValue INT64_TO_JSVALUE(void* globalObject, int64_t val);
static EncodedJSValue INT32_TO_JSVALUE(int32_t val) __attribute__((__always_inline__));
static EncodedJSValue DOUBLE_TO_JSVALUE(double val) __attribute__((__always_inline__));
@@ -184,11 +166,9 @@ static bool JSVALUE_TO_BOOL(EncodedJSValue val) {
}
#define arg(i) ((EncodedJSValue*)args)[i]
+#ifndef IS_CALLBACK
void* JSFunctionCall(void* globalObject, void* callFrame);
-// int64_t JSFunctionCall(void* globalObject, void* callFrame) {
-// EncodedJSValue* args = (EncodedJSValue*)((unsigned char*)callFrame + Bun_FFI_PointerOffsetToArgumentsList);
-// }
-
+#endif
// --- Generated Code ---
diff --git a/integration/bunjs-only-snippets/ffi.test.fixture.receiver.c b/integration/bunjs-only-snippets/ffi.test.fixture.receiver.c
index 0f7047ab5..121f2d3a0 100644
--- a/integration/bunjs-only-snippets/ffi.test.fixture.receiver.c
+++ b/integration/bunjs-only-snippets/ffi.test.fixture.receiver.c
@@ -38,28 +38,6 @@ typedef _Bool bool;
#define true 1
#define false 0
-#ifdef USES_FLOAT
-// https://git.musl-libc.org/cgit/musl/tree/src/math/trunc.c
-double trunc(double x);
-double trunc(double x)
-{
- union {double f; uint64_t i;} u = {x};
- int e = (int)(u.i >> 52 & 0x7ff) - 0x3ff + 12;
- uint64_t m;
-
- if (e >= 52 + 12)
- return x;
- if (e < 12)
- e = 1;
- m = -1ULL >> e;
- if ((u.i & m) == 0)
- return x;
- x + 0x1p120f;
- u.i &= ~m;
- return u.f;
-}
-#endif
-
// This value is 2^49, used to encode doubles such that the encoded value will
// begin with a 15-bit pattern within the range 0x0002..0xFFFC.
@@ -82,7 +60,6 @@ typedef void* JSCell;
typedef union EncodedJSValue {
int64_t asInt64;
#if USE_JSVALUE32_64
- double asDouble;
#elif USE_JSVALUE64
JSCell *ptr;
#endif
@@ -117,6 +94,11 @@ JSContext cachedJSContext;
void* cachedCallbackFunction;
#endif
+uint64_t JSVALUE_TO_UINT64(void* globalObject, EncodedJSValue value);
+int64_t JSVALUE_TO_INT64(EncodedJSValue value);
+
+EncodedJSValue UINT64_TO_JSVALUE(void* globalObject, uint64_t val);
+EncodedJSValue INT64_TO_JSVALUE(void* globalObject, int64_t val);
static EncodedJSValue INT32_TO_JSVALUE(int32_t val) __attribute__((__always_inline__));
static EncodedJSValue DOUBLE_TO_JSVALUE(double val) __attribute__((__always_inline__));
@@ -184,11 +166,9 @@ static bool JSVALUE_TO_BOOL(EncodedJSValue val) {
}
#define arg(i) ((EncodedJSValue*)args)[i]
+#ifndef IS_CALLBACK
void* JSFunctionCall(void* globalObject, void* callFrame);
-// int64_t JSFunctionCall(void* globalObject, void* callFrame) {
-// EncodedJSValue* args = (EncodedJSValue*)((unsigned char*)callFrame + Bun_FFI_PointerOffsetToArgumentsList);
-// }
-
+#endif
// --- Generated Code ---
diff --git a/integration/bunjs-only-snippets/ffi.test.js b/integration/bunjs-only-snippets/ffi.test.js
index 597c0ef1f..b95bcfa8e 100644
--- a/integration/bunjs-only-snippets/ffi.test.js
+++ b/integration/bunjs-only-snippets/ffi.test.js
@@ -95,10 +95,10 @@ it("ffi run", () => {
return_type: "uint32_t",
args: [],
},
- // // returns_42_uint64_t: {
- // // return_type: "uint64_t",
- // // args: [],
- // // },
+ returns_42_uint64_t: {
+ return_type: "uint64_t",
+ args: [],
+ },
returns_neg_42_int16_t: {
return_type: "int16_t",
args: [],
@@ -107,10 +107,10 @@ it("ffi run", () => {
return_type: "int32_t",
args: [],
},
- // returns_neg_42_int64_t: {
- // return_type: "int64_t",
- // args: [],
- // },
+ returns_neg_42_int64_t: {
+ return_type: "int64_t",
+ args: [],
+ },
identity_char: {
return_type: "char",
@@ -140,10 +140,10 @@ it("ffi run", () => {
return_type: "int32_t",
args: ["int32_t"],
},
- // identity_int64_t: {
- // return_type: "int64_t",
- // args: ["int64_t"],
- // },
+ identity_int64_t: {
+ return_type: "int64_t",
+ args: ["int64_t"],
+ },
identity_uint8_t: {
return_type: "uint8_t",
args: ["uint8_t"],
@@ -156,10 +156,10 @@ it("ffi run", () => {
return_type: "uint32_t",
args: ["uint32_t"],
},
- // identity_uint64_t: {
- // return_type: "uint64_t",
- // args: ["uint64_t"],
- // },
+ identity_uint64_t: {
+ return_type: "uint64_t",
+ args: ["uint64_t"],
+ },
add_char: {
return_type: "char",
@@ -185,10 +185,10 @@ it("ffi run", () => {
return_type: "int32_t",
args: ["int32_t", "int32_t"],
},
- // add_int64_t: {
- // return_type: "int64_t",
- // args: ["int64_t", "int64_t"],
- // },
+ add_int64_t: {
+ return_type: "int64_t",
+ args: ["int64_t", "int64_t"],
+ },
add_uint8_t: {
return_type: "uint8_t",
args: ["uint8_t", "uint8_t"],
@@ -215,10 +215,10 @@ it("ffi run", () => {
return_type: "ptr",
args: ["ptr"],
},
- // add_uint64_t: {
- // return_type: "uint64_t",
- // args: ["uint64_t", "uint64_t"],
- // },
+ add_uint64_t: {
+ return_type: "uint64_t",
+ args: ["uint64_t", "uint64_t"],
+ },
cb_identity_true: {
return_type: "bool",
@@ -232,14 +232,14 @@ it("ffi run", () => {
return_type: "char",
args: ["ptr"],
},
- // cb_identity_42_float: {
- // return_type: "float",
- // args: ["ptr"],
- // },
- // cb_identity_42_double: {
- // return_type: "double",
- // args: ["ptr"],
- // },
+ cb_identity_42_float: {
+ return_type: "float",
+ args: ["ptr"],
+ },
+ cb_identity_42_double: {
+ return_type: "double",
+ args: ["ptr"],
+ },
cb_identity_42_uint8_t: {
return_type: "uint8_t",
args: ["ptr"],
@@ -256,10 +256,10 @@ it("ffi run", () => {
return_type: "uint32_t",
args: ["ptr"],
},
- // cb_identity_42_uint64_t: {
- // return_type: "uint64_t",
- // args: ["ptr"],
- // },
+ cb_identity_42_uint64_t: {
+ return_type: "uint64_t",
+ args: ["ptr"],
+ },
cb_identity_neg_42_int16_t: {
return_type: "int16_t",
args: ["ptr"],
@@ -268,10 +268,10 @@ it("ffi run", () => {
return_type: "int32_t",
args: ["ptr"],
},
- // cb_identity_neg_42_int64_t: {
- // return_type: "int64_t",
- // args: ["ptr"],
- // },
+ cb_identity_neg_42_int64_t: {
+ return_type: "int64_t",
+ args: ["ptr"],
+ },
return_a_function_ptr_to_function_that_returns_true: {
return_type: "ptr",
@@ -340,6 +340,7 @@ it("ffi run", () => {
expect(returns_true()).toBe(true);
expect(returns_false()).toBe(false);
expect(returns_42_char()).toBe(42);
+ expect(returns_42_uint64_t().valueOf()).toBe(42);
expect(Math.fround(returns_42_float())).toBe(Math.fround(42.41999804973602));
@@ -348,11 +349,11 @@ it("ffi run", () => {
expect(returns_neg_42_int8_t()).toBe(-42);
expect(returns_42_uint16_t()).toBe(42);
expect(returns_42_uint32_t()).toBe(42);
- // expect(returns_42_uint64_t()).toBe(42);
+ expect(returns_42_uint64_t()).toBe(42);
expect(returns_neg_42_int16_t()).toBe(-42);
expect(returns_neg_42_int32_t()).toBe(-42);
expect(identity_int32_t(10)).toBe(10);
- // expect(returns_neg_42_int64_t()).toBe(-42);
+ expect(returns_neg_42_int64_t()).toBe(-42);
expect(identity_char(10)).toBe(10);
expect(identity_float(10.199999809265137)).toBe(10.199999809265137);
expect(identity_bool(true)).toBe(true);
@@ -360,18 +361,38 @@ it("ffi run", () => {
expect(identity_double(10.100000000000364)).toBe(10.100000000000364);
expect(identity_int8_t(10)).toBe(10);
expect(identity_int16_t(10)).toBe(10);
- console.log("here");
- // expect(identity_int64_t(10)).toBe(10);
+ expect(identity_int64_t(10)).toBe(10);
expect(identity_uint8_t(10)).toBe(10);
expect(identity_uint16_t(10)).toBe(10);
expect(identity_uint32_t(10)).toBe(10);
+ expect(identity_uint64_t(10)).toBe(10);
+ var bigArray = new BigUint64Array(8);
+ new Uint8Array(bigArray.buffer).fill(255);
+ var bigIntArray = new BigInt64Array(bigArray.buffer);
+
+ expect(identity_uint64_t(bigArray[0])).toBe(bigArray[0]);
+ expect(identity_uint64_t(bigArray[0] - BigInt(1))).toBe(
+ bigArray[0] - BigInt(1)
+ );
+ expect(add_uint64_t(BigInt(-1) * bigArray[0], bigArray[0])).toBe(0);
+ expect(add_uint64_t(BigInt(-1) * bigArray[0] + BigInt(10), bigArray[0])).toBe(
+ 10
+ );
+ expect(identity_uint64_t(0)).toBe(0);
+ expect(identity_uint64_t(100)).toBe(100);
+ expect(identity_uint64_t(BigInt(100))).toBe(100);
+ expect(identity_int64_t(bigIntArray[0])).toBe(bigIntArray[0]);
+ expect(identity_int64_t(bigIntArray[0] - BigInt(1))).toBe(
+ bigIntArray[0] - BigInt(1)
+ );
+
expect(add_char(1, 1)).toBe(2);
expect(add_float(2.4, 2.8)).toBe(Math.fround(5.2));
expect(add_double(4.2, 0.1)).toBe(4.3);
expect(add_int8_t(1, 1)).toBe(2);
expect(add_int16_t(1, 1)).toBe(2);
expect(add_int32_t(1, 1)).toBe(2);
- // expect(add_int64_t(1, 1)).toBe(2);
+ expect(add_int64_t(1, 1)).toBe(2);
expect(add_uint8_t(1, 1)).toBe(2);
expect(add_uint16_t(1, 1)).toBe(2);
expect(add_uint32_t(1, 1)).toBe(2);
@@ -391,7 +412,6 @@ it("ffi run", () => {
const second_ptr = ptr(new Buffer(8));
expect(identity_ptr(second_ptr)).toBe(second_ptr);
function identityBool() {
- console.log("hi");
return true;
}
globalThis.identityBool = identityBool;
@@ -408,7 +428,6 @@ it("ffi run", () => {
).toBe(true);
expect(cb_identity_true(first)).toBe(true);
- console.log("second");
expect(
cb_identity_false(
diff --git a/src/javascript/jsc/api/FFI.h b/src/javascript/jsc/api/FFI.h
index 42bc03fc8..69af59dc6 100644
--- a/src/javascript/jsc/api/FFI.h
+++ b/src/javascript/jsc/api/FFI.h
@@ -37,28 +37,6 @@ typedef _Bool bool;
#define true 1
#define false 0
-#ifdef USES_FLOAT
-// https://git.musl-libc.org/cgit/musl/tree/src/math/trunc.c
-double trunc(double x);
-double trunc(double x)
-{
- union {double f; uint64_t i;} u = {x};
- int e = (int)(u.i >> 52 & 0x7ff) - 0x3ff + 12;
- uint64_t m;
-
- if (e >= 52 + 12)
- return x;
- if (e < 12)
- e = 1;
- m = -1ULL >> e;
- if ((u.i & m) == 0)
- return x;
- x + 0x1p120f;
- u.i &= ~m;
- return u.f;
-}
-#endif
-
// This value is 2^49, used to encode doubles such that the encoded value will
// begin with a 15-bit pattern within the range 0x0002..0xFFFC.
@@ -81,7 +59,6 @@ typedef void* JSCell;
typedef union EncodedJSValue {
int64_t asInt64;
#if USE_JSVALUE32_64
- double asDouble;
#elif USE_JSVALUE64
JSCell *ptr;
#endif
@@ -116,6 +93,11 @@ JSContext cachedJSContext;
void* cachedCallbackFunction;
#endif
+uint64_t JSVALUE_TO_UINT64(void* globalObject, EncodedJSValue value);
+int64_t JSVALUE_TO_INT64(EncodedJSValue value);
+
+EncodedJSValue UINT64_TO_JSVALUE(void* globalObject, uint64_t val);
+EncodedJSValue INT64_TO_JSVALUE(void* globalObject, int64_t val);
static EncodedJSValue INT32_TO_JSVALUE(int32_t val) __attribute__((__always_inline__));
static EncodedJSValue DOUBLE_TO_JSVALUE(double val) __attribute__((__always_inline__));
@@ -183,11 +165,9 @@ static bool JSVALUE_TO_BOOL(EncodedJSValue val) {
}
#define arg(i) ((EncodedJSValue*)args)[i]
+#ifndef IS_CALLBACK
void* JSFunctionCall(void* globalObject, void* callFrame);
-// int64_t JSFunctionCall(void* globalObject, void* callFrame) {
-// EncodedJSValue* args = (EncodedJSValue*)((unsigned char*)callFrame + Bun_FFI_PointerOffsetToArgumentsList);
-// }
-
+#endif
// --- Generated Code ---
diff --git a/src/javascript/jsc/api/ffi.zig b/src/javascript/jsc/api/ffi.zig
index b3be0062f..702d0d6d6 100644
--- a/src/javascript/jsc/api/ffi.zig
+++ b/src/javascript/jsc/api/ffi.zig
@@ -591,6 +591,21 @@ pub const FFI = struct {
extern fn pthread_jit_write_protect_np(enable: bool) callconv(.C) void;
+ const MyFunctionSStructWorkAround = struct {
+ JSVALUE_TO_INT64: fn (JSValue0: JSC.JSValue) callconv(.C) i64,
+ JSVALUE_TO_UINT64: fn (JSValue0: JSC.JSValue) callconv(.C) u64,
+ INT64_TO_JSVALUE: fn (arg0: [*c]JSC.JSGlobalObject, arg1: i64) callconv(.C) JSC.JSValue,
+ UINT64_TO_JSVALUE: fn (arg0: [*c]JSC.JSGlobalObject, arg1: u64) callconv(.C) JSC.JSValue,
+ };
+ const headers = @import("../bindings/headers.zig");
+
+ var workaround: MyFunctionSStructWorkAround = .{
+ .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,
+ };
+
const tcc_options = "-std=c11 -nostdlib -Wl,--export-all-symbols";
pub fn compile(
@@ -625,6 +640,7 @@ pub const FFI = struct {
"Bun_FFI_PointerOffsetToArgumentsList",
std.fmt.bufPrintZ(&symbol_buf, "{d}", .{Sizes.Bun_FFI_PointerOffsetToArgumentsList}) catch unreachable,
);
+
// TCC.tcc_define_symbol(
// state,
// "Bun_FFI_PointerOffsetToArgumentsCount",
@@ -647,7 +663,31 @@ pub const FFI = struct {
}
CompilerRT.inject(state);
_ = TCC.tcc_add_symbol(state, this.base_name, this.symbol_from_dynamic_library.?);
+ _ = TCC.tcc_add_symbol(
+ state,
+ "JSVALUE_TO_INT64",
+ workaround.JSVALUE_TO_INT64,
+ );
+ _ = TCC.tcc_add_symbol(
+ state,
+ "JSVALUE_TO_UINT64",
+ 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);
+ _ = TCC.tcc_add_symbol(
+ state,
+ "INT64_TO_JSVALUE",
+ workaround.INT64_TO_JSVALUE,
+ );
+ _ = TCC.tcc_add_symbol(
+ state,
+ "UINT64_TO_JSVALUE",
+ workaround.UINT64_TO_JSVALUE,
+ );
if (this.step == .failed) {
return;
}
@@ -1131,8 +1171,12 @@ pub const FFI = struct {
.char, .int8_t, .uint8_t, .int16_t, .uint16_t, .int32_t, .uint32_t => {
try writer.print("JSVALUE_TO_INT32({s})", .{self.symbol});
},
- .int64_t => {},
- .uint64_t => {},
+ .int64_t => {
+ try writer.print("JSVALUE_TO_INT64({s})", .{self.symbol});
+ },
+ .uint64_t => {
+ try writer.print("JSVALUE_TO_UINT64(globalObject, {s})", .{self.symbol});
+ },
.cstring, .ptr => {
try writer.print("JSVALUE_TO_PTR({s})", .{self.symbol});
},
@@ -1159,8 +1203,12 @@ pub const FFI = struct {
.char, .int8_t, .uint8_t, .int16_t, .uint16_t, .int32_t, .uint32_t => {
try writer.print("INT32_TO_JSVALUE({s})", .{self.symbol});
},
- .int64_t => {},
- .uint64_t => {},
+ .int64_t => {
+ try writer.print("INT64_TO_JSVALUE(globalObject, {s})", .{self.symbol});
+ },
+ .uint64_t => {
+ try writer.print("UINT64_TO_JSVALUE(globalObject, {s})", .{self.symbol});
+ },
.cstring, .ptr => {
try writer.print("PTR_TO_JSVALUE({s})", .{self.symbol});
},
diff --git a/src/javascript/jsc/bindings/bindings.cpp b/src/javascript/jsc/bindings/bindings.cpp
index 16900c191..a5a51adbc 100644
--- a/src/javascript/jsc/bindings/bindings.cpp
+++ b/src/javascript/jsc/bindings/bindings.cpp
@@ -1898,6 +1898,37 @@ int64_t JSC__JSValue__toInt64(JSC__JSValue val)
return _val.asAnyInt();
}
+JSC__JSValue JSC__JSValue__fromInt64NoTruncate(JSC__JSGlobalObject* globalObject, int64_t val)
+{
+ return JSC::JSValue::encode(JSC::JSValue(JSC::JSBigInt::createFrom(globalObject, val)));
+}
+
+JSC__JSValue JSC__JSValue__fromUInt64NoTruncate(JSC__JSGlobalObject* globalObject, uint64_t val)
+{
+ return JSC::JSValue::encode(JSC::JSValue(JSC::JSBigInt::createFrom(globalObject, val)));
+}
+
+uint64_t JSC__JSValue__toUInt64NoTruncate(JSC__JSValue val)
+{
+ JSC::JSValue _val = JSC::JSValue::decode(val);
+
+ int64_t result = JSC::tryConvertToInt52(_val.asDouble());
+ if (result != JSC::JSValue::notInt52) {
+ if (result < 0)
+ return 0;
+
+ return static_cast<uint64_t>(result);
+ }
+
+ if (_val.isHeapBigInt()) {
+
+ if (auto* heapBigInt = _val.asHeapBigInt()) {
+ return heapBigInt->toBigUInt64(heapBigInt);
+ }
+ }
+ return static_cast<uint64_t>(_val.asAnyInt());
+}
+
JSC__JSValue JSC__JSValue__createObject2(JSC__JSGlobalObject* globalObject, const ZigString* arg1,
const ZigString* arg2, JSC__JSValue JSValue3,
JSC__JSValue JSValue4)
diff --git a/src/javascript/jsc/bindings/bindings.zig b/src/javascript/jsc/bindings/bindings.zig
index dbcfabf7b..5c1d2c0cc 100644
--- a/src/javascript/jsc/bindings/bindings.zig
+++ b/src/javascript/jsc/bindings/bindings.zig
@@ -2567,6 +2567,18 @@ pub const JSValue = enum(u64) {
return null;
}
+ pub fn fromInt64NoTruncate(globalObject: *JSGlobalObject, i: i64) JSValue {
+ return cppFn("fromInt64NoTruncate", .{ globalObject, i });
+ }
+ pub fn fromUInt64NoTruncate(globalObject: *JSGlobalObject, i: u64) JSValue {
+ return cppFn("fromUInt64NoTruncate", .{ globalObject, i });
+ }
+ pub fn toUInt64NoTruncate(this: JSValue) u64 {
+ return cppFn("toUInt64NoTruncate", .{
+ this,
+ });
+ }
+
pub inline fn getZigString(this: JSValue, global: *JSGlobalObject) ZigString {
var str = ZigString.init("");
this.toZigString(&str, global);
@@ -2828,7 +2840,7 @@ pub const JSValue = enum(u64) {
return @intToPtr(*anyopaque, @enumToInt(this));
}
- pub const Extern = [_][]const u8{ "asPromise", "toInt64", "_then", "put", "makeWithNameAndPrototype", "parseJSON", "symbolKeyFor", "symbolFor", "getSymbolDescription", "createInternalPromise", "asInternalPromise", "asArrayBuffer_", "getReadableStreamState", "getWritableStreamState", "fromEntries", "createTypeError", "createRangeError", "createObject2", "getIfPropertyExistsImpl", "jsType", "jsonStringify", "kind_", "isTerminationException", "isSameValue", "getLengthOfArray", "toZigString", "createStringArray", "createEmptyObject", "putRecord", "asPromise", "isClass", "getNameProperty", "getClassName", "getErrorsProperty", "toInt32", "toBoolean", "isInt32", "isIterable", "forEach", "isAggregateError", "toZigException", "isException", "toWTFString", "hasProperty", "getPropertyNames", "getDirect", "putDirect", "getIfExists", "asString", "asObject", "asNumber", "isError", "jsNull", "jsUndefined", "jsTDZValue", "jsBoolean", "jsDoubleNumber", "jsNumberFromDouble", "jsNumberFromChar", "jsNumberFromU16", "jsNumberFromInt32", "jsNumberFromInt64", "jsNumberFromUint64", "isBoolean", "isAnyInt", "isUInt32AsAnyInt", "isInt32AsAnyInt", "isNumber", "isString", "isBigInt", "isHeapBigInt", "isBigInt32", "isSymbol", "isPrimitive", "isGetterSetter", "isCustomGetterSetter", "isObject", "isCell", "asCell", "toString", "toStringOrNull", "toPropertyKey", "toPropertyKeyValue", "toObject", "toString", "getPrototype", "getPropertyByPropertyName", "eqlValue", "eqlCell", "isCallable" };
+ pub const Extern = [_][]const u8{ "fromInt64NoTruncate", "fromUInt64NoTruncate", "toUInt64NoTruncate", "asPromise", "toInt64", "_then", "put", "makeWithNameAndPrototype", "parseJSON", "symbolKeyFor", "symbolFor", "getSymbolDescription", "createInternalPromise", "asInternalPromise", "asArrayBuffer_", "getReadableStreamState", "getWritableStreamState", "fromEntries", "createTypeError", "createRangeError", "createObject2", "getIfPropertyExistsImpl", "jsType", "jsonStringify", "kind_", "isTerminationException", "isSameValue", "getLengthOfArray", "toZigString", "createStringArray", "createEmptyObject", "putRecord", "asPromise", "isClass", "getNameProperty", "getClassName", "getErrorsProperty", "toInt32", "toBoolean", "isInt32", "isIterable", "forEach", "isAggregateError", "toZigException", "isException", "toWTFString", "hasProperty", "getPropertyNames", "getDirect", "putDirect", "getIfExists", "asString", "asObject", "asNumber", "isError", "jsNull", "jsUndefined", "jsTDZValue", "jsBoolean", "jsDoubleNumber", "jsNumberFromDouble", "jsNumberFromChar", "jsNumberFromU16", "jsNumberFromInt32", "jsNumberFromInt64", "jsNumberFromUint64", "isBoolean", "isAnyInt", "isUInt32AsAnyInt", "isInt32AsAnyInt", "isNumber", "isString", "isBigInt", "isHeapBigInt", "isBigInt32", "isSymbol", "isPrimitive", "isGetterSetter", "isCustomGetterSetter", "isObject", "isCell", "asCell", "toString", "toStringOrNull", "toPropertyKey", "toPropertyKeyValue", "toObject", "toString", "getPrototype", "getPropertyByPropertyName", "eqlValue", "eqlCell", "isCallable" };
};
extern "c" fn Microtask__run(*Microtask, *JSGlobalObject) void;
diff --git a/src/javascript/jsc/bindings/headers-cpp.h b/src/javascript/jsc/bindings/headers-cpp.h
index fdac529b7..e33e5893c 100644
--- a/src/javascript/jsc/bindings/headers-cpp.h
+++ b/src/javascript/jsc/bindings/headers-cpp.h
@@ -1,4 +1,4 @@
-//-- AUTOGENERATED FILE -- 1651480881
+//-- AUTOGENERATED FILE -- 1651495723
// clang-format off
#pragma once
@@ -218,7 +218,7 @@ 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);
@@ -242,9 +242,7 @@ extern "C" const size_t Bun__Writable_object_align_ = alignof(Bun__Writable);
#ifndef INCLUDED_Path_h
#define INCLUDED_Path_h
-// #include "Path.h"
-#define Bun__Path void*
-#define Bun__Timer void*
+#include "Path.h"
#endif
extern "C" const size_t Bun__Path_object_size_ = sizeof(Bun__Path);
@@ -252,7 +250,7 @@ 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);
@@ -260,7 +258,7 @@ extern "C" const size_t Zig__ConsoleClient_object_align_ = alignof(Zig::ConsoleC
#ifndef INCLUDED_
#define INCLUDED_
-// #include ""
+#include ""
#endif
extern "C" const size_t Bun__Timer_object_size_ = sizeof(Bun__Timer);
diff --git a/src/javascript/jsc/bindings/headers.h b/src/javascript/jsc/bindings/headers.h
index 057e38eb8..5e58781e2 100644
--- a/src/javascript/jsc/bindings/headers.h
+++ b/src/javascript/jsc/bindings/headers.h
@@ -1,5 +1,5 @@
// clang-format: off
-//-- AUTOGENERATED FILE -- 1651480881
+//-- AUTOGENERATED FILE -- 1651495723
#pragma once
#include <stddef.h>
@@ -55,7 +55,7 @@ typedef struct bJSC__PropertyName {
} bJSC__PropertyName;
typedef char* bJSC__PropertyName_buf;
typedef struct bJSC__JSGlobalObject {
- unsigned char bytes[2400];
+ unsigned char bytes[2312];
} bJSC__JSGlobalObject;
typedef char* bJSC__JSGlobalObject_buf;
typedef struct bJSC__JSCell {
@@ -87,7 +87,7 @@ typedef struct bJSC__Exception {
} bJSC__Exception;
typedef char* bJSC__Exception_buf;
typedef struct bJSC__VM {
- unsigned char bytes[48824];
+ unsigned char bytes[52168];
} bJSC__VM;
typedef char* bJSC__VM_buf;
typedef struct bJSC__JSString {
@@ -99,7 +99,7 @@ typedef struct bJSC__SourceOrigin {
} bJSC__SourceOrigin;
typedef char* bJSC__SourceOrigin_buf;
typedef struct bWTF__ExternalStringImpl {
- unsigned char bytes[32];
+ unsigned char bytes[40];
} bWTF__ExternalStringImpl;
typedef char* bWTF__ExternalStringImpl_buf;
typedef struct bJSC__JSInternalPromise {
@@ -528,6 +528,8 @@ CPP_DECL bool JSC__JSValue__eqlCell(JSC__JSValue JSValue0, JSC__JSCell* arg1);
CPP_DECL bool JSC__JSValue__eqlValue(JSC__JSValue JSValue0, JSC__JSValue JSValue1);
CPP_DECL void JSC__JSValue__forEach(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, void* arg2, void (*ArgFn3)(JSC__VM* arg0, JSC__JSGlobalObject* arg1, void* arg2, JSC__JSValue JSValue3));
CPP_DECL JSC__JSValue JSC__JSValue__fromEntries(JSC__JSGlobalObject* arg0, ZigString* arg1, ZigString* arg2, size_t arg3, bool arg4);
+CPP_DECL JSC__JSValue JSC__JSValue__fromInt64NoTruncate(JSC__JSGlobalObject* arg0, int64_t arg1);
+CPP_DECL JSC__JSValue JSC__JSValue__fromUInt64NoTruncate(JSC__JSGlobalObject* arg0, uint64_t arg1);
CPP_DECL void JSC__JSValue__getClassName(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, ZigString* arg2);
CPP_DECL JSC__JSValue JSC__JSValue__getErrorsProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
CPP_DECL JSC__JSValue JSC__JSValue__getIfPropertyExistsImpl(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, const unsigned char* arg2, uint32_t arg3);
@@ -589,6 +591,7 @@ CPP_DECL JSC__JSValue JSC__JSValue__toPropertyKeyValue(JSC__JSValue JSValue0, JS
CPP_DECL JSC__JSString* JSC__JSValue__toString(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
CPP_DECL JSC__JSString* JSC__JSValue__toString(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
CPP_DECL JSC__JSString* JSC__JSValue__toStringOrNull(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
+CPP_DECL uint64_t JSC__JSValue__toUInt64NoTruncate(JSC__JSValue JSValue0);
CPP_DECL bWTF__String JSC__JSValue__toWTFString(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
CPP_DECL void JSC__JSValue__toZigException(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, ZigException* arg2);
CPP_DECL void JSC__JSValue__toZigString(JSC__JSValue JSValue0, ZigString* arg1, JSC__JSGlobalObject* arg2);
diff --git a/src/javascript/jsc/bindings/headers.zig b/src/javascript/jsc/bindings/headers.zig
index 6fd6b644b..3b74bd4cd 100644
--- a/src/javascript/jsc/bindings/headers.zig
+++ b/src/javascript/jsc/bindings/headers.zig
@@ -324,6 +324,8 @@ pub extern fn JSC__JSValue__eqlCell(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSCel
pub extern fn JSC__JSValue__eqlValue(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue) bool;
pub extern fn JSC__JSValue__forEach(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSGlobalObject, arg2: ?*anyopaque, ArgFn3: ?fn ([*c]JSC__VM, [*c]JSC__JSGlobalObject, ?*anyopaque, JSC__JSValue) callconv(.C) void) void;
pub extern fn JSC__JSValue__fromEntries(arg0: [*c]JSC__JSGlobalObject, arg1: [*c]ZigString, arg2: [*c]ZigString, arg3: usize, arg4: bool) JSC__JSValue;
+pub extern fn JSC__JSValue__fromInt64NoTruncate(arg0: [*c]JSC__JSGlobalObject, arg1: i64) JSC__JSValue;
+pub extern fn JSC__JSValue__fromUInt64NoTruncate(arg0: [*c]JSC__JSGlobalObject, arg1: u64) JSC__JSValue;
pub extern fn JSC__JSValue__getClassName(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSGlobalObject, arg2: [*c]ZigString) void;
pub extern fn JSC__JSValue__getErrorsProperty(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSGlobalObject) JSC__JSValue;
pub extern fn JSC__JSValue__getIfPropertyExistsImpl(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSGlobalObject, arg2: [*c]const u8, arg3: u32) JSC__JSValue;
@@ -384,6 +386,7 @@ pub extern fn JSC__JSValue__toPropertyKey(JSValue0: JSC__JSValue, arg1: [*c]JSC_
pub extern fn JSC__JSValue__toPropertyKeyValue(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSGlobalObject) JSC__JSValue;
pub extern fn JSC__JSValue__toString(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSGlobalObject) [*c]JSC__JSString;
pub extern fn JSC__JSValue__toStringOrNull(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSGlobalObject) [*c]JSC__JSString;
+pub extern fn JSC__JSValue__toUInt64NoTruncate(JSValue0: JSC__JSValue) u64;
pub extern fn JSC__JSValue__toWTFString(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSGlobalObject) bWTF__String;
pub extern fn JSC__JSValue__toZigException(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSGlobalObject, arg2: [*c]ZigException) void;
pub extern fn JSC__JSValue__toZigString(JSValue0: JSC__JSValue, arg1: [*c]ZigString, arg2: [*c]JSC__JSGlobalObject) void;
diff --git a/src/javascript/jsc/ffi.exports.js b/src/javascript/jsc/ffi.exports.js
index 2f23f8104..8f6c47e41 100644
--- a/src/javascript/jsc/ffi.exports.js
+++ b/src/javascript/jsc/ffi.exports.js
@@ -84,6 +84,20 @@ ffiWrappers[FFIType.int64_t] = function int64(val) {
return val;
};
+ffiWrappers[FFIType.uint64_t] = function int64(val) {
+ if (typeof val === "bigint") {
+ if (val < Number.MAX_VALUE && val > 0) {
+ return Number(val).valueOf();
+ }
+ }
+
+ if (!val) {
+ return 0;
+ }
+
+ return val;
+};
+
ffiWrappers[FFIType.uint16_t] = function uint64(val) {
if (typeof val === "bigint") {
if (val < Number.MAX_VALUE) {