Bug 1533617 part 3. Add a [can_run_script] xpidl annotation. r=nika
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 11 Mar 2019 15:16:57 +0000
changeset 521386 341a6a2e5237
parent 521385 dc5ced18861d
child 521387 005ab4b76f8c
push id10866
push usernerli@mozilla.com
push dateTue, 12 Mar 2019 18:59:09 +0000
treeherdermozilla-beta@445c24a51727 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika
bugs1533617
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1533617 part 3. Add a [can_run_script] xpidl annotation. r=nika Differential Revision: https://phabricator.services.mozilla.com/D22837
xpcom/idl-parser/xpidl/header.py
xpcom/idl-parser/xpidl/xpidl.py
--- a/xpcom/idl-parser/xpidl/header.py
+++ b/xpcom/idl-parser/xpidl/header.py
@@ -64,16 +64,22 @@ def attributeReturnType(a, getter, macro
     else:
         if ret == "nsresult":
             ret = macro
         else:
             ret = "%s_(%s)" % (macro, ret)
 
     if a.must_use:
         ret = "MOZ_MUST_USE " + ret
+    # Ideally, we'd set MOZ_CAN_RUN_SCRIPT in the "scriptable and not
+    # builtinclass" case too, so we'd just have memberCanRunScript() check
+    # can_explicitly_run_script and call it here.  But that would likely require
+    # a fair amount of Gecko-side annotation work.  See bug 1534292.
+    if a.explicit_can_run_script:
+        ret = "MOZ_CAN_RUN_SCRIPT " + ret
     return ret
 
 
 def attributeParamlist(a, getter):
     if getter and a.notxpcom:
         l = []
     else:
         l = ["%s%s" % (a.realtype.nativeType(getter and 'out' or 'in'),
@@ -110,16 +116,22 @@ def methodReturnType(m, macro):
     else:
         if ret == "nsresult":
             ret = macro
         else:
             ret = "%s_(%s)" % (macro, ret)
 
     if m.must_use:
         ret = "MOZ_MUST_USE " + ret
+    # Ideally, we'd set MOZ_CAN_RUN_SCRIPT in the "scriptable and not
+    # builtinclass" case too, so we'd just have memberCanRunScript() check
+    # can_explicitly_run_script and call it here.  But that would likely require
+    # a fair amount of Gecko-side annotation work.  See bug 1534292.
+    if m.explicit_can_run_script:
+        ret = "MOZ_CAN_RUN_SCRIPT " + ret
     return ret
 
 
 def methodAsNative(m, declType='NS_IMETHOD'):
     return "%s %s(%s)" % (methodReturnType(m, declType),
                           methodNativeName(m),
                           paramlistAsNative(m))
 
--- a/xpcom/idl-parser/xpidl/xpidl.py
+++ b/xpcom/idl-parser/xpidl/xpidl.py
@@ -1005,16 +1005,19 @@ class Attribute(object):
     notxpcom = False
     readonly = False
     symbol = False
     implicit_jscontext = False
     nostdcall = False
     must_use = False
     binaryname = None
     infallible = False
+    # explicit_can_run_script is true if the attribute is explicitly annotated
+    # as being able to cause script to run.
+    explicit_can_run_script = False
 
     def __init__(self, type, name, attlist, readonly, location, doccomments):
         self.type = type
         self.name = name
         self.attlist = attlist
         self.readonly = readonly
         self.location = location
         self.doccomments = doccomments
@@ -1040,16 +1043,18 @@ class Attribute(object):
             elif name == 'implicit_jscontext':
                 self.implicit_jscontext = True
             elif name == 'nostdcall':
                 self.nostdcall = True
             elif name == 'must_use':
                 self.must_use = True
             elif name == 'infallible':
                 self.infallible = True
+            elif name == 'can_run_script':
+                self.explicit_can_run_script = True
             else:
                 raise IDLError("Unexpected attribute '%s'" % name, aloc)
 
     def resolve(self, iface):
         self.iface = iface
         self.realtype = iface.idl.getName(self.type, self.location)
         if self.infallible and self.realtype.kind not in ['builtin',
                                                           'interface',
@@ -1087,16 +1092,19 @@ class Method(object):
     noscript = False
     notxpcom = False
     symbol = False
     binaryname = None
     implicit_jscontext = False
     nostdcall = False
     must_use = False
     optional_argc = False
+    # explicit_can_run_script is true if the method is explicitly annotated
+    # as being able to cause script to run.
+    explicit_can_run_script = False
 
     def __init__(self, type, name, attlist, paramlist, location, doccomments, raises):
         self.type = type
         self.name = name
         self.attlist = attlist
         self.params = paramlist
         self.location = location
         self.doccomments = doccomments
@@ -1123,16 +1131,18 @@ class Method(object):
             elif name == 'implicit_jscontext':
                 self.implicit_jscontext = True
             elif name == 'optional_argc':
                 self.optional_argc = True
             elif name == 'nostdcall':
                 self.nostdcall = True
             elif name == 'must_use':
                 self.must_use = True
+            elif name == 'can_run_script':
+                self.explicit_can_run_script = True
             else:
                 raise IDLError("Unexpected attribute '%s'" % name, aloc)
 
         self.namemap = NameMap()
         for p in paramlist:
             self.namemap.set(p)
 
     def resolve(self, iface):