summaryrefslogtreecommitdiff
path: root/tests/napi/object_wrap_test.js
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2024-02-12 13:46:50 -0700
committerGitHub <noreply@github.com>2024-02-12 13:46:50 -0700
commitf60720090c7bd8cdf91d7aebd0c42e01c86b3b83 (patch)
tree9becb7ff7e40d37769601fa049beccd101d58a98 /tests/napi/object_wrap_test.js
parentbd1358efab8ba7339a8e70034315fa7da840292e (diff)
chore: move test_ffi and test_nap to tests/ [WIP] (#22394)
Moving some additional NAPI and. FFI tests out of the tree root.
Diffstat (limited to 'tests/napi/object_wrap_test.js')
-rw-r--r--tests/napi/object_wrap_test.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/napi/object_wrap_test.js b/tests/napi/object_wrap_test.js
new file mode 100644
index 000000000..f79fd08f8
--- /dev/null
+++ b/tests/napi/object_wrap_test.js
@@ -0,0 +1,41 @@
+// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+
+import { assert, assertEquals, loadTestLibrary } from "./common.js";
+
+const objectWrap = loadTestLibrary();
+
+Deno.test("napi object wrap new", function () {
+ const obj = new objectWrap.NapiObject(0);
+ assertEquals(obj.get_value(), 0);
+ obj.set_value(10);
+ assertEquals(obj.get_value(), 10);
+ obj.increment();
+ assertEquals(obj.get_value(), 11);
+ obj.increment();
+ obj.set_value(10);
+ assertEquals(obj.get_value(), 10);
+ assertEquals(objectWrap.NapiObject.factory(), 64);
+});
+
+Deno.test("napi bind finalizer", function () {
+ const obj = {};
+ objectWrap.test_bind_finalizer(obj);
+});
+
+Deno.test("napi external finalizer", function () {
+ let obj = objectWrap.test_external_finalizer();
+ assert(obj);
+ obj = null;
+});
+
+Deno.test("napi external buffer", function () {
+ let buf = objectWrap.test_external_buffer();
+ assertEquals(buf, new Uint8Array([1, 2, 3]));
+ buf = null;
+});
+
+Deno.test("napi external arraybuffer", function () {
+ let buf = objectWrap.test_external_arraybuffer();
+ assertEquals(new Uint8Array(buf), new Uint8Array([1, 2, 3]));
+ buf = null;
+});