js/src/builtin/Utilities.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.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 /*jshint bitwise: true, camelcase: false, curly: false, eqeqeq: true,
     6          es5: true, forin: true, immed: true, indent: 4, latedef: false,
     7          newcap: false, noarg: true, noempty: true, nonew: true,
     8          plusplus: false, quotmark: false, regexp: true, undef: true,
     9          unused: false, strict: false, trailing: true,
    10 */
    12 /*global ToObject: false, ToInteger: false, IsCallable: false,
    13          ThrowError: false, AssertionFailed: false, SetScriptHints: false,
    14          MakeConstructible: false, DecompileArg: false,
    15          RuntimeDefaultLocale: false,
    16          ParallelDo: false, ParallelSlices: false, NewDenseArray: false,
    17          UnsafePutElements: false, ShouldForceSequential: false,
    18          ParallelTestsShouldPass: false,
    19          Dump: false,
    20          callFunction: false,
    21          TO_UINT32: false,
    22          JSMSG_NOT_FUNCTION: false, JSMSG_MISSING_FUN_ARG: false,
    23          JSMSG_EMPTY_ARRAY_REDUCE: false, JSMSG_CANT_CONVERT_TO: false,
    24 */
    26 #include "SelfHostingDefines.h"
    28 // Remove unsafe builtin functions.
    29 Object.defineProperty = null; // See bug 988416.
    31 // Cache builtin functions so using them doesn't require cloning the whole object they're 
    32 // installed on.
    33 var std_isFinite = isFinite;
    34 var std_isNaN = isNaN;
    35 var std_Array_indexOf = ArrayIndexOf;
    36 var std_Array_iterator = Array.prototype.iterator;
    37 var std_Array_join = Array.prototype.join;
    38 var std_Array_push = Array.prototype.push;
    39 var std_Array_pop = Array.prototype.pop;
    40 var std_Array_shift = Array.prototype.shift;
    41 var std_Array_slice = Array.prototype.slice;
    42 var std_Array_sort = Array.prototype.sort;
    43 var std_Array_unshift = Array.prototype.unshift;
    44 var std_Boolean_toString = Boolean.prototype.toString;
    45 var Std_Date = Date;
    46 var std_Date_now = Date.now;
    47 var std_Date_valueOf = Date.prototype.valueOf;
    48 var std_Function_bind = Function.prototype.bind;
    49 var std_Function_apply = Function.prototype.apply;
    50 var std_Math_floor = Math.floor;
    51 var std_Math_max = Math.max;
    52 var std_Math_min = Math.min;
    53 var std_Math_imul = Math.imul;
    54 var std_Math_log2 = Math.log2;
    55 var std_Number_valueOf = Number.prototype.valueOf;
    56 var std_Number_POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
    57 var std_Object_create = Object.create;
    58 var std_Object_getOwnPropertyNames = Object.getOwnPropertyNames;
    59 var std_Object_hasOwnProperty = Object.prototype.hasOwnProperty;
    60 var std_RegExp_test = RegExp.prototype.test;
    61 var Std_String = String;
    62 var std_String_fromCharCode = String.fromCharCode;
    63 var std_String_charCodeAt = String.prototype.charCodeAt;
    64 var std_String_indexOf = String.prototype.indexOf;
    65 var std_String_lastIndexOf = String.prototype.lastIndexOf;
    66 var std_String_match = String.prototype.match;
    67 var std_String_replace = String.prototype.replace;
    68 var std_String_split = String.prototype.split;
    69 var std_String_startsWith = String.prototype.startsWith;
    70 var std_String_substring = String.prototype.substring;
    71 var std_String_toLowerCase = String.prototype.toLowerCase;
    72 var std_String_toUpperCase = String.prototype.toUpperCase;
    73 var std_WeakMap = WeakMap;
    74 var std_WeakMap_get = WeakMap.prototype.get;
    75 var std_WeakMap_has = WeakMap.prototype.has;
    76 var std_WeakMap_set = WeakMap.prototype.set;
    77 var std_Map_has = Map.prototype.has;
    78 var std_Set_has = Set.prototype.has;
    79 var std_iterator = '@@iterator'; // FIXME: Change to be a symbol.
    80 var std_StopIteration = StopIteration;
    81 var std_Map_iterator = Map.prototype[std_iterator];
    82 var std_Set_iterator = Set.prototype[std_iterator];
    83 var std_Map_iterator_next = Object.getPrototypeOf(Map()[std_iterator]()).next;
    84 var std_Set_iterator_next = Object.getPrototypeOf(Set()[std_iterator]()).next;
    88 /********** List specification type **********/
    91 /* Spec: ECMAScript Language Specification, 5.1 edition, 8.8 */
    92 function List() {}
    93 {
    94   let ListProto = std_Object_create(null);
    95   ListProto.indexOf = std_Array_indexOf;
    96   ListProto.join = std_Array_join;
    97   ListProto.push = std_Array_push;
    98   ListProto.slice = std_Array_slice;
    99   ListProto.sort = std_Array_sort;
   100   MakeConstructible(List, ListProto);
   101 }
   104 /********** Record specification type **********/
   107 /* Spec: ECMAScript Internationalization API Specification, draft, 5 */
   108 function Record() {
   109     return std_Object_create(null);
   110 }
   111 MakeConstructible(Record, {});
   114 /********** Abstract operations defined in ECMAScript Language Specification **********/
   117 /* Spec: ECMAScript Language Specification, 5.1 edition, 8.12.6 and 11.8.7 */
   118 function HasProperty(o, p) {
   119     return p in o;
   120 }
   123 /* Spec: ECMAScript Language Specification, 5.1 edition, 9.2 and 11.4.9 */
   124 function ToBoolean(v) {
   125     return !!v;
   126 }
   129 /* Spec: ECMAScript Language Specification, 5.1 edition, 9.3 and 11.4.6 */
   130 function ToNumber(v) {
   131     return +v;
   132 }
   135 /* Spec: ECMAScript Language Specification, 5.1 edition, 9.8 and 15.2.1.1 */
   136 function ToString(v) {
   137     assert(arguments.length > 0, "__toString");
   138     return Std_String(v);
   139 }
   142 /* Spec: ECMAScript Language Specification, 5.1 edition, 9.10 */
   143 function CheckObjectCoercible(v) {
   144     if (v === undefined || v === null)
   145         ThrowError(JSMSG_CANT_CONVERT_TO, ToString(v), "object");
   146 }
   149 /********** Various utility functions **********/
   152 /** Returns true iff Type(v) is Object; see ES5 8.6. */
   153 function IsObject(v) {
   154     // Watch out for |typeof null === "object"| as the most obvious pitfall.
   155     // But also be careful of SpiderMonkey's objects that emulate undefined
   156     // (i.e. |document.all|), which have bogus |typeof| behavior.  Detect
   157     // these objects using strict equality, which said bogosity doesn't affect.
   158     return (typeof v === "object" && v !== null) ||
   159            typeof v === "function" ||
   160            (typeof v === "undefined" && v !== undefined);
   161 }
   164 /********** Testing code **********/
   166 #ifdef ENABLE_PARALLEL_JS
   168 /**
   169  * Internal debugging tool: checks that the given `mode` permits
   170  * sequential execution
   171  */
   172 function AssertSequentialIsOK(mode) {
   173   if (mode && mode.mode && mode.mode !== "seq" && ParallelTestsShouldPass())
   174     ThrowError(JSMSG_WRONG_VALUE, "parallel execution", "sequential was forced");
   175 }
   177 function ForkJoinMode(mode) {
   178   // WARNING: this must match the enum ForkJoinMode in ForkJoin.cpp
   179   if (!mode || !mode.mode) {
   180     return 0;
   181   } else if (mode.mode === "compile") {
   182     return 1;
   183   } else if (mode.mode === "par") {
   184     return 2;
   185   } else if (mode.mode === "recover") {
   186     return 3;
   187   } else if (mode.mode === "bailout") {
   188     return 4;
   189   }
   190   ThrowError(JSMSG_PAR_ARRAY_BAD_ARG);
   191   return undefined;
   192 }
   194 #endif

mercurial