Skip to content

Commit b3b277d

Browse files
committed
use skipTest and version check for experimental features
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
1 parent 9a64a95 commit b3b277d

4 files changed

Lines changed: 100 additions & 76 deletions

File tree

implementors/node/features.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
// Declares which experimental Node-API features this runtime supports.
22
// Each key corresponds to a NODE_API_EXPERIMENTAL_HAS_* compile-time macro.
33
// Other implementors should set unsupported features to false or omit them.
4+
5+
const [major, minor] = process.version.slice(1).split('.').map(Number);
6+
47
globalThis.experimentalFeatures = {
5-
sharedArrayBuffer: true,
8+
// node_api_is_sharedarraybuffer and node_api_create_sharedarraybuffer were
9+
// added in Node.js v24.9.0. Earlier versions do not export these symbols,
10+
// causing addons that reference them to fail at dlopen time.
11+
sharedArrayBuffer: major >= 25 || (major === 24 && minor >= 9),
612
createObjectWithProperties: true,
713
setPrototype: true,
814
postFinalizer: true,

implementors/node/process.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const napiVersion = Number(process.versions.napi);
2+
3+
const skipTest = () => {
4+
process.exit(0);
5+
};
6+
7+
Object.assign(globalThis, { napiVersion, skipTest });

implementors/node/tests.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ const GC_MODULE_PATH = path.join(
3434
"node",
3535
"gc.js"
3636
);
37+
const PROCESS_MODULE_PATH = path.join(
38+
ROOT_PATH,
39+
"implementors",
40+
"node",
41+
"process.js"
42+
);
3743
const MUST_CALL_MODULE_PATH = path.join(
3844
ROOT_PATH,
3945
"implementors",
@@ -79,6 +85,8 @@ export function runFileInSubprocess(
7985
"--import",
8086
"file://" + GC_MODULE_PATH,
8187
"--import",
88+
"file://" + PROCESS_MODULE_PATH,
89+
"--import",
8290
"file://" + MUST_CALL_MODULE_PATH,
8391
filePath,
8492
],
Lines changed: 78 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,91 @@
11
"use strict";
22

3-
if (experimentalFeatures.sharedArrayBuffer) {
4-
const test_sharedarraybuffer = loadAddon("test_sharedarraybuffer");
3+
// SharedArrayBuffer support is an experimental feature.
4+
if (!experimentalFeatures.sharedArrayBuffer) {
5+
skipTest();
6+
}
57

6-
{
7-
const sab = new SharedArrayBuffer(16);
8-
const ab = new ArrayBuffer(16);
9-
const obj = {};
10-
const arr = [];
8+
const test_sharedarraybuffer = loadAddon("test_sharedarraybuffer");
119

12-
assert.strictEqual(
13-
test_sharedarraybuffer.TestIsSharedArrayBuffer(sab),
14-
true,
15-
);
16-
assert.strictEqual(
17-
test_sharedarraybuffer.TestIsSharedArrayBuffer(ab),
18-
false,
19-
);
20-
assert.strictEqual(
21-
test_sharedarraybuffer.TestIsSharedArrayBuffer(obj),
22-
false,
23-
);
24-
assert.strictEqual(
25-
test_sharedarraybuffer.TestIsSharedArrayBuffer(arr),
26-
false,
27-
);
28-
assert.strictEqual(
29-
test_sharedarraybuffer.TestIsSharedArrayBuffer(null),
30-
false,
31-
);
32-
assert.strictEqual(
33-
test_sharedarraybuffer.TestIsSharedArrayBuffer(undefined),
34-
false,
35-
);
36-
}
10+
{
11+
const sab = new SharedArrayBuffer(16);
12+
const ab = new ArrayBuffer(16);
13+
const obj = {};
14+
const arr = [];
3715

38-
// Test node_api_create_sharedarraybuffer
39-
{
40-
const sab = test_sharedarraybuffer.TestCreateSharedArrayBuffer(16);
41-
assert(sab instanceof SharedArrayBuffer);
42-
assert.strictEqual(sab.byteLength, 16);
43-
}
16+
assert.strictEqual(
17+
test_sharedarraybuffer.TestIsSharedArrayBuffer(sab),
18+
true,
19+
);
20+
assert.strictEqual(
21+
test_sharedarraybuffer.TestIsSharedArrayBuffer(ab),
22+
false,
23+
);
24+
assert.strictEqual(
25+
test_sharedarraybuffer.TestIsSharedArrayBuffer(obj),
26+
false,
27+
);
28+
assert.strictEqual(
29+
test_sharedarraybuffer.TestIsSharedArrayBuffer(arr),
30+
false,
31+
);
32+
assert.strictEqual(
33+
test_sharedarraybuffer.TestIsSharedArrayBuffer(null),
34+
false,
35+
);
36+
assert.strictEqual(
37+
test_sharedarraybuffer.TestIsSharedArrayBuffer(undefined),
38+
false,
39+
);
40+
}
4441

45-
// Test node_api_create_get_sharedarraybuffer_info
46-
{
47-
const sab = new SharedArrayBuffer(32);
48-
const byteLength = test_sharedarraybuffer.TestGetSharedArrayBufferInfo(sab);
49-
assert.strictEqual(byteLength, 32);
50-
}
42+
// Test node_api_create_sharedarraybuffer
43+
{
44+
const sab = test_sharedarraybuffer.TestCreateSharedArrayBuffer(16);
45+
assert(sab instanceof SharedArrayBuffer);
46+
assert.strictEqual(sab.byteLength, 16);
47+
}
48+
49+
// Test node_api_create_get_sharedarraybuffer_info
50+
{
51+
const sab = new SharedArrayBuffer(32);
52+
const byteLength = test_sharedarraybuffer.TestGetSharedArrayBufferInfo(sab);
53+
assert.strictEqual(byteLength, 32);
54+
}
5155

52-
// Test data access
53-
{
54-
const sab = new SharedArrayBuffer(8);
55-
const result = test_sharedarraybuffer.TestSharedArrayBufferData(sab);
56-
assert.strictEqual(result, true);
56+
// Test data access
57+
{
58+
const sab = new SharedArrayBuffer(8);
59+
const result = test_sharedarraybuffer.TestSharedArrayBufferData(sab);
60+
assert.strictEqual(result, true);
5761

58-
// Check if data was written correctly
59-
const view = new Uint8Array(sab);
60-
for (let i = 0; i < 8; i++) {
61-
assert.strictEqual(view[i], i % 256);
62-
}
62+
// Check if data was written correctly
63+
const view = new Uint8Array(sab);
64+
for (let i = 0; i < 8; i++) {
65+
assert.strictEqual(view[i], i % 256);
6366
}
67+
}
6468

65-
// Test data pointer from existing SharedArrayBuffer
66-
{
67-
const sab = new SharedArrayBuffer(16);
68-
const result = test_sharedarraybuffer.TestSharedArrayBufferData(sab);
69-
assert.strictEqual(result, true);
70-
}
69+
// Test data pointer from existing SharedArrayBuffer
70+
{
71+
const sab = new SharedArrayBuffer(16);
72+
const result = test_sharedarraybuffer.TestSharedArrayBufferData(sab);
73+
assert.strictEqual(result, true);
74+
}
7175

72-
// Test zero-length SharedArrayBuffer
73-
{
74-
const sab = test_sharedarraybuffer.TestCreateSharedArrayBuffer(0);
75-
assert(sab instanceof SharedArrayBuffer);
76-
assert.strictEqual(sab.byteLength, 0);
77-
}
76+
// Test zero-length SharedArrayBuffer
77+
{
78+
const sab = test_sharedarraybuffer.TestCreateSharedArrayBuffer(0);
79+
assert(sab instanceof SharedArrayBuffer);
80+
assert.strictEqual(sab.byteLength, 0);
81+
}
7882

79-
// Test invalid arguments
80-
{
81-
assert.throws(
82-
() => {
83-
test_sharedarraybuffer.TestGetSharedArrayBufferInfo({});
84-
},
85-
{ name: "Error", message: "Invalid argument" },
86-
);
87-
}
83+
// Test invalid arguments
84+
{
85+
assert.throws(
86+
() => {
87+
test_sharedarraybuffer.TestGetSharedArrayBufferInfo({});
88+
},
89+
{ name: "Error", message: "Invalid argument" },
90+
);
8891
}

0 commit comments

Comments
 (0)