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

Implement transfer argument on window.postMessage

  • Loading branch information
KiChjang committed Jun 9, 2019
commit e4d075b9c1cce55a8e6b93bc8a7ec8eb388a599c
@@ -63,9 +63,8 @@
unsigned long requestAnimationFrame(FrameRequestCallback callback);
void cancelAnimationFrame(unsigned long handle);

//void postMessage(any message, DOMString targetOrigin, optional sequence<Transferable> transfer);
[Throws]
void postMessage(any message, DOMString targetOrigin);
void postMessage(any message, USVString targetOrigin, optional sequence<object> transfer /*= []*/);

// also has obsolete members
};
@@ -17,6 +17,7 @@ use crate::dom::bindings::codegen::Bindings::WindowBinding::{
};
use crate::dom::bindings::codegen::Bindings::WindowBinding::{ScrollBehavior, ScrollToOptions};
use crate::dom::bindings::codegen::UnionTypes::RequestOrUSVString;
use crate::dom::bindings::conversions::ToJSValConvertible;
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::num::Finite;
@@ -43,6 +44,7 @@ use crate::dom::location::Location;
use crate::dom::mediaquerylist::{MediaQueryList, MediaQueryListMatchState};
use crate::dom::mediaquerylistevent::MediaQueryListEvent;
use crate::dom::messageevent::MessageEvent;
use crate::dom::messageport::TRANSFERRED_MESSAGE_PORTS;
use crate::dom::navigator::Navigator;
use crate::dom::node::{document_from_node, from_untrusted_node_address, Node, NodeDamage};
use crate::dom::performance::Performance;
@@ -77,14 +79,10 @@ use embedder_traits::EmbedderMsg;
use euclid::{Point2D, Rect, Size2D, TypedPoint2D, TypedScale, TypedSize2D, Vector2D};
use ipc_channel::ipc::{channel, IpcSender};
use ipc_channel::router::ROUTER;
use js::jsapi::JSAutoRealm;
use js::jsapi::JSContext;
use js::jsapi::JSPROP_ENUMERATE;
use js::jsapi::{GCReason, JS_GC};
use js::jsval::JSVal;
use js::jsval::UndefinedValue;
use js::jsapi::{GCReason, JSAutoRealm, JSContext, JSObject, JSPROP_ENUMERATE, JS_GC};
use js::jsval::{JSVal, UndefinedValue};
use js::rust::{CustomAutoRooterGuard, HandleValue};
use js::rust::wrappers::JS_DefineProperty;
use js::rust::HandleValue;
use msg::constellation_msg::PipelineId;
use net_traits::image_cache::{ImageCache, ImageResponder, ImageResponse};
use net_traits::image_cache::{PendingImageId, PendingImageResponse};
@@ -860,13 +858,14 @@ impl WindowMethods for Window {
&self,
cx: *mut JSContext,
message: HandleValue,
origin: DOMString,
origin: USVString,
transfer: CustomAutoRooterGuard<Option<Vec<*mut JSObject>>>,
) -> ErrorResult {
let source_global = GlobalScope::incumbent().expect("no incumbent global??");
let source = source_global.as_window();

// Step 3-5.
let origin = match &origin[..] {
let origin = match &origin.0[..] {
"*" => None,
"/" => Some(source.Document().origin().immutable().clone()),
url => match ServoUrl::parse(&url) {
@@ -876,9 +875,10 @@ impl WindowMethods for Window {
};

// Step 1-2, 6-8.
// TODO(#12717): Should implement the `transfer` argument.
rooted!(in(cx) let transfer = UndefinedValue());
let data = StructuredCloneData::write(cx, message, transfer.handle())?;
rooted!(in(cx) let mut val = UndefinedValue());
(*transfer).as_ref().unwrap_or(&Vec::new()).to_jsval(cx, val.handle_mut());

let data = StructuredCloneData::write(cx, message, val.handle())?;

// Step 9.
self.post_message(origin, &*source.window_proxy(), data);
@@ -2229,7 +2229,9 @@ impl Window {
));

// Step 7.6.
// TODO: MessagePort array.
let new_ports = TRANSFERRED_MESSAGE_PORTS.with(|list| {
mem::replace(&mut *list.borrow_mut(), vec![])
});

// Step 7.7.
// TODO(#12719): Set the other attributes.
@@ -2239,7 +2241,7 @@ impl Window {
message_clone.handle(),
None,
Some(&*source),
vec![],
new_ports,
);
});
// FIXME(nox): Why are errors silenced here?
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.