2012-08-24 08:08:09 +04:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
# You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import string
|
2016-05-16 22:28:48 +03:00
|
|
|
import argparse
|
2018-05-04 06:44:51 +03:00
|
|
|
import runpy
|
2012-08-24 08:08:09 +04:00
|
|
|
|
2016-02-04 07:17:44 +03:00
|
|
|
# Generates a line of WebIDL with the given spelling of the property name
|
|
|
|
# (whether camelCase, _underscorePrefixed, etc.) and the given array of
|
|
|
|
# extended attributes.
|
|
|
|
def generateLine(propName, extendedAttrs):
|
|
|
|
return " [%s] attribute DOMString %s;\n" % (", ".join(extendedAttrs),
|
|
|
|
propName)
|
2018-04-17 07:40:12 +03:00
|
|
|
def generate(output, idlFilename, dataFile):
|
2018-05-04 06:44:51 +03:00
|
|
|
propList = runpy.run_path(dataFile)["data"]
|
2016-05-16 22:28:48 +03:00
|
|
|
props = ""
|
2018-05-04 06:44:51 +03:00
|
|
|
for p in propList:
|
2018-06-27 08:34:29 +03:00
|
|
|
if "Internal" in p.flags:
|
2016-05-16 22:28:48 +03:00
|
|
|
continue
|
|
|
|
# Unfortunately, even some of the getters here are fallible
|
|
|
|
# (e.g. on nsComputedDOMStyle).
|
2017-12-13 19:24:35 +03:00
|
|
|
extendedAttrs = ["CEReactions", "Throws", "TreatNullAs=EmptyString",
|
2017-12-21 01:43:18 +03:00
|
|
|
"SetterNeedsSubjectPrincipal=NonSystem"]
|
2018-05-04 06:44:51 +03:00
|
|
|
if p.pref is not "":
|
|
|
|
extendedAttrs.append('Pref="%s"' % p.pref)
|
|
|
|
|
|
|
|
prop = p.method
|
2016-02-04 07:17:45 +03:00
|
|
|
|
2018-01-23 22:47:05 +03:00
|
|
|
# webkit properties get a camelcase "webkitFoo" accessor
|
|
|
|
# as well as a capitalized "WebkitFoo" alias (added here).
|
2016-05-16 22:28:48 +03:00
|
|
|
if (prop.startswith("Webkit")):
|
2018-01-23 22:47:05 +03:00
|
|
|
extendedAttrs.append('BindingAlias="%s"' % prop)
|
2016-05-16 22:28:48 +03:00
|
|
|
|
2018-01-23 22:47:05 +03:00
|
|
|
# Generate a name with camelCase spelling of property-name (or capitalized,
|
2016-05-16 22:28:48 +03:00
|
|
|
# for Moz-prefixed properties):
|
|
|
|
if not prop.startswith("Moz"):
|
|
|
|
prop = prop[0].lower() + prop[1:]
|
2016-02-04 07:17:45 +03:00
|
|
|
|
2016-05-16 22:28:48 +03:00
|
|
|
# Per spec, what's actually supposed to happen here is that we're supposed
|
|
|
|
# to have properties for:
|
|
|
|
#
|
|
|
|
# 1) Each supported CSS property name, camelCased.
|
2016-07-21 19:22:36 +03:00
|
|
|
# 2) Each supported name that contains or starts with dashes,
|
|
|
|
# without any changes to the name.
|
2016-05-16 22:28:48 +03:00
|
|
|
# 3) cssFloat
|
|
|
|
#
|
|
|
|
# Note that "float" will cause a property called "float" to exist due to (1)
|
|
|
|
# in that list.
|
|
|
|
#
|
|
|
|
# In practice, cssFloat is the only case in which "name" doesn't contain
|
2018-01-23 22:47:05 +03:00
|
|
|
# "-" but also doesn't match "prop". So the generateLine() call will
|
|
|
|
# cover (3) and all of (1) except "float". If we now add an alias
|
2016-07-21 19:22:36 +03:00
|
|
|
# for all the cases where "name" doesn't match "prop", that will cover
|
|
|
|
# "float" and (2).
|
2018-05-04 06:44:51 +03:00
|
|
|
if prop != p.name:
|
|
|
|
extendedAttrs.append('BindingAlias="%s"' % p.name)
|
2018-01-23 22:47:05 +03:00
|
|
|
|
|
|
|
props += generateLine(prop, extendedAttrs)
|
2016-05-16 22:28:48 +03:00
|
|
|
|
2016-02-04 07:17:44 +03:00
|
|
|
|
2016-05-16 22:28:48 +03:00
|
|
|
idlFile = open(idlFilename, "r")
|
|
|
|
idlTemplate = idlFile.read()
|
|
|
|
idlFile.close()
|
2016-02-04 07:17:44 +03:00
|
|
|
|
2016-05-16 22:28:48 +03:00
|
|
|
output.write("/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT */\n\n" +
|
|
|
|
string.Template(idlTemplate).substitute({"props": props}) + '\n')
|
2012-08-24 08:08:09 +04:00
|
|
|
|
2016-05-16 22:28:48 +03:00
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('idlFilename', help='IDL property file template')
|
2016-05-16 22:43:56 +03:00
|
|
|
parser.add_argument('preprocessorHeader', help='Header file to pass through the preprocessor')
|
2016-05-16 22:28:48 +03:00
|
|
|
args = parser.parse_args()
|
2016-05-16 22:43:56 +03:00
|
|
|
generate(sys.stdout, args.idlFilename, args.preprocessorHeader)
|
2012-08-24 08:08:09 +04:00
|
|
|
|
2016-05-16 22:28:48 +03:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|