Skip to content

Commit

Permalink
Add object-map test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongin committed Jul 24, 2024
1 parent 32e4d9e commit 2a48504
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/TestCases/napi-dotnet/object_map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

// Test the JSRuntimeContext "object map" which keeps track of JS wrapper objects
// for corresponding .NET objects.

const assert = require('assert');

/** @type {import('./napi-dotnet')} */
const binding = require('../common').binding;

const ComplexTypes = binding.ComplexTypes;
assert.strictEqual(typeof ComplexTypes, 'object');

let obj1 = ComplexTypes.classObject;
assert(obj1);

// The same JS wrapper instance should be returned every time.
let obj2 = ComplexTypes.classObject;
assert.strictEqual(obj1, obj2);

// Force the JS wrapper object to be collected.
obj1 = obj2 = undefined;
global.gc();

// A new JS wrapper object should be created.
let obj3 = ComplexTypes.classObject;
assert(obj3);

0 comments on commit 2a48504

Please sign in to comment.