aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/globalscope.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-12-29 01:38:19 -0800
committerGitHub <noreply@github.com>2016-12-29 01:38:19 -0800
commit885d152e92b20bdaeb0d0ad20affd269fc3b55d3 (patch)
treed79a81148534ca9b0a4a38551bee4779774f22b2 /components/script/dom/globalscope.rs
parentc7991d596f7453d09c2b2a98eecce72f182a4e24 (diff)
parentd49e34c1b1e6e3759633c9315a3e02dde091546c (diff)
downloadservo-885d152e92b20bdaeb0d0ad20affd269fc3b55d3.tar.gz
servo-885d152e92b20bdaeb0d0ad20affd269fc3b55d3.zip
Auto merge of #14647 - servo:current-global, r=jdm
Support the 'current' global object. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14647) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/globalscope.rs')
-rw-r--r--components/script/dom/globalscope.rs15
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 {