| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (function(global, utils) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 %CheckIsBootstrapping(); | 7 %CheckIsBootstrapping(); |
| 8 | 8 |
| 9 // ---------------------------------------------------------------------------- | 9 // ---------------------------------------------------------------------------- |
| 10 // Imports | 10 // Imports |
| 11 | 11 |
| 12 var GlobalNumber = global.Number; | 12 var GlobalNumber = global.Number; |
| 13 var GlobalObject = global.Object; | 13 var GlobalObject = global.Object; |
| 14 var iteratorSymbol = utils.ImportNow("iterator_symbol"); | 14 var iteratorSymbol = utils.ImportNow("iterator_symbol"); |
| 15 var NaN = %GetRootNaN(); | 15 var NaN = %GetRootNaN(); |
| 16 var ObjectToString = utils.ImportNow("object_to_string"); | 16 var ObjectToString = utils.ImportNow("object_to_string"); |
| 17 | 17 |
| 18 // ---------------------------------------------------------------------------- | 18 // ---------------------------------------------------------------------------- |
| 19 | 19 |
| 20 | 20 |
| 21 // ES6 18.2.3 isNaN(number) | |
| 22 function GlobalIsNaN(number) { | |
| 23 number = TO_NUMBER(number); | |
| 24 return NUMBER_IS_NAN(number); | |
| 25 } | |
| 26 | |
| 27 | |
| 28 // ES6 18.2.2 isFinite(number) | |
| 29 function GlobalIsFinite(number) { | |
| 30 number = TO_NUMBER(number); | |
| 31 return NUMBER_IS_FINITE(number); | |
| 32 } | |
| 33 | |
| 34 | |
| 35 // ES6 18.2.5 parseInt(string, radix) | 21 // ES6 18.2.5 parseInt(string, radix) |
| 36 function GlobalParseInt(string, radix) { | 22 function GlobalParseInt(string, radix) { |
| 37 if (IS_UNDEFINED(radix) || radix === 10 || radix === 0) { | 23 if (IS_UNDEFINED(radix) || radix === 10 || radix === 0) { |
| 38 // Some people use parseInt instead of Math.floor. This | 24 // Some people use parseInt instead of Math.floor. This |
| 39 // optimization makes parseInt on a Smi 12 times faster (60ns | 25 // optimization makes parseInt on a Smi 12 times faster (60ns |
| 40 // vs 800ns). The following optimization makes parseInt on a | 26 // vs 800ns). The following optimization makes parseInt on a |
| 41 // non-Smi number 9 times faster (230ns vs 2070ns). Together | 27 // non-Smi number 9 times faster (230ns vs 2070ns). Together |
| 42 // they make parseInt on a string 1.4% slower (274ns vs 270ns). | 28 // they make parseInt on a string 1.4% slower (274ns vs 270ns). |
| 43 if (%_IsSmi(string)) return string; | 29 if (%_IsSmi(string)) return string; |
| 44 if (IS_NUMBER(string) && | 30 if (IS_NUMBER(string) && |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // ES6 18.1.1 | 70 // ES6 18.1.1 |
| 85 "Infinity", INFINITY, | 71 "Infinity", INFINITY, |
| 86 // ES6 18.1.2 | 72 // ES6 18.1.2 |
| 87 "NaN", NaN, | 73 "NaN", NaN, |
| 88 // ES6 18.1.3 | 74 // ES6 18.1.3 |
| 89 "undefined", UNDEFINED, | 75 "undefined", UNDEFINED, |
| 90 ]); | 76 ]); |
| 91 | 77 |
| 92 // Set up non-enumerable function on the global object. | 78 // Set up non-enumerable function on the global object. |
| 93 utils.InstallFunctions(global, DONT_ENUM, [ | 79 utils.InstallFunctions(global, DONT_ENUM, [ |
| 94 "isNaN", GlobalIsNaN, | |
| 95 "isFinite", GlobalIsFinite, | |
| 96 "parseInt", GlobalParseInt, | 80 "parseInt", GlobalParseInt, |
| 97 "parseFloat", GlobalParseFloat, | 81 "parseFloat", GlobalParseFloat, |
| 98 ]); | 82 ]); |
| 99 | 83 |
| 100 | 84 |
| 101 // ---------------------------------------------------------------------------- | 85 // ---------------------------------------------------------------------------- |
| 102 // Object | 86 // Object |
| 103 | 87 |
| 104 // ES6 19.1.3.5 Object.prototype.toLocaleString([reserved1 [,reserved2]]) | 88 // ES6 19.1.3.5 Object.prototype.toLocaleString([reserved1 [,reserved2]]) |
| 105 function ObjectToLocaleString() { | 89 function ObjectToLocaleString() { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 "setPrototypeOf", ObjectSetPrototypeOf, | 184 "setPrototypeOf", ObjectSetPrototypeOf, |
| 201 // getOwnPropertySymbols is added in symbol.js. | 185 // getOwnPropertySymbols is added in symbol.js. |
| 202 // Others are added in bootstrapper.cc. | 186 // Others are added in bootstrapper.cc. |
| 203 ]); | 187 ]); |
| 204 | 188 |
| 205 | 189 |
| 206 | 190 |
| 207 // ---------------------------------------------------------------------------- | 191 // ---------------------------------------------------------------------------- |
| 208 // Number | 192 // Number |
| 209 | 193 |
| 210 // Harmony isFinite. | |
| 211 function NumberIsFinite(number) { | |
| 212 return IS_NUMBER(number) && NUMBER_IS_FINITE(number); | |
| 213 } | |
| 214 | |
| 215 | |
| 216 // Harmony isInteger | |
| 217 function NumberIsInteger(number) { | |
| 218 return NumberIsFinite(number) && TO_INTEGER(number) == number; | |
| 219 } | |
| 220 | |
| 221 | |
| 222 // Harmony isNaN. | |
| 223 function NumberIsNaN(number) { | |
| 224 return IS_NUMBER(number) && NUMBER_IS_NAN(number); | |
| 225 } | |
| 226 | |
| 227 | |
| 228 // Harmony isSafeInteger | |
| 229 function NumberIsSafeInteger(number) { | |
| 230 if (NumberIsFinite(number)) { | |
| 231 var integral = TO_INTEGER(number); | |
| 232 if (integral == number) { | |
| 233 return -kMaxSafeInteger <= integral && integral <= kMaxSafeInteger; | |
| 234 } | |
| 235 } | |
| 236 return false; | |
| 237 } | |
| 238 | |
| 239 | |
| 240 // ---------------------------------------------------------------------------- | |
| 241 | |
| 242 utils.InstallConstants(GlobalNumber, [ | 194 utils.InstallConstants(GlobalNumber, [ |
| 243 // ECMA-262 section 15.7.3.1. | 195 // ECMA-262 section 15.7.3.1. |
| 244 "MAX_VALUE", 1.7976931348623157e+308, | 196 "MAX_VALUE", 1.7976931348623157e+308, |
| 245 // ECMA-262 section 15.7.3.2. | 197 // ECMA-262 section 15.7.3.2. |
| 246 "MIN_VALUE", 5e-324, | 198 "MIN_VALUE", 5e-324, |
| 247 // ECMA-262 section 15.7.3.3. | 199 // ECMA-262 section 15.7.3.3. |
| 248 "NaN", NaN, | 200 "NaN", NaN, |
| 249 // ECMA-262 section 15.7.3.4. | 201 // ECMA-262 section 15.7.3.4. |
| 250 "NEGATIVE_INFINITY", -INFINITY, | 202 "NEGATIVE_INFINITY", -INFINITY, |
| 251 // ECMA-262 section 15.7.3.5. | 203 // ECMA-262 section 15.7.3.5. |
| 252 "POSITIVE_INFINITY", INFINITY, | 204 "POSITIVE_INFINITY", INFINITY, |
| 253 | 205 |
| 254 // --- Harmony constants (no spec refs until settled.) | 206 // --- Harmony constants (no spec refs until settled.) |
| 255 | 207 |
| 256 "MAX_SAFE_INTEGER", 9007199254740991, | 208 "MAX_SAFE_INTEGER", 9007199254740991, |
| 257 "MIN_SAFE_INTEGER", -9007199254740991, | 209 "MIN_SAFE_INTEGER", -9007199254740991, |
| 258 "EPSILON", 2.220446049250313e-16, | 210 "EPSILON", 2.220446049250313e-16, |
| 259 ]); | 211 ]); |
| 260 | 212 |
| 261 // Harmony Number constructor additions | 213 // Harmony Number constructor additions |
| 262 utils.InstallFunctions(GlobalNumber, DONT_ENUM, [ | 214 utils.InstallFunctions(GlobalNumber, DONT_ENUM, [ |
| 263 "isFinite", NumberIsFinite, | |
| 264 "isInteger", NumberIsInteger, | |
| 265 "isNaN", NumberIsNaN, | |
| 266 "isSafeInteger", NumberIsSafeInteger, | |
| 267 "parseInt", GlobalParseInt, | 215 "parseInt", GlobalParseInt, |
| 268 "parseFloat", GlobalParseFloat | 216 "parseFloat", GlobalParseFloat |
| 269 ]); | 217 ]); |
| 270 | 218 |
| 271 %SetForceInlineFlag(NumberIsNaN); | |
| 272 | 219 |
| 273 | 220 |
| 274 // ---------------------------------------------------------------------------- | 221 // ---------------------------------------------------------------------------- |
| 275 // Iterator related spec functions. | 222 // Iterator related spec functions. |
| 276 | 223 |
| 277 // ES6 7.4.1 GetIterator(obj, method) | 224 // ES6 7.4.1 GetIterator(obj, method) |
| 278 function GetIterator(obj, method) { | 225 function GetIterator(obj, method) { |
| 279 if (IS_UNDEFINED(method)) { | 226 if (IS_UNDEFINED(method)) { |
| 280 method = obj[iteratorSymbol]; | 227 method = obj[iteratorSymbol]; |
| 281 } | 228 } |
| 282 if (!IS_CALLABLE(method)) { | 229 if (!IS_CALLABLE(method)) { |
| 283 throw %make_type_error(kNotIterable, obj); | 230 throw %make_type_error(kNotIterable, obj); |
| 284 } | 231 } |
| 285 var iterator = %_Call(method, obj); | 232 var iterator = %_Call(method, obj); |
| 286 if (!IS_RECEIVER(iterator)) { | 233 if (!IS_RECEIVER(iterator)) { |
| 287 throw %make_type_error(kNotAnIterator, iterator); | 234 throw %make_type_error(kNotAnIterator, iterator); |
| 288 } | 235 } |
| 289 return iterator; | 236 return iterator; |
| 290 } | 237 } |
| 291 | 238 |
| 292 // ---------------------------------------------------------------------------- | 239 // ---------------------------------------------------------------------------- |
| 293 // Exports | 240 // Exports |
| 294 | 241 |
| 295 utils.Export(function(to) { | 242 utils.Export(function(to) { |
| 296 to.GetIterator = GetIterator; | 243 to.GetIterator = GetIterator; |
| 297 to.GetMethod = GetMethod; | 244 to.GetMethod = GetMethod; |
| 298 to.IsNaN = GlobalIsNaN; | |
| 299 to.NumberIsNaN = NumberIsNaN; | |
| 300 to.NumberIsInteger = NumberIsInteger; | |
| 301 to.ObjectHasOwnProperty = GlobalObject.prototype.hasOwnProperty; | 245 to.ObjectHasOwnProperty = GlobalObject.prototype.hasOwnProperty; |
| 302 }); | 246 }); |
| 303 | 247 |
| 304 %InstallToContext([ | 248 %InstallToContext([ |
| 305 "object_value_of", ObjectValueOf, | 249 "object_value_of", ObjectValueOf, |
| 306 ]); | 250 ]); |
| 307 | 251 |
| 308 }) | 252 }) |
| OLD | NEW |