Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"use strict";
var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
const { ProcessorBase } = ChromeUtils.import("resource://rewrites/Processor.jsm");
const { Replacer } = ChromeUtils.import("resource://rewrites/Replacer.jsm");
const { Parser, NodeWalker } = ChromeUtils.import("resource://rewrites/Parser.jsm");
var EXPORTED_SYMBOLS = ["Processor"];
const kIgnorePaths = [
"devtools/client/inspector/markup/test",
"devtools/client/debugger/new/test/mochitest/examples/sourcemaps2",
"devtools/client/jsonview/lib",
"devtools/client/shared/vendor",
"devtools/client/sourceeditor/codemirror",
"dom/tests/mochitest/ajax",
"dom/tests/mochitest/dom-level",
"dom/canvas/test/webgl-conf/checkout",
"testing/mochitest/MochiKit",
"testing/mochitest/tests/MochiKit",
"testing/web-platform/tests",
"testing/marionette/harness/marionette_harness/runner/mixins/browsermob-proxy-py/docs/_build/html/_static/jquery.js",
"testing/marionette/atom.js",
"browser/extensions/pocket/content/panels/js/vendor/jquery-2.1.1.min.js",
"servo/",
"browser/extensions/pdfjs/content/web",
"third_party",
"tools/lint/eslint",
];
const {isEmptyObject, isLiteral, isMemberExpression} = Replacer.Utils;
class Processor extends ProcessorBase {
constructor(filters) {
super([], filters.length ? filters : null);
}
shouldProcess(path, text) {
return /\bChromeUtils.generateQI\(/.test(text());
}
process(path, replacer) {
let isJSM = path.endsWith(".jsm");
let handlers = {
ChromeUtilsGenerateQI(node) {
let ifaces = node.arguments[0].elements || [];
for (let iface of ifaces) {
if (isMemberExpression(iface, "Ci")) {
replacer.replace(iface, JSON.stringify(iface.property.name));
}
}
},
};
let root = Parser.parse(replacer.code, path);
root.walk(new NodeWalker({
CallExpression(node) {
if (isMemberExpression(node.callee, "ChromeUtils", "generateQI")) {
return handlers.ChromeUtilsGenerateQI(node);
}
},
}).onNode);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.