mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
c6bf07ec6d
In the implementation of structured serialization in `Deno.core.serialize`, whenever there is a serialization error, an exception will be thrown with the message "Failed to serialize response", even though V8 provides a message to use in such cases. This change instead throws an exception with the V8-provided message, if there is one.
30 lines
1 KiB
TypeScript
30 lines
1 KiB
TypeScript
import { assert, assertEquals, assertThrows } from "./test_util.ts";
|
|
|
|
// Basic tests for the structured clone algorithm. Mainly tests TypeScript
|
|
// typings. Actual functionality is tested in WPT.
|
|
|
|
Deno.test("self.structuredClone", async () => {
|
|
const arrayOriginal = ["hello world"];
|
|
const channelOriginal = new MessageChannel();
|
|
const [arrayCloned, portTransferred] = self
|
|
.structuredClone([arrayOriginal, channelOriginal.port2], {
|
|
transfer: [channelOriginal.port2],
|
|
});
|
|
assert(arrayOriginal !== arrayCloned); // not the same identity
|
|
assertEquals(arrayCloned, arrayOriginal); // but same value
|
|
channelOriginal.port1.postMessage("1");
|
|
await new Promise((resolve) => portTransferred.onmessage = () => resolve(1));
|
|
channelOriginal.port1.close();
|
|
portTransferred.close();
|
|
});
|
|
|
|
Deno.test("correct DataCloneError message", () => {
|
|
assertThrows(
|
|
() => {
|
|
const sab = new SharedArrayBuffer(1024);
|
|
structuredClone(sab, { transfer: [sab] });
|
|
},
|
|
DOMException,
|
|
"Value not transferable",
|
|
);
|
|
});
|