Bug 1493675 - Generate an array of the javascript keywords; r=arai.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Fri, 19 Oct 2018 14:58:42 +0000
changeset 500677 887b52d6d707a0f3030c5a4ec10fc6ab3724c2be
parent 500676 418fa1fa4f746f82b0a1a070ef9dfb12849b5281
child 500678 cc4cf78044586c9eb1932686d453835824c67e46
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1493675
milestone64.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 1493675 - Generate an array of the javascript keywords; r=arai. This list is generated from /js/src/frontend/ReservedWords.h, which is already used on the platform to generate list of js reserved words. This list will be used in the console autocomplete code to expose those keywords to the user. Differential Revision: https://phabricator.services.mozilla.com/D8998
devtools/shared/webconsole/GenerateReservedWordsJS.py
devtools/shared/webconsole/moz.build
new file mode 100644
--- /dev/null
+++ b/devtools/shared/webconsole/GenerateReservedWordsJS.py
@@ -0,0 +1,42 @@
+# 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/.
+
+from __future__ import absolute_import
+import re
+import sys
+
+def read_reserved_word_list(filename):
+    macro_pat = re.compile(r"^\s*macro\(([^,]+), *[^,]+, *[^\)]+\)\s*\\?$")
+
+    reserved_word_list = []
+    with open(filename, 'r') as f:
+        for line in f:
+            m = macro_pat.search(line)
+            if m:
+                reserved_word_list.append(m.group(1))
+
+    assert(len(reserved_word_list) != 0)
+
+    return reserved_word_list
+
+
+def line(opt, s):
+    opt['output'].write('{}\n'.format(s))
+
+
+def main(output, reserved_words_h):
+    reserved_word_list = read_reserved_word_list(reserved_words_h)
+    opt = {
+        'output': output
+    }
+
+    line(opt, 'const JS_RESERVED_WORDS = [');
+    for word in reserved_word_list:
+        line(opt, '  "{}",'.format(word))
+    line(opt, '];');
+    line(opt, 'module.exports = JS_RESERVED_WORDS;');
+
+
+if __name__ == '__main__':
+    main(sys.stdout, *sys.argv[1:])
--- a/devtools/shared/webconsole/moz.build
+++ b/devtools/shared/webconsole/moz.build
@@ -3,14 +3,29 @@
 # 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/.
 
 if CONFIG['OS_TARGET'] != 'Android':
     MOCHITEST_CHROME_MANIFESTS += ['test/chrome.ini']
     XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
 
+# Compute where to put transpiled files into omni.ja package
+# All DevTools modules are used via resource://devtools/ URI
+# See devtools/shared/jar.mn for how this resource is mapped into jar package.
+base = FINAL_TARGET_FILES.chrome.devtools.modules
+
+# Now, navigate to the right sub-directory into devtools root modules folder
+for dir in RELATIVEDIR.split('/'):
+    base = base[dir]
+base += ["!reserved-js-words.js"]
+
+GENERATED_FILES += ['reserved-js-words.js']
+ReservedWordsGenerated = GENERATED_FILES['reserved-js-words.js']
+ReservedWordsGenerated.script = 'GenerateReservedWordsJS.py'
+ReservedWordsGenerated.inputs = ['/js/src/frontend/ReservedWords.h']
+
 DevToolsModules(
     'client.js',
     'js-property-provider.js',
     'network-helper.js',
     'throttle.js',
-)
+)
\ No newline at end of file