diff options
author | 2022-05-02 20:26:18 -0700 | |
---|---|---|
committer | 2022-05-02 20:26:18 -0700 | |
commit | c6d732eee2721cd6191672cbe2c57fb17c3fffe4 (patch) | |
tree | da2716453ab256ea0b389b077ac7c98513abbfe7 /integration/bunjs-only-snippets/ffi.test.js | |
parent | 21ab47d9fe1085b7a1a959df810386367ebd5c23 (diff) | |
download | bun-c6d732eee2721cd6191672cbe2c57fb17c3fffe4.tar.gz bun-c6d732eee2721cd6191672cbe2c57fb17c3fffe4.tar.zst bun-c6d732eee2721cd6191672cbe2c57fb17c3fffe4.zip |
[bun:ffi] Improve `uint64_t` and `int64_t` performance
Diffstat (limited to 'integration/bunjs-only-snippets/ffi.test.js')
-rw-r--r-- | integration/bunjs-only-snippets/ffi.test.js | 181 |
1 files changed, 94 insertions, 87 deletions
diff --git a/integration/bunjs-only-snippets/ffi.test.js b/integration/bunjs-only-snippets/ffi.test.js index b95bcfa8e..56e36d6e0 100644 --- a/integration/bunjs-only-snippets/ffi.test.js +++ b/integration/bunjs-only-snippets/ffi.test.js @@ -2,6 +2,7 @@ import { describe, it, expect } from "bun:test"; import { unsafe } from "bun"; // import { + native, viewSource, dlopen, CString, @@ -29,7 +30,7 @@ it("ffi print", async () => { { not_a_callback: { return_type: "float", - args: [], + args: ["float"], }, }, false @@ -338,12 +339,13 @@ it("ffi run", () => { } = dlopen("/tmp/bun-ffi-test.dylib", types); 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)); - expect(returns_42_double()).toBe(42.42); expect(returns_42_uint8_t()).toBe(42); expect(returns_neg_42_int8_t()).toBe(-42); @@ -354,11 +356,16 @@ it("ffi run", () => { expect(returns_neg_42_int32_t()).toBe(-42); expect(identity_int32_t(10)).toBe(10); 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); + expect(identity_bool(false)).toBe(false); expect(identity_double(10.100000000000364)).toBe(10.100000000000364); + expect(identity_int8_t(10)).toBe(10); expect(identity_int16_t(10)).toBe(10); expect(identity_int64_t(10)).toBe(10); @@ -366,6 +373,7 @@ it("ffi run", () => { 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); @@ -411,100 +419,99 @@ it("ffi run", () => { expect(identity_ptr(cptr)).toBe(cptr); const second_ptr = ptr(new Buffer(8)); expect(identity_ptr(second_ptr)).toBe(second_ptr); - function identityBool() { - return true; - } - globalThis.identityBool = identityBool; + // function identityBool() { + // return true; + // } + // globalThis.identityBool = identityBool; - const first = callback( - { - return_type: "bool", - }, - identityBool - ); + // const first = native.callback( + // { + // return_type: "bool", + // }, + // identityBool + // ); + // expect( + // cb_identity_true(return_a_function_ptr_to_function_that_returns_true()) + // ).toBe(true); - expect( - cb_identity_true(return_a_function_ptr_to_function_that_returns_true()) - ).toBe(true); + // expect(cb_identity_true(first)).toBe(true); - expect(cb_identity_true(first)).toBe(true); + // expect( + // cb_identity_false( + // callback( + // { + // return_type: "bool", + // }, + // () => false + // ) + // ) + // ).toBe(false); - expect( - cb_identity_false( - callback( - { - return_type: "bool", - }, - () => false - ) - ) - ).toBe(false); + // expect( + // cb_identity_42_char( + // callback( + // { + // return_type: "char", + // }, + // () => 42 + // ) + // ) + // ).toBe(42); + // expect( + // cb_identity_42_uint8_t( + // callback( + // { + // return_type: "uint8_t", + // }, + // () => 42 + // ) + // ) + // ).toBe(42); - expect( - cb_identity_42_char( - callback( - { - return_type: "char", - }, - () => 42 - ) - ) - ).toBe(42); - expect( - cb_identity_42_uint8_t( - callback( - { - return_type: "uint8_t", - }, - () => 42 - ) - ) - ).toBe(42); - - cb_identity_neg_42_int8_t( - callback( - { - return_type: "int8_t", - }, - () => -42 - ) - ).toBe(-42); + // cb_identity_neg_42_int8_t( + // callback( + // { + // return_type: "int8_t", + // }, + // () => -42 + // ) + // ).toBe(-42); - cb_identity_42_uint16_t( - callback( - { - return_type: "uint16_t", - }, - () => 42 - ) - ).toBe(42); + // cb_identity_42_uint16_t( + // callback( + // { + // return_type: "uint16_t", + // }, + // () => 42 + // ) + // ).toBe(42); - cb_identity_42_uint32_t( - callback( - { - return_type: "uint32_t", - }, - () => 42 - ) - ).toBe(42); + // cb_identity_42_uint32_t( + // callback( + // { + // return_type: "uint32_t", + // }, + // () => 42 + // ) + // ).toBe(42); - cb_identity_neg_42_int16_t( - callback( - { - return_type: "int16_t", - }, - () => -42 - ) - ).toBe(-42); + // cb_identity_neg_42_int16_t( + // callback( + // { + // return_type: "int16_t", + // }, + // () => -42 + // ) + // ).toBe(-42); - cb_identity_neg_42_int32_t( - callback( - { - return_type: "int32_t", - }, - () => -42 - ) - ).toBe(-42); + // cb_identity_neg_42_int32_t( + // callback( + // { + // return_type: "int32_t", + // }, + // () => -42 + // ) + // ).toBe(-42); close(); }); |