Fix for bug 818219 (Replace HTMLElement quickstubs with new binding methods) - Remove hardcoded interface list in workers. r=bz.
authorPeter Van der Beken <peterv@propagandism.org>
Thu, 06 Dec 2012 11:41:14 +0100
changeset 120774 92187bc8ec482fc7b86992d45946f77a8eb6de25
parent 120773 a0e79206a110f38c5c6e29bf21c00b4d9f85bd5f
child 120775 f23cff8ec6c9ab4cac0c4582967647140855a625
push idunknown
push userunknown
push dateunknown
reviewersbz
bugs818219
milestone20.0a1
Fix for bug 818219 (Replace HTMLElement quickstubs with new binding methods) - Remove hardcoded interface list in workers. r=bz.
dom/bindings/Codegen.py
dom/workers/Worker.cpp
dom/workers/WorkerScope.cpp
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -7652,18 +7652,31 @@ class GlobalGenRoots():
     @staticmethod
     def PrototypeList(config):
 
         # Prototype ID enum.
         protos = [d.name for d in config.getDescriptors(hasInterfacePrototypeObject=True)]
         idEnum = CGNamespacedEnum('id', 'ID', ['_ID_Start'] + protos,
                                   [0, '_ID_Start'])
         idEnum = CGList([idEnum])
-        idEnum.append(CGGeneric(declare="const unsigned MaxProtoChainLength = " +
-                                str(config.maxProtoChainLength) + ";\n\n"))
+
+        # This is only used by DOM worker code, once there are no more consumers
+        # of INTERFACE_CHAIN_* this code should be removed.
+        def ifaceChainMacro(ifaceCount):
+            supplied = [CGGeneric(declare="_iface_" + str(i + 1)) for i in range(ifaceCount)]
+            remaining = [CGGeneric(declare="prototypes::id::_ID_Count")] * (config.maxProtoChainLength - ifaceCount)
+            macro = CGWrapper(CGList(supplied, ", "),
+                              pre="#define INTERFACE_CHAIN_" + str(ifaceCount) + "(",
+                              post=") \\\n")
+            macroContent = CGIndenter(CGList(supplied + remaining, ", \\\n"))
+            macroContent = CGIndenter(CGWrapper(macroContent, pre="{ \\\n",
+                                                post=" \\\n}"))
+            return CGWrapper(CGList([macro, macroContent]), post="\n\n")
+
+        idEnum.append(ifaceChainMacro(1))
 
         # Wrap all of that in our namespaces.
         idEnum = CGNamespace.build(['mozilla', 'dom', 'prototypes'],
                                    CGWrapper(idEnum, pre='\n'))
         idEnum = CGWrapper(idEnum, post='\n')
 
         curr = CGList([idEnum])
 
--- a/dom/workers/Worker.cpp
+++ b/dom/workers/Worker.cpp
@@ -272,31 +272,27 @@ private:
                              &message, &transferable)) {
       return false;
     }
 
     return worker->PostMessage(aCx, message, transferable);
   }
 };
 
-MOZ_STATIC_ASSERT(prototypes::MaxProtoChainLength == 3,
-                  "The MaxProtoChainLength must match our manual DOMJSClasses");
-
 DOMJSClass Worker::sClass = {
   {
     "Worker",
     JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(2) |
     JSCLASS_IMPLEMENTS_BARRIERS,
     JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
     JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, Finalize,
     NULL, NULL, NULL, NULL, Trace
   },
   {
-    { prototypes::id::EventTarget_workers, prototypes::id::_ID_Count,
-      prototypes::id::_ID_Count },
+    INTERFACE_CHAIN_1(prototypes::id::EventTarget_workers),
     false,
     &sWorkerNativePropertyHooks
   }
 };
 
 JSPropertySpec Worker::sProperties[] = {
   { sEventStrings[STRING_onerror], STRING_onerror, PROPERTY_FLAGS,
     JSOP_WRAPPER(GetEventListener), JSOP_WRAPPER(SetEventListener) },
@@ -396,30 +392,26 @@ private:
     WorkerPrivate* worker =
       UnwrapDOMObject<WorkerPrivate>(aObj, eRegularDOMObject);
     if (worker) {
       worker->_trace(aTrc);
     }
   }
 };
 
-MOZ_STATIC_ASSERT(prototypes::MaxProtoChainLength == 3,
-                  "The MaxProtoChainLength must match our manual DOMJSClasses");
-
 DOMJSClass ChromeWorker::sClass = {
   { "ChromeWorker",
     JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(2) |
     JSCLASS_IMPLEMENTS_BARRIERS,
     JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
     JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, Finalize,
     NULL, NULL, NULL, NULL, Trace,
   },
   {
-    { prototypes::id::EventTarget_workers, prototypes::id::_ID_Count,
-      prototypes::id::_ID_Count },
+    INTERFACE_CHAIN_1(prototypes::id::EventTarget_workers),
     false,
     &sWorkerNativePropertyHooks
   }
 };
 
 WorkerPrivate*
 Worker::GetInstancePrivate(JSContext* aCx, JSObject* aObj,
                            const char* aFunctionName)
--- a/dom/workers/WorkerScope.cpp
+++ b/dom/workers/WorkerScope.cpp
@@ -845,33 +845,29 @@ private:
                              &message, &transferable)) {
       return false;
     }
 
     return scope->mWorker->PostMessageToParent(aCx, message, transferable);
   }
 };
 
-MOZ_STATIC_ASSERT(prototypes::MaxProtoChainLength == 3,
-                  "The MaxProtoChainLength must match our manual DOMJSClasses");
-
 DOMJSClass DedicatedWorkerGlobalScope::sClass = {
   {
     // We don't have to worry about Xray expando slots here because we'll never
     // have an Xray wrapper to a worker global scope.
     "DedicatedWorkerGlobalScope",
     JSCLASS_DOM_GLOBAL | JSCLASS_IS_DOMJSCLASS | JSCLASS_IMPLEMENTS_BARRIERS |
     JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(3) | JSCLASS_NEW_RESOLVE,
     JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
     JS_EnumerateStub, reinterpret_cast<JSResolveOp>(Resolve), JS_ConvertStub,
     Finalize, NULL, NULL, NULL, NULL, Trace
   },
   {
-    { prototypes::id::EventTarget_workers, prototypes::id::_ID_Count,
-      prototypes::id::_ID_Count },
+    INTERFACE_CHAIN_1(prototypes::id::EventTarget_workers),
     false,
     &sWorkerNativePropertyHooks
   }
 };
 
 JSPropertySpec DedicatedWorkerGlobalScope::sProperties[] = {
   { sEventStrings[STRING_onmessage], STRING_onmessage, PROPERTY_FLAGS,
     JSOP_WRAPPER(GetEventListener), JSOP_WRAPPER(SetEventListener) },