diff options
Diffstat (limited to 'components')
-rw-r--r-- | components/script/dom/bindings/reflector.rs | 14 | ||||
-rw-r--r-- | components/script_bindings/interface.rs | 18 | ||||
-rw-r--r-- | components/script_bindings/reflector.rs | 13 |
3 files changed, 24 insertions, 21 deletions
diff --git a/components/script/dom/bindings/reflector.rs b/components/script/dom/bindings/reflector.rs index 0a5afbce487..c888686974e 100644 --- a/components/script/dom/bindings/reflector.rs +++ b/components/script/dom/bindings/reflector.rs @@ -11,7 +11,7 @@ use crate::DomTypes; use crate::dom::bindings::conversions::DerivedFrom; use crate::dom::bindings::root::DomRoot; use crate::dom::globalscope::GlobalScope; -use crate::realms::InRealm; +use crate::realms::{InRealm, enter_realm}; use crate::script_runtime::CanGc; /// Create the reflector for a new DOM object and yield ownership to the @@ -42,7 +42,16 @@ where } pub(crate) trait DomGlobal { + /// Returns the [relevant global] in whatever realm is currently active. + /// + /// [relevant global]: https://html.spec.whatwg.org/multipage/#concept-relevant-global fn global_(&self, realm: InRealm) -> DomRoot<GlobalScope>; + + /// Returns the [relevant global] in the same realm as the callee object. + /// If you know the callee's realm is already the current realm, it is + /// more efficient to call [DomGlobal::global_] instead. + /// + /// [relevant global]: https://html.spec.whatwg.org/multipage/#concept-relevant-global fn global(&self) -> DomRoot<GlobalScope>; } @@ -51,7 +60,8 @@ impl<T: DomGlobalGeneric<crate::DomTypeHolder>> DomGlobal for T { <Self as DomGlobalGeneric<crate::DomTypeHolder>>::global_(self, realm) } fn global(&self) -> DomRoot<GlobalScope> { - <Self as DomGlobalGeneric<crate::DomTypeHolder>>::global(self) + let realm = enter_realm(self); + <Self as DomGlobalGeneric<crate::DomTypeHolder>>::global_(self, InRealm::entered(&realm)) } } diff --git a/components/script_bindings/interface.rs b/components/script_bindings/interface.rs index 08ee0a4f420..e185cfe9cfd 100644 --- a/components/script_bindings/interface.rs +++ b/components/script_bindings/interface.rs @@ -16,11 +16,11 @@ use js::jsapi::{ GetFunctionRealm, GetNonCCWObjectGlobal, GetRealmGlobalOrNull, GetWellKnownSymbol, HandleObject as RawHandleObject, IsSharableCompartment, IsSystemCompartment, JS_AtomizeAndPinString, JS_GetFunctionObject, JS_GetProperty, JS_IterateCompartments, - JS_NewFunction, JS_NewGlobalObject, JS_NewObject, JS_NewPlainObject, JS_NewStringCopyN, - JS_SetReservedSlot, JS_WrapObject, JSAutoRealm, JSClass, JSClassOps, JSContext, - JSFUN_CONSTRUCTOR, JSFunctionSpec, JSObject, JSPROP_PERMANENT, JSPROP_READONLY, - JSPROP_RESOLVING, JSPropertySpec, JSString, JSTracer, ObjectOps, OnNewGlobalHookOption, - SymbolCode, TrueHandleValue, Value, jsid, + JS_NewFunction, JS_NewGlobalObject, JS_NewObject, JS_NewStringCopyN, JS_SetReservedSlot, + JS_WrapObject, JSAutoRealm, JSClass, JSClassOps, JSContext, JSFUN_CONSTRUCTOR, JSFunctionSpec, + JSObject, JSPROP_ENUMERATE, JSPROP_PERMANENT, JSPROP_READONLY, JSPROP_RESOLVING, + JSPropertySpec, JSString, JSTracer, ObjectOps, OnNewGlobalHookOption, SymbolCode, + TrueHandleValue, Value, jsid, }; use js::jsval::{JSVal, NullValue, PrivateValue}; use js::rust::wrappers::{ @@ -473,7 +473,11 @@ fn create_unscopable_object(cx: SafeJSContext, names: &[&CStr], mut rval: Mutabl assert!(!names.is_empty()); assert!(rval.is_null()); unsafe { - rval.set(JS_NewPlainObject(*cx)); + rval.set(JS_NewObjectWithGivenProto( + *cx, + ptr::null(), + HandleObject::null(), + )); assert!(!rval.is_null()); for &name in names { assert!(JS_DefineProperty( @@ -481,7 +485,7 @@ fn create_unscopable_object(cx: SafeJSContext, names: &[&CStr], mut rval: Mutabl rval.handle(), name.as_ptr(), HandleValue::from_raw(TrueHandleValue), - JSPROP_READONLY as u32, + JSPROP_ENUMERATE as u32, )); } } diff --git a/components/script_bindings/reflector.rs b/components/script_bindings/reflector.rs index 6b6ae03cb69..4b91b0536fc 100644 --- a/components/script_bindings/reflector.rs +++ b/components/script_bindings/reflector.rs @@ -8,7 +8,7 @@ use malloc_size_of_derive::MallocSizeOf; use crate::interfaces::GlobalScopeHelpers; use crate::iterable::{Iterable, IterableIterator}; -use crate::realms::{AlreadyInRealm, InRealm}; +use crate::realms::InRealm; use crate::root::{Dom, DomRoot, Root}; use crate::script_runtime::{CanGc, JSContext}; use crate::{DomTypes, JSTraceable}; @@ -108,17 +108,6 @@ pub trait DomGlobalGeneric<D: DomTypes>: DomObject { { D::GlobalScope::from_reflector(self, realm) } - - /// Returns the [`GlobalScope`] of the realm that the [`DomObject`] was created in. If this - /// object is a `Node`, this will be different from it's owning `Document` if adopted by. For - /// `Node`s it's almost always better to use `NodeTraits::owning_global`. - fn global(&self) -> DomRoot<D::GlobalScope> - where - Self: Sized, - { - let realm = AlreadyInRealm::assert_for_cx(D::GlobalScope::get_cx()); - D::GlobalScope::from_reflector(self, InRealm::already(&realm)) - } } impl<D: DomTypes, T: DomObject> DomGlobalGeneric<D> for T {} |