js/src/devtools/rootAnalysis/CFG.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: Javascript; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2
michael@0 3 "use strict";
michael@0 4
michael@0 5 var functionBodies;
michael@0 6
michael@0 7 function findAllPoints(blockId)
michael@0 8 {
michael@0 9 var points = [];
michael@0 10 var body;
michael@0 11
michael@0 12 for (var xbody of functionBodies) {
michael@0 13 if (sameBlockId(xbody.BlockId, blockId)) {
michael@0 14 assert(!body);
michael@0 15 body = xbody;
michael@0 16 }
michael@0 17 }
michael@0 18 assert(body);
michael@0 19
michael@0 20 if (!("PEdge" in body))
michael@0 21 return;
michael@0 22 for (var edge of body.PEdge) {
michael@0 23 points.push([body, edge.Index[0]]);
michael@0 24 if (edge.Kind == "Loop")
michael@0 25 Array.prototype.push.apply(points, findAllPoints(edge.BlockId));
michael@0 26 }
michael@0 27
michael@0 28 return points;
michael@0 29 }
michael@0 30
michael@0 31 function isMatchingDestructor(constructor, edge)
michael@0 32 {
michael@0 33 if (edge.Kind != "Call")
michael@0 34 return false;
michael@0 35 var callee = edge.Exp[0];
michael@0 36 if (callee.Kind != "Var")
michael@0 37 return false;
michael@0 38 var variable = callee.Variable;
michael@0 39 assert(variable.Kind == "Func");
michael@0 40 if (!/::~/.test(variable.Name[0]))
michael@0 41 return false;
michael@0 42
michael@0 43 var constructExp = constructor.PEdgeCallInstance.Exp;
michael@0 44 assert(constructExp.Kind == "Var");
michael@0 45
michael@0 46 var destructExp = edge.PEdgeCallInstance.Exp;
michael@0 47 if (destructExp.Kind != "Var")
michael@0 48 return false;
michael@0 49
michael@0 50 return sameVariable(constructExp.Variable, destructExp.Variable);
michael@0 51 }
michael@0 52
michael@0 53 // Return all calls within the RAII scope of the constructor matched by
michael@0 54 // isConstructor()
michael@0 55 function allRAIIGuardedCallPoints(body, isConstructor)
michael@0 56 {
michael@0 57 if (!("PEdge" in body))
michael@0 58 return [];
michael@0 59
michael@0 60 var points = [];
michael@0 61
michael@0 62 for (var edge of body.PEdge) {
michael@0 63 if (edge.Kind != "Call")
michael@0 64 continue;
michael@0 65 var callee = edge.Exp[0];
michael@0 66 if (callee.Kind != "Var")
michael@0 67 continue;
michael@0 68 var variable = callee.Variable;
michael@0 69 assert(variable.Kind == "Func");
michael@0 70 if (!isConstructor(variable.Name[0]))
michael@0 71 continue;
michael@0 72 if (edge.PEdgeCallInstance.Exp.Kind != "Var")
michael@0 73 continue;
michael@0 74
michael@0 75 Array.prototype.push.apply(points, pointsInRAIIScope(body, edge));
michael@0 76 }
michael@0 77
michael@0 78 return points;
michael@0 79 }
michael@0 80
michael@0 81 // Test whether the given edge is the constructor corresponding to the given
michael@0 82 // destructor edge
michael@0 83 function isMatchingConstructor(destructor, edge)
michael@0 84 {
michael@0 85 if (edge.Kind != "Call")
michael@0 86 return false;
michael@0 87 var callee = edge.Exp[0];
michael@0 88 if (callee.Kind != "Var")
michael@0 89 return false;
michael@0 90 var variable = callee.Variable;
michael@0 91 if (variable.Kind != "Func")
michael@0 92 return false;
michael@0 93 var name = readable(variable.Name[0]);
michael@0 94 var destructorName = readable(destructor.Exp[0].Variable.Name[0]);
michael@0 95 var match = destructorName.match(/^(.*?::)~(\w+)\(/);
michael@0 96 if (!match) {
michael@0 97 printErr("Unhandled destructor syntax: " + destructorName);
michael@0 98 return false;
michael@0 99 }
michael@0 100 var constructorSubstring = match[1] + match[2];
michael@0 101 if (name.indexOf(constructorSubstring) == -1)
michael@0 102 return false;
michael@0 103
michael@0 104 var destructExp = destructor.PEdgeCallInstance.Exp;
michael@0 105 assert(destructExp.Kind == "Var");
michael@0 106
michael@0 107 var constructExp = edge.PEdgeCallInstance.Exp;
michael@0 108 if (constructExp.Kind != "Var")
michael@0 109 return false;
michael@0 110
michael@0 111 return sameVariable(constructExp.Variable, destructExp.Variable);
michael@0 112 }
michael@0 113
michael@0 114 function findMatchingConstructor(destructorEdge, body)
michael@0 115 {
michael@0 116 var worklist = [destructorEdge];
michael@0 117 var predecessors = getPredecessors(body);
michael@0 118 while(worklist.length > 0) {
michael@0 119 var edge = worklist.pop();
michael@0 120 if (isMatchingConstructor(destructorEdge, edge))
michael@0 121 return edge;
michael@0 122 if (edge.Index[0] in predecessors) {
michael@0 123 for (var e of predecessors[edge.Index[0]])
michael@0 124 worklist.push(e);
michael@0 125 }
michael@0 126 }
michael@0 127 printErr("Could not find matching constructor!");
michael@0 128 debugger;
michael@0 129 }
michael@0 130
michael@0 131 function pointsInRAIIScope(body, constructorEdge) {
michael@0 132 var seen = {};
michael@0 133 var worklist = [constructorEdge.Index[1]];
michael@0 134 var points = [];
michael@0 135 while (worklist.length) {
michael@0 136 var point = worklist.pop();
michael@0 137 if (point in seen)
michael@0 138 continue;
michael@0 139 seen[point] = true;
michael@0 140 points.push([body, point]);
michael@0 141 var successors = getSuccessors(body);
michael@0 142 if (!(point in successors))
michael@0 143 continue;
michael@0 144 for (var nedge of successors[point]) {
michael@0 145 if (isMatchingDestructor(constructorEdge, nedge))
michael@0 146 continue;
michael@0 147 if (nedge.Kind == "Loop")
michael@0 148 Array.prototype.push.apply(points, findAllPoints(nedge.BlockId));
michael@0 149 worklist.push(nedge.Index[1]);
michael@0 150 }
michael@0 151 }
michael@0 152
michael@0 153 return points;
michael@0 154 }

mercurial