From 75f85b799bc22e81863b2dfab9d77610f8c3ed01 Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Mon, 17 Sep 2012 11:44:59 +0200 Subject: [PATCH] Fix for bug 791345 (Support non-wrappercached objects in proxy-based bindings). r=bz. --HG-- extra : rebase_source : 884073cf7dccc2e9d1fa1769b00d5ee581d22573 --- dom/bindings/Codegen.py | 48 ++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 0ced5b3d8a3..2aa55d2f504 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -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',