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

Allow structured clone reads to return a boolean

  • Loading branch information
KiChjang committed Jun 9, 2019
commit ea481b7cabe713365a0de1c74b680c38be2cf4d5
@@ -309,7 +309,12 @@ impl StructuredCloneData {
/// Reads a structured clone.
///
/// Panics if `JS_ReadStructuredClone` fails.
fn read_clone(global: &GlobalScope, data: *mut u64, nbytes: size_t, rval: MutableHandleValue) {
fn read_clone(
global: &GlobalScope,
data: *mut u64,
nbytes: size_t,
rval: MutableHandleValue,
) -> bool {
let cx = global.get_cx();
let globalhandle = global.reflector().get_jsobject();
let _ac = JSAutoRealm::new(cx, globalhandle.get());
@@ -324,31 +329,33 @@ impl StructuredCloneData {

WriteBytesToJSStructuredCloneData(data as *const u8, nbytes, scdata);

assert!(JS_ReadStructuredClone(
cx,
scdata,
JS_STRUCTURED_CLONE_VERSION,
StructuredCloneScope::DifferentProcess,
rval,
&STRUCTURED_CLONE_CALLBACKS,
sc_holder_ptr as *mut raw::c_void
));
let result = JS_ReadStructuredClone(
cx,
scdata,
JS_STRUCTURED_CLONE_VERSION,
StructuredCloneScope::DifferentProcess,
rval,
&STRUCTURED_CLONE_CALLBACKS,
sc_holder_ptr as *mut raw::c_void
);

DeleteJSAutoStructuredCloneBuffer(scbuf);

result
}
}

/// Thunk for the actual `read_clone` method. Resolves proper variant for read_clone.
pub fn read(self, global: &GlobalScope, rval: MutableHandleValue) {
pub fn read(self, global: &GlobalScope, rval: MutableHandleValue) -> bool {
match self {
StructuredCloneData::Vector(mut vec_msg) => {
let nbytes = vec_msg.len();
let data = vec_msg.as_mut_ptr() as *mut u64;
StructuredCloneData::read_clone(global, data, nbytes, rval);
},
StructuredCloneData::read_clone(global, data, nbytes, rval)
}
StructuredCloneData::Struct(data, nbytes) => {
StructuredCloneData::read_clone(global, data, nbytes, rval)
},
}
}
}
}
@@ -464,7 +464,7 @@ impl DedicatedWorkerGlobalScope {
let target = self.upcast();
let _ac = JSAutoRealm::new(scope.get_cx(), scope.reflector().get_jsobject().get());
rooted!(in(scope.get_cx()) let mut message = UndefinedValue());
data.read(scope.upcast(), message.handle_mut());
assert!(data.read(scope.upcast(), message.handle_mut()));
MessageEvent::dispatch_jsval(target, scope.upcast(), message.handle(), None, None);
},
WorkerScriptMsg::Common(msg) => {
@@ -412,7 +412,7 @@ impl ServiceWorkerGlobalScope {
let target = self.upcast();
let _ac = JSAutoRealm::new(scope.get_cx(), scope.reflector().get_jsobject().get());
rooted!(in(scope.get_cx()) let mut message = UndefinedValue());
data.read(scope.upcast(), message.handle_mut());
assert!(data.read(scope.upcast(), message.handle_mut()));
ExtendableMessageEvent::dispatch_jsval(target, scope.upcast(), message.handle());
},
CommonWorker(WorkerScriptMsg::Common(msg)) => {
@@ -2223,10 +2223,10 @@ impl Window {
let obj = this.reflector().get_jsobject();
let _ac = JSAutoRealm::new(cx, obj.get());
rooted!(in(cx) let mut message_clone = UndefinedValue());
serialize_with_transfer_result.read(
assert!(serialize_with_transfer_result.read(
this.upcast(),
message_clone.handle_mut(),
);
));

// Step 7.6.
// TODO: MessagePort array.
@@ -146,7 +146,7 @@ impl Worker {
let target = worker.upcast();
let _ac = JSAutoRealm::new(global.get_cx(), target.reflector().get_jsobject().get());
rooted!(in(global.get_cx()) let mut message = UndefinedValue());
data.read(&global, message.handle_mut());
assert!(data.read(&global, message.handle_mut()));
MessageEvent::dispatch_jsval(target, &global, message.handle(), None, None);
}

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