[Pkg-mozext-commits] [adblock-plus] 19/464: A more powerful script, findInterfaces, has been added. Woot!

David Prévot taffit at moszumanska.debian.org
Tue Jul 22 20:43:58 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository adblock-plus.

commit 51d05502f9d2bc599715f2c61b1e584a0b37ffb4
Author: Joshua Cranmer <Pidgeot18 at gmail.com>
Date:   Tue Mar 10 15:31:43 2009 -0400

    A more powerful script, findInterfaces, has been added. Woot!
---
 tests/findInterfaces.js | 72 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)

diff --git a/tests/findInterfaces.js b/tests/findInterfaces.js
new file mode 100644
index 0000000..6e67f05
--- /dev/null
+++ b/tests/findInterfaces.js
@@ -0,0 +1,72 @@
+// This is a simple script to find all interfaces that a JS code uses, at least
+// via Components.interfaces.
+
+include("../scripts/cleanast.js");
+
+function visit(root_ast, func) {
+	function v_r(ast, func) {
+		if (ast == null)
+			return;
+		func(ast);
+		for each (let child in ast.kids)
+			v_r(child, func);
+	}
+
+	function sanitize(ast) {
+		if (ast == null)
+			return null;
+		if (ast.op == JSOP_NAME && ast.atom in aliases) {
+			ast = sanitize(aliases[ast.atom]);
+			ast.expanded = true;
+		}
+		let sanitized_ast = { kids: [] };
+		for (let key in ast) {
+			if (key == 'kids') {
+				for each (let kid in ast.kids) {
+					sanitized_ast.kids.push(sanitize(kid));
+				}
+			} else {
+				sanitized_ast[key] = ast[key];
+			}
+		}
+		return sanitized_ast;
+	}
+	
+	v_r(sanitize(root_ast), func);
+}
+
+function process_js(ast) {
+	let global = clean_ast(ast);
+	for each (let c in global.constants) {
+		mark_globals(c);
+	}
+	//_print(uneval(aliases));
+	for each (let v in global.variables) {
+		visit(v.init, find_interfaces);
+	}
+	for each (let statement in global.code)
+		visit(statement, find_interfaces);
+	//_print(uneval(global));
+}
+
+let aliases = {};
+
+function mark_globals(constant) {
+	aliases[constant.name] = constant.init;
+}
+
+function find_interfaces(ast) {
+	if (ast.op == JSOP_GETPROP && ast.kids[0]) {
+		let check = ast.kids[0];
+		if (check.atom == "interfaces" && check.kids[0] &&
+				check.kids[0].atom == "Components") {
+			_print("Interface " + ast.atom + " used at " + loc2str(ast));
+		} else if (ast.atom && ast.atom == "nsIMimeStreamConverter") {
+			_print(uneval(ast));
+		}
+	}
+}
+
+function loc2str(ast) {
+	return ast.line + ":" + ast.column;
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git



More information about the Pkg-mozext-commits mailing list