Skip to content

Commit bc0a6fe

Browse files
committed
merge tests
1 parent eed4117 commit bc0a6fe

File tree

7 files changed

+38
-305
lines changed

7 files changed

+38
-305
lines changed

β€Žtest/node-api/test_reference_all_types/binding.gypβ€Ž

Lines changed: 0 additions & 9 deletions
This file was deleted.

β€Žtest/node-api/test_reference_all_types/test.jsβ€Ž

Lines changed: 0 additions & 90 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"targets": [
3+
{
4+
"target_name": "test_reference_all_types",
5+
"sources": [ "test_reference_by_node_api_version.c" ],
6+
"defines": [ "NAPI_EXPERIMENTAL" ],
7+
},
8+
{
9+
"target_name": "test_reference_obj_only",
10+
"sources": [ "test_reference_by_node_api_version.c" ],
11+
"defines": [ "NAPI_VERSION=8" ],
12+
}
13+
]
14+
}

β€Žtest/node-api/test_reference_obj_only/test.jsβ€Ž renamed to β€Žtest/node-api/test_reference_by_node_api_version/test.jsβ€Ž

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
'use strict';
22
// Flags: --expose-gc
33
//
4-
// Testing API calls for references to only object, function, and symbol types.
5-
// This is the reference behavior without the napi_feature_reference_all_types
6-
// feature enabled.
7-
// This test uses NAPI_MODULE_INIT macro to initialize module.
4+
// Testing API calls for Node-API references.
5+
// We compare their behavior between Node-API version 8 and later.
6+
// In version 8 references can be created only for object, function,
7+
// and symbol types. While in newer versions they can be created for
8+
// any value type.
89
//
910
const { gcUntil, buildType } = require('../../common');
1011
const assert = require('assert');
11-
const addon = require(`./build/${buildType}/test_reference_obj_only`);
12+
const addon_v8 = require(`./build/${buildType}/test_reference_obj_only`);
13+
const addon_new = require(`./build/${buildType}/test_reference_all_types`);
1214

13-
async function runTests() {
15+
async function runTests(addon, isVersion8) {
1416
let allEntries = [];
1517

1618
(() => {
@@ -27,22 +29,22 @@ async function runTests() {
2729
const bigintValue = 9007199254740991n;
2830

2931
allEntries = [
30-
{ value: undefinedValue, canBeWeak: false, canBeRef: false },
31-
{ value: nullValue, canBeWeak: false, canBeRef: false },
32-
{ value: booleanValue, canBeWeak: false, canBeRef: false },
33-
{ value: numberValue, canBeWeak: false, canBeRef: false },
34-
{ value: stringValue, canBeWeak: false, canBeRef: false },
35-
{ value: symbolValue, canBeWeak: false, canBeRef: true },
36-
{ value: objectValue, canBeWeak: true, canBeRef: true },
37-
{ value: functionValue, canBeWeak: true, canBeRef: true },
38-
{ value: externalValue, canBeWeak: true, canBeRef: true },
39-
{ value: bigintValue, canBeWeak: false, canBeRef: false },
32+
{ value: undefinedValue, canBeWeak: false, canBeRefV8: false },
33+
{ value: nullValue, canBeWeak: false, canBeRefV8: false },
34+
{ value: booleanValue, canBeWeak: false, canBeRefV8: false },
35+
{ value: numberValue, canBeWeak: false, canBeRefV8: false },
36+
{ value: stringValue, canBeWeak: false, canBeRefV8: false },
37+
{ value: symbolValue, canBeWeak: false, canBeRefV8: true },
38+
{ value: objectValue, canBeWeak: true, canBeRefV8: true },
39+
{ value: functionValue, canBeWeak: true, canBeRefV8: true },
40+
{ value: externalValue, canBeWeak: true, canBeRefV8: true },
41+
{ value: bigintValue, canBeWeak: false, canBeRefV8: false },
4042
];
4143

4244
// Go over all values of different types, create strong ref values for
4345
// them, read the stored values, and check how the ref count works.
4446
for (const entry of allEntries) {
45-
if (entry.canBeRef) {
47+
if (!isVersion8 || entry.canBeRefV8) {
4648
const index = addon.createRef(entry.value);
4749
const refValue = addon.getRefValue(index);
4850
assert.strictEqual(entry.value, refValue);
@@ -59,12 +61,10 @@ async function runTests() {
5961
}
6062

6163
// The references become weak pointers when the ref count is 0.
62-
// The old reference were supported for objects, external objects,
63-
// functions, and symbols.
6464
// Here we know that the GC is not run yet because the values are
6565
// still in the allEntries array.
6666
allEntries.forEach((entry, index) => {
67-
if (entry.canBeRef) {
67+
if (!isVersion8 || entry.canBeRefV8) {
6868
assert.strictEqual(addon.getRefValue(index), entry.value);
6969
}
7070
// Set to undefined to allow GC collect the value.
@@ -93,7 +93,7 @@ async function runTests() {
9393
// It also includes the value at index 0 because it is the undefined value.
9494
// Other value types are not collected by GC.
9595
allEntries.forEach((entry, index) => {
96-
if (entry.canBeRef) {
96+
if (!isVersion8 || entry.canBeRefV8) {
9797
if (entry.canBeWeak || index === 0) {
9898
assert.strictEqual(addon.getRefValue(index), undefined);
9999
} else {
@@ -103,4 +103,6 @@ async function runTests() {
103103
}
104104
});
105105
}
106-
runTests();
106+
107+
runTests(addon_v8, /* isVersion8 */ true);
108+
runTests(addon_new, /* isVersion8 */ false);

β€Žtest/node-api/test_reference_obj_only/binding.gypβ€Ž

Lines changed: 0 additions & 9 deletions
This file was deleted.

β€Žtest/node-api/test_reference_obj_only/test_reference_obj_only.cβ€Ž

Lines changed: 0 additions & 175 deletions
This file was deleted.

0 commit comments

Comments
Β (0)