[Pkg-mozext-commits] [adblock-plus] 21/464: Make findInterfaces working again.

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 46aa3a1070ddb4622849af66a22e962801d6c871
Author: Joshua Cranmer <Pidgeot18 at gmail.com>
Date:   Mon Apr 20 23:34:52 2009 -0400

    Make findInterfaces working again.
    
    So this stops the nodes from recursing the cached definitions of TOK_NAME nodes, thanks to pn_used. It also works on multiple files. YAY!
---
 jshydra.cpp             | 10 +++++++---
 scripts/dumpast.js      | 38 ++++++++++++++++++++++++++++++++++++++
 tests/findInterfaces.js | 10 +++++++---
 3 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/jshydra.cpp b/jshydra.cpp
index fd677e3..6b75757 100644
--- a/jshydra.cpp
+++ b/jshydra.cpp
@@ -183,8 +183,10 @@ JSObject *makeNode(JSParseNode *node) {
 	}
 	case NAME: {
 		JS_DefineProperty(cx, object, "atom", ATOM_KEY(node->pn_atom), NULL, NULL, JSPROP_READONLY | JSPROP_ENUMERATE);
+		setIntProperty(object, "flags", node->pn_dflags);
 		JSObject *array = JS_NewArrayObject(cx, 0, NULL);
-		setArrayElement(array, 0, makeNode(node->pn_expr));
+		if (!node->pn_used)
+			setArrayElement(array, 0, makeNode(node->pn_expr));
 		setObjectProperty(object, "kids", array);
 		break;
 	}
@@ -234,9 +236,11 @@ void parseFile(FILE *file, char *filename) {
 		fprintf(stderr, "No function process_js!\n");
 		return;
 	}
-	jsval rval, argv[1];
+	jsval rval, argv[2];
 	argv[0] = OBJECT_TO_JSVAL(ast);
-	JS_CallFunctionValue(cx, globalObj, func, 1, argv, &rval);
+	JSString *newfname = JS_NewStringCopyZ(cx, filename);
+	argv[1] = STRING_TO_JSVAL(newfname);
+	JS_CallFunctionValue(cx, globalObj, func, 2, argv, &rval);
 }
 
 int main(int argc, char **argv) {
diff --git a/scripts/dumpast.js b/scripts/dumpast.js
new file mode 100644
index 0000000..d87c89a
--- /dev/null
+++ b/scripts/dumpast.js
@@ -0,0 +1,38 @@
+/**
+ * Dumps the tree of the ast rooted at the given point.
+ */
+function dump_ast(ast, prefix) {
+	if (ast == null)
+		return;
+	if (!prefix)
+		prefix = "";
+	let str = prefix + "+ ";
+	for (let key in ast) {
+		if (key == 'column' || key == 'line' || key == 'kids')
+			continue;
+		let val = (key == 'op' ? decode_op(ast[key]) : ast[key]);
+		str += key + ": " + val + "; ";
+	}
+	str += ast.line + ":" + ast.column;
+	_print(str);
+	prefix += " ";
+	for each (let kid in ast.kids) {
+		dump_ast(kid, prefix);
+	}
+}
+
+var global = this;
+var table = null;
+function decode_op(opcode) {
+	if (!table) {
+		table = [];
+		for (let key in global) {
+			if (key.indexOf("JSOP_") == 0) {
+				table[global[key]] = key;
+			}
+		}
+	}
+	if (opcode in table)
+		return table[opcode];
+	return opcode;
+}
diff --git a/tests/findInterfaces.js b/tests/findInterfaces.js
index 6e67f05..9208aae 100644
--- a/tests/findInterfaces.js
+++ b/tests/findInterfaces.js
@@ -2,6 +2,7 @@
 // via Components.interfaces.
 
 include("../scripts/cleanast.js");
+include("../scripts/dumpast.js");
 
 function visit(root_ast, func) {
 	function v_r(ast, func) {
@@ -31,11 +32,14 @@ function visit(root_ast, func) {
 		}
 		return sanitized_ast;
 	}
-	
+
 	v_r(sanitize(root_ast), func);
 }
 
-function process_js(ast) {
+let filename;
+
+function process_js(ast, f) {
+	filename = f;
 	let global = clean_ast(ast);
 	for each (let c in global.constants) {
 		mark_globals(c);
@@ -68,5 +72,5 @@ function find_interfaces(ast) {
 }
 
 function loc2str(ast) {
-	return ast.line + ":" + ast.column;
+	return filename + ":" + 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