-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix weak reference handling in runtime object map (#334)
- Loading branch information
Showing
2 changed files
with
30 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |