mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #21218 - gterzian:root_cloned_blobs, r=jdm
Use a structured clone holder to store rooted clones <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #21164 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21218) <!-- Reviewable:end -->
This commit is contained in:
commit
2ceb8dcd22
1 changed files with 14 additions and 5 deletions
|
@ -104,14 +104,17 @@ impl StructuredCloneReader {
|
|||
}
|
||||
|
||||
unsafe fn read_blob(cx: *mut JSContext,
|
||||
r: *mut JSStructuredCloneReader)
|
||||
r: *mut JSStructuredCloneReader,
|
||||
sc_holder: &mut StructuredCloneHolder)
|
||||
-> *mut JSObject {
|
||||
let structured_reader = StructuredCloneReader { r: r };
|
||||
let blob_buffer = structured_reader.read_bytes();
|
||||
let type_str = structured_reader.read_str();
|
||||
let target_global = GlobalScope::from_context(cx);
|
||||
let blob = Blob::new(&target_global, BlobImpl::new_from_bytes(blob_buffer), type_str);
|
||||
return blob.reflector().get_jsobject().get()
|
||||
let js_object = blob.reflector().get_jsobject().get();
|
||||
sc_holder.blob = Some(blob);
|
||||
js_object
|
||||
}
|
||||
|
||||
unsafe fn write_blob(blob: DomRoot<Blob>,
|
||||
|
@ -129,12 +132,12 @@ unsafe extern "C" fn read_callback(cx: *mut JSContext,
|
|||
r: *mut JSStructuredCloneReader,
|
||||
tag: u32,
|
||||
_data: u32,
|
||||
_closure: *mut raw::c_void)
|
||||
closure: *mut raw::c_void)
|
||||
-> *mut JSObject {
|
||||
assert!(tag < StructuredCloneTags::Max as u32, "tag should be lower than StructuredCloneTags::Max");
|
||||
assert!(tag > StructuredCloneTags::Min as u32, "tag should be higher than StructuredCloneTags::Min");
|
||||
if tag == StructuredCloneTags::DomBlob as u32 {
|
||||
return read_blob(cx, r)
|
||||
return read_blob(cx, r, &mut *(closure as *mut StructuredCloneHolder))
|
||||
}
|
||||
return ptr::null_mut()
|
||||
}
|
||||
|
@ -191,6 +194,10 @@ static STRUCTURED_CLONE_CALLBACKS: JSStructuredCloneCallbacks = JSStructuredClon
|
|||
freeTransfer: Some(free_transfer_callback),
|
||||
};
|
||||
|
||||
struct StructuredCloneHolder {
|
||||
blob: Option<DomRoot<Blob>>
|
||||
}
|
||||
|
||||
/// A buffer for a structured clone.
|
||||
pub enum StructuredCloneData {
|
||||
/// A non-serializable (default) variant
|
||||
|
@ -244,6 +251,8 @@ impl StructuredCloneData {
|
|||
let cx = global.get_cx();
|
||||
let globalhandle = global.reflector().get_jsobject();
|
||||
let _ac = JSAutoCompartment::new(cx, globalhandle.get());
|
||||
let mut sc_holder = StructuredCloneHolder { blob: None };
|
||||
let sc_holder_ptr = &mut sc_holder as *mut _;
|
||||
unsafe {
|
||||
assert!(JS_ReadStructuredClone(cx,
|
||||
data,
|
||||
|
@ -251,7 +260,7 @@ impl StructuredCloneData {
|
|||
JS_STRUCTURED_CLONE_VERSION,
|
||||
rval,
|
||||
&STRUCTURED_CLONE_CALLBACKS,
|
||||
ptr::null_mut()));
|
||||
sc_holder_ptr as *mut raw::c_void));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue