From 01e336f6912292b5ca4c7349846a5d100974d99e Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 20 Dec 2016 17:00:57 +0100 Subject: [PATCH] Implement a getter for the 'current' global object. --- components/script/dom/globalscope.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 { + 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 {