Make a prototypeChain on nsDOMClassImplementation.
authorBobby Holley <bobbyholley@gmail.com>
Fri, 27 Jan 2012 14:25:08 +0100
changeset 85162 bf7b25de94ba513b6bb72cb2c0640bddc5604b27
parent 85161 b7092a3eba49cecfa99a6d161ef2de063bfc2ac7
child 85163 ceccb07186bc5dafb9205f7e601dbb22b53feb27
push id62
push userbobbyholley@gmail.com
push dateFri, 27 Jan 2012 13:26:53 +0000
milestone12.0a1
Make a prototypeChain on nsDOMClassImplementation.
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -18,29 +18,28 @@ class CodegenThing():
         return "" # Override me!
 
 class DOMJSClass(CodegenThing):
     def __init__(self, implementation):
         CodegenThing.__init__(self, implementation)
     def declare(self):
         return "extern DOMJSClass Class;\n\n"
     def define(self):
-        suffix = "_workers" if self.implementation.workers else ""
-        interfaceChainString = ', '.join(['id::' + iface + suffix \
-                                          for iface in self.implementation.domClass.interfaceChain])
+        prototypeChainString = ', '.join(['id::' + proto \
+                                          for proto in self.implementation.prototypeChain])
         return """DOMJSClass Class = {
   { "%s",
     JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1),
     JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
     JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
   },
     {%s}, -1, %s
 };
-""" % (self.implementation.domClass.name, interfaceChainString,
+""" % (self.implementation.domClass.name, prototypeChainString,
        str(self.implementation.nativeIsISupports).lower())
 
 
 
 
 class Argument():
     def __init__(self, argType, name):
         self.argType = argType
@@ -73,21 +72,21 @@ class AbstractMethod(CodegenThing):
     def definition_body(self):
         return "" # Override me!
 
 class CreateProtoObjectMethod(AbstractMethod):
     def __init__(self, implementation):
         args = [Argument('JSContext*', 'aCx'), Argument('JSObject*', 'aGlobal')]
         AbstractMethod.__init__(self, implementation, 'CreateProtoObject', 'JSObject*', args)
     def definition_body(self):
-        interfaceChain = self.implementation.domClass.interfaceChain
-        if len(interfaceChain) == 1:
+        protoChain = self.implementation.prototypeChain
+        if len(protoChain) == 1:
             getParentProto = "GetCanonicalObjectProto(aCx, aGlobal)"
         else:
-            parentProtoName = self.implementation.domClass.interfaceChain[-2]
+            parentProtoName = self.implementation.prototypeChain[-2]
             getParentProto = "%s::GetProtoObject(aCx, aGlobal)" % (parentProtoName)
         return """
   JSObject* parentProto = %s;
   if (!parentProto) {
     return NULL;
   }
 
   JSObject* ourProto = JS_NewObject(aCx, NULL, parentProto, aGlobal);
@@ -115,47 +114,46 @@ class GetProtoObjectMethod(AbstractMetho
   JSObject **protoArray =
     static_cast<JSObject**>(js::GetReservedSlot(aGlobal, DOM_PROTOTYPE_SLOT).toPrivate());
   JSObject *ourProto = protoArray[id::%s];
   if (!ourProto) {
     ourProto = protoArray[id::%s] = CreateProtoObject(aCx, aGlobal);
   }
 
   /* ourProto might _still_ be null, but that's OK */
-  return ourProto;""" % (self.implementation.domClass.name, self.implementation.domClass.name)
+  return ourProto;""" % (self.implementation.name, self.implementation.name)
 
 
 class DOMClassImplementation():
     def __init__(self, domClass, implConf):
         self.domClass = domClass
         self.nativeClass = implConf['nativeClass']
         self.workers = implConf.get('workers', False)
-        if self.workers:
-            self.name = domClass.name + '_workers'
-        else:
-            self.name = domClass.name
+        def make_name(name):
+            return name + "_workers" if self.workers else name
+        self.name = make_name(domClass.name)
         self.nativeIsISupports = not self.workers
 
+        # Build the prototype chain.
+        self.prototypeChain = []
+        parent = domClass.interface
+        while parent:
+            self.prototypeChain.insert(0, make_name(parent.identifier.name))
+            parent = parent.parent
+
         # XXXbholley - Not everything should actually have a jsclass.
         self.codegenThings = [DOMJSClass(self), CreateProtoObjectMethod(self),
                               GetProtoObjectMethod(self)]
 
 class DOMClass():
     def __init__(self, classConf, interface):
         self.name = classConf['name']
+        self.interface = interface
         self.implementations = [DOMClassImplementation(self, implConf) for implConf in classConf['implementations']]
 
-        # Build the interface chain.
-        self.interfaceChain = [self.name]
-        parent = interface.parent
-        while parent:
-            self.interfaceChain.insert(0, parent.identifier.name)
-            parent = parent.parent
-        self.interface = interface
-
 class Configuration:
     def __init__(self, filename, parseData):
         self.configFile = {}
         execfile(filename, self.configFile)
 
         # We need dom_classes.
         if 'dom_classes' not in self.configFile:
             raise UserError(filename + ": `dom_classes` was not defined.")