Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: src/js/v8natives.js

Issue 2126453002: [intrinsic] Drop the %_ValueOf intrinsic. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix noi18n build (narf) Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/js/symbol.js ('k') | src/runtime/runtime.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 "setPrototypeOf", ObjectSetPrototypeOf, 215 "setPrototypeOf", ObjectSetPrototypeOf,
216 // getOwnPropertySymbols is added in symbol.js. 216 // getOwnPropertySymbols is added in symbol.js.
217 // Others are added in bootstrapper.cc. 217 // Others are added in bootstrapper.cc.
218 ]); 218 ]);
219 219
220 220
221 221
222 // ---------------------------------------------------------------------------- 222 // ----------------------------------------------------------------------------
223 // Number 223 // Number
224 224
225 // ES6 Number.prototype.toString([ radix ])
226 function NumberToStringJS(radix) {
227 // NOTE: Both Number objects and values can enter here as
228 // 'this'. This is not as dictated by ECMA-262.
229 var number = this;
230 if (!IS_NUMBER(this)) {
231 if (!IS_NUMBER_WRAPPER(this)) {
232 throw MakeTypeError(kNotGeneric, 'Number.prototype.toString');
233 }
234 // Get the value of this number in case it's an object.
235 number = %_ValueOf(this);
236 }
237 // Fast case: Convert number in radix 10.
238 if (IS_UNDEFINED(radix) || radix === 10) {
239 return %_NumberToString(number);
240 }
241
242 // Convert the radix to an integer and check the range.
243 radix = TO_INTEGER(radix);
244 if (radix < 2 || radix > 36) throw MakeRangeError(kToRadixFormatRange);
245 // Convert the number to a string in the given radix.
246 return %NumberToRadixString(number, radix);
247 }
248
249
250 // ES6 20.1.3.4 Number.prototype.toLocaleString([reserved1 [, reserved2]])
251 function NumberToLocaleString() {
252 return %_Call(NumberToStringJS, this);
253 }
254
255
256 // ES6 20.1.3.7 Number.prototype.valueOf()
257 function NumberValueOf() {
258 // NOTE: Both Number objects and values can enter here as
259 // 'this'. This is not as dictated by ECMA-262.
260 if (!IS_NUMBER(this) && !IS_NUMBER_WRAPPER(this)) {
261 throw MakeTypeError(kNotGeneric, 'Number.prototype.valueOf');
262 }
263 return %_ValueOf(this);
264 }
265
266
267 // ES6 20.1.3.3 Number.prototype.toFixed(fractionDigits)
268 function NumberToFixedJS(fractionDigits) {
269 var x = this;
270 if (!IS_NUMBER(this)) {
271 if (!IS_NUMBER_WRAPPER(this)) {
272 throw MakeTypeError(kIncompatibleMethodReceiver,
273 "Number.prototype.toFixed", this);
274 }
275 // Get the value of this number in case it's an object.
276 x = %_ValueOf(this);
277 }
278 var f = TO_INTEGER(fractionDigits);
279
280 if (f < 0 || f > 20) {
281 throw MakeRangeError(kNumberFormatRange, "toFixed() digits");
282 }
283
284 if (NUMBER_IS_NAN(x)) return "NaN";
285 if (x == INFINITY) return "Infinity";
286 if (x == -INFINITY) return "-Infinity";
287
288 return %NumberToFixed(x, f);
289 }
290
291
292 // ES6 20.1.3.2 Number.prototype.toExponential(fractionDigits)
293 function NumberToExponentialJS(fractionDigits) {
294 var x = this;
295 if (!IS_NUMBER(this)) {
296 if (!IS_NUMBER_WRAPPER(this)) {
297 throw MakeTypeError(kIncompatibleMethodReceiver,
298 "Number.prototype.toExponential", this);
299 }
300 // Get the value of this number in case it's an object.
301 x = %_ValueOf(this);
302 }
303 var f = IS_UNDEFINED(fractionDigits) ? UNDEFINED : TO_INTEGER(fractionDigits);
304
305 if (NUMBER_IS_NAN(x)) return "NaN";
306 if (x == INFINITY) return "Infinity";
307 if (x == -INFINITY) return "-Infinity";
308
309 if (IS_UNDEFINED(f)) {
310 f = -1; // Signal for runtime function that f is not defined.
311 } else if (f < 0 || f > 20) {
312 throw MakeRangeError(kNumberFormatRange, "toExponential()");
313 }
314 return %NumberToExponential(x, f);
315 }
316
317
318 // ES6 20.1.3.5 Number.prototype.toPrecision(precision)
319 function NumberToPrecisionJS(precision) {
320 var x = this;
321 if (!IS_NUMBER(this)) {
322 if (!IS_NUMBER_WRAPPER(this)) {
323 throw MakeTypeError(kIncompatibleMethodReceiver,
324 "Number.prototype.toPrecision", this);
325 }
326 // Get the value of this number in case it's an object.
327 x = %_ValueOf(this);
328 }
329 if (IS_UNDEFINED(precision)) return TO_STRING(x);
330 var p = TO_INTEGER(precision);
331
332 if (NUMBER_IS_NAN(x)) return "NaN";
333 if (x == INFINITY) return "Infinity";
334 if (x == -INFINITY) return "-Infinity";
335
336 if (p < 1 || p > 21) {
337 throw MakeRangeError(kToPrecisionFormatRange);
338 }
339 return %NumberToPrecision(x, p);
340 }
341
342
343 // Harmony isFinite. 225 // Harmony isFinite.
344 function NumberIsFinite(number) { 226 function NumberIsFinite(number) {
345 return IS_NUMBER(number) && NUMBER_IS_FINITE(number); 227 return IS_NUMBER(number) && NUMBER_IS_FINITE(number);
346 } 228 }
347 229
348 230
349 // Harmony isInteger 231 // Harmony isInteger
350 function NumberIsInteger(number) { 232 function NumberIsInteger(number) {
351 return NumberIsFinite(number) && TO_INTEGER(number) == number; 233 return NumberIsFinite(number) && TO_INTEGER(number) == number;
352 } 234 }
(...skipping 12 matching lines...) Expand all
365 if (integral == number) { 247 if (integral == number) {
366 return -kMaxSafeInteger <= integral && integral <= kMaxSafeInteger; 248 return -kMaxSafeInteger <= integral && integral <= kMaxSafeInteger;
367 } 249 }
368 } 250 }
369 return false; 251 return false;
370 } 252 }
371 253
372 254
373 // ---------------------------------------------------------------------------- 255 // ----------------------------------------------------------------------------
374 256
375 %FunctionSetPrototype(GlobalNumber, new GlobalNumber(0));
376
377 %OptimizeObjectForAddingMultipleProperties(GlobalNumber.prototype, 8);
378 // Set up the constructor property on the Number prototype object.
379 %AddNamedProperty(GlobalNumber.prototype, "constructor", GlobalNumber,
380 DONT_ENUM);
381
382 utils.InstallConstants(GlobalNumber, [ 257 utils.InstallConstants(GlobalNumber, [
383 // ECMA-262 section 15.7.3.1. 258 // ECMA-262 section 15.7.3.1.
384 "MAX_VALUE", 1.7976931348623157e+308, 259 "MAX_VALUE", 1.7976931348623157e+308,
385 // ECMA-262 section 15.7.3.2. 260 // ECMA-262 section 15.7.3.2.
386 "MIN_VALUE", 5e-324, 261 "MIN_VALUE", 5e-324,
387 // ECMA-262 section 15.7.3.3. 262 // ECMA-262 section 15.7.3.3.
388 "NaN", NaN, 263 "NaN", NaN,
389 // ECMA-262 section 15.7.3.4. 264 // ECMA-262 section 15.7.3.4.
390 "NEGATIVE_INFINITY", -INFINITY, 265 "NEGATIVE_INFINITY", -INFINITY,
391 // ECMA-262 section 15.7.3.5. 266 // ECMA-262 section 15.7.3.5.
392 "POSITIVE_INFINITY", INFINITY, 267 "POSITIVE_INFINITY", INFINITY,
393 268
394 // --- Harmony constants (no spec refs until settled.) 269 // --- Harmony constants (no spec refs until settled.)
395 270
396 "MAX_SAFE_INTEGER", 9007199254740991, 271 "MAX_SAFE_INTEGER", 9007199254740991,
397 "MIN_SAFE_INTEGER", -9007199254740991, 272 "MIN_SAFE_INTEGER", -9007199254740991,
398 "EPSILON", 2.220446049250313e-16, 273 "EPSILON", 2.220446049250313e-16,
399 ]); 274 ]);
400 275
401 // Set up non-enumerable functions on the Number prototype object.
402 utils.InstallFunctions(GlobalNumber.prototype, DONT_ENUM, [
403 "toString", NumberToStringJS,
404 "toLocaleString", NumberToLocaleString,
405 "valueOf", NumberValueOf,
406 "toFixed", NumberToFixedJS,
407 "toExponential", NumberToExponentialJS,
408 "toPrecision", NumberToPrecisionJS
409 ]);
410
411 // Harmony Number constructor additions 276 // Harmony Number constructor additions
412 utils.InstallFunctions(GlobalNumber, DONT_ENUM, [ 277 utils.InstallFunctions(GlobalNumber, DONT_ENUM, [
413 "isFinite", NumberIsFinite, 278 "isFinite", NumberIsFinite,
414 "isInteger", NumberIsInteger, 279 "isInteger", NumberIsInteger,
415 "isNaN", NumberIsNaN, 280 "isNaN", NumberIsNaN,
416 "isSafeInteger", NumberIsSafeInteger, 281 "isSafeInteger", NumberIsSafeInteger,
417 "parseInt", GlobalParseInt, 282 "parseInt", GlobalParseInt,
418 "parseFloat", GlobalParseFloat 283 "parseFloat", GlobalParseFloat
419 ]); 284 ]);
420 285
(...skipping 28 matching lines...) Expand all
449 to.NumberIsNaN = NumberIsNaN; 314 to.NumberIsNaN = NumberIsNaN;
450 to.NumberIsInteger = NumberIsInteger; 315 to.NumberIsInteger = NumberIsInteger;
451 to.ObjectHasOwnProperty = GlobalObject.prototype.hasOwnProperty; 316 to.ObjectHasOwnProperty = GlobalObject.prototype.hasOwnProperty;
452 }); 317 });
453 318
454 %InstallToContext([ 319 %InstallToContext([
455 "object_value_of", ObjectValueOf, 320 "object_value_of", ObjectValueOf,
456 ]); 321 ]);
457 322
458 }) 323 })
OLDNEW
« no previous file with comments | « src/js/symbol.js ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698