summaryrefslogtreecommitdiff
path: root/test_ffi/tests/test.js
diff options
context:
space:
mode:
authorAapo Alasuutari <aapo.alasuutari@gmail.com>2022-07-23 20:11:06 +0300
committerGitHub <noreply@github.com>2022-07-23 22:41:06 +0530
commite1cbd2364f536a1cef817961967e1738b89be734 (patch)
tree5e4c335cab348696a46558a0cd8d2be37160db8a /test_ffi/tests/test.js
parent2843160fc79a9651e9b2c2ddc4f834c15e138db6 (diff)
feat(ext/ffi): Add support to get ArrayBuffers from UnsafePointerView (#15143)
Diffstat (limited to 'test_ffi/tests/test.js')
-rw-r--r--test_ffi/tests/test.js13
1 files changed, 12 insertions, 1 deletions
diff --git a/test_ffi/tests/test.js b/test_ffi/tests/test.js
index ff81f302e..516182f6f 100644
--- a/test_ffi/tests/test.js
+++ b/test_ffi/tests/test.js
@@ -3,7 +3,9 @@
// Run using cargo test or `--v8-options=--allow-natives-syntax`
-import { assertThrows } from "../../test_util/std/testing/asserts.ts";
+import {
+ assertThrows,
+} from "../../test_util/std/testing/asserts.ts";
const targetDir = Deno.execPath().replace(/[^\/\\]+$/, "");
const [libPrefix, libSuffix] = {
@@ -442,6 +444,15 @@ console.log(
const view = new Deno.UnsafePointerView(dylib.symbols.static_ptr);
console.log("Static ptr value:", view.getUint32());
+const arrayBuffer = view.getArrayBuffer(4);
+const uint32Array = new Uint32Array(arrayBuffer);
+console.log("arrayBuffer.byteLength:", arrayBuffer.byteLength);
+console.log("uint32Array.length:", uint32Array.length);
+console.log("uint32Array[0]:", uint32Array[0]);
+uint32Array[0] = 55; // MUTATES!
+console.log("uint32Array[0] after mutation:", uint32Array[0]);
+console.log("Static ptr value after mutation:", view.getUint32());
+
(function cleanup() {
dylib.close();
throwCallback.close();