-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: #39759 Fixes: #39713 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
- Loading branch information
1 parent
21cf618
commit d0a8986
Showing
16 changed files
with
774 additions
and
1 deletion.
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
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,21 @@ | ||
'use strict'; | ||
|
||
const { | ||
MessageChannel, | ||
receiveMessageOnPort, | ||
} = require('internal/worker/io'); | ||
|
||
let channel; | ||
function structuredClone(value, transfer) { | ||
// TODO: Improve this with a more efficient solution that avoids | ||
// instantiating a MessageChannel | ||
channel ??= new MessageChannel(); | ||
channel.port1.unref(); | ||
channel.port2.unref(); | ||
channel.port1.postMessage(value, transfer); | ||
return receiveMessageOnPort(channel.port2).message; | ||
} | ||
|
||
module.exports = { | ||
structuredClone | ||
}; |
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
44 changes: 44 additions & 0 deletions
44
...ixtures/wpt/html/webappapis/structured-clone/structured-clone-battery-of-tests-harness.js
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,44 @@ | ||
/** | ||
* Runs a collection of tests that determine if an API implements structured clone | ||
* correctly. | ||
* | ||
* The `runner` parameter has the following properties: | ||
* - `setup()`: An optional function run once before testing starts | ||
* - `teardown()`: An option function run once after all tests are done | ||
* - `preTest()`: An optional, async function run before a test | ||
* - `postTest()`: An optional, async function run after a test is done | ||
* - `structuredClone(obj, transferList)`: Required function that somehow | ||
* structurally clones an object. | ||
* - `hasDocument`: When true, disables tests that require a document. True by default. | ||
*/ | ||
|
||
function runStructuredCloneBatteryOfTests(runner) { | ||
const defaultRunner = { | ||
setup() {}, | ||
preTest() {}, | ||
postTest() {}, | ||
teardown() {}, | ||
hasDocument: true | ||
}; | ||
runner = Object.assign({}, defaultRunner, runner); | ||
|
||
let setupPromise = runner.setup(); | ||
const allTests = structuredCloneBatteryOfTests.map(test => { | ||
|
||
if (!runner.hasDocument && test.requiresDocument) { | ||
return; | ||
} | ||
|
||
return new Promise(resolve => { | ||
promise_test(async _ => { | ||
test = await test; | ||
await setupPromise; | ||
await runner.preTest(test); | ||
await test.f(runner) | ||
await runner.postTest(test); | ||
resolve(); | ||
}, test.description); | ||
}).catch(_ => {}); | ||
}); | ||
Promise.all(allTests).then(_ => runner.teardown()); | ||
} |
22 changes: 22 additions & 0 deletions
22
.../html/webappapis/structured-clone/structured-clone-battery-of-tests-with-transferables.js
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,22 @@ | ||
structuredCloneBatteryOfTests.push({ | ||
description: 'ArrayBuffer', | ||
async f(runner) { | ||
const buffer = new Uint8Array([1]).buffer; | ||
const copy = await runner.structuredClone(buffer, [buffer]); | ||
assert_equals(buffer.byteLength, 0); | ||
assert_equals(copy.byteLength, 1); | ||
} | ||
}); | ||
|
||
structuredCloneBatteryOfTests.push({ | ||
description: 'MessagePort', | ||
async f(runner) { | ||
const {port1, port2} = new MessageChannel(); | ||
const copy = await runner.structuredClone(port2, [port2]); | ||
const msg = new Promise(resolve => port1.onmessage = resolve); | ||
copy.postMessage('ohai'); | ||
assert_equals((await msg).data, 'ohai'); | ||
} | ||
}); | ||
|
||
// TODO: ImageBitmap |
Oops, something went wrong.