diff options
Diffstat (limited to 'components/script')
30 files changed, 116 insertions, 120 deletions
diff --git a/components/script/body.rs b/components/script/body.rs index 466523f394f..41886e0aee0 100644 --- a/components/script/body.rs +++ b/components/script/body.rs @@ -98,13 +98,14 @@ fn run_package_data_algorithm<T: BodyOperations + Reflectable>(object: &T, body_type: BodyType, mime_type: Ref<Vec<u8>>) -> Fallible<FetchedData> { - let cx = object.global().r().get_cx(); + let global = object.global_scope(); + let cx = global.get_cx(); let mime = &*mime_type; match body_type { BodyType::Text => run_text_data_algorithm(bytes), BodyType::Json => run_json_data_algorithm(cx, bytes), - BodyType::Blob => run_blob_data_algorithm(object.global().r().as_global_scope(), bytes, mime), - BodyType::FormData => run_form_data_algorithm(object.global().r().as_global_scope(), bytes, mime), + BodyType::Blob => run_blob_data_algorithm(&global, bytes, mime), + BodyType::FormData => run_form_data_algorithm(&global, bytes, mime), } } diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index 0dbbba2c376..cf108e5e526 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -280,30 +280,44 @@ impl GlobalRoot { } } +/// Returns the global scope of the realm that the given DOM object's reflector was created in. +pub fn global_scope_from_reflector<T: Reflectable>(reflector: &T) -> Root<GlobalScope> { + unsafe { global_scope_from_object(*reflector.reflector().get_jsobject()) } +} + /// Returns the global object of the realm that the given DOM object's reflector was created in. pub fn global_root_from_reflector<T: Reflectable>(reflector: &T) -> GlobalRoot { unsafe { global_root_from_object(*reflector.reflector().get_jsobject()) } } -/// Returns the Rust global object from a JS global object. -#[allow(unrooted_must_root)] -unsafe fn global_root_from_global(global: *mut JSObject) -> GlobalRoot { +/// Returns the Rust global scope from a JS global object. +unsafe fn global_scope_from_global(global: *mut JSObject) -> Root<GlobalScope> { assert!(!global.is_null()); let clasp = JS_GetClass(global); assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0); - match root_from_object(global) { - Ok(window) => return GlobalRoot::Window(window), - Err(_) => (), - } + root_from_object(global).unwrap() +} - match root_from_object(global) { - Ok(worker) => return GlobalRoot::Worker(worker), - Err(_) => (), +/// Returns the Rust global object from a JS global object. +#[allow(unrooted_must_root)] +unsafe fn global_root_from_global(global: *mut JSObject) -> GlobalRoot { + let global_scope = global_scope_from_global(global); + if let Some(window) = global_scope.downcast::<window::Window>() { + return GlobalRoot::Window(Root::from_ref(window)); + } + if let Some(worker) = Root::downcast(global_scope) { + return GlobalRoot::Worker(worker); } - panic!("found DOM global that doesn't unwrap to Window or WorkerGlobalScope") } +/// Returns the global scope of the realm that the given JS object was created in. +pub unsafe fn global_scope_from_object(obj: *mut JSObject) -> Root<GlobalScope> { + assert!(!obj.is_null()); + let global = GetGlobalForObjectCrossCompartment(obj); + global_scope_from_global(global) +} + /// Returns the global object of the realm that the given JS object was created in. #[allow(unrooted_must_root)] pub unsafe fn global_root_from_object(obj: *mut JSObject) -> GlobalRoot { diff --git a/components/script/dom/bindings/iterable.rs b/components/script/dom/bindings/iterable.rs index 5a86dcf64d8..8e316336607 100644 --- a/components/script/dom/bindings/iterable.rs +++ b/components/script/dom/bindings/iterable.rs @@ -93,8 +93,7 @@ impl<T: Reflectable + JSTraceable + Iterable> IterableIterator<T> { iterable: JS::from_ref(iterable), index: Cell::new(0), }; - let global = iterable.global(); - reflect_dom_object(iterator, global.r().as_global_scope(), wrap) + reflect_dom_object(iterator, &*iterable.global_scope(), wrap) } /// Return the next value from the iterable object. diff --git a/components/script/dom/bindings/reflector.rs b/components/script/dom/bindings/reflector.rs index 74c039688f7..bb48cee0b1a 100644 --- a/components/script/dom/bindings/reflector.rs +++ b/components/script/dom/bindings/reflector.rs @@ -5,7 +5,7 @@ //! The `Reflector` struct. use dom::bindings::conversions::DerivedFrom; -use dom::bindings::global::{GlobalRoot, global_root_from_reflector}; +use dom::bindings::global::{GlobalRoot, global_root_from_reflector, global_scope_from_reflector}; use dom::bindings::js::Root; use dom::globalscope::GlobalScope; use js::jsapi::{HandleObject, JSContext, JSObject}; @@ -80,6 +80,11 @@ pub trait Reflectable { /// Returns the receiver's reflector. fn reflector(&self) -> &Reflector; + /// Returns the global scope of the realm that the Reflectable was created in. + fn global_scope(&self) -> Root<GlobalScope> where Self: Sized { + global_scope_from_reflector(self) + } + /// Returns the global object of the realm that the Reflectable was created in. fn global(&self) -> GlobalRoot where Self: Sized { global_root_from_reflector(self) diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs index 011f547c96a..997edb52d6c 100644 --- a/components/script/dom/blob.rs +++ b/components/script/dom/blob.rs @@ -117,7 +117,7 @@ impl Blob { } }; - Blob::new(parent.global().r().as_global_scope(), blob_impl, relative_content_type.into()) + Blob::new(&parent.global_scope(), blob_impl, relative_content_type.into()) } // https://w3c.github.io/FileAPI/#constructorBlob diff --git a/components/script/dom/bluetooth.rs b/components/script/dom/bluetooth.rs index dd5d05d4f2a..db32bcd4edf 100644 --- a/components/script/dom/bluetooth.rs +++ b/components/script/dom/bluetooth.rs @@ -106,14 +106,12 @@ impl Bluetooth { // Step 12-13. match device { Ok(device) => { - let global = self.global(); - let global = global.r(); - let global = global.as_global_scope(); - let ad_data = BluetoothAdvertisingData::new(global, + let global = self.global_scope(); + let ad_data = BluetoothAdvertisingData::new(&global, device.appearance, device.tx_power, device.rssi); - Ok(BluetoothDevice::new(global, + Ok(BluetoothDevice::new(&global, DOMString::from(device.id), device.name.map(DOMString::from), &ad_data)) diff --git a/components/script/dom/bluetoothdevice.rs b/components/script/dom/bluetoothdevice.rs index 04327080cd4..c4ceaa333d0 100644 --- a/components/script/dom/bluetoothdevice.rs +++ b/components/script/dom/bluetoothdevice.rs @@ -67,7 +67,7 @@ impl BluetoothDeviceMethods for BluetoothDevice { // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-gatt fn Gatt(&self) -> Root<BluetoothRemoteGATTServer> { self.gatt.or_init(|| { - BluetoothRemoteGATTServer::new(self.global().r().as_global_scope(), self) + BluetoothRemoteGATTServer::new(&self.global_scope(), self) }) } } diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs index 701a6ddd2a2..0dbb7c4670e 100644 --- a/components/script/dom/bluetoothremotegattcharacteristic.rs +++ b/components/script/dom/bluetoothremotegattcharacteristic.rs @@ -95,7 +95,7 @@ impl BluetoothRemoteGATTCharacteristic { let descriptor = receiver.recv().unwrap(); match descriptor { Ok(descriptor) => { - Ok(BluetoothRemoteGATTDescriptor::new(self.global().r().as_global_scope(), + Ok(BluetoothRemoteGATTDescriptor::new(&self.global_scope(), self, DOMString::from(descriptor.uuid), descriptor.instance_id)) @@ -126,7 +126,7 @@ impl BluetoothRemoteGATTCharacteristic { match descriptors_vec { Ok(descriptor_vec) => { Ok(descriptor_vec.into_iter() - .map(|desc| BluetoothRemoteGATTDescriptor::new(self.global().r().as_global_scope(), + .map(|desc| BluetoothRemoteGATTDescriptor::new(&self.global_scope(), self, DOMString::from(desc.uuid), desc.instance_id)) diff --git a/components/script/dom/bluetoothremotegattserver.rs b/components/script/dom/bluetoothremotegattserver.rs index 3a939614d36..7bb4d8fb05d 100644 --- a/components/script/dom/bluetoothremotegattserver.rs +++ b/components/script/dom/bluetoothremotegattserver.rs @@ -80,7 +80,7 @@ impl BluetoothRemoteGATTServer { let service = receiver.recv().unwrap(); match service { Ok(service) => { - Ok(BluetoothRemoteGATTService::new(self.global().r().as_global_scope(), + Ok(BluetoothRemoteGATTService::new(&self.global_scope(), &self.device.get(), DOMString::from(service.uuid), service.is_primary, @@ -112,7 +112,7 @@ impl BluetoothRemoteGATTServer { match services_vec { Ok(service_vec) => { Ok(service_vec.into_iter() - .map(|service| BluetoothRemoteGATTService::new(self.global().r().as_global_scope(), + .map(|service| BluetoothRemoteGATTService::new(&self.global_scope(), &self.device.get(), DOMString::from(service.uuid), service.is_primary, diff --git a/components/script/dom/bluetoothremotegattservice.rs b/components/script/dom/bluetoothremotegattservice.rs index 3a590b4738a..df1718ef403 100644 --- a/components/script/dom/bluetoothremotegattservice.rs +++ b/components/script/dom/bluetoothremotegattservice.rs @@ -84,10 +84,8 @@ impl BluetoothRemoteGATTService { let characteristic = receiver.recv().unwrap(); match characteristic { Ok(characteristic) => { - let global = self.global(); - let global = global.r(); - let global = global.as_global_scope(); - let properties = BluetoothCharacteristicProperties::new(global, + let global = self.global_scope(); + let properties = BluetoothCharacteristicProperties::new(&global, characteristic.broadcast, characteristic.read, characteristic.write_without_response, @@ -97,7 +95,7 @@ impl BluetoothRemoteGATTService { characteristic.authenticated_signed_writes, characteristic.reliable_write, characteristic.writable_auxiliaries); - Ok(BluetoothRemoteGATTCharacteristic::new(global, + Ok(BluetoothRemoteGATTCharacteristic::new(&global, self, DOMString::from(characteristic.uuid), &properties, @@ -130,10 +128,8 @@ impl BluetoothRemoteGATTService { match characteristics_vec { Ok(characteristic_vec) => { for characteristic in characteristic_vec { - let global = self.global(); - let global = global.r(); - let global = global.as_global_scope(); - let properties = BluetoothCharacteristicProperties::new(global, + let global = self.global_scope(); + let properties = BluetoothCharacteristicProperties::new(&global, characteristic.broadcast, characteristic.read, characteristic.write_without_response, @@ -143,7 +139,7 @@ impl BluetoothRemoteGATTService { characteristic.authenticated_signed_writes, characteristic.reliable_write, characteristic.writable_auxiliaries); - characteristics.push(BluetoothRemoteGATTCharacteristic::new(global, + characteristics.push(BluetoothRemoteGATTCharacteristic::new(&global, self, DOMString::from(characteristic.uuid), &properties, @@ -173,7 +169,7 @@ impl BluetoothRemoteGATTService { let service = receiver.recv().unwrap(); match service { Ok(service) => { - Ok(BluetoothRemoteGATTService::new(self.global().r().as_global_scope(), + Ok(BluetoothRemoteGATTService::new(&self.global_scope(), &self.device.get(), DOMString::from(service.uuid), service.is_primary, @@ -207,7 +203,7 @@ impl BluetoothRemoteGATTService { match services_vec { Ok(service_vec) => { Ok(service_vec.into_iter() - .map(|service| BluetoothRemoteGATTService::new(self.global().r().as_global_scope(), + .map(|service| BluetoothRemoteGATTService::new(&self.global_scope(), &self.device.get(), DOMString::from(service.uuid), service.is_primary, diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index 3872eb31272..3a965f14d6f 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -1016,12 +1016,12 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D { let sw = cmp::max(1, sw.abs().to_u32().unwrap()); let sh = cmp::max(1, sh.abs().to_u32().unwrap()); - Ok(ImageData::new(self.global().r().as_global_scope(), sw, sh, None)) + Ok(ImageData::new(&self.global_scope(), sw, sh, None)) } // https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata fn CreateImageData_(&self, imagedata: &ImageData) -> Fallible<Root<ImageData>> { - Ok(ImageData::new(self.global().r().as_global_scope(), + Ok(ImageData::new(&self.global_scope(), imagedata.Width(), imagedata.Height(), None)) @@ -1077,7 +1077,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D { chunk[2] = UNPREMULTIPLY_TABLE[256 * alpha + chunk[2] as usize]; } - Ok(ImageData::new(self.global().r().as_global_scope(), sw, sh, Some(data))) + Ok(ImageData::new(&self.global_scope(), sw, sh, Some(data))) } // https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata @@ -1121,7 +1121,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D { x1: Finite<f64>, y1: Finite<f64>) -> Root<CanvasGradient> { - CanvasGradient::new(self.global().r().as_global_scope(), + CanvasGradient::new(&self.global_scope(), CanvasGradientStyle::Linear(LinearGradientStyle::new(*x0, *y0, *x1, @@ -1142,7 +1142,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D { return Err(Error::IndexSize); } - Ok(CanvasGradient::new(self.global().r().as_global_scope(), + Ok(CanvasGradient::new(&self.global_scope(), CanvasGradientStyle::Radial(RadialGradientStyle::new(*x0, *y0, *r0, @@ -1182,7 +1182,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D { } if let Ok(rep) = RepetitionStyle::from_str(&repetition) { - Ok(CanvasPattern::new(self.global().r().as_global_scope(), + Ok(CanvasPattern::new(&self.global_scope(), image_data, image_size, rep, diff --git a/components/script/dom/dommatrixreadonly.rs b/components/script/dom/dommatrixreadonly.rs index b643ef3131a..23feb88a348 100644 --- a/components/script/dom/dommatrixreadonly.rs +++ b/components/script/dom/dommatrixreadonly.rs @@ -464,50 +464,50 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly { // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-translate fn Translate(&self, tx: f64, ty: f64, tz: f64) -> Root<DOMMatrix> { - DOMMatrix::from_readonly(self.global().r().as_global_scope(), self).TranslateSelf(tx, ty, tz) + DOMMatrix::from_readonly(&self.global_scope(), self).TranslateSelf(tx, ty, tz) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-scale fn Scale(&self, scaleX: f64, scaleY: Option<f64>, scaleZ: f64, originX: f64, originY: f64, originZ: f64) -> Root<DOMMatrix> { - DOMMatrix::from_readonly(self.global().r().as_global_scope(), self) + DOMMatrix::from_readonly(&self.global_scope(), self) .ScaleSelf(scaleX, scaleY, scaleZ, originX, originY, originZ) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-scale3d fn Scale3d(&self, scale: f64, originX: f64, originY: f64, originZ: f64) -> Root<DOMMatrix> { - DOMMatrix::from_readonly(self.global().r().as_global_scope(), self) + DOMMatrix::from_readonly(&self.global_scope(), self) .Scale3dSelf(scale, originX, originY, originZ) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-rotate fn Rotate(&self, rotX: f64, rotY: Option<f64>, rotZ: Option<f64>) -> Root<DOMMatrix> { - DOMMatrix::from_readonly(self.global().r().as_global_scope(), self).RotateSelf(rotX, rotY, rotZ) + DOMMatrix::from_readonly(&self.global_scope(), self).RotateSelf(rotX, rotY, rotZ) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-rotatefromvector fn RotateFromVector(&self, x: f64, y: f64) -> Root<DOMMatrix> { - DOMMatrix::from_readonly(self.global().r().as_global_scope(), self).RotateFromVectorSelf(x, y) + DOMMatrix::from_readonly(&self.global_scope(), self).RotateFromVectorSelf(x, y) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-rotateaxisangle fn RotateAxisAngle(&self, x: f64, y: f64, z: f64, angle: f64) -> Root<DOMMatrix> { - DOMMatrix::from_readonly(self.global().r().as_global_scope(), self).RotateAxisAngleSelf(x, y, z, angle) + DOMMatrix::from_readonly(&self.global_scope(), self).RotateAxisAngleSelf(x, y, z, angle) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-skewx fn SkewX(&self, sx: f64) -> Root<DOMMatrix> { - DOMMatrix::from_readonly(self.global().r().as_global_scope(), self).SkewXSelf(sx) + DOMMatrix::from_readonly(&self.global_scope(), self).SkewXSelf(sx) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-skewy fn SkewY(&self, sy: f64) -> Root<DOMMatrix> { - DOMMatrix::from_readonly(self.global().r().as_global_scope(), self).SkewYSelf(sy) + DOMMatrix::from_readonly(&self.global_scope(), self).SkewYSelf(sy) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-multiply fn Multiply(&self, other: &DOMMatrixInit) -> Fallible<Root<DOMMatrix>> { - DOMMatrix::from_readonly(self.global().r().as_global_scope(), self).MultiplySelf(&other) + DOMMatrix::from_readonly(&self.global_scope(), self).MultiplySelf(&other) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-flipx @@ -518,7 +518,7 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0); let matrix = flip.post_mul(&self.matrix.borrow()); - DOMMatrix::new(self.global().r().as_global_scope(), is2D, matrix) + DOMMatrix::new(&self.global_scope(), is2D, matrix) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-flipy @@ -529,12 +529,12 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0); let matrix = flip.post_mul(&self.matrix.borrow()); - DOMMatrix::new(self.global().r().as_global_scope(), is2D, matrix) + DOMMatrix::new(&self.global_scope(), is2D, matrix) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-inverse fn Inverse(&self) -> Root<DOMMatrix> { - DOMMatrix::from_readonly(self.global().r().as_global_scope(), self).InvertSelf() + DOMMatrix::from_readonly(&self.global_scope(), self).InvertSelf() } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-transformpoint @@ -542,7 +542,7 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly { let matrix = self.matrix.borrow(); let result = matrix.transform_point4d(&Point4D::new(point.x, point.y, point.z, point.w)); DOMPoint::new( - self.global().r().as_global_scope(), + &self.global_scope(), result.x as f64, result.y as f64, result.z as f64, diff --git a/components/script/dom/domquad.rs b/components/script/dom/domquad.rs index 238258889a8..f4a388df284 100644 --- a/components/script/dom/domquad.rs +++ b/components/script/dom/domquad.rs @@ -111,7 +111,7 @@ impl DOMQuadMethods for DOMQuad { let right = self.p1.X().max(self.p2.X()).max(self.p3.X()).max(self.p4.X()); let bottom = self.p1.Y().max(self.p2.Y()).max(self.p3.Y()).max(self.p4.Y()); - DOMRect::new(self.global().r().as_global_scope(), + DOMRect::new(&self.global_scope(), left, top, right - left, diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index fb647d3d590..af13822c456 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -500,8 +500,7 @@ impl EventTarget { bubbles: EventBubbles, cancelable: EventCancelable) -> Root<Event> { - let event = Event::new( - self.global().r().as_global_scope(), Atom::from(name), bubbles, cancelable); + let event = Event::new(&self.global_scope(), Atom::from(name), bubbles, cancelable); event.fire(self); diff --git a/components/script/dom/filereader.rs b/components/script/dom/filereader.rs index ac2aa37ee56..afd291c8f62 100644 --- a/components/script/dom/filereader.rs +++ b/components/script/dom/filereader.rs @@ -115,8 +115,7 @@ impl FileReader { fr.change_ready_state(FileReaderReadyState::Done); *fr.result.borrow_mut() = None; - let global = fr.r().global(); - let exception = DOMException::new(global.r().as_global_scope(), error); + let exception = DOMException::new(&fr.global_scope(), error); fr.error.set(Some(&exception)); fr.dispatch_progress_event(atom!("error"), 0, None); @@ -290,8 +289,7 @@ impl FileReaderMethods for FileReader { // Steps 1 & 3 *self.result.borrow_mut() = None; - let global = self.global(); - let exception = DOMException::new(global.r().as_global_scope(), DOMErrorName::AbortError); + let exception = DOMException::new(&self.global_scope(), DOMErrorName::AbortError); self.error.set(Some(&exception)); self.terminate_ongoing_reading(); @@ -319,8 +317,7 @@ impl FileReaderMethods for FileReader { impl FileReader { fn dispatch_progress_event(&self, type_: Atom, loaded: u64, total: Option<u64>) { - let global = self.global(); - let progressevent = ProgressEvent::new(global.r().as_global_scope(), + let progressevent = ProgressEvent::new(&self.global_scope(), type_, EventBubbles::DoesNotBubble, EventCancelable::NotCancelable, total.is_some(), loaded, total.unwrap_or(0)); progressevent.upcast::<Event>().fire(self.upcast()); @@ -338,8 +335,7 @@ impl FileReader { } // Step 2 if blob.IsClosed() { - let global = self.global(); - let exception = DOMException::new(global.r().as_global_scope(), DOMErrorName::InvalidStateError); + let exception = DOMException::new(&self.global_scope(), DOMErrorName::InvalidStateError); self.error.set(Some(&exception)); self.dispatch_progress_event(atom!("error"), 0, None); diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs index e5bdc6ca1d5..50747245c21 100644 --- a/components/script/dom/formdata.rs +++ b/components/script/dom/formdata.rs @@ -146,8 +146,6 @@ impl FormDataMethods for FormData { impl FormData { fn get_file(&self, blob: &Blob, opt_filename: Option<USVString>) -> Root<File> { - let global = self.global(); - let name = match opt_filename { Some(filename) => DOMString::from(filename.0), None => DOMString::from(""), @@ -155,7 +153,7 @@ impl FormData { let bytes = blob.get_bytes().unwrap_or(vec![]); - File::new(global.r().as_global_scope(), BlobImpl::new_from_bytes(bytes), name, None, "") + File::new(&self.global_scope(), BlobImpl::new_from_bytes(bytes), name, None, "") } pub fn datums(&self) -> Vec<FormDatum> { diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index f74946ba841..b387990b68e 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -267,7 +267,7 @@ impl HTMLLinkElement { credentials_mode: CredentialsMode::Include, use_url_credentials: true, origin: document.url().clone(), - pipeline_id: Some(self.global().r().as_global_scope().pipeline_id()), + pipeline_id: Some(self.global_scope().pipeline_id()), referrer_url: Some(document.url().clone()), referrer_policy: referrer_policy, .. RequestInit::default() diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index 4cf7e2df59c..2132d41edf7 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -242,7 +242,7 @@ fn fetch_a_classic_script(script: &HTMLScriptElement, _ => CredentialsMode::Include, }, origin: doc.url().clone(), - pipeline_id: Some(script.global().r().as_global_scope().pipeline_id()), + pipeline_id: Some(script.global_scope().pipeline_id()), referrer_url: Some(doc.url().clone()), referrer_policy: doc.get_referrer_policy(), .. RequestInit::default() diff --git a/components/script/dom/navigator.rs b/components/script/dom/navigator.rs index d4e4629e486..51dbf5bbfa7 100644 --- a/components/script/dom/navigator.rs +++ b/components/script/dom/navigator.rs @@ -79,7 +79,7 @@ impl NavigatorMethods for Navigator { // https://webbluetoothcg.github.io/web-bluetooth/#dom-navigator-bluetooth fn Bluetooth(&self) -> Root<Bluetooth> { - self.bluetooth.or_init(|| Bluetooth::new(self.global().r().as_global_scope())) + self.bluetooth.or_init(|| Bluetooth::new(&self.global_scope())) } // https://html.spec.whatwg.org/multipage/#navigatorlanguage @@ -89,12 +89,12 @@ impl NavigatorMethods for Navigator { // https://html.spec.whatwg.org/multipage/#dom-navigator-plugins fn Plugins(&self) -> Root<PluginArray> { - self.plugins.or_init(|| PluginArray::new(self.global().r().as_global_scope())) + self.plugins.or_init(|| PluginArray::new(&self.global_scope())) } // https://html.spec.whatwg.org/multipage/#dom-navigator-mimetypes fn MimeTypes(&self) -> Root<MimeTypeArray> { - self.mime_types.or_init(|| MimeTypeArray::new(self.global().r().as_global_scope())) + self.mime_types.or_init(|| MimeTypeArray::new(&self.global_scope())) } // https://html.spec.whatwg.org/multipage/#dom-navigator-javaenabled @@ -105,7 +105,7 @@ impl NavigatorMethods for Navigator { // https://w3c.github.io/ServiceWorker/#navigator-service-worker-attribute fn ServiceWorker(&self) -> Root<ServiceWorkerContainer> { self.service_worker.or_init(|| { - ServiceWorkerContainer::new(self.global().r().as_global_scope()) + ServiceWorkerContainer::new(&self.global_scope()) }) } diff --git a/components/script/dom/request.rs b/components/script/dom/request.rs index 4a9343b76b4..1060f4b963b 100644 --- a/components/script/dom/request.rs +++ b/components/script/dom/request.rs @@ -305,7 +305,7 @@ impl Request { let r = Request::from_net_request(global, false, request); - r.headers.or_init(|| Headers::for_request(r.global().r().as_global_scope())); + r.headers.or_init(|| Headers::for_request(&r.global_scope())); // Step 27 let mut headers_copy = r.Headers(); @@ -549,7 +549,7 @@ impl RequestMethods for Request { // https://fetch.spec.whatwg.org/#dom-request-headers fn Headers(&self) -> Root<Headers> { - self.headers.or_init(|| Headers::new(self.global().r().as_global_scope())) + self.headers.or_init(|| Headers::new(&self.global_scope())) } // https://fetch.spec.whatwg.org/#dom-request-type diff --git a/components/script/dom/response.rs b/components/script/dom/response.rs index a90a551b20a..5306a152156 100644 --- a/components/script/dom/response.rs +++ b/components/script/dom/response.rs @@ -293,7 +293,7 @@ impl ResponseMethods for Response { // https://fetch.spec.whatwg.org/#dom-response-headers fn Headers(&self) -> Root<Headers> { - self.headers_reflector.or_init(|| Headers::for_response(self.global().r().as_global_scope())) + self.headers_reflector.or_init(|| Headers::for_response(&self.global_scope())) } // https://fetch.spec.whatwg.org/#dom-response-clone @@ -302,7 +302,7 @@ impl ResponseMethods for Response { // TODO: This step relies on body and stream, which are still unimplemented. // Step 2 - let new_response = Response::new(self.global().r().as_global_scope()); + let new_response = Response::new(&self.global_scope()); new_response.Headers().set_guard(self.Headers().get_guard()); // https://fetch.spec.whatwg.org/#concept-response-clone diff --git a/components/script/dom/serviceworker.rs b/components/script/dom/serviceworker.rs index 6f2dce2f8e0..3b3cd58eee4 100644 --- a/components/script/dom/serviceworker.rs +++ b/components/script/dom/serviceworker.rs @@ -90,8 +90,7 @@ impl ServiceWorkerMethods for ServiceWorker { let data = try!(StructuredCloneData::write(cx, message)); let msg_vec = DOMMessage(data.move_to_arraybuffer()); let _ = - self.global().r() - .as_global_scope() + self.global_scope() .constellation_chan() .send(ScriptMsg::ForwardDOMMessage(msg_vec, self.scope_url.clone())); Ok(()) diff --git a/components/script/dom/serviceworkercontainer.rs b/components/script/dom/serviceworkercontainer.rs index 993241445d5..12bab94fe12 100644 --- a/components/script/dom/serviceworkercontainer.rs +++ b/components/script/dom/serviceworkercontainer.rs @@ -95,14 +95,12 @@ impl ServiceWorkerContainerMethods for ServiceWorkerContainer { return Err(Error::Type("Scope URL contains forbidden characters".to_owned())); } - let global = self.global(); - let global = global.r(); - let global_scope = global.as_global_scope(); - let worker_registration = ServiceWorkerRegistration::new(global_scope, + let global = self.global_scope(); + let worker_registration = ServiceWorkerRegistration::new(&global, script_url, scope.clone(), self); - ScriptThread::set_registration(scope, &*worker_registration, global_scope.pipeline_id()); + ScriptThread::set_registration(scope, &*worker_registration, global.pipeline_id()); Ok(worker_registration) } } diff --git a/components/script/dom/storage.rs b/components/script/dom/storage.rs index 30afd8719c4..7152e27acc7 100644 --- a/components/script/dom/storage.rs +++ b/components/script/dom/storage.rs @@ -185,13 +185,11 @@ impl Runnable for StorageEventRunnable { let this = *self; let storage_root = this.element.root(); let storage = storage_root.r(); - let global_root = storage.global(); - let global_ref = global_root.r(); - let ev_window = global_ref.as_window(); + let global = storage.global_scope(); let ev_url = storage.get_url(); let storage_event = StorageEvent::new( - global_ref.as_global_scope(), + &global, atom!("storage"), EventBubbles::DoesNotBubble, EventCancelable::NotCancelable, this.key.map(DOMString::from), this.old_value.map(DOMString::from), this.new_value.map(DOMString::from), @@ -206,7 +204,7 @@ impl Runnable for StorageEventRunnable { assert!(UrlHelper::SameOrigin(&ev_url, &it_window.get_url())); // TODO: Such a Document object is not necessarily fully active, but events fired on such // objects are ignored by the event loop until the Document becomes fully active again. - if ev_window.upcast::<GlobalScope>().pipeline_id() != it_window.upcast::<GlobalScope>().pipeline_id() { + if global.pipeline_id() != it_window.upcast::<GlobalScope>().pipeline_id() { storage_event.upcast::<Event>().fire(it_window.upcast()); } } diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs index 62714dfc220..0ebeac1ccb1 100644 --- a/components/script/dom/testbinding.rs +++ b/components/script/dom/testbinding.rs @@ -114,7 +114,7 @@ impl TestBindingMethods for TestBinding { fn EnumAttribute(&self) -> TestEnum { TestEnum::_empty } fn SetEnumAttribute(&self, _: TestEnum) {} fn InterfaceAttribute(&self) -> Root<Blob> { - Blob::new(self.global().r().as_global_scope(), BlobImpl::new_from_bytes(vec![]), "".to_owned()) + Blob::new(&self.global_scope(), BlobImpl::new_from_bytes(vec![]), "".to_owned()) } fn SetInterfaceAttribute(&self, _: &Blob) {} fn UnionAttribute(&self) -> HTMLElementOrLong { HTMLElementOrLong::Long(0) } @@ -210,7 +210,7 @@ impl TestBindingMethods for TestBinding { fn SetAttr_to_automatically_rename(&self, _: DOMString) {} fn GetEnumAttributeNullable(&self) -> Option<TestEnum> { Some(TestEnum::_empty) } fn GetInterfaceAttributeNullable(&self) -> Option<Root<Blob>> { - Some(Blob::new(self.global().r().as_global_scope(), BlobImpl::new_from_bytes(vec![]), "".to_owned())) + Some(Blob::new(&self.global_scope(), BlobImpl::new_from_bytes(vec![]), "".to_owned())) } fn SetInterfaceAttributeNullable(&self, _: Option<&Blob>) {} fn GetInterfaceAttributeWeak(&self) -> Option<Root<URL>> { @@ -265,7 +265,7 @@ impl TestBindingMethods for TestBinding { fn ReceiveByteString(&self) -> ByteString { ByteString::new(vec!()) } fn ReceiveEnum(&self) -> TestEnum { TestEnum::_empty } fn ReceiveInterface(&self) -> Root<Blob> { - Blob::new(self.global().r().as_global_scope(), BlobImpl::new_from_bytes(vec![]), "".to_owned()) + Blob::new(&self.global_scope(), BlobImpl::new_from_bytes(vec![]), "".to_owned()) } fn ReceiveAny(&self, _: *mut JSContext) -> JSVal { NullValue() } fn ReceiveObject(&self, cx: *mut JSContext) -> NonZero<*mut JSObject> { @@ -288,7 +288,7 @@ impl TestBindingMethods for TestBinding { } fn ReceiveSequence(&self) -> Vec<i32> { vec![1] } fn ReceiveInterfaceSequence(&self) -> Vec<Root<Blob>> { - vec![Blob::new(self.global().r().as_global_scope(), BlobImpl::new_from_bytes(vec![]), "".to_owned())] + vec![Blob::new(&self.global_scope(), BlobImpl::new_from_bytes(vec![]), "".to_owned())] } fn ReceiveNullableBoolean(&self) -> Option<bool> { Some(false) } @@ -309,7 +309,7 @@ impl TestBindingMethods for TestBinding { fn ReceiveNullableByteString(&self) -> Option<ByteString> { Some(ByteString::new(vec!())) } fn ReceiveNullableEnum(&self) -> Option<TestEnum> { Some(TestEnum::_empty) } fn ReceiveNullableInterface(&self) -> Option<Root<Blob>> { - Some(Blob::new(self.global().r().as_global_scope(), BlobImpl::new_from_bytes(vec![]), "".to_owned())) + Some(Blob::new(&self.global_scope(), BlobImpl::new_from_bytes(vec![]), "".to_owned())) } fn ReceiveNullableObject(&self, cx: *mut JSContext) -> Option<NonZero<*mut JSObject>> { self.GetObjectAttributeNullable(cx) diff --git a/components/script/dom/url.rs b/components/script/dom/url.rs index 5fd4a9b005f..2d5968e9e07 100644 --- a/components/script/dom/url.rs +++ b/components/script/dom/url.rs @@ -285,7 +285,7 @@ impl URLMethods for URL { // https://url.spec.whatwg.org/#dom-url-searchparams fn SearchParams(&self) -> Root<URLSearchParams> { self.search_params.or_init(|| { - URLSearchParams::new(self.global().r().as_global_scope(), Some(self)) + URLSearchParams::new(&self.global_scope(), Some(self)) }) } diff --git a/components/script/dom/webglprogram.rs b/components/script/dom/webglprogram.rs index 4b3b39b05cc..5c2648de4b9 100644 --- a/components/script/dom/webglprogram.rs +++ b/components/script/dom/webglprogram.rs @@ -230,7 +230,7 @@ impl WebGLProgram { .unwrap(); receiver.recv().unwrap().map(|(size, ty, name)| - WebGLActiveInfo::new(self.global().r().as_global_scope(), size, ty, DOMString::from(name))) + WebGLActiveInfo::new(&self.global_scope(), size, ty, DOMString::from(name))) } /// glGetActiveAttrib @@ -244,7 +244,7 @@ impl WebGLProgram { .unwrap(); receiver.recv().unwrap().map(|(size, ty, name)| - WebGLActiveInfo::new(self.global().r().as_global_scope(), size, ty, DOMString::from(name))) + WebGLActiveInfo::new(&self.global_scope(), size, ty, DOMString::from(name))) } /// glGetAttribLocation diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 1b29bd47621..5b1f20a6218 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -1154,27 +1154,27 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // generated objects, either here or in the webgl thread // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5 fn CreateBuffer(&self) -> Option<Root<WebGLBuffer>> { - WebGLBuffer::maybe_new(self.global().r().as_global_scope(), self.ipc_renderer.clone()) + WebGLBuffer::maybe_new(&self.global_scope(), self.ipc_renderer.clone()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.6 fn CreateFramebuffer(&self) -> Option<Root<WebGLFramebuffer>> { - WebGLFramebuffer::maybe_new(self.global().r().as_global_scope(), self.ipc_renderer.clone()) + WebGLFramebuffer::maybe_new(&self.global_scope(), self.ipc_renderer.clone()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.7 fn CreateRenderbuffer(&self) -> Option<Root<WebGLRenderbuffer>> { - WebGLRenderbuffer::maybe_new(self.global().r().as_global_scope(), self.ipc_renderer.clone()) + WebGLRenderbuffer::maybe_new(&self.global_scope(), self.ipc_renderer.clone()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 fn CreateTexture(&self) -> Option<Root<WebGLTexture>> { - WebGLTexture::maybe_new(self.global().r().as_global_scope(), self.ipc_renderer.clone()) + WebGLTexture::maybe_new(&self.global_scope(), self.ipc_renderer.clone()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9 fn CreateProgram(&self) -> Option<Root<WebGLProgram>> { - WebGLProgram::maybe_new(self.global().r().as_global_scope(), self.ipc_renderer.clone()) + WebGLProgram::maybe_new(&self.global_scope(), self.ipc_renderer.clone()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9 @@ -1186,7 +1186,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { return None; } } - WebGLShader::maybe_new(self.global().r().as_global_scope(), self.ipc_renderer.clone(), shader_type) + WebGLShader::maybe_new(&self.global_scope(), self.ipc_renderer.clone(), shader_type) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5 @@ -1480,7 +1480,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { name: DOMString) -> Option<Root<WebGLUniformLocation>> { program.and_then(|p| { handle_potential_webgl_error!(self, p.get_uniform_location(name), None) - .map(|location| WebGLUniformLocation::new(self.global().r().as_global_scope(), location, p.id())) + .map(|location| WebGLUniformLocation::new(&self.global_scope(), location, p.id())) }) } diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index 4e86241f36a..a7bf55b6757 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -535,8 +535,6 @@ impl Runnable for CloseTask { fn handler(self: Box<Self>) { let ws = self.address.root(); - let ws = ws.r(); - let global = ws.global(); if ws.ready_state.get() == WebSocketRequestState::Closed { // Do nothing if already closed. @@ -558,7 +556,7 @@ impl Runnable for CloseTask { let clean_close = !self.failed; let code = self.code.unwrap_or(close_code::NO_STATUS); let reason = DOMString::from(self.reason.unwrap_or("".to_owned())); - let close_event = CloseEvent::new(global.r().as_global_scope(), + let close_event = CloseEvent::new(&ws.global_scope(), atom!("close"), EventBubbles::DoesNotBubble, EventCancelable::NotCancelable, diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 0cf5381767d..fe99410419b 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -283,8 +283,7 @@ impl LoadOrigin for XMLHttpRequest { } fn pipeline_id(&self) -> Option<PipelineId> { - let global = self.global(); - Some(global.r().as_global_scope().pipeline_id()) + Some(self.global_scope().pipeline_id()) } } @@ -859,8 +858,7 @@ impl XMLHttpRequest { fn change_ready_state(&self, rs: XMLHttpRequestState) { assert!(self.ready_state.get() != rs); self.ready_state.set(rs); - let global = self.global(); - let event = Event::new(global.r().as_global_scope(), + let event = Event::new(&self.global_scope(), atom!("readystatechange"), EventBubbles::DoesNotBubble, EventCancelable::Cancelable); @@ -1049,8 +1047,7 @@ impl XMLHttpRequest { } fn dispatch_progress_event(&self, upload: bool, type_: Atom, loaded: u64, total: Option<u64>) { - let global = self.global(); - let progressevent = ProgressEvent::new(global.r().as_global_scope(), + let progressevent = ProgressEvent::new(&self.global_scope(), type_, EventBubbles::DoesNotBubble, EventCancelable::NotCancelable, @@ -1118,7 +1115,7 @@ impl XMLHttpRequest { // Step 3, 4 let bytes = self.response.borrow().to_vec(); - let blob = Blob::new(self.global().r().as_global_scope(), BlobImpl::new_from_bytes(bytes), mime); + let blob = Blob::new(&self.global_scope(), BlobImpl::new_from_bytes(bytes), mime); self.response_blob.set(Some(blob.r())); blob } |