mirror of
https://github.com/servo/servo.git
synced 2025-06-18 13:24:29 +00:00
Remove WrapNativeParent and nearby cleanup.
This commit is contained in:
parent
5c101526a1
commit
edd9c1d5eb
3 changed files with 19 additions and 38 deletions
|
@ -2,7 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::utils::{WrapNativeParent, Reflectable};
|
||||
use dom::bindings::utils::Reflectable;
|
||||
use js::jsapi::{JSContext, JSObject, JS_WrapObject, JSVal, JS_ObjectIsCallable};
|
||||
use js::jsapi::JS_GetProperty;
|
||||
use js::{JSVAL_IS_OBJECT, JSVAL_TO_OBJECT};
|
||||
|
@ -67,15 +67,10 @@ pub fn GetJSObjectFromCallback<T: CallbackContainer>(callback: &T) -> *JSObject
|
|||
|
||||
#[fixed_stack_segment]
|
||||
pub fn WrapCallThisObject<T: 'static + CallbackContainer + Reflectable>(cx: *JSContext,
|
||||
scope: *JSObject,
|
||||
_scope: *JSObject,
|
||||
p: @mut T) -> *JSObject {
|
||||
let mut obj = GetJSObjectFromCallback(p);
|
||||
if obj.is_null() {
|
||||
obj = WrapNativeParent(cx, scope, Some(p as @mut Reflectable));
|
||||
if obj.is_null() {
|
||||
return ptr::null();
|
||||
}
|
||||
}
|
||||
let obj = GetJSObjectFromCallback(p);
|
||||
assert!(obj.is_not_null());
|
||||
|
||||
unsafe {
|
||||
if JS_WrapObject(cx, &obj) == 0 {
|
||||
|
|
|
@ -2506,8 +2506,8 @@ class CGAbstractMethod(CGThing):
|
|||
|
||||
def CreateBindingJSObject(descriptor, parent=None):
|
||||
if descriptor.proxy:
|
||||
handler = """ //let reflector = aObject.mut_reflector();
|
||||
|
||||
assert not descriptor.createGlobal
|
||||
handler = """
|
||||
let page = page_from_context(aCx);
|
||||
let handler = (*page).js_info.get_ref().dom_static.proxy_handlers.get(&(PrototypeList::id::%s as uint));
|
||||
""" % descriptor.name
|
||||
|
@ -2546,33 +2546,29 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
|
|||
return """return aObject->GetJSObject();"""
|
||||
|
||||
if not self.descriptor.createGlobal:
|
||||
return """let mut parent = aObject.GetParentObject(aCx);
|
||||
let parent = WrapNativeParent(aCx, aScope, parent);
|
||||
if parent.is_null() {
|
||||
return ptr::null();
|
||||
}
|
||||
return """
|
||||
assert!(aScope.is_not_null());
|
||||
assert!(((*JS_GetClass(aScope)).flags & JSCLASS_IS_GLOBAL) != 0);
|
||||
|
||||
//JSAutoCompartment ac(aCx, parent);
|
||||
let global = JS_GetGlobalForObject(aCx, parent);
|
||||
let proto = GetProtoObject(aCx, global, global);
|
||||
//JSAutoCompartment ac(aCx, aScope);
|
||||
let proto = GetProtoObject(aCx, aScope, aScope);
|
||||
if proto.is_null() {
|
||||
return ptr::null();
|
||||
}
|
||||
|
||||
let reflector = aObject.mut_reflector();
|
||||
%s
|
||||
|
||||
//NS_ADDREF(aObject);
|
||||
|
||||
(*reflector).set_jsobject(obj);
|
||||
aObject.mut_reflector().set_jsobject(obj);
|
||||
|
||||
return obj;""" % (CreateBindingJSObject(self.descriptor, "parent"))
|
||||
return obj;""" % (CreateBindingJSObject(self.descriptor, "aScope"))
|
||||
else:
|
||||
return """ let reflector = aObject.mut_reflector();
|
||||
return """
|
||||
assert!(aScope.is_null());
|
||||
%s
|
||||
let proto = GetProtoObject(aCx, obj, obj);
|
||||
JS_SetPrototype(aCx, obj, proto);
|
||||
(*reflector).set_jsobject(obj);
|
||||
aObject.mut_reflector().set_jsobject(obj);
|
||||
return obj;""" % CreateBindingJSObject(self.descriptor)
|
||||
|
||||
class CGWrapMethod(CGAbstractMethod):
|
||||
|
|
|
@ -18,7 +18,7 @@ use std::unstable::raw::Box;
|
|||
use js::glue::*;
|
||||
use js::glue::{DefineFunctionWithReserved, GetObjectJSClass, RUST_OBJECT_TO_JSVAL};
|
||||
use js::glue::{js_IsObjectProxyClass, js_IsFunctionProxyClass, IsProxyHandlerFamily};
|
||||
use js::jsapi::{JS_AlreadyHasOwnProperty, JS_NewObject, JS_NewFunction, JS_GetGlobalObject};
|
||||
use js::jsapi::{JS_AlreadyHasOwnProperty, JS_NewObject, JS_NewFunction};
|
||||
use js::jsapi::{JS_DefineProperties, JS_WrapValue, JS_ForwardGetPropertyTo};
|
||||
use js::jsapi::{JS_GetClass, JS_LinkConstructorAndPrototype, JS_GetStringCharsAndLength};
|
||||
use js::jsapi::{JS_ObjectIsRegExp, JS_ObjectIsDate};
|
||||
|
@ -567,6 +567,8 @@ impl Reflector {
|
|||
}
|
||||
|
||||
pub fn set_jsobject(&mut self, object: *JSObject) {
|
||||
assert!(self.object.is_null());
|
||||
assert!(object.is_not_null());
|
||||
self.object = object;
|
||||
}
|
||||
|
||||
|
@ -592,18 +594,6 @@ pub fn GetReflector(cx: *JSContext, reflector: &Reflector,
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn WrapNativeParent(cx: *JSContext, _scope: *JSObject, mut p: Option<@mut Reflectable>) -> *JSObject {
|
||||
match p {
|
||||
Some(ref mut p) => {
|
||||
let obj = p.reflector().get_jsobject();
|
||||
assert!(obj.is_not_null());
|
||||
obj
|
||||
}
|
||||
None => unsafe { JS_GetGlobalObject(cx) }
|
||||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn GetPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid, found: *mut bool,
|
||||
vp: *JSVal) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue