2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 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));
|
|
|
|
});
|
|
|
|
});
|