diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-10-08 14:02:07 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-08 14:02:07 +0900 |
commit | 6cb5d8eb86fe205ad4f4411e20c206246ff25682 (patch) | |
tree | 51d8ec1d17cd617417a11562893cb914db59631a /cli/tests | |
parent | effb5e1ce417e9b7f22adcdc598e9a5ec593f4a2 (diff) |
fix(ext/ffi): use anybuffer for op_ffi_ptr_of (#20820)
Fixes #20817
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/unit/ffi_test.ts | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/cli/tests/unit/ffi_test.ts b/cli/tests/unit/ffi_test.ts index c5961c6fb..018cec674 100644 --- a/cli/tests/unit/ffi_test.ts +++ b/cli/tests/unit/ffi_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertThrows } from "./test_util.ts"; +import { assertEquals, assertThrows } from "./test_util.ts"; Deno.test({ permissions: { ffi: true } }, function dlopenInvalidArguments() { const filename = "/usr/lib/libc.so.6"; @@ -77,3 +77,24 @@ Deno.test({ permissions: { ffi: false } }, function ffiPermissionDenied() { ptrView.getFloat64(); }, Deno.errors.PermissionDenied); }); + +Deno.test({ permissions: { ffi: true } }, function pointerOf() { + const buffer = new ArrayBuffer(1024); + const baseAddress = Deno.UnsafePointer.value(Deno.UnsafePointer.of(buffer)); + const uint8Address = Deno.UnsafePointer.value( + Deno.UnsafePointer.of(new Uint8Array(buffer)), + ); + assertEquals(baseAddress, uint8Address); + const float64Address = Deno.UnsafePointer.value( + Deno.UnsafePointer.of(new Float64Array(buffer)), + ); + assertEquals(baseAddress, float64Address); + const uint8AddressOffset = Deno.UnsafePointer.value( + Deno.UnsafePointer.of(new Uint8Array(buffer, 100)), + ); + assertEquals(Number(baseAddress) + 100, uint8AddressOffset); + const float64AddressOffset = Deno.UnsafePointer.value( + Deno.UnsafePointer.of(new Float64Array(buffer, 80)), + ); + assertEquals(Number(baseAddress) + 80, float64AddressOffset); +}); |