summaryrefslogtreecommitdiffstats
path: root/tools/ts/build_nsresult.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
commitfbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch)
tree4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /tools/ts/build_nsresult.js
parentReleasing progress-linux version 124.0.1-1~progress7.99u1. (diff)
downloadfirefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz
firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/ts/build_nsresult.js')
-rw-r--r--tools/ts/build_nsresult.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/ts/build_nsresult.js b/tools/ts/build_nsresult.js
new file mode 100644
index 0000000000..6926d87bf2
--- /dev/null
+++ b/tools/ts/build_nsresult.js
@@ -0,0 +1,56 @@
+/* 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/. */
+"use strict";
+
+/**
+ * Build: <objdir>/dist/@types/lib.gecko.nsresult.d.ts,
+ *
+ * from: <srcdir>/js/xpconnect/src/xpc.msg and
+ * <srcdir>/tools/ts/error_list.json,
+ * generated manually for now.
+ */
+
+const fs = require("fs");
+const peggy = require("peggy");
+
+const HEADER = `/**
+ * NOTE: Do not modify this file by hand.
+ * Content was generated from xpc.msg and error_list.json.
+ */
+`;
+
+const XPC_MSG_GRAMMAR = `
+ File = Header @( Comment / Definition / NL )*
+ Header = '/*' (!'*/' .)* '*/' NL
+ Comment = '/*' @$(!'*/' !NL .)* '*/' NL
+ Definition = 'XPC_MSG_DEF(' @$[A-Z0-9_]+ [ ]* ', "' @$[^"]+ '")' NL
+ NL = @$[ ]* '\\n'
+`;
+
+function main(lib_dts, xpc_msg, errors_json) {
+ let parser = peggy.generate(XPC_MSG_GRAMMAR);
+
+ let messages = parser.parse(fs.readFileSync(xpc_msg, "utf8"));
+ let errors = JSON.parse(fs.readFileSync(errors_json, "utf8"));
+
+ let lines = messages.map(line => {
+ if (!Array.isArray(line)) {
+ return line ? ` // ${line.trim()}` : "";
+ }
+ let [name, msg] = line;
+ return `\n /** ${msg} */\n ${name}: 0x${errors[name].toString(16)};`;
+ });
+
+ let dts = [
+ HEADER,
+ "interface nsIXPCComponents_Results {",
+ lines.join("\n").replaceAll("\n\n\n", "\n\n"),
+ "}\n",
+ ].join("\n");
+
+ console.log(`[INFO] ${lib_dts} (${dts.length.toLocaleString()} bytes)`);
+ fs.writeFileSync(lib_dts, dts);
+}
+
+main(...process.argv.slice(2));