Skip to content

Commit

Permalink
Bug 1446200 - Add a helper method to encode Method flags. r=froydnj
Browse files Browse the repository at this point in the history
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
  • Loading branch information
amccreight committed Mar 15, 2018
1 parent 69c711b commit 843721a
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions xpcom/typelib/xpt/tools/xpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,23 @@ def write_directory_entry(self, file):
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
Expand All @@ -1137,16 +1154,7 @@ def write(self, typelib, file, data_pool_offset):
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):
"""
Expand Down

0 comments on commit 843721a

Please sign in to comment.