diff options
author | 2022-04-29 07:49:48 -0700 | |
---|---|---|
committer | 2022-04-29 07:49:48 -0700 | |
commit | d49ba5028949f726e68b31093921c2187759ab4b (patch) | |
tree | 91fdcf74bc342c872ee7047fe1bd6ca9d3a0fe93 /integration/bunjs-only-snippets/ffi.test.js | |
parent | 22f74756b4cf173749b2f72fdae438f8def24bd2 (diff) | |
download | bun-d49ba5028949f726e68b31093921c2187759ab4b.tar.gz bun-d49ba5028949f726e68b31093921c2187759ab4b.tar.zst bun-d49ba5028949f726e68b31093921c2187759ab4b.zip |
[bun.js] Implement unsafe.{`arrayBufferToPtr`, `arrayBufferFromPtr`, `bufferFromPtr`}
Diffstat (limited to 'integration/bunjs-only-snippets/ffi.test.js')
-rw-r--r-- | integration/bunjs-only-snippets/ffi.test.js | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/integration/bunjs-only-snippets/ffi.test.js b/integration/bunjs-only-snippets/ffi.test.js index cd51a4594..16967fe51 100644 --- a/integration/bunjs-only-snippets/ffi.test.js +++ b/integration/bunjs-only-snippets/ffi.test.js @@ -1,4 +1,5 @@ import { describe, it, expect } from "bun:test"; +import { unsafe } from "bun"; it("ffi print", () => { Bun.dlprint({ @@ -168,7 +169,6 @@ it("ffi run", () => { // params: ["uint64_t", "uint64_t"], // }, }; - console.log(Bun.dlprint(types)[0]); const { symbols: { returns_true, @@ -253,7 +253,12 @@ it("ffi run", () => { expect(ptr != 0).toBe(true); expect(typeof ptr === "number").toBe(true); expect(does_pointer_equal_42_as_int32_t(ptr)).toBe(true); - // expect(add_uint64_t(1, 1)).toBe(2); + const buffer = unsafe.bufferFromPtr(ptr, 4); + expect(buffer.readInt32(0)).toBe(42); + expect( + new DataView(unsafe.arrayBufferFromPtr(ptr, 4), 0, 4).getInt32(0, true) + ).toBe(42); + expect(unsafe.arrayBufferToPtr(buffer)).toBe(ptr); close(); }); ``; |