js/src/devtools/rootAnalysis/utility.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 function assert(x, msg)
michael@0 6 {
michael@0 7 if (x)
michael@0 8 return;
michael@0 9 debugger;
michael@0 10 if (msg)
michael@0 11 throw "assertion failed: " + msg + "\n" + (Error().stack);
michael@0 12 else
michael@0 13 throw "assertion failed: " + (Error().stack);
michael@0 14 }
michael@0 15
michael@0 16 function defined(x) {
michael@0 17 return x !== undefined;
michael@0 18 }
michael@0 19
michael@0 20 function xprint(x, padding)
michael@0 21 {
michael@0 22 if (!padding)
michael@0 23 padding = "";
michael@0 24 if (x instanceof Array) {
michael@0 25 print(padding + "[");
michael@0 26 for (var elem of x)
michael@0 27 xprint(elem, padding + " ");
michael@0 28 print(padding + "]");
michael@0 29 } else if (x instanceof Object) {
michael@0 30 print(padding + "{");
michael@0 31 for (var prop in x) {
michael@0 32 print(padding + " " + prop + ":");
michael@0 33 xprint(x[prop], padding + " ");
michael@0 34 }
michael@0 35 print(padding + "}");
michael@0 36 } else {
michael@0 37 print(padding + x);
michael@0 38 }
michael@0 39 }
michael@0 40
michael@0 41 function sameBlockId(id0, id1)
michael@0 42 {
michael@0 43 if (id0.Kind != id1.Kind)
michael@0 44 return false;
michael@0 45 if (!sameVariable(id0.Variable, id1.Variable))
michael@0 46 return false;
michael@0 47 if (id0.Kind == "Loop" && id0.Loop != id1.Loop)
michael@0 48 return false;
michael@0 49 return true;
michael@0 50 }
michael@0 51
michael@0 52 function sameVariable(var0, var1)
michael@0 53 {
michael@0 54 assert("Name" in var0 || var0.Kind == "This" || var0.Kind == "Return");
michael@0 55 assert("Name" in var1 || var1.Kind == "This" || var1.Kind == "Return");
michael@0 56 if ("Name" in var0)
michael@0 57 return "Name" in var1 && var0.Name[0] == var1.Name[0];
michael@0 58 return var0.Kind == var1.Kind;
michael@0 59 }
michael@0 60
michael@0 61 function blockIdentifier(body)
michael@0 62 {
michael@0 63 if (body.BlockId.Kind == "Loop")
michael@0 64 return body.BlockId.Loop;
michael@0 65 assert(body.BlockId.Kind == "Function", "body.Kind should be Function, not " + body.BlockId.Kind);
michael@0 66 return body.BlockId.Variable.Name[0];
michael@0 67 }
michael@0 68
michael@0 69 function collectBodyEdges(body)
michael@0 70 {
michael@0 71 body.predecessors = [];
michael@0 72 body.successors = [];
michael@0 73 if (!("PEdge" in body))
michael@0 74 return;
michael@0 75
michael@0 76 for (var edge of body.PEdge) {
michael@0 77 var [ source, target ] = edge.Index;
michael@0 78 if (!(target in body.predecessors))
michael@0 79 body.predecessors[target] = [];
michael@0 80 body.predecessors[target].push(edge);
michael@0 81 if (!(source in body.successors))
michael@0 82 body.successors[source] = [];
michael@0 83 body.successors[source].push(edge);
michael@0 84 }
michael@0 85 }
michael@0 86
michael@0 87 function getPredecessors(body)
michael@0 88 {
michael@0 89 try {
michael@0 90 if (!('predecessors' in body))
michael@0 91 collectBodyEdges(body);
michael@0 92 } catch (e) {
michael@0 93 debugger;
michael@0 94 printErr("body is " + body);
michael@0 95 }
michael@0 96 return body.predecessors;
michael@0 97 }
michael@0 98
michael@0 99 function getSuccessors(body)
michael@0 100 {
michael@0 101 if (!('successors' in body))
michael@0 102 collectBodyEdges(body);
michael@0 103 return body.successors;
michael@0 104 }
michael@0 105
michael@0 106 // Split apart a function from sixgill into its mangled and unmangled name. If
michael@0 107 // no mangled name was given, use the unmangled name as its mangled name
michael@0 108 function splitFunction(func)
michael@0 109 {
michael@0 110 var split = func.indexOf("|");
michael@0 111 if (split == -1)
michael@0 112 return [ func, func ];
michael@0 113 return [ func.substr(0, split), func.substr(split+1) ];
michael@0 114 }
michael@0 115
michael@0 116 function mangled(fullname)
michael@0 117 {
michael@0 118 var split = fullname.indexOf("|");
michael@0 119 if (split == -1)
michael@0 120 return fullname;
michael@0 121 return fullname.substr(0, split);
michael@0 122 }
michael@0 123
michael@0 124 function readable(fullname)
michael@0 125 {
michael@0 126 var split = fullname.indexOf("|");
michael@0 127 if (split == -1)
michael@0 128 return fullname;
michael@0 129 return fullname.substr(split+1);
michael@0 130 }
michael@0 131
michael@0 132 function xdbLibrary()
michael@0 133 {
michael@0 134 var lib = ctypes.open(environment['XDB']);
michael@0 135 return {
michael@0 136 open: lib.declare("xdb_open", ctypes.default_abi, ctypes.void_t, ctypes.char.ptr),
michael@0 137 min_data_stream: lib.declare("xdb_min_data_stream", ctypes.default_abi, ctypes.int),
michael@0 138 max_data_stream: lib.declare("xdb_max_data_stream", ctypes.default_abi, ctypes.int),
michael@0 139 read_key: lib.declare("xdb_read_key", ctypes.default_abi, ctypes.char.ptr, ctypes.int),
michael@0 140 read_entry: lib.declare("xdb_read_entry", ctypes.default_abi, ctypes.char.ptr, ctypes.char.ptr),
michael@0 141 free_string: lib.declare("xdb_free", ctypes.default_abi, ctypes.void_t, ctypes.char.ptr)
michael@0 142 };
michael@0 143 }

mercurial