fix(napi): improve napi_is_detached_arraybuffer (#17498)

This commit is contained in:
Divy Srivastava 2023-01-23 00:52:18 -08:00 committed by GitHub
parent 2e1df62380
commit b96bbc32c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 5 deletions

View file

@ -1,6 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals, loadTestLibrary } from "./common.js";
import { assert, assertEquals, loadTestLibrary } from "./common.js";
const typedarray = loadTestLibrary();
@ -10,3 +10,15 @@ Deno.test("napi arraybuffer detach", function () {
typedarray.test_detached(buf);
assertEquals(buf.byteLength, 0);
});
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));
});
});