2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2022-10-30 13:13:46 -04:00
|
|
|
|
2023-01-23 03:52:18 -05:00
|
|
|
import { assert, assertEquals, loadTestLibrary } from "./common.js";
|
2022-10-30 13:13:46 -04:00
|
|
|
|
|
|
|
const typedarray = loadTestLibrary();
|
|
|
|
|
|
|
|
Deno.test("napi arraybuffer detach", function () {
|
|
|
|
const buf = new ArrayBuffer(5);
|
|
|
|
assertEquals(buf.byteLength, 5);
|
|
|
|
typedarray.test_detached(buf);
|
|
|
|
assertEquals(buf.byteLength, 0);
|
|
|
|
});
|
2023-01-23 03:52:18 -05:00
|
|
|
|
|
|
|
Deno.test("napi arraybuffer is detached", function () {
|
|
|
|
const buf = new ArrayBuffer(5);
|
|
|
|
assertEquals(buf.byteLength, 5);
|
|
|
|
assert(!typedarray.is_detached(buf));
|
|
|
|
typedarray.test_detached(buf);
|
|
|
|
assert(typedarray.is_detached(buf));
|
|
|
|
|
|
|
|
[2, {}, "foo", null, undefined, new Uint8Array(10)].forEach((value) => {
|
|
|
|
assert(!typedarray.is_detached(value));
|
|
|
|
});
|
|
|
|
});
|