addon-sdk/source/lib/diffpatcher/rebase.js

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 "use strict";
michael@0 2
michael@0 3 var nil = {}
michael@0 4 var owns = ({}).hasOwnProperty
michael@0 5
michael@0 6 function rebase(result, parent, delta) {
michael@0 7 var key, current, previous, update
michael@0 8 for (key in parent) {
michael@0 9 if (owns.call(parent, key)) {
michael@0 10 previous = parent[key]
michael@0 11 update = owns.call(delta, key) ? delta[key] : nil
michael@0 12 if (previous === null) continue
michael@0 13 else if (previous === void(0)) continue
michael@0 14 else if (update === null) continue
michael@0 15 else if (update === void(0)) continue
michael@0 16 else result[key] = previous
michael@0 17 }
michael@0 18 }
michael@0 19 for (key in delta) {
michael@0 20 if (owns.call(delta, key)) {
michael@0 21 update = delta[key]
michael@0 22 current = owns.call(result, key) ? result[key] : nil
michael@0 23 if (current === update) continue
michael@0 24 else if (update === null) continue
michael@0 25 else if (update === void(0)) continue
michael@0 26 else if (current === nil) result[key] = update
michael@0 27 else if (typeof(update) !== "object") result[key] = update
michael@0 28 else if (typeof(current) !== "object") result[key] = update
michael@0 29 else result[key]= rebase({}, current, update)
michael@0 30 }
michael@0 31 }
michael@0 32
michael@0 33 return result
michael@0 34 }
michael@0 35
michael@0 36 module.exports = rebase

mercurial