Skip to content

Commit c5a8338

Browse files
committed
test: workerd does not support transfer list
1 parent 063224c commit c5a8338

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

tests/encoding/mistakes.test.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,8 @@ describe('Common implementation mistakes', () => {
877877
// text-encoding is wrong, naive whatwg-encoding usage fails too
878878
// https://webidl.spec.whatwg.org/#dfn-get-buffer-source-copy
879879
// 7. If IsDetachedBuffer(jsArrayBuffer) is true, then return the empty byte sequence.
880-
test('decoding detached returns empty data', { skip: !globalThis.MessageChannel }, (t) => {
880+
const canDetach = ArrayBuffer.prototype.transfer || globalThis.MessageChannel
881+
test('decoding detached returns empty data', { skip: !canDetach }, (t) => {
881882
for (const fatal of [false, true]) {
882883
const decoder = new TextDecoder('utf-8', { fatal })
883884
const a = new ArrayBuffer(2)
@@ -889,7 +890,12 @@ describe('Common implementation mistakes', () => {
889890
// second time
890891
t.assert.strictEqual(decoder.decode(a), '$%')
891892
t.assert.strictEqual(decoder.decode(b), '$%')
892-
new MessageChannel().port1.postMessage(a, [a])
893+
if (a.transfer) {
894+
a.transfer()
895+
} else {
896+
new MessageChannel().port1.postMessage(a, [a])
897+
}
898+
893899
// but not anymore
894900
t.assert.strictEqual(decoder.decode(a), '')
895901
t.assert.strictEqual(decoder.decode(b), '')

tests/wpt/loader.cjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,20 @@ if (!globalThis.Float16Array) {
1616
Object.assign(globalThis, { Float16Array })
1717
}
1818

19+
function haveMessageChannelTransfer() {
20+
if (!globalThis.MessageChannel) return false
21+
try {
22+
const a = new ArrayBuffer(2)
23+
new MessageChannel().port1.postMessage(a, [a])
24+
return true
25+
} catch {}
26+
27+
return false
28+
}
29+
1930
// MessageChannel is used to test detached ArrayBuffer instances
2031
// We can polyfill that on modern barebone engines except Hermes
21-
if (!globalThis.MessageChannel && ArrayBuffer.prototype.transfer) {
32+
if (!haveMessageChannelTransfer() && ArrayBuffer.prototype.transfer) {
2233
const MessageChannel = class {
2334
port1 = { postMessage: (_, transfer = []) => transfer.forEach((x) => x.transfer()) }
2435
}

0 commit comments

Comments
 (0)