Fix for bug 791345 (Support non-wrappercached objects in proxy-based bindings). r=bz.

--HG--
extra : rebase_source : 884073cf7dccc2e9d1fa1769b00d5ee581d22573
This commit is contained in:
Peter Van der Beken 2012-09-17 11:44:59 +02:00
parent 71b55b1f68
commit 75f85b799b

View File

@ -1366,6 +1366,25 @@ class CGIsMethod(CGAbstractMethod):
# js::GetObjectJSClass(obj) == &Class.mBase
return """ return IsProxy(obj);"""
def CreateBindingJSObject(descriptor, parent):
if descriptor.proxy:
create = """ JSObject *obj = NewProxyObject(aCx, DOMProxyHandler::getInstance(),
JS::PrivateValue(aObject), proto, %s);
if (!obj) {
return NULL;
}
"""
else:
create = """ JSObject* obj = JS_NewObject(aCx, &Class.mBase, proto, %s);
if (!obj) {
return NULL;
}
js::SetReservedSlot(obj, DOM_OBJECT_SLOT, PRIVATE_TO_JSVAL(aObject));
"""
return create % parent
class CGWrapWithCacheMethod(CGAbstractMethod):
def __init__(self, descriptor):
assert descriptor.interface.hasInterfacePrototypeObject()
@ -1380,23 +1399,6 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
return """ *aTriedToWrap = true;
return aObject->GetJSObject();"""
if self.descriptor.proxy:
create = """ JSObject *obj = NewProxyObject(aCx, DOMProxyHandler::getInstance(),
JS::PrivateValue(aObject), proto, parent);
if (!obj) {
return NULL;
}
"""
else:
create = """ JSObject* obj = JS_NewObject(aCx, &Class.mBase, proto, parent);
if (!obj) {
return NULL;
}
js::SetReservedSlot(obj, DOM_OBJECT_SLOT, PRIVATE_TO_JSVAL(aObject));
"""
return """ *aTriedToWrap = true;
JSObject* parent = WrapNativeParent(aCx, aScope, aObject->GetParentObject());
@ -1417,7 +1419,8 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
aCache->SetWrapper(obj);
return obj;""" % (CheckPref(self.descriptor, "global", "*aTriedToWrap", "NULL", "aCache"), create)
return obj;""" % (CheckPref(self.descriptor, "global", "*aTriedToWrap", "NULL", "aCache"),
CreateBindingJSObject(self.descriptor, "parent"))
class CGWrapMethod(CGAbstractMethod):
def __init__(self, descriptor):
@ -1446,15 +1449,10 @@ class CGWrapNonWrapperCacheMethod(CGAbstractMethod):
return NULL;
}
JSObject* obj = JS_NewObject(aCx, &Class.mBase, proto, global);
if (!obj) {
return NULL;
}
js::SetReservedSlot(obj, DOM_OBJECT_SLOT, PRIVATE_TO_JSVAL(aObject));
%s
NS_ADDREF(aObject);
return obj;"""
return obj;""" % CreateBindingJSObject(self.descriptor, "global")
builtinNames = {
IDLType.Tags.bool: 'bool',