summaryrefslogtreecommitdiff
path: root/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'extensions')
-rw-r--r--extensions/web/13_message_port.js49
-rw-r--r--extensions/web/lib.deno_web.d.ts17
2 files changed, 48 insertions, 18 deletions
diff --git a/extensions/web/13_message_port.js b/extensions/web/13_message_port.js
index d111b5e01..d5014fdb9 100644
--- a/extensions/web/13_message_port.js
+++ b/extensions/web/13_message_port.js
@@ -89,7 +89,7 @@
/**
* @param {any} message
- * @param {object[] | PostMessageOptions} transferOrOptions
+ * @param {object[] | StructuredSerializeOptions} transferOrOptions
*/
postMessage(message, transferOrOptions = {}) {
webidl.assertBranded(this, MessagePort);
@@ -108,10 +108,13 @@
);
options = { transfer };
} else {
- options = webidl.converters.PostMessageOptions(transferOrOptions, {
- prefix,
- context: "Argument 2",
- });
+ options = webidl.converters.StructuredSerializeOptions(
+ transferOrOptions,
+ {
+ prefix,
+ context: "Argument 2",
+ },
+ );
}
const { transfer } = options;
if (transfer.includes(this)) {
@@ -247,23 +250,37 @@
};
}
- webidl.converters.PostMessageOptions = webidl.createDictionaryConverter(
- "PostMessageOptions",
- [
- {
- key: "transfer",
- converter: webidl.converters["sequence<object>"],
- get defaultValue() {
- return [];
+ webidl.converters.StructuredSerializeOptions = webidl
+ .createDictionaryConverter(
+ "StructuredSerializeOptions",
+ [
+ {
+ key: "transfer",
+ converter: webidl.converters["sequence<object>"],
+ get defaultValue() {
+ return [];
+ },
},
- },
- ],
- );
+ ],
+ );
+
+ function structuredClone(value, options) {
+ const prefix = "Failed to execute 'structuredClone'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ options = webidl.converters.StructuredSerializeOptions(options, {
+ prefix,
+ context: "Argument 2",
+ });
+ const messageData = serializeJsMessageData(value, options.transfer);
+ const [data] = deserializeJsMessageData(messageData);
+ return data;
+ }
window.__bootstrap.messagePort = {
MessageChannel,
MessagePort,
deserializeJsMessageData,
serializeJsMessageData,
+ structuredClone,
};
})(globalThis);
diff --git a/extensions/web/lib.deno_web.d.ts b/extensions/web/lib.deno_web.d.ts
index 6c79f61bd..3f110353f 100644
--- a/extensions/web/lib.deno_web.d.ts
+++ b/extensions/web/lib.deno_web.d.ts
@@ -673,7 +673,15 @@ declare class MessageEvent<T = any> extends Event {
type Transferable = ArrayBuffer | MessagePort;
-interface PostMessageOptions {
+/**
+ * @deprecated
+ *
+ * This type has been renamed to StructuredSerializeOptions. Use that type for
+ * new code.
+ */
+type PostMessageOptions = StructuredSerializeOptions;
+
+interface StructuredSerializeOptions {
transfer?: Transferable[];
}
@@ -710,7 +718,7 @@ declare class MessagePort extends EventTarget {
* objects or port, or if message could not be cloned.
*/
postMessage(message: any, transfer: Transferable[]): void;
- postMessage(message: any, options?: PostMessageOptions): void;
+ postMessage(message: any, options?: StructuredSerializeOptions): void;
/**
* Begins dispatching messages received on the port. This is implictly called
* when assiging a value to `this.onmessage`.
@@ -737,3 +745,8 @@ declare class MessagePort extends EventTarget {
options?: boolean | EventListenerOptions,
): void;
}
+
+declare function structuredClone(
+ value: any,
+ options?: StructuredSerializeOptions,
+): any;