1 // Copyright 2012 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 (function(global, utils) { 6 7 %CheckIsBootstrapping(); 8 9 // ---------------------------------------------------------------------------- 10 // Imports 11 12 var GlobalNumber = global.Number; 13 var GlobalObject = global.Object; 14 var iteratorSymbol = utils.ImportNow("iterator_symbol"); 15 var NaN = %GetRootNaN(); 16 var ObjectToString = utils.ImportNow("object_to_string"); 17 18 // ---------------------------------------------------------------------------- 19 20 21 // Set up global object. 22 var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY; 23 24 utils.InstallConstants(global, [ 25 // ES6 18.1.1 26 "Infinity", INFINITY, 27 // ES6 18.1.2 28 "NaN", NaN, 29 // ES6 18.1.3 30 "undefined", UNDEFINED, 31 ]); 32 33 34 // ---------------------------------------------------------------------------- 35 // Object 36 37 // ES6 19.1.3.5 Object.prototype.toLocaleString([reserved1 [,reserved2]]) 38 function ObjectToLocaleString() { 39 CHECK_OBJECT_COERCIBLE(this, "Object.prototype.toLocaleString"); 40 return this.toString(); 41 } 42 43 44 // ES6 19.1.3.7 Object.prototype.valueOf() 45 function ObjectValueOf() { 46 return TO_OBJECT(this); 47 } 48 49 50 // ES6 19.1.3.3 Object.prototype.isPrototypeOf(V) 51 function ObjectIsPrototypeOf(V) { 52 if (!IS_RECEIVER(V)) return false; 53 var O = TO_OBJECT(this); 54 return %HasInPrototypeChain(V, O); 55 } 56 57 58 // ES6 7.3.9 59 function GetMethod(obj, p) { 60 var func = obj[p]; 61 if (IS_NULL_OR_UNDEFINED(func)) return UNDEFINED; 62 if (IS_CALLABLE(func)) return func; 63 throw %make_type_error(kCalledNonCallable, typeof func); 64 } 65 66 // ES6 19.1.1.1 67 function ObjectConstructor(x) { 68 if (GlobalObject != new.target && !IS_UNDEFINED(new.target)) { 69 return this; 70 } 71 if (IS_NULL(x) || IS_UNDEFINED(x)) return {}; 72 return TO_OBJECT(x); 73 } 74 75 76 // ---------------------------------------------------------------------------- 77 // Object 78 79 %SetNativeFlag(GlobalObject); 80 %SetCode(GlobalObject, ObjectConstructor); 81 82 %AddNamedProperty(GlobalObject.prototype, "constructor", GlobalObject, 83 DONT_ENUM); 84 85 // Set up non-enumerable functions on the Object.prototype object. 86 utils.InstallFunctions(GlobalObject.prototype, DONT_ENUM, [ 87 "toString", ObjectToString, 88 "toLocaleString", ObjectToLocaleString, 89 "valueOf", ObjectValueOf, 90 "isPrototypeOf", ObjectIsPrototypeOf, 91 // propertyIsEnumerable is added in bootstrapper.cc. 92 // __defineGetter__ is added in bootstrapper.cc. 93 // __lookupGetter__ is added in bootstrapper.cc. 94 // __defineSetter__ is added in bootstrapper.cc. 95 // __lookupSetter__ is added in bootstrapper.cc. 96 ]); 97 98 99 // ---------------------------------------------------------------------------- 100 // Number 101 102 utils.InstallConstants(GlobalNumber, [ 103 // ECMA-262 section 15.7.3.1. 104 "MAX_VALUE", 1.7976931348623157e+308, 105 // ECMA-262 section 15.7.3.2. 106 "MIN_VALUE", 5e-324, 107 // ECMA-262 section 15.7.3.3. 108 "NaN", NaN, 109 // ECMA-262 section 15.7.3.4. 110 "NEGATIVE_INFINITY", -INFINITY, 111 // ECMA-262 section 15.7.3.5. 112 "POSITIVE_INFINITY", INFINITY, 113 114 // --- Harmony constants (no spec refs until settled.) 115 116 "MAX_SAFE_INTEGER", 9007199254740991, 117 "MIN_SAFE_INTEGER", -9007199254740991, 118 "EPSILON", 2.220446049250313e-16, 119 ]); 120 121 122 // ---------------------------------------------------------------------------- 123 // Iterator related spec functions. 124 125 // ES6 7.4.1 GetIterator(obj, method) 126 function GetIterator(obj, method) { 127 if (IS_UNDEFINED(method)) { 128 method = obj[iteratorSymbol]; 129 } 130 if (!IS_CALLABLE(method)) { 131 throw %make_type_error(kNotIterable, obj); 132 } 133 var iterator = %_Call(method, obj); 134 if (!IS_RECEIVER(iterator)) { 135 throw %make_type_error(kNotAnIterator, iterator); 136 } 137 return iterator; 138 } 139 140 // ---------------------------------------------------------------------------- 141 // Exports 142 143 utils.Export(function(to) { 144 to.GetIterator = GetIterator; 145 to.GetMethod = GetMethod; 146 to.ObjectHasOwnProperty = GlobalObject.prototype.hasOwnProperty; 147 }); 148 149 %InstallToContext([ 150 "object_value_of", ObjectValueOf, 151 ]); 152 153 }) 154