Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MessagePort and MessageChannel #16622

Closed
wants to merge 15 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Fix BorrowMut crash with pending_port_message

  • Loading branch information
KiChjang committed Jun 11, 2019
commit 5bc41b5e39083b4bd12caca67e5d135e27672990
@@ -64,38 +64,41 @@ impl MessagePortInternal {
// Step 7 substeps
#[allow(unrooted_must_root)]
fn process_pending_port_messages(&self) {
if let Some(PortMessageTask { origin, data }) = self.pending_port_messages.borrow_mut().pop_front() {
// Substep 1
let final_target_port = self.dom_port.borrow().as_ref().unwrap().root();

// Substep 2
let target_global = final_target_port.global();

// Substep 3-4
rooted!(in(target_global.get_cx()) let mut message_clone = UndefinedValue());
let deserialize_result = StructuredCloneData::Vector(data).read(
&target_global,
message_clone.handle_mut(),
);
if !deserialize_result {
return;
}
let PortMessageTask { origin, data } = match self.pending_port_messages.borrow_mut().pop_front() {
Some(task) => task,
None => return,
};

// Substep 5
let new_ports = TRANSFERRED_MESSAGE_PORTS.with(|list| {
mem::replace(&mut *list.borrow_mut(), vec![])
});

// Substep 6
MessageEvent::dispatch_jsval(
final_target_port.upcast(),
&target_global,
message_clone.handle(),
Some(&origin),
None,
new_ports,
);
// Substep 1
let final_target_port = self.dom_port.borrow().as_ref().unwrap().root();

// Substep 2
let target_global = final_target_port.global();

// Substep 3-4
rooted!(in(target_global.get_cx()) let mut message_clone = UndefinedValue());
let deserialize_result = StructuredCloneData::Vector(data).read(
&target_global,
message_clone.handle_mut()
);
if !deserialize_result {
return;
}

// Substep 5
let new_ports = TRANSFERRED_MESSAGE_PORTS.with(|list| {
mem::replace(&mut *list.borrow_mut(), vec![])
});

// Substep 6
MessageEvent::dispatch_jsval(
final_target_port.upcast(),
&target_global,
message_clone.handle(),
Some(&origin),
None,
new_ports,
);
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.