mirror of
https://github.com/servo/servo.git
synced 2025-06-08 16:43:28 +00:00
structuredclone::read throws a DataClone error on failure (#36361)
In the structured clone writing API, the read function should throw a DataClone error on failure, just like the write function. Testing: It doesn't require tests. Fixes: #36217 Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
This commit is contained in:
parent
aef8537d75
commit
3f24b44e15
1 changed files with 8 additions and 10 deletions
|
@ -566,7 +566,7 @@ pub(crate) fn read(
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
mut data: StructuredSerializedData,
|
mut data: StructuredSerializedData,
|
||||||
rval: MutableHandleValue,
|
rval: MutableHandleValue,
|
||||||
) -> Result<Vec<DomRoot<MessagePort>>, ()> {
|
) -> Fallible<Vec<DomRoot<MessagePort>>> {
|
||||||
let cx = GlobalScope::get_cx();
|
let cx = GlobalScope::get_cx();
|
||||||
let _ac = enter_realm(global);
|
let _ac = enter_realm(global);
|
||||||
let mut sc_reader = StructuredDataReader {
|
let mut sc_reader = StructuredDataReader {
|
||||||
|
@ -605,18 +605,16 @@ pub(crate) fn read(
|
||||||
&STRUCTURED_CLONE_CALLBACKS,
|
&STRUCTURED_CLONE_CALLBACKS,
|
||||||
sc_reader_ptr as *mut raw::c_void,
|
sc_reader_ptr as *mut raw::c_void,
|
||||||
);
|
);
|
||||||
|
if !result {
|
||||||
|
JS_ClearPendingException(*cx);
|
||||||
|
return Err(Error::DataClone);
|
||||||
|
}
|
||||||
|
|
||||||
DeleteJSAutoStructuredCloneBuffer(scbuf);
|
DeleteJSAutoStructuredCloneBuffer(scbuf);
|
||||||
|
|
||||||
if result {
|
|
||||||
// Any transfer-received port-impls should have been taken out.
|
// Any transfer-received port-impls should have been taken out.
|
||||||
assert!(sc_reader.port_impls.is_none());
|
assert!(sc_reader.port_impls.is_none());
|
||||||
|
|
||||||
match sc_reader.message_ports.take() {
|
Ok(sc_reader.message_ports.take().unwrap_or_default())
|
||||||
Some(ports) => return Ok(ports),
|
|
||||||
None => return Ok(Vec::with_capacity(0)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue