mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
script: Propagate a pending JS exception on structured cloning (#37964)
During the object (de)serialization steps on structured cloning https://html.spec.whatwg.org/multipage/#safe-passing-of-structured-data it is possible to throw a JS exception. `self.postMessage({ get whatever() { throw customError } }));` Require to propagate a pending JS exception and not throw the default "DataCloneError" DOM exception. Testing: Improvements in the following tests - html/infrastructure/safe-passing-of-structured-data/* - html/webappapis/structured-clone/structured-clone.any.js* - wasm/serialization/arraybuffer/transfer.window.js - webmessaging/without-ports/026.html - workers/semantics/structured-clone/dedicated.html Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
This commit is contained in:
parent
34c31ee418
commit
26f4da8249
9 changed files with 15 additions and 44 deletions
|
@ -24,7 +24,7 @@ use js::glue::{
|
|||
NewJSAutoStructuredCloneBuffer, WriteBytesToJSStructuredCloneData,
|
||||
};
|
||||
use js::jsapi::{
|
||||
CloneDataPolicy, HandleObject as RawHandleObject, Heap, JS_ClearPendingException,
|
||||
CloneDataPolicy, HandleObject as RawHandleObject, Heap, JS_IsExceptionPending,
|
||||
JS_ReadUint32Pair, JS_STRUCTURED_CLONE_VERSION, JS_WriteUint32Pair, JSContext, JSObject,
|
||||
JSStructuredCloneCallbacks, JSStructuredCloneReader, JSStructuredCloneWriter,
|
||||
MutableHandleObject as RawMutableHandleObject, StructuredCloneScope, TransferableOwnership,
|
||||
|
@ -619,8 +619,13 @@ pub(crate) fn write(
|
|||
val.handle(),
|
||||
);
|
||||
if !result {
|
||||
JS_ClearPendingException(*cx);
|
||||
return Err(sc_writer.error.unwrap_or(Error::DataClone(None)));
|
||||
let error = if JS_IsExceptionPending(*cx) {
|
||||
Error::JSFailed
|
||||
} else {
|
||||
sc_writer.error.unwrap_or(Error::DataClone(None))
|
||||
};
|
||||
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
let nbytes = GetLengthOfJSStructuredCloneData(scdata);
|
||||
|
@ -696,8 +701,13 @@ pub(crate) fn read(
|
|||
sc_reader_ptr as *mut raw::c_void,
|
||||
);
|
||||
if !result {
|
||||
JS_ClearPendingException(*cx);
|
||||
return Err(sc_reader.error.unwrap_or(Error::DataClone(None)));
|
||||
let error = if JS_IsExceptionPending(*cx) {
|
||||
Error::JSFailed
|
||||
} else {
|
||||
sc_reader.error.unwrap_or(Error::DataClone(None))
|
||||
};
|
||||
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
DeleteJSAutoStructuredCloneBuffer(scbuf);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue