diff options
Diffstat (limited to 'components/script/dom/globalscope.rs')
-rw-r--r-- | components/script/dom/globalscope.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index ae08bc0e5fd..d0976ec302c 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -27,7 +27,7 @@ use js::jsapi::{HandleValue, Evaluate2, JSAutoCompartment, JSContext}; use js::jsapi::{JSObject, JS_GetContext}; use js::jsapi::{JS_GetObjectRuntime, MutableHandleValue}; use js::panic::maybe_resume_unwind; -use js::rust::{CompileOptionsWrapper, get_object_class}; +use js::rust::{CompileOptionsWrapper, Runtime, get_object_class}; use libc; use msg::constellation_msg::PipelineId; use net_traits::{CoreResourceThread, ResourceThreads, IpcSend}; @@ -506,6 +506,19 @@ impl GlobalScope { } unreachable!(); } + + /// Returns the ["current"] global object. + /// + /// ["current"]: https://html.spec.whatwg.org/multipage/#current + #[allow(unsafe_code)] + pub fn current() -> Root<Self> { + unsafe { + let cx = Runtime::get(); + assert!(!cx.is_null()); + let global = CurrentGlobalOrNull(cx); + global_scope_from_global(global) + } + } } fn timestamp_in_ms(time: Timespec) -> u64 { |