toolkit/components/url-classifier/content/moz/lang.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 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4
michael@0 5
michael@0 6 /**
michael@0 7 * lang.js - Some missing JavaScript language features
michael@0 8 */
michael@0 9
michael@0 10 /**
michael@0 11 * Partially applies a function to a particular "this object" and zero or
michael@0 12 * more arguments. The result is a new function with some arguments of the first
michael@0 13 * function pre-filled and the value of |this| "pre-specified".
michael@0 14 *
michael@0 15 * Remaining arguments specified at call-time are appended to the pre-
michael@0 16 * specified ones.
michael@0 17 *
michael@0 18 * Usage:
michael@0 19 * var barMethBound = BindToObject(myFunction, myObj, "arg1", "arg2");
michael@0 20 * barMethBound("arg3", "arg4");
michael@0 21 *
michael@0 22 * @param fn {string} Reference to the function to be bound
michael@0 23 *
michael@0 24 * @param self {object} Specifies the object which |this| should point to
michael@0 25 * when the function is run. If the value is null or undefined, it will default
michael@0 26 * to the global object.
michael@0 27 *
michael@0 28 * @returns {function} A partially-applied form of the speficied function.
michael@0 29 */
michael@0 30 function BindToObject(fn, self, opt_args) {
michael@0 31 var boundargs = fn.boundArgs_ || [];
michael@0 32 boundargs = boundargs.concat(Array.slice(arguments, 2, arguments.length));
michael@0 33
michael@0 34 if (fn.boundSelf_)
michael@0 35 self = fn.boundSelf_;
michael@0 36 if (fn.boundFn_)
michael@0 37 fn = fn.boundFn_;
michael@0 38
michael@0 39 var newfn = function() {
michael@0 40 // Combine the static args and the new args into one big array
michael@0 41 var args = boundargs.concat(Array.slice(arguments));
michael@0 42 return fn.apply(self, args);
michael@0 43 }
michael@0 44
michael@0 45 newfn.boundArgs_ = boundargs;
michael@0 46 newfn.boundSelf_ = self;
michael@0 47 newfn.boundFn_ = fn;
michael@0 48
michael@0 49 return newfn;
michael@0 50 }
michael@0 51
michael@0 52 /**
michael@0 53 * Inherit the prototype methods from one constructor into another.
michael@0 54 *
michael@0 55 * Usage:
michael@0 56 *
michael@0 57 * function ParentClass(a, b) { }
michael@0 58 * ParentClass.prototype.foo = function(a) { }
michael@0 59 *
michael@0 60 * function ChildClass(a, b, c) {
michael@0 61 * ParentClass.call(this, a, b);
michael@0 62 * }
michael@0 63 *
michael@0 64 * ChildClass.inherits(ParentClass);
michael@0 65 *
michael@0 66 * var child = new ChildClass("a", "b", "see");
michael@0 67 * child.foo(); // works
michael@0 68 *
michael@0 69 * In addition, a superclass' implementation of a method can be invoked
michael@0 70 * as follows:
michael@0 71 *
michael@0 72 * ChildClass.prototype.foo = function(a) {
michael@0 73 * ChildClass.superClass_.foo.call(this, a);
michael@0 74 * // other code
michael@0 75 * };
michael@0 76 */
michael@0 77 Function.prototype.inherits = function(parentCtor) {
michael@0 78 var tempCtor = function(){};
michael@0 79 tempCtor.prototype = parentCtor.prototype;
michael@0 80 this.superClass_ = parentCtor.prototype;
michael@0 81 this.prototype = new tempCtor();
michael@0 82 }

mercurial