Skip to content

Commit 53894c9

Browse files
committed
fixup! lib: refactor internal webidl converters
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
1 parent a1a64b2 commit 53894c9

3 files changed

Lines changed: 54 additions & 36 deletions

File tree

test/parallel/test-internal-webidl-buffer-source.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ const TYPED_ARRAY_CTORS = [
1515
Float16Array, Float32Array, Float64Array,
1616
BigInt64Array, BigUint64Array,
1717
];
18+
const hasGrowableSharedArrayBuffer = (() => {
19+
try {
20+
return new SharedArrayBuffer(0, { maxByteLength: 1 }).growable === true;
21+
} catch {
22+
return false;
23+
}
24+
})();
1825

1926
test('BufferSource accepts ArrayBuffer', () => {
2027
const ab = new ArrayBuffer(8);
@@ -159,7 +166,9 @@ test('BufferSource handles resizable-backed views with explicit options', () =>
159166
}
160167
});
161168

162-
test('BufferSource handles growable SAB-backed views with explicit options', () => {
169+
test('BufferSource handles growable SAB-backed views with explicit options', {
170+
skip: !hasGrowableSharedArrayBuffer,
171+
}, () => {
163172
for (const Ctor of [DataView, ...TYPED_ARRAY_CTORS]) {
164173
{
165174
const view = new Ctor(new SharedArrayBuffer(0, { maxByteLength: 1 }));

test/parallel/test-internal-webidl.js

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ const opts = {
1212
prefix: 'Prefix',
1313
context: 'Context',
1414
};
15+
const hasGrowableSharedArrayBuffer = (() => {
16+
try {
17+
return new SharedArrayBuffer(0, { maxByteLength: 1 }).growable === true;
18+
} catch {
19+
return false;
20+
}
21+
})();
1522

1623
function assertInvalidArgType(fn) {
1724
assert.throws(fn, {
@@ -429,38 +436,40 @@ assert.throws(() => webidl.requiredArguments(1, 2, opts), {
429436
assert.strictEqual(converters.BufferSource(view, allowShared), view);
430437
assert.strictEqual(converters.Uint8Array(view, allowShared), view);
431438

432-
const growable = new SharedArrayBuffer(4, { maxByteLength: 8 });
433-
const growableView = new Uint8Array(growable);
434-
435-
assert.throws(() => converters.BufferSource(growableView, {
436-
__proto__: null,
437-
...opts,
438-
allowShared: true,
439-
allowResizable: false,
440-
}), {
441-
name: 'TypeError',
442-
code: 'ERR_INVALID_ARG_TYPE',
443-
message: 'Prefix: Context is backed by a growable ' +
444-
'SharedArrayBuffer, which is not allowed.',
445-
});
446-
assert.throws(() => converters.Uint8Array(growableView, {
447-
__proto__: null,
448-
...opts,
449-
allowShared: true,
450-
}), {
451-
name: 'TypeError',
452-
code: 'ERR_INVALID_ARG_TYPE',
453-
message: 'Prefix: Context is backed by a growable ' +
454-
'SharedArrayBuffer, which is not allowed.',
455-
});
456-
assert.strictEqual(converters.BufferSource(growableView, {
457-
__proto__: null,
458-
allowShared: true,
459-
allowResizable: true,
460-
}), growableView);
461-
assert.strictEqual(converters.Uint8Array(growableView, {
462-
__proto__: null,
463-
allowShared: true,
464-
allowResizable: true,
465-
}), growableView);
439+
if (hasGrowableSharedArrayBuffer) {
440+
const growable = new SharedArrayBuffer(4, { maxByteLength: 8 });
441+
const growableView = new Uint8Array(growable);
442+
443+
assert.throws(() => converters.BufferSource(growableView, {
444+
__proto__: null,
445+
...opts,
446+
allowShared: true,
447+
allowResizable: false,
448+
}), {
449+
name: 'TypeError',
450+
code: 'ERR_INVALID_ARG_TYPE',
451+
message: 'Prefix: Context is backed by a growable ' +
452+
'SharedArrayBuffer, which is not allowed.',
453+
});
454+
assert.throws(() => converters.Uint8Array(growableView, {
455+
__proto__: null,
456+
...opts,
457+
allowShared: true,
458+
}), {
459+
name: 'TypeError',
460+
code: 'ERR_INVALID_ARG_TYPE',
461+
message: 'Prefix: Context is backed by a growable ' +
462+
'SharedArrayBuffer, which is not allowed.',
463+
});
464+
assert.strictEqual(converters.BufferSource(growableView, {
465+
__proto__: null,
466+
allowShared: true,
467+
allowResizable: true,
468+
}), growableView);
469+
assert.strictEqual(converters.Uint8Array(growableView, {
470+
__proto__: null,
471+
allowShared: true,
472+
allowResizable: true,
473+
}), growableView);
474+
}
466475
}

test/parallel/test-structuredClone-global.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const assert = require('assert');
66
const prefix = "Failed to execute 'structuredClone'";
77
const key = 'transfer';
88
const context = 'Options';
9-
const memberConverterError = `${prefix}: ${key} in ${context} can not be converted to sequence.`;
9+
const memberConverterError = `${prefix}: ${key} in ${context} cannot be converted to sequence.`;
1010
const dictionaryConverterError = `${prefix}: ${context} cannot be converted to a dictionary`;
1111

1212
assert.throws(() => structuredClone(), { code: 'ERR_MISSING_ARGS' });

0 commit comments

Comments
 (0)