[Pkg-mozext-commits] [adblock-plus] 31/464: __proto__ usage busted clean_ast. Now fixed.

David Prévot taffit at moszumanska.debian.org
Tue Jul 22 20:43:59 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 5d5d7e47392a29e5cc0e435b686bbe12d359039f
Author: Joshua Cranmer <Pidgeot18 at gmail.com>
Date:   Mon May 11 15:19:23 2009 -0400

    __proto__ usage busted clean_ast. Now fixed.
---
 utils/cleanast.js | 138 ++++++++++++++++++++++++++++--------------------------
 1 file changed, 72 insertions(+), 66 deletions(-)

diff --git a/utils/cleanast.js b/utils/cleanast.js
index 97740ca..7c316b9 100644
--- a/utils/cleanast.js
+++ b/utils/cleanast.js
@@ -14,36 +14,36 @@
  * Takes the node rooted at the AST and decomposes it into readable sections.
  */
 function clean_ast(ast) {
-	// TOK_LC
-	assert(ast.type == 25);
-	let info = {
-		variables: [],
-		constants: [],
+  // TOK_LC
+  assert(ast.type == 25);
+  let info = {
+    variables: [],
+    constants: [],
     objects: [],
     classes: [],
-		functions: [],
-		code: []
-	};
+    functions: [],
+    code: []
+  };
 
-	for each (let statement in ast.kids) {
+  for each (let statement in ast.kids) {
     if (statement.op == JSOP_DEFVAR) {
       let ret = make_variables(statement);
-			info.variables = info.variables.concat(ret.vars);
+      info.variables = info.variables.concat(ret.vars);
       info.objects = info.objects.concat(ret.objs);
-		} else if (statement.op == JSOP_DEFCONST) {
+    } else if (statement.op == JSOP_DEFCONST) {
       let ret = make_variables(statement);
-			info.constants = info.constants.concat(ret.vars);
+      info.constants = info.constants.concat(ret.vars);
       info.objects = info.objects.concat(ret.objs);
-		} else if (statement.type == 34) { // TOK_FUNCTION
-			info.functions.push(make_function(statement));
+    } else if (statement.type == 34) { // TOK_FUNCTION
+      info.functions.push(make_function(statement));
     } else if (prototype_assign(statement)) {
       let obj = make_class(statement);
       merge_class(info, obj);
-		} else {
-			info.code.push(statement);
-		}
-	}
-	return info;
+    } else {
+      info.code.push(statement);
+    }
+  }
+  return info;
 }
 
 /**
@@ -51,36 +51,36 @@ function clean_ast(ast) {
  * 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 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;
-	}
+  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);
+    v_r(sanitize(root_ast), func);
   else
     v_r(root_ast, func);
 }
@@ -154,20 +154,20 @@ function merge_class(info_list, obj) {
   }
 }
 function make_variables(var_root) {
-	assert(var_root.op == JSOP_DEFVAR || var_root.op == JSOP_DEFCONST);
-	let variables = [];
+  assert(var_root.op == JSOP_DEFVAR || var_root.op == JSOP_DEFCONST);
+  let variables = [];
   let objects = [];
-	for each (let name in var_root.kids) {
-		let v = { name: name.atom };
-		v.init = (name.kids.length > 0 ? name.kids[0] : null);
-		v.loc = get_location(var_root);
+  for each (let name in var_root.kids) {
+    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 && v.init.kids[0] &&
         v.init.kids[0].type == 6)
       objects.push(make_object(v));
     else
-  		variables.push(v);
-	}
-	return { vars: variables, objs: objects };
+      variables.push(v);
+  }
+  return { vars: variables, objs: objects };
 }
 
 function make_object(stub) {
@@ -191,6 +191,12 @@ function make_object(stub) {
         stub.setters[name] = make_function(value);
       else if (value.type == 34) // TOK_FUNCTION
         stub.functions[name] = make_function(value);
+      else if (name == '__proto__' && value.type == 49) { // TOK_NEW
+        if ('inherits' in stub)
+      stub.inherits.push(value.kids[0].atom);
+    else
+      stub.inherits = [value.kids[0].atom];
+    }
       else
         stub.variables[name] = { loc: get_location(value), init: value };
     } else {
@@ -201,22 +207,22 @@ function make_object(stub) {
 }
 
 function make_function(func_root) {
-	assert(func_root.type == 34); // TOK_FUNCTION
-	let stmts = func_root.kids[0];
-	if (stmts.type == 85) // TOK_UPVARS
-		stmts = stmts.kids[0];
-	if (stmts.type == 84) // TOK_ARGSBODY
-		stmts = stmts.kids[stmts.kids.length - 1];
-	assert(stmts.type == 25);
-	return { name: func_root.name, body: stmts, loc: get_location(func_root)};
+  assert(func_root.type == 34); // TOK_FUNCTION
+  let stmts = func_root.kids[0];
+  if (stmts.type == 85) // TOK_UPVARS
+    stmts = stmts.kids[0];
+  if (stmts.type == 84) // TOK_ARGSBODY
+    stmts = stmts.kids[stmts.kids.length - 1];
+  assert(stmts.type == 25);
+  return { name: func_root.name, body: stmts, loc: get_location(func_root)};
 }
 
 function assert(cmd) {
-	if (!cmd) {
+  if (!cmd) {
     throw new Error("Assertion failed");
-	}
+  }
 }
 
 function get_location(ast_node) {
-	return { line: ast_node.line, column: ast_node.column };
+  return { line: ast_node.line, column: ast_node.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