michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /*jshint bitwise: true, camelcase: false, curly: false, eqeqeq: true, michael@0: es5: true, forin: true, immed: true, indent: 4, latedef: false, michael@0: newcap: false, noarg: true, noempty: true, nonew: true, michael@0: plusplus: false, quotmark: false, regexp: true, undef: true, michael@0: unused: false, strict: false, trailing: true, michael@0: */ michael@0: michael@0: /*global ToObject: false, ToInteger: false, IsCallable: false, michael@0: ThrowError: false, AssertionFailed: false, SetScriptHints: false, michael@0: MakeConstructible: false, DecompileArg: false, michael@0: RuntimeDefaultLocale: false, michael@0: ParallelDo: false, ParallelSlices: false, NewDenseArray: false, michael@0: UnsafePutElements: false, ShouldForceSequential: false, michael@0: ParallelTestsShouldPass: false, michael@0: Dump: false, michael@0: callFunction: false, michael@0: TO_UINT32: false, michael@0: JSMSG_NOT_FUNCTION: false, JSMSG_MISSING_FUN_ARG: false, michael@0: JSMSG_EMPTY_ARRAY_REDUCE: false, JSMSG_CANT_CONVERT_TO: false, michael@0: */ michael@0: michael@0: #include "SelfHostingDefines.h" michael@0: michael@0: // Remove unsafe builtin functions. michael@0: Object.defineProperty = null; // See bug 988416. michael@0: michael@0: // Cache builtin functions so using them doesn't require cloning the whole object they're michael@0: // installed on. michael@0: var std_isFinite = isFinite; michael@0: var std_isNaN = isNaN; michael@0: var std_Array_indexOf = ArrayIndexOf; michael@0: var std_Array_iterator = Array.prototype.iterator; michael@0: var std_Array_join = Array.prototype.join; michael@0: var std_Array_push = Array.prototype.push; michael@0: var std_Array_pop = Array.prototype.pop; michael@0: var std_Array_shift = Array.prototype.shift; michael@0: var std_Array_slice = Array.prototype.slice; michael@0: var std_Array_sort = Array.prototype.sort; michael@0: var std_Array_unshift = Array.prototype.unshift; michael@0: var std_Boolean_toString = Boolean.prototype.toString; michael@0: var Std_Date = Date; michael@0: var std_Date_now = Date.now; michael@0: var std_Date_valueOf = Date.prototype.valueOf; michael@0: var std_Function_bind = Function.prototype.bind; michael@0: var std_Function_apply = Function.prototype.apply; michael@0: var std_Math_floor = Math.floor; michael@0: var std_Math_max = Math.max; michael@0: var std_Math_min = Math.min; michael@0: var std_Math_imul = Math.imul; michael@0: var std_Math_log2 = Math.log2; michael@0: var std_Number_valueOf = Number.prototype.valueOf; michael@0: var std_Number_POSITIVE_INFINITY = Number.POSITIVE_INFINITY; michael@0: var std_Object_create = Object.create; michael@0: var std_Object_getOwnPropertyNames = Object.getOwnPropertyNames; michael@0: var std_Object_hasOwnProperty = Object.prototype.hasOwnProperty; michael@0: var std_RegExp_test = RegExp.prototype.test; michael@0: var Std_String = String; michael@0: var std_String_fromCharCode = String.fromCharCode; michael@0: var std_String_charCodeAt = String.prototype.charCodeAt; michael@0: var std_String_indexOf = String.prototype.indexOf; michael@0: var std_String_lastIndexOf = String.prototype.lastIndexOf; michael@0: var std_String_match = String.prototype.match; michael@0: var std_String_replace = String.prototype.replace; michael@0: var std_String_split = String.prototype.split; michael@0: var std_String_startsWith = String.prototype.startsWith; michael@0: var std_String_substring = String.prototype.substring; michael@0: var std_String_toLowerCase = String.prototype.toLowerCase; michael@0: var std_String_toUpperCase = String.prototype.toUpperCase; michael@0: var std_WeakMap = WeakMap; michael@0: var std_WeakMap_get = WeakMap.prototype.get; michael@0: var std_WeakMap_has = WeakMap.prototype.has; michael@0: var std_WeakMap_set = WeakMap.prototype.set; michael@0: var std_Map_has = Map.prototype.has; michael@0: var std_Set_has = Set.prototype.has; michael@0: var std_iterator = '@@iterator'; // FIXME: Change to be a symbol. michael@0: var std_StopIteration = StopIteration; michael@0: var std_Map_iterator = Map.prototype[std_iterator]; michael@0: var std_Set_iterator = Set.prototype[std_iterator]; michael@0: var std_Map_iterator_next = Object.getPrototypeOf(Map()[std_iterator]()).next; michael@0: var std_Set_iterator_next = Object.getPrototypeOf(Set()[std_iterator]()).next; michael@0: michael@0: michael@0: michael@0: /********** List specification type **********/ michael@0: michael@0: michael@0: /* Spec: ECMAScript Language Specification, 5.1 edition, 8.8 */ michael@0: function List() {} michael@0: { michael@0: let ListProto = std_Object_create(null); michael@0: ListProto.indexOf = std_Array_indexOf; michael@0: ListProto.join = std_Array_join; michael@0: ListProto.push = std_Array_push; michael@0: ListProto.slice = std_Array_slice; michael@0: ListProto.sort = std_Array_sort; michael@0: MakeConstructible(List, ListProto); michael@0: } michael@0: michael@0: michael@0: /********** Record specification type **********/ michael@0: michael@0: michael@0: /* Spec: ECMAScript Internationalization API Specification, draft, 5 */ michael@0: function Record() { michael@0: return std_Object_create(null); michael@0: } michael@0: MakeConstructible(Record, {}); michael@0: michael@0: michael@0: /********** Abstract operations defined in ECMAScript Language Specification **********/ michael@0: michael@0: michael@0: /* Spec: ECMAScript Language Specification, 5.1 edition, 8.12.6 and 11.8.7 */ michael@0: function HasProperty(o, p) { michael@0: return p in o; michael@0: } michael@0: michael@0: michael@0: /* Spec: ECMAScript Language Specification, 5.1 edition, 9.2 and 11.4.9 */ michael@0: function ToBoolean(v) { michael@0: return !!v; michael@0: } michael@0: michael@0: michael@0: /* Spec: ECMAScript Language Specification, 5.1 edition, 9.3 and 11.4.6 */ michael@0: function ToNumber(v) { michael@0: return +v; michael@0: } michael@0: michael@0: michael@0: /* Spec: ECMAScript Language Specification, 5.1 edition, 9.8 and 15.2.1.1 */ michael@0: function ToString(v) { michael@0: assert(arguments.length > 0, "__toString"); michael@0: return Std_String(v); michael@0: } michael@0: michael@0: michael@0: /* Spec: ECMAScript Language Specification, 5.1 edition, 9.10 */ michael@0: function CheckObjectCoercible(v) { michael@0: if (v === undefined || v === null) michael@0: ThrowError(JSMSG_CANT_CONVERT_TO, ToString(v), "object"); michael@0: } michael@0: michael@0: michael@0: /********** Various utility functions **********/ michael@0: michael@0: michael@0: /** Returns true iff Type(v) is Object; see ES5 8.6. */ michael@0: function IsObject(v) { michael@0: // Watch out for |typeof null === "object"| as the most obvious pitfall. michael@0: // But also be careful of SpiderMonkey's objects that emulate undefined michael@0: // (i.e. |document.all|), which have bogus |typeof| behavior. Detect michael@0: // these objects using strict equality, which said bogosity doesn't affect. michael@0: return (typeof v === "object" && v !== null) || michael@0: typeof v === "function" || michael@0: (typeof v === "undefined" && v !== undefined); michael@0: } michael@0: michael@0: michael@0: /********** Testing code **********/ michael@0: michael@0: #ifdef ENABLE_PARALLEL_JS michael@0: michael@0: /** michael@0: * Internal debugging tool: checks that the given `mode` permits michael@0: * sequential execution michael@0: */ michael@0: function AssertSequentialIsOK(mode) { michael@0: if (mode && mode.mode && mode.mode !== "seq" && ParallelTestsShouldPass()) michael@0: ThrowError(JSMSG_WRONG_VALUE, "parallel execution", "sequential was forced"); michael@0: } michael@0: michael@0: function ForkJoinMode(mode) { michael@0: // WARNING: this must match the enum ForkJoinMode in ForkJoin.cpp michael@0: if (!mode || !mode.mode) { michael@0: return 0; michael@0: } else if (mode.mode === "compile") { michael@0: return 1; michael@0: } else if (mode.mode === "par") { michael@0: return 2; michael@0: } else if (mode.mode === "recover") { michael@0: return 3; michael@0: } else if (mode.mode === "bailout") { michael@0: return 4; michael@0: } michael@0: ThrowError(JSMSG_PAR_ARRAY_BAD_ARG); michael@0: return undefined; michael@0: } michael@0: michael@0: #endif