From f69ee078d2df2ea7625065f8a17b9984b96ff0ea Mon Sep 17 00:00:00 2001 From: Sam <16504129+sagudev@users.noreply.github.com> Date: Fri, 20 Feb 2026 17:19:15 +0100 Subject: [PATCH] script: Add `reflect_dom_object_with_cx` (#42725) Just to complement existing with_proto method introduced in #42699. Justification for arg ordering: reflect_dom_* have arguments reversed, so first one is Box (the most important) then global, proto and lastly cx. --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- components/script/dom/bindings/reflector.rs | 16 ++++++++++++++++ .../dom/bluetooth/bluetoothremotegattservice.rs | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/components/script/dom/bindings/reflector.rs b/components/script/dom/bindings/reflector.rs index eb1f0ca123c..4484b14186d 100644 --- a/components/script/dom/bindings/reflector.rs +++ b/components/script/dom/bindings/reflector.rs @@ -43,6 +43,22 @@ where unsafe { T::WRAP(&mut cx, global_scope, proto, obj) } } +/// Create the reflector for a new DOM object and yield ownership to the +/// reflector. +pub(crate) fn reflect_dom_object_with_cx( + obj: Box, + global: &U, + cx: &mut js::context::JSContext, +) -> DomRoot +where + D: DomTypes, + T: DomObject + DomObjectWrap, + U: DerivedFrom, +{ + let global_scope = global.upcast(); + unsafe { T::WRAP(cx, global_scope, None, obj) } +} + /// Create the reflector for a new DOM object and yield ownership to the /// reflector. pub(crate) fn reflect_dom_object_with_proto_and_cx( diff --git a/components/script/dom/bluetooth/bluetoothremotegattservice.rs b/components/script/dom/bluetooth/bluetoothremotegattservice.rs index a53eb4c0f27..a977baec20c 100644 --- a/components/script/dom/bluetooth/bluetoothremotegattservice.rs +++ b/components/script/dom/bluetooth/bluetoothremotegattservice.rs @@ -10,7 +10,7 @@ use dom_struct::dom_struct; use crate::dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods; use crate::dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods; use crate::dom::bindings::error::Error; -use crate::dom::bindings::reflector::reflect_dom_object; +use crate::dom::bindings::reflector::reflect_dom_object_with_cx; use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::str::DOMString; use crate::dom::bluetooth::{AsyncBluetoothListener, get_gatt_children}; @@ -56,12 +56,12 @@ impl BluetoothRemoteGATTService { isPrimary: bool, instanceID: String, ) -> DomRoot { - reflect_dom_object( + reflect_dom_object_with_cx( Box::new(BluetoothRemoteGATTService::new_inherited( device, uuid, isPrimary, instanceID, )), global, - CanGc::from_cx(cx), + cx, ) }