Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: scripts/findInterfaces.js

Issue 29350140: Issue 4353 - Remove non standard for each syntax (Closed)
Left Patch Set: Created Aug. 24, 2016, 11:08 a.m.
Right Patch Set: Removed unused code Created Aug. 24, 2016, 2:40 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « scripts/dxr.js ('k') | scripts/outASTML.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // This is a simple script to find all interfaces that a JS code uses, at least
2 // via Components.interfaces.
3
4 include("../utils/cleanast.js");
5 include("../utils/dumpast.js");
6
7 function visit(root_ast, func) {
8 function v_r(ast, func) {
9 if (ast == null)
10 return;
11 func(ast);
12 for (let child of ast.kids)
13 v_r(child, func);
14 }
15
16 function sanitize(ast) {
17 if (ast == null)
18 return null;
19 if (ast.op == JSOP_NAME && ast.atom in aliases) {
20 ast = sanitize(aliases[ast.atom]);
21 ast.expanded = true;
22 }
23 let sanitized_ast = { kids: [] };
24 for (let key in ast) {
25 if (key == 'kids') {
26 for (let kid of ast.kids) {
27 sanitized_ast.kids.push(sanitize(kid));
28 }
29 } else {
30 sanitized_ast[key] = ast[key];
31 }
32 }
33 return sanitized_ast;
34 }
35
36 v_r(sanitize(root_ast), func);
37 }
38
39 let filename;
40
41 function process_js(ast, f) {
42 filename = f;
43 let global = clean_ast(ast);
44 for (let c of global.constants) {
45 mark_globals(c);
46 }
47 //_print(uneval(aliases));
48 for (let v of global.variables) {
49 visit(v.init, find_interfaces);
50 }
51 for (let statement of global.code)
52 visit(statement, find_interfaces);
53 //_print(uneval(global));
54 }
55
56 let aliases = {};
57
58 function mark_globals(constant) {
59 aliases[constant.name] = constant.init;
60 }
61
62 function find_interfaces(ast) {
63 if (ast.op == JSOP_GETPROP && ast.kids[0]) {
64 let check = ast.kids[0];
65 if (check.atom == "interfaces" && check.kids[0] &&
66 check.kids[0].atom == "Components") {
67 _print("Interface " + ast.atom + " used at " + loc2str(a st));
68 } else if (ast.atom && ast.atom == "nsIMimeStreamConverter") {
69 _print(uneval(ast));
70 }
71 }
72 }
73
74 function loc2str(ast) {
75 return filename + ":" + ast.line + ":" + ast.column;
76 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld