Sat, 03 Jan 2015 20:18:00 +0100
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 | "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 |