mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
auto merge of #1809 : Ms2ger/servo/constructor-global-from-object, r=jdm
...rather than the JSContext. Requires <https://github.com/mozilla-servo/rust-mozjs/pull/51>.
This commit is contained in:
commit
f7821e40c2
3 changed files with 11 additions and 19 deletions
|
@ -4805,13 +4805,7 @@ class CGClassConstructHook(CGAbstractExternMethod):
|
|||
|
||||
def generate_code(self):
|
||||
preamble = """
|
||||
//JSObject* obj = JS_GetGlobalForObject(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
|
||||
//XXXjdm Gecko obtains a GlobalObject from the global (maybe from the private value,
|
||||
// or through unwrapping a slot or something). We'll punt and get the Window
|
||||
// from the context for now.
|
||||
let page = page_from_context(cx);
|
||||
let frame = (*page).frame();
|
||||
let global = frame.get().get_ref().window.clone();
|
||||
let global = global_object_for_js_object(RUST_JSVAL_TO_OBJECT(JS_CALLEE(cx, &*vp)));
|
||||
let obj = global.reflector().get_jsobject();
|
||||
"""
|
||||
nativeName = MakeNativeName(self._ctor.identifier.name)
|
||||
|
|
|
@ -720,32 +720,30 @@ pub fn CreateDOMGlobal(cx: *JSContext, class: *JSClass) -> *JSObject {
|
|||
}
|
||||
|
||||
/// Returns the global object of the realm that the given JS object was created in.
|
||||
fn global_object_for_js_object(obj: *JSObject) -> *Box<window::Window> {
|
||||
pub fn global_object_for_js_object(obj: *JSObject) -> JS<window::Window> {
|
||||
unsafe {
|
||||
let global = GetGlobalForObjectCrossCompartment(obj);
|
||||
let clasp = JS_GetClass(global);
|
||||
assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0);
|
||||
// FIXME(jdm): Either don't hardcode or sanity assert prototype stuff.
|
||||
match unwrap_object::<*Box<window::Window>>(global, PrototypeList::id::Window, 1) {
|
||||
Ok(win) => win,
|
||||
match unwrap_object::<*mut Box<window::Window>>(global, PrototypeList::id::Window, 1) {
|
||||
Ok(win) => JS::from_box(win),
|
||||
Err(_) => fail!("found DOM global that doesn't unwrap to Window"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext {
|
||||
unsafe {
|
||||
let win = global_object_for_js_object(obj);
|
||||
let js_info = (*win).data.page().js_info();
|
||||
match *js_info.get() {
|
||||
Some(ref info) => info.js_context.borrow().ptr,
|
||||
None => fail!("no JS context for DOM global")
|
||||
}
|
||||
let win = global_object_for_js_object(obj);
|
||||
let js_info = win.get().page().js_info();
|
||||
match *js_info.get() {
|
||||
Some(ref info) => info.js_context.borrow().ptr,
|
||||
None => fail!("no JS context for DOM global")
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the global object of the realm that the given DOM object was created in.
|
||||
pub fn global_object_for_dom_object<T: Reflectable>(obj: &T) -> *Box<window::Window> {
|
||||
pub fn global_object_for_dom_object<T: Reflectable>(obj: &T) -> JS<window::Window> {
|
||||
global_object_for_js_object(obj.reflector().get_jsobject())
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit b04df09b61a68ed47e4829045804173fc849f370
|
||||
Subproject commit 1730e6bf24fdacb958061b8ee80d5289f7a7b496
|
Loading…
Add table
Add a link
Reference in a new issue