Implement a getter for the 'current' global object.

This commit is contained in:
Ms2ger 2016-12-20 17:00:57 +01:00
parent 07b18265f3
commit 01e336f691

View file

@ -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 {