mirror of
https://github.com/servo/servo.git
synced 2025-06-19 06:38:59 +01: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
|
* 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/. */
|
* 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::{JSContext, JSObject, JS_WrapObject, JSVal, JS_ObjectIsCallable};
|
||||||
use js::jsapi::JS_GetProperty;
|
use js::jsapi::JS_GetProperty;
|
||||||
use js::{JSVAL_IS_OBJECT, JSVAL_TO_OBJECT};
|
use js::{JSVAL_IS_OBJECT, JSVAL_TO_OBJECT};
|
||||||
|
@ -67,15 +67,10 @@ pub fn GetJSObjectFromCallback<T: CallbackContainer>(callback: &T) -> *JSObject
|
||||||
|
|
||||||
#[fixed_stack_segment]
|
#[fixed_stack_segment]
|
||||||
pub fn WrapCallThisObject<T: 'static + CallbackContainer + Reflectable>(cx: *JSContext,
|
pub fn WrapCallThisObject<T: 'static + CallbackContainer + Reflectable>(cx: *JSContext,
|
||||||
scope: *JSObject,
|
_scope: *JSObject,
|
||||||
p: @mut T) -> *JSObject {
|
p: @mut T) -> *JSObject {
|
||||||
let mut obj = GetJSObjectFromCallback(p);
|
let obj = GetJSObjectFromCallback(p);
|
||||||
if obj.is_null() {
|
assert!(obj.is_not_null());
|
||||||
obj = WrapNativeParent(cx, scope, Some(p as @mut Reflectable));
|
|
||||||
if obj.is_null() {
|
|
||||||
return ptr::null();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
if JS_WrapObject(cx, &obj) == 0 {
|
if JS_WrapObject(cx, &obj) == 0 {
|
||||||
|
|
|
@ -2506,8 +2506,8 @@ class CGAbstractMethod(CGThing):
|
||||||
|
|
||||||
def CreateBindingJSObject(descriptor, parent=None):
|
def CreateBindingJSObject(descriptor, parent=None):
|
||||||
if descriptor.proxy:
|
if descriptor.proxy:
|
||||||
handler = """ //let reflector = aObject.mut_reflector();
|
assert not descriptor.createGlobal
|
||||||
|
handler = """
|
||||||
let page = page_from_context(aCx);
|
let page = page_from_context(aCx);
|
||||||
let handler = (*page).js_info.get_ref().dom_static.proxy_handlers.get(&(PrototypeList::id::%s as uint));
|
let handler = (*page).js_info.get_ref().dom_static.proxy_handlers.get(&(PrototypeList::id::%s as uint));
|
||||||
""" % descriptor.name
|
""" % descriptor.name
|
||||||
|
@ -2546,33 +2546,29 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
|
||||||
return """return aObject->GetJSObject();"""
|
return """return aObject->GetJSObject();"""
|
||||||
|
|
||||||
if not self.descriptor.createGlobal:
|
if not self.descriptor.createGlobal:
|
||||||
return """let mut parent = aObject.GetParentObject(aCx);
|
return """
|
||||||
let parent = WrapNativeParent(aCx, aScope, parent);
|
assert!(aScope.is_not_null());
|
||||||
if parent.is_null() {
|
assert!(((*JS_GetClass(aScope)).flags & JSCLASS_IS_GLOBAL) != 0);
|
||||||
return ptr::null();
|
|
||||||
}
|
|
||||||
|
|
||||||
//JSAutoCompartment ac(aCx, parent);
|
//JSAutoCompartment ac(aCx, aScope);
|
||||||
let global = JS_GetGlobalForObject(aCx, parent);
|
let proto = GetProtoObject(aCx, aScope, aScope);
|
||||||
let proto = GetProtoObject(aCx, global, global);
|
|
||||||
if proto.is_null() {
|
if proto.is_null() {
|
||||||
return ptr::null();
|
return ptr::null();
|
||||||
}
|
}
|
||||||
|
|
||||||
let reflector = aObject.mut_reflector();
|
|
||||||
%s
|
%s
|
||||||
|
|
||||||
//NS_ADDREF(aObject);
|
//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:
|
else:
|
||||||
return """ let reflector = aObject.mut_reflector();
|
return """
|
||||||
|
assert!(aScope.is_null());
|
||||||
%s
|
%s
|
||||||
let proto = GetProtoObject(aCx, obj, obj);
|
let proto = GetProtoObject(aCx, obj, obj);
|
||||||
JS_SetPrototype(aCx, obj, proto);
|
JS_SetPrototype(aCx, obj, proto);
|
||||||
(*reflector).set_jsobject(obj);
|
aObject.mut_reflector().set_jsobject(obj);
|
||||||
return obj;""" % CreateBindingJSObject(self.descriptor)
|
return obj;""" % CreateBindingJSObject(self.descriptor)
|
||||||
|
|
||||||
class CGWrapMethod(CGAbstractMethod):
|
class CGWrapMethod(CGAbstractMethod):
|
||||||
|
|
|
@ -18,7 +18,7 @@ use std::unstable::raw::Box;
|
||||||
use js::glue::*;
|
use js::glue::*;
|
||||||
use js::glue::{DefineFunctionWithReserved, GetObjectJSClass, RUST_OBJECT_TO_JSVAL};
|
use js::glue::{DefineFunctionWithReserved, GetObjectJSClass, RUST_OBJECT_TO_JSVAL};
|
||||||
use js::glue::{js_IsObjectProxyClass, js_IsFunctionProxyClass, IsProxyHandlerFamily};
|
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_DefineProperties, JS_WrapValue, JS_ForwardGetPropertyTo};
|
||||||
use js::jsapi::{JS_GetClass, JS_LinkConstructorAndPrototype, JS_GetStringCharsAndLength};
|
use js::jsapi::{JS_GetClass, JS_LinkConstructorAndPrototype, JS_GetStringCharsAndLength};
|
||||||
use js::jsapi::{JS_ObjectIsRegExp, JS_ObjectIsDate};
|
use js::jsapi::{JS_ObjectIsRegExp, JS_ObjectIsDate};
|
||||||
|
@ -567,6 +567,8 @@ impl Reflector {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_jsobject(&mut self, object: *JSObject) {
|
pub fn set_jsobject(&mut self, object: *JSObject) {
|
||||||
|
assert!(self.object.is_null());
|
||||||
|
assert!(object.is_not_null());
|
||||||
self.object = object;
|
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]
|
#[fixed_stack_segment]
|
||||||
pub fn GetPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid, found: *mut bool,
|
pub fn GetPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid, found: *mut bool,
|
||||||
vp: *JSVal) -> bool {
|
vp: *JSVal) -> bool {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue