aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/ffi.test.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-05-04 00:16:36 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-05-04 00:16:36 -0700
commit5b760fe7c48e439670d56e55d7b72283892cb27b (patch)
tree91f6cdb2936d3c9ffec7844d5fb8d8e22376a4e3 /integration/bunjs-only-snippets/ffi.test.js
parent162e8911db21110f25b0814f5c4f66833000ea99 (diff)
downloadbun-5b760fe7c48e439670d56e55d7b72283892cb27b.tar.gz
bun-5b760fe7c48e439670d56e55d7b72283892cb27b.tar.zst
bun-5b760fe7c48e439670d56e55d7b72283892cb27b.zip
Safer i64/u64
Diffstat (limited to 'integration/bunjs-only-snippets/ffi.test.js')
-rw-r--r--integration/bunjs-only-snippets/ffi.test.js41
1 files changed, 27 insertions, 14 deletions
diff --git a/integration/bunjs-only-snippets/ffi.test.js b/integration/bunjs-only-snippets/ffi.test.js
index 258ee93ec..9198df3f7 100644
--- a/integration/bunjs-only-snippets/ffi.test.js
+++ b/integration/bunjs-only-snippets/ffi.test.js
@@ -58,8 +58,10 @@ it("ffi print", async () => {
).toBe(true);
});
-it("ffi run", () => {
- const types = {
+function getTypes(fast) {
+ const int64_t = fast ? "i64_fast" : "int64_t";
+ const uint64_t = fast ? "u64_fast" : "uint64_t";
+ return {
returns_true: {
returns: "bool",
args: [],
@@ -97,7 +99,7 @@ it("ffi run", () => {
args: [],
},
returns_42_uint64_t: {
- returns: "uint64_t",
+ returns: uint64_t,
args: [],
},
returns_neg_42_int16_t: {
@@ -109,7 +111,7 @@ it("ffi run", () => {
args: [],
},
returns_neg_42_int64_t: {
- returns: "int64_t",
+ returns: int64_t,
args: [],
},
@@ -142,8 +144,8 @@ it("ffi run", () => {
args: ["int32_t"],
},
identity_int64_t: {
- returns: "int64_t",
- args: ["int64_t"],
+ returns: int64_t,
+ args: [int64_t],
},
identity_uint8_t: {
returns: "uint8_t",
@@ -158,8 +160,8 @@ it("ffi run", () => {
args: ["uint32_t"],
},
identity_uint64_t: {
- returns: "uint64_t",
- args: ["uint64_t"],
+ returns: uint64_t,
+ args: [uint64_t],
},
add_char: {
@@ -187,8 +189,8 @@ it("ffi run", () => {
args: ["int32_t", "int32_t"],
},
add_int64_t: {
- returns: "int64_t",
- args: ["int64_t", "int64_t"],
+ returns: int64_t,
+ args: [int64_t, int64_t],
},
add_uint8_t: {
returns: "uint8_t",
@@ -217,8 +219,8 @@ it("ffi run", () => {
args: ["ptr"],
},
add_uint64_t: {
- returns: "uint64_t",
- args: ["uint64_t", "uint64_t"],
+ returns: uint64_t,
+ args: [uint64_t, uint64_t],
},
cb_identity_true: {
@@ -258,7 +260,7 @@ it("ffi run", () => {
args: ["ptr"],
},
cb_identity_42_uint64_t: {
- returns: "uint64_t",
+ returns: uint64_t,
args: ["ptr"],
},
cb_identity_neg_42_int16_t: {
@@ -270,7 +272,7 @@ it("ffi run", () => {
args: ["ptr"],
},
cb_identity_neg_42_int64_t: {
- returns: "int64_t",
+ returns: int64_t,
args: ["ptr"],
},
@@ -279,6 +281,9 @@ it("ffi run", () => {
args: [],
},
};
+}
+
+function ffiRunner(types) {
const {
symbols: {
returns_true,
@@ -514,4 +519,12 @@ it("ffi run", () => {
// ).toBe(-42);
close();
+}
+
+it("run ffi fast", () => {
+ ffiRunner(getTypes(true));
+});
+
+it("run ffi", () => {
+ ffiRunner(getTypes(false));
});