When calling constructors, retrieve the global object from the callee rather than the JSContext.

This commit is contained in:
Ms2ger 2014-03-04 10:46:49 +01:00
parent 4a6077ca4c
commit c8bd9615f4
3 changed files with 6 additions and 11 deletions

View file

@ -4805,13 +4805,8 @@ class CGClassConstructHook(CGAbstractExternMethod):
def generate_code(self): def generate_code(self):
preamble = """ preamble = """
//JSObject* obj = JS_GetGlobalForObject(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp))); let window = global_object_for_js_object(RUST_JSVAL_TO_OBJECT(JS_CALLEE(cx, &*vp)));
//XXXjdm Gecko obtains a GlobalObject from the global (maybe from the private value, let global = JS::from_box(window);
// 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 obj = global.reflector().get_jsobject(); let obj = global.reflector().get_jsobject();
""" """
nativeName = MakeNativeName(self._ctor.identifier.name) nativeName = MakeNativeName(self._ctor.identifier.name)

View file

@ -720,13 +720,13 @@ pub fn CreateDOMGlobal(cx: *JSContext, class: *JSClass) -> *JSObject {
} }
/// Returns the global object of the realm that the given JS object was created in. /// 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) -> *mut Box<window::Window> {
unsafe { unsafe {
let global = GetGlobalForObjectCrossCompartment(obj); let global = GetGlobalForObjectCrossCompartment(obj);
let clasp = JS_GetClass(global); let clasp = JS_GetClass(global);
assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0); assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0);
// FIXME(jdm): Either don't hardcode or sanity assert prototype stuff. // FIXME(jdm): Either don't hardcode or sanity assert prototype stuff.
match unwrap_object::<*Box<window::Window>>(global, PrototypeList::id::Window, 1) { match unwrap_object::<*mut Box<window::Window>>(global, PrototypeList::id::Window, 1) {
Ok(win) => win, Ok(win) => win,
Err(_) => fail!("found DOM global that doesn't unwrap to Window"), Err(_) => fail!("found DOM global that doesn't unwrap to Window"),
} }
@ -745,7 +745,7 @@ fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext {
} }
/// Returns the global object of the realm that the given DOM object was created in. /// 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) -> *mut Box<window::Window> {
global_object_for_js_object(obj.reflector().get_jsobject()) global_object_for_js_object(obj.reflector().get_jsobject())
} }

@ -1 +1 @@
Subproject commit b04df09b61a68ed47e4829045804173fc849f370 Subproject commit 1730e6bf24fdacb958061b8ee80d5289f7a7b496