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
--- 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.