summaryrefslogtreecommitdiff
path: root/ext/web/message_port.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-03-16 00:59:18 +0000
committerGitHub <noreply@github.com>2024-03-16 01:59:18 +0100
commit92576fdcfd3e32dce63b533ab20d4974136b097d (patch)
tree6f3b61c4d1d10569e4bb54f8ee59fb5f1ff274da /ext/web/message_port.rs
parentebbc897b69f906d88a99768a2fff7661e2894670 (diff)
fix(ext/node): support MessagePort in `WorkerOptions.workerData` (#22950)
This commit fixes passing `MessagePort` instances to `WorkerOptions.workerData`. Before they were not serialized and deserialized properly when spawning a worker thread. Closes https://github.com/denoland/deno/issues/22935
Diffstat (limited to 'ext/web/message_port.rs')
-rw-r--r--ext/web/message_port.rs11
1 files changed, 5 insertions, 6 deletions
diff --git a/ext/web/message_port.rs b/ext/web/message_port.rs
index 18429a179..1cd29c64d 100644
--- a/ext/web/message_port.rs
+++ b/ext/web/message_port.rs
@@ -22,7 +22,7 @@ use tokio::sync::mpsc::unbounded_channel;
use tokio::sync::mpsc::UnboundedReceiver;
use tokio::sync::mpsc::UnboundedSender;
-enum Transferable {
+pub enum Transferable {
MessagePort(MessagePort),
ArrayBuffer(u32),
}
@@ -140,7 +140,7 @@ pub enum JsTransferable {
ArrayBuffer(u32),
}
-fn deserialize_js_transferables(
+pub fn deserialize_js_transferables(
state: &mut OpState,
js_transferables: Vec<JsTransferable>,
) -> Result<Vec<Transferable>, AnyError> {
@@ -165,7 +165,7 @@ fn deserialize_js_transferables(
Ok(transferables)
}
-fn serialize_transferables(
+pub fn serialize_transferables(
state: &mut OpState,
transferables: Vec<Transferable>,
) -> Vec<JsTransferable> {
@@ -189,8 +189,8 @@ fn serialize_transferables(
#[derive(Deserialize, Serialize)]
pub struct JsMessageData {
- data: DetachedBuffer,
- transferables: Vec<JsTransferable>,
+ pub data: DetachedBuffer,
+ pub transferables: Vec<JsTransferable>,
}
#[op2]
@@ -208,7 +208,6 @@ pub fn op_message_port_post_message(
}
let resource = state.resource_table.get::<MessagePortResource>(rid)?;
-
resource.port.send(state, data)
}