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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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