Multiple CanGc fixes in components/script/dom (#33924)

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
This commit is contained in:
tanishka 2024-10-20 21:37:15 +05:30 committed by GitHub
parent ee9e1fbbd6
commit 65c866285f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 77 additions and 37 deletions

View file

@ -25,7 +25,7 @@ DOMInterfaces = {
'BaseAudioContext': {
'inRealms': ['DecodeAudioData', 'Resume', 'ParseFromString', 'GetBounds', 'GetClientRects'],
'canGc': ['CreateChannelMerger', 'CreateOscillator', 'CreateStereoPanner', 'CreateGain', 'CreateIIRFilter', 'CreateBiquadFilter', 'CreateBufferSource', 'CreateAnalyser', 'CreatePanner', 'CreateChannelSplitter'],
'canGc': ['CreateChannelMerger', 'CreateOscillator', 'CreateStereoPanner', 'CreateGain', 'CreateIIRFilter', 'CreateBiquadFilter', 'CreateBufferSource', 'CreateAnalyser', 'CreatePanner', 'CreateChannelSplitter', 'CreateBuffer'],
},
'Blob': {
@ -109,6 +109,10 @@ DOMInterfaces = {
'weakReferenceable': True,
},
'EventTarget': {
'canGc': ['DispatchEvent'],
},
'File': {
'weakReferenceable': True,
},
@ -144,7 +148,7 @@ DOMInterfaces = {
},
'HTMLElement': {
'canGc': ['Focus', 'Blur'],
'canGc': ['Focus', 'Blur', 'Click'],
},
'HTMLFieldSetElement': {

View file

@ -8,6 +8,7 @@
use crate::dom::bindings::reflector::DomObject;
use crate::dom::bindings::structuredclone::StructuredDataHolder;
use crate::dom::globalscope::GlobalScope;
use crate::script_runtime::CanGc;
/// The key corresponding to the storage location
/// of a serialized platform object stored in a StructuredDataHolder.
@ -27,5 +28,6 @@ pub trait Serializable: DomObject {
owner: &GlobalScope,
sc_holder: &mut StructuredDataHolder,
extra_data: StorageKey,
can_gc: CanGc,
) -> Result<(), ()>;
}

View file

@ -37,7 +37,7 @@ use crate::dom::blob::Blob;
use crate::dom::globalscope::GlobalScope;
use crate::dom::messageport::MessagePort;
use crate::realms::{enter_realm, AlreadyInRealm, InRealm};
use crate::script_runtime::JSContext as SafeJSContext;
use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
// TODO: Should we add Min and Max const to https://github.com/servo/rust-mozjs/blob/master/src/consts.rs?
// TODO: Determine for sure which value Min and Max should have.
@ -57,6 +57,7 @@ unsafe fn read_blob(
owner: &GlobalScope,
r: *mut JSStructuredCloneReader,
sc_holder: &mut StructuredDataHolder,
can_gc: CanGc,
) -> *mut JSObject {
let mut name_space: u32 = 0;
let mut index: u32 = 0;
@ -66,7 +67,7 @@ unsafe fn read_blob(
&mut index as *mut u32
));
let storage_key = StorageKey { index, name_space };
if <Blob as Serializable>::deserialize(owner, sc_holder, storage_key).is_ok() {
if <Blob as Serializable>::deserialize(owner, sc_holder, storage_key, can_gc).is_ok() {
let blobs = match sc_holder {
StructuredDataHolder::Read { blobs, .. } => blobs,
_ => panic!("Unexpected variant of StructuredDataHolder"),
@ -133,6 +134,7 @@ unsafe extern "C" fn read_callback(
&GlobalScope::from_context(cx, InRealm::Already(&in_realm_proof)),
r,
&mut *(closure as *mut StructuredDataHolder),
CanGc::note(),
);
}
ptr::null_mut()