[Pkg-mozext-commits] [adblock-plus] 23/464: More dxr work, testing on larger files. Also shunted around files.
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 7e5fc2e7fe23514c3a75e859e9109901b69e0fbf
Author: Joshua Cranmer <Pidgeot18 at gmail.com>
Date: Wed Apr 22 19:53:53 2009 -0400
More dxr work, testing on larger files. Also shunted around files.
--HG--
rename : tests/ast.js => scripts/ast.js
rename : tests/basic.js => scripts/basic.js
rename : tests/dxr.js => scripts/dxr.js
rename : tests/findInterfaces.js => scripts/findInterfaces.js
rename : scripts/cleanast.js => utils/cleanast.js
rename : scripts/dumpast.js => utils/dumpast.js
---
jshydra.cpp | 7 ++---
jshydra_bridge.cpp | 2 +-
scripts/ast.js | 7 +++++
{tests => scripts}/basic.js | 0
{tests => scripts}/dxr.js | 13 ++++++++--
{tests => scripts}/findInterfaces.js | 4 +--
tests/ast.js | 26 -------------------
{scripts => utils}/cleanast.js | 50 ++++++++++++++++++++++++++++++++++--
{scripts => utils}/dumpast.js | 0
utils/jstypes.js | 38 +++++++++++++++++++++++++++
10 files changed, 111 insertions(+), 36 deletions(-)
diff --git a/jshydra.cpp b/jshydra.cpp
index 973fda7..b17bd10 100644
--- a/jshydra.cpp
+++ b/jshydra.cpp
@@ -78,14 +78,14 @@ TokenValue tokens[] = {
BINARY, /*TOK_WITH*/
UNARY, /*TOK_RETURN*/
LIST, /*TOK_NEW*/
- ERROR, /*TOK_DELETE*/
+ UNARY, /*TOK_DELETE*/
UNARY, /*TOK_DEFSHARP*/
NULLARY, /*TOK_USESHARP (use pn_num)*/
TERNARY, /*TOK_TRY*/
TERNARY, /*TOK_CATCH*/
ERROR, /*TOK_FINALLY*/
UNARY, /*TOK_THROW*/
- ERROR, /*TOK_INSTANCEOF*/
+ BINARY, /*TOK_INSTANCEOF*/
ERROR, /*TOK_DEBUGGER*/
ERROR, /*TOK_XMLSTAGO*/
ERROR, /*TOK_XMLETAGO*/
@@ -134,7 +134,8 @@ JSObject *makeNode(JSParseNode *node) {
// Some of our nodes actually need the arity to work right.
TokenValue value = tokens[node->pn_type];
- if (node->pn_type == TOK_COLON)
+ if (node->pn_type == TOK_COLON ||
+ (node->pn_type >= TOK_OR && node->pn_type <= TOK_DIVOP))
value = arityFix[node->pn_arity];
switch (value) {
diff --git a/jshydra_bridge.cpp b/jshydra_bridge.cpp
index 03e2270..8461d03 100644
--- a/jshydra_bridge.cpp
+++ b/jshydra_bridge.cpp
@@ -48,7 +48,7 @@ void jshydra_init(const char *file) {
rt = JS_NewRuntime (0x9000000L);
cx = JS_NewContext (rt, 8192);
JS_BeginRequest(cx);
- JS_SetGCZeal(cx, 2);
+ //JS_SetGCZeal(cx, 2);
//JS_SetContextPrivate (this->cx, this);
diff --git a/scripts/ast.js b/scripts/ast.js
new file mode 100644
index 0000000..98bfc61
--- /dev/null
+++ b/scripts/ast.js
@@ -0,0 +1,7 @@
+// This just dumps out an ast for your viewing pleasure.
+
+include("../utils/dumpast.js");
+
+function process_js(ast) {
+ dump_ast(ast);
+}
diff --git a/tests/basic.js b/scripts/basic.js
similarity index 100%
rename from tests/basic.js
rename to scripts/basic.js
diff --git a/tests/dxr.js b/scripts/dxr.js
similarity index 84%
rename from tests/dxr.js
rename to scripts/dxr.js
index 8251924..86cce88 100644
--- a/tests/dxr.js
+++ b/scripts/dxr.js
@@ -1,7 +1,8 @@
// This is a simple test to test global magic
-include("../scripts/cleanast.js");
-include("../scripts/dumpast.js");
+include("../utils/cleanast.js");
+include("../utils/dumpast.js");
+include("../utils/jstypes.js");
function process_js(ast, f) {
function loc(l) {
@@ -18,7 +19,11 @@ function process_js(ast, f) {
}
_print("Global objects:");
for each (let v in toplevel.objects) {
+ divine_inheritance(v, toplevel.constants);
_print("\t" + v.name + " at " + f + ":" + v.loc.line + ":" + v.loc.column);
+ if (v.inherits) {
+ _print("\tInherits from " + v.inherits.join(", "));
+ }
_print("\tFunctions:");
for (let name in v.functions) {
_print("\t\t" + name + " at " + loc(v.functions[name].loc));
@@ -38,7 +43,11 @@ function process_js(ast, f) {
}
_print("Global classes:");
for each (let v in toplevel.classes) {
+ divine_inheritance(v, toplevel.constants);
_print("\t" + v.name + " at " + f + ":" + v.loc.line + ":" + v.loc.column);
+ if (v.inherits) {
+ _print("\tInherits from " + v.inherits.join(", "));
+ }
_print("\tFunctions:");
for (let name in v.functions) {
_print("\t\t" + name + " at " + loc(v.functions[name].loc));
diff --git a/tests/findInterfaces.js b/scripts/findInterfaces.js
similarity index 95%
rename from tests/findInterfaces.js
rename to scripts/findInterfaces.js
index 9208aae..4e5ce4c 100644
--- a/tests/findInterfaces.js
+++ b/scripts/findInterfaces.js
@@ -1,8 +1,8 @@
// This is a simple script to find all interfaces that a JS code uses, at least
// via Components.interfaces.
-include("../scripts/cleanast.js");
-include("../scripts/dumpast.js");
+include("../utils/cleanast.js");
+include("../utils/dumpast.js");
function visit(root_ast, func) {
function v_r(ast, func) {
diff --git a/tests/ast.js b/tests/ast.js
deleted file mode 100644
index 8367aef..0000000
--- a/tests/ast.js
+++ /dev/null
@@ -1,26 +0,0 @@
-// This is a simple test to test global magic
-
-include("../scripts/cleanast.js");
-include("../scripts/dumpast.js");
-
-var glob = this;
-const LS = "foobar";
-
-function process_js(ast) {
- dump_ast(ast);
- let toplevel = clean_ast(ast);
- _print("Global variables:");
- for each (let v in toplevel.variables) {
- _print("\t" + v.name + " at " + v.loc.line + ":" + v.loc.column);
- }
- _print("Global constants:");
- for each (let v in toplevel.constants) {
- _print("\t" + v.name + " at " + v.loc.line + ":" + v.loc.column);
- _print(uneval(v));
- }
- _print("Global functions:");
- for each (let v in toplevel.functions) {
- _print("\t" + v.name + " at " + v.loc.line + ":" + v.loc.column);
- _print(v.body.kids[0].column);
- }
-}
diff --git a/scripts/cleanast.js b/utils/cleanast.js
similarity index 80%
rename from scripts/cleanast.js
rename to utils/cleanast.js
index 76571ac..97740ca 100644
--- a/scripts/cleanast.js
+++ b/utils/cleanast.js
@@ -5,6 +5,8 @@
* variables (Variable[]): a list of variables declared in the block
* functions (Function[]): a list of functions declared in the block
* constants (Variable[]): a list of constants declared in the block
+ * classes (Class[]): a list of classes declared in the block
+ * objects (Class[]): a list of objects declared in the block
* code (Statement[]): a list of statements in the block
*/
@@ -22,6 +24,7 @@ function clean_ast(ast) {
functions: [],
code: []
};
+
for each (let statement in ast.kids) {
if (statement.op == JSOP_DEFVAR) {
let ret = make_variables(statement);
@@ -43,6 +46,45 @@ function clean_ast(ast) {
return info;
}
+/**
+ * Visits the AST using the given function as a parameter.
+ * The parameter will take in a single argument, the AST node.
+ */
+function visit(root_ast, func, to_expand) {
+ 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 to_expand) {
+ ast = sanitize(to_expand[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;
+ }
+
+ if (to_expand)
+ v_r(sanitize(root_ast), func);
+ else
+ v_r(root_ast, func);
+}
+
function prototype_assign(statement) {
if (statement.type != 2 || !statement.kids[0]) // TOK_SEMI
return false;
@@ -119,7 +161,8 @@ function make_variables(var_root) {
let v = { name: name.atom };
v.init = (name.kids.length > 0 ? name.kids[0] : null);
v.loc = get_location(var_root);
- if (v.init && v.init.op == JSOP_NEWINIT)
+ if (v.init && v.init.op == JSOP_NEWINIT && v.init.kids[0] &&
+ v.init.kids[0].type == 6)
objects.push(make_object(v));
else
variables.push(v);
@@ -135,6 +178,9 @@ function make_object(stub) {
let ast = stub.init;
delete stub['init'];
for each (let init in ast.kids) {
+ if (init.type != 6) {
+ dump_ast(init);
+ }
assert(init.type == 6); // TOK_COLON
if (init.kids[0].type == 29) { // TOK_NAME
let name = init.kids[0].atom;
@@ -167,7 +213,7 @@ function make_function(func_root) {
function assert(cmd) {
if (!cmd) {
- _print("ACK! I fail!");
+ throw new Error("Assertion failed");
}
}
diff --git a/scripts/dumpast.js b/utils/dumpast.js
similarity index 100%
rename from scripts/dumpast.js
rename to utils/dumpast.js
diff --git a/utils/jstypes.js b/utils/jstypes.js
new file mode 100644
index 0000000..baa4e8f
--- /dev/null
+++ b/utils/jstypes.js
@@ -0,0 +1,38 @@
+/**
+ * This file presents various methods to create a JS typing system.
+ */
+
+function divine_inheritance(clazz, constants) {
+ let aliases = {};
+ for each (let c in constants) {
+ aliases[c.name] = c.init;
+ }
+
+ // First, do we have a QueryInterface variable?
+ if ("QueryInterface" in clazz.variables) {
+ // Yes, it's a function, but the variable means that we found a XPCOMUtils
+ // utility. This'll be easy!
+ let xpcom = clazz.variables.QueryInterface.init;
+ assert(xpcom.op == JSOP_CALL && xpcom.kids[0].atom == "generateQI");
+
+ clazz.inherits = [];
+ for each (let iface in xpcom.kids[1].kids)
+ clazz.inherits.push(iface.atom);
+ return;
+ }
+
+ if ("QueryInterface" in clazz.functions) {
+ clazz.inherits = [];
+ function findInterfaces(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") {
+ clazz.inherits.push(ast.atom);
+ }
+ }
+ }
+ visit(clazz.functions.QueryInterface.body, findInterfaces, aliases);
+ return;
+ }
+}
--
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