Bug 1446200 - Add a helper method to encode Method flags. r=glandium draft
authorAndrew McCreight <continuation@gmail.com>
Thu, 15 Mar 2018 15:46:08 -0700
changeset 768297 ba4d5138d9cba435da78bdc03dd1bcea817fd9f9
parent 767347 80b4777a6421d8df4bb27ac23fb607c318a3006c
child 768306 3fff8a054091688ebec65d42e918cdd9d526e302
push id102838
push userbmo:continuation@gmail.com
push dateThu, 15 Mar 2018 23:03:03 +0000
reviewersglandium
bugs1446200
milestone61.0a1
Bug 1446200 - Add a helper method to encode Method flags. r=glandium Most of the classes in xpt.py define a helper method to encode the values of the flags into a byte, but for some reason Method does not. It'll be useful to have one for Method for the C++ backend I am working on. MozReview-Commit-ID: ESi1CnstbN2
xpcom/typelib/xpt/tools/xpt.py
--- a/xpcom/typelib/xpt/tools/xpt.py
+++ b/xpcom/typelib/xpt/tools/xpt.py
@@ -1112,16 +1112,33 @@ class Interface(object):
         to |file|, which is assumed to be seeked to the correct offset.
 
         """
         file.write(Interface._direntry.pack(Typelib.string_to_iid(self.iid),
                                             self._name_offset,
                                             self._namespace_offset,
                                             self._descriptor_offset))
 
+    def encodeflags(self):
+        """
+        Encode the flags of this Interface object, return a byte
+        suitable for writing to a typelib file.
+
+        """
+        flags = 0
+        if self.scriptable:
+            flags |= 0x80
+        if self.function:
+            flags |= 0x40
+        if self.builtinclass:
+            flags |= 0x20
+        if self.main_process_scriptable_only:
+            flags |= 0x10
+        return flags
+
     def write(self, typelib, file, data_pool_offset):
         """
         Write an InterfaceDescriptor to |file|, which is assumed
         to be seeked to the proper position. If this interface
         is not resolved, do not write any data.
 
         """
         if not self.resolved:
@@ -1132,26 +1149,17 @@ class Interface(object):
         if self.parent:
             parent_idx = typelib.interfaces.index(self.parent) + 1
         file.write(Interface._descriptorstart.pack(parent_idx, len(self.methods)))
         for m in self.methods:
             m.write(typelib, file)
         file.write(struct.pack(">H", len(self.constants)))
         for c in self.constants:
             c.write(typelib, file)
-        flags = 0
-        if self.scriptable:
-            flags |= 0x80
-        if self.function:
-            flags |= 0x40
-        if self.builtinclass:
-            flags |= 0x20
-        if self.main_process_scriptable_only:
-            flags |= 0x10
-        file.write(struct.pack(">B", flags))
+        file.write(struct.pack(">B", self.encodeflags()))
 
     def write_names(self, string_writer):
         """
         Write this interface's name and namespace to |string_writer|'s
         file, as well as the names of all of its methods and constants.
         Assumes that this file is currently seeked to an unused portion
         of the data pool.