Bug 1119652, create mozilla::dom::Event::As*Event automatically for all the codegen'ed Events and annotate As*Event with MOZ_OVERRIDE in the codegen, r=bz
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Sat, 10 Jan 2015 13:46:41 +0200
changeset 223183 2ea97247b91ac2930e23e1d55b864c54950d288f
parent 223182 305c554e799427e6161709c07035737e4007e363
child 223184 ab841f36d62f699d04853b7cc613bc27845a4760
push id10769
push usercbook@mozilla.com
push dateMon, 12 Jan 2015 14:15:52 +0000
treeherderfx-team@0e9765732906 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1119652
milestone37.0a1
Bug 1119652, create mozilla::dom::Event::As*Event automatically for all the codegen'ed Events and annotate As*Event with MOZ_OVERRIDE in the codegen, r=bz
dom/bindings/Codegen.py
dom/bindings/Configuration.py
dom/bindings/mozwebidlcodegen/__init__.py
dom/events/Event.h
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -14343,16 +14343,23 @@ class GlobalGenRoots():
 
         # Add the auto-generated comment.
         curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
 
         # Done.
         return curr
 
     @staticmethod
+    def GeneratedEventList(config):
+        eventList = CGList([]);
+        for generatedEvent in config.generatedEvents:
+            eventList.append(CGGeneric(declare=("GENERATED_EVENT(%s)\n" % generatedEvent)))
+        return eventList
+
+    @staticmethod
     def PrototypeList(config):
 
         # Prototype ID enum.
         descriptorsWithPrototype = config.getDescriptors(hasInterfacePrototypeObject=True)
         protos = [d.name for d in descriptorsWithPrototype]
         idEnum = CGNamespacedEnum('id', 'ID', ['_ID_Start'] + protos,
                                   [0, '_ID_Start'])
         idEnum = CGList([idEnum])
@@ -14904,17 +14911,18 @@ class CGEventClass(CGBindingImplClass):
             parentType=self.parentType)
 
         className = descriptor.nativeType.split('::')[-1]
         asConcreteTypeMethod = ClassMethod("As%s" % className,
                                            "%s*" % className,
                                            [],
                                            virtual=True,
                                            body="return this;\n",
-                                           breakAfterReturnDecl=" ")
+                                           breakAfterReturnDecl=" ",
+                                           override=True)
 
         CGClass.__init__(self, className,
                          bases=[ClassBase(self.parentType)],
                          methods=[asConcreteTypeMethod]+self.methodDecls,
                          members=members,
                          extradeclarations=baseDeclarations)
 
     def getWrapObjectBody(self):
--- a/dom/bindings/Configuration.py
+++ b/dom/bindings/Configuration.py
@@ -8,28 +8,29 @@ from collections import defaultdict
 
 autogenerated_comment = "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n"
 
 class Configuration:
     """
     Represents global configuration state based on IDL parse data and
     the configuration file.
     """
-    def __init__(self, filename, parseData):
+    def __init__(self, filename, parseData, generatedEvents=[]):
 
         # Read the configuration file.
         glbl = {}
         execfile(filename, glbl)
         config = glbl['DOMInterfaces']
 
         # Build descriptors for all the interfaces we have in the parse data.
         # This allows callers to specify a subset of interfaces by filtering
         # |parseData|.
         self.descriptors = []
         self.interfaces = {}
+        self.generatedEvents = generatedEvents;
         self.maxProtoChainLength = 0;
         for thing in parseData:
             if isinstance(thing, IDLImplementsStatement):
                 # Our build system doesn't support dep build involving
                 # addition/removal of "implements" statements that appear in a
                 # different .webidl file than their LHS interface.  Make sure we
                 # don't have any of those.
                 #
--- a/dom/bindings/mozwebidlcodegen/__init__.py
+++ b/dom/bindings/mozwebidlcodegen/__init__.py
@@ -124,16 +124,17 @@ class WebIDLCodegenManager(LoggingMixin)
     To facilitate testing, this object is meant to be generic and reusable.
     Paths, etc should be parameters and not hardcoded.
     """
 
     # Global parser derived declaration files.
     GLOBAL_DECLARE_FILES = {
         'FeatureList.h',
         'GeneratedAtomList.h',
+        'GeneratedEventList.h',
         'PrototypeList.h',
         'RegisterBindings.h',
         'RegisterWorkerBindings.h',
         'ResolveSystemBinding.h',
         'UnionConversions.h',
         'UnionTypes.h',
     }
 
@@ -170,16 +171,17 @@ class WebIDLCodegenManager(LoggingMixin)
         self.populate_logger()
 
         input_paths, exported_stems, generated_events_stems, example_interfaces = inputs
 
         self._config_path = config_path
         self._input_paths = set(input_paths)
         self._exported_stems = set(exported_stems)
         self._generated_events_stems = set(generated_events_stems)
+        self._generated_events_stems_as_array = generated_events_stems;
         self._example_interfaces = set(example_interfaces)
         self._exported_header_dir = exported_header_dir
         self._codegen_dir = codegen_dir
         self._state_path = state_path
         self._cache_dir = cache_dir
         self._make_deps_path = make_deps_path
         self._make_deps_target = make_deps_target
 
@@ -319,17 +321,18 @@ class WebIDLCodegenManager(LoggingMixin)
 
         for path in sorted(self._input_paths):
             with open(path, 'rb') as fh:
                 data = fh.read()
                 hashes[path] = hashlib.sha1(data).hexdigest()
                 parser.parse(data, path)
 
         self._parser_results = parser.finish()
-        self._config = Configuration(self._config_path, self._parser_results)
+        self._config = Configuration(self._config_path, self._parser_results,
+                                     self._generated_events_stems_as_array)
         self._input_hashes = hashes
 
     def _write_global_derived(self):
         from Codegen import GlobalGenRoots
 
         things = [('declare', f) for f in self.GLOBAL_DECLARE_FILES]
         things.extend(('define', f) for f in self.GLOBAL_DEFINE_FILES)
 
--- a/dom/events/Event.h
+++ b/dom/events/Event.h
@@ -23,19 +23,20 @@
 class nsIContent;
 class nsIDOMEventTarget;
 class nsPresContext;
 
 namespace mozilla {
 namespace dom {
 
 class EventTarget;
-class ErrorEvent;
-class ProgressEvent;
 class WantsPopupControlCheck;
+#define GENERATED_EVENT(EventClass_) class EventClass_;
+#include "mozilla/dom/GeneratedEventList.h"
+#undef GENERATED_EVENT
 
 // Dummy class so we can cast through it to get from nsISupports to
 // Event subclasses with only two non-ambiguous static casts.
 class EventBase : public nsIDOMEvent
 {
 };
 
 class Event : public EventBase,
@@ -90,25 +91,23 @@ public:
   {
     return mOwner;
   }
 
   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE MOZ_FINAL;
 
   virtual JSObject* WrapObjectInternal(JSContext* aCx);
 
-  virtual ErrorEvent* AsErrorEvent()
-  {
-    return nullptr;
+#define GENERATED_EVENT(EventClass_) \
+  virtual EventClass_* As##EventClass_()  \
+  {                                       \
+    return nullptr;                       \
   }
-
-  virtual ProgressEvent* AsProgressEvent()
-  {
-    return nullptr;
-  }
+#include "mozilla/dom/GeneratedEventList.h"
+#undef GENERATED_EVENT
 
   // nsIDOMEvent Interface
   NS_DECL_NSIDOMEVENT
 
   void InitPresContextData(nsPresContext* aPresContext);
 
   // Returns true if the event should be trusted.
   bool Init(EventTarget* aGlobal);