2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2022-10-05 10:06:44 -04:00
|
|
|
|
2024-06-10 12:20:44 -04:00
|
|
|
import { Buffer } from "node:buffer";
|
2023-05-18 09:45:47 -04:00
|
|
|
import { assert, assertEquals, loadTestLibrary } from "./common.js";
|
2022-10-05 10:06:44 -04:00
|
|
|
|
|
|
|
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);
|
2023-01-10 09:35:46 -05:00
|
|
|
assertEquals(objectWrap.NapiObject.factory(), 64);
|
2022-10-05 10:06:44 -04:00
|
|
|
});
|
2023-05-18 09:45:47 -04:00
|
|
|
|
|
|
|
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();
|
2024-06-10 12:20:44 -04:00
|
|
|
assertEquals(buf, new Buffer([1, 2, 3]));
|
2023-05-18 09:45:47 -04:00
|
|
|
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;
|
|
|
|
});
|