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

Side by Side Diff: src/v8natives.js

Issue 11465005: Fix spec violations in methods of Number.prototype. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/function-call.js » ('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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 if (radix < 2 || radix > 36) { 1406 if (radix < 2 || radix > 36) {
1407 throw new $RangeError('toString() radix argument must be between 2 and 36'); 1407 throw new $RangeError('toString() radix argument must be between 2 and 36');
1408 } 1408 }
1409 // Convert the number to a string in the given radix. 1409 // Convert the number to a string in the given radix.
1410 return %NumberToRadixString(number, radix); 1410 return %NumberToRadixString(number, radix);
1411 } 1411 }
1412 1412
1413 1413
1414 // ECMA-262 section 15.7.4.3 1414 // ECMA-262 section 15.7.4.3
1415 function NumberToLocaleString() { 1415 function NumberToLocaleString() {
1416 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 1416 return NumberToString();
1417 throw MakeTypeError("called_on_null_or_undefined",
1418 ["Number.prototype.toLocaleString"]);
1419 }
1420 return this.toString();
1421 } 1417 }
1422 1418
1423 1419
1424 // ECMA-262 section 15.7.4.4 1420 // ECMA-262 section 15.7.4.4
1425 function NumberValueOf() { 1421 function NumberValueOf() {
1426 // NOTE: Both Number objects and values can enter here as 1422 // NOTE: Both Number objects and values can enter here as
1427 // 'this'. This is not as dictated by ECMA-262. 1423 // 'this'. This is not as dictated by ECMA-262.
1428 if (!IS_NUMBER(this) && !IS_NUMBER_WRAPPER(this)) { 1424 if (!IS_NUMBER(this) && !IS_NUMBER_WRAPPER(this)) {
1429 throw new $TypeError('Number.prototype.valueOf is not generic'); 1425 throw new $TypeError('Number.prototype.valueOf is not generic');
1430 } 1426 }
1431 return %_ValueOf(this); 1427 return %_ValueOf(this);
1432 } 1428 }
1433 1429
1434 1430
1435 // ECMA-262 section 15.7.4.5 1431 // ECMA-262 section 15.7.4.5
1436 function NumberToFixed(fractionDigits) { 1432 function NumberToFixed(fractionDigits) {
1433 var x = this;
1434 if (!IS_NUMBER(this)) {
1435 if (!IS_NUMBER_WRAPPER(this)) {
1436 throw MakeTypeError("incompatible_method_receiver",
1437 ["Number.prototype.toFixed", this]);
1438 }
1439 // Get the value of this number in case it's an object.
1440 x = %_ValueOf(this);
1441 }
1437 var f = TO_INTEGER(fractionDigits); 1442 var f = TO_INTEGER(fractionDigits);
1443
1438 if (f < 0 || f > 20) { 1444 if (f < 0 || f > 20) {
1439 throw new $RangeError("toFixed() digits argument must be between 0 and 20"); 1445 throw new $RangeError("toFixed() digits argument must be between 0 and 20");
1440 } 1446 }
1441 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 1447
1442 throw MakeTypeError("called_on_null_or_undefined", 1448 if (NUMBER_IS_NAN(x)) return "NaN";
1443 ["Number.prototype.toFixed"]); 1449 if (x == 1/0) return "Infinity";
1444 } 1450 if (x == -1/0) return "-Infinity";
1445 var x = ToNumber(this); 1451
1446 return %NumberToFixed(x, f); 1452 return %NumberToFixed(x, f);
1447 } 1453 }
1448 1454
1449 1455
1450 // ECMA-262 section 15.7.4.6 1456 // ECMA-262 section 15.7.4.6
1451 function NumberToExponential(fractionDigits) { 1457 function NumberToExponential(fractionDigits) {
1452 var f = -1; 1458 var x = this;
1453 if (!IS_UNDEFINED(fractionDigits)) { 1459 if (!IS_NUMBER(this)) {
1454 f = TO_INTEGER(fractionDigits); 1460 if (!IS_NUMBER_WRAPPER(this)) {
1455 if (f < 0 || f > 20) { 1461 throw MakeTypeError("incompatible_method_receiver",
1456 throw new $RangeError( 1462 ["Number.prototype.toExponential", this]);
1457 "toExponential() argument must be between 0 and 20");
1458 } 1463 }
1464 // Get the value of this number in case it's an object.
1465 x = %_ValueOf(this);
1459 } 1466 }
1460 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 1467 var f = IS_UNDEFINED(fractionDigits) ? void 0 : TO_INTEGER(fractionDigits);
1461 throw MakeTypeError("called_on_null_or_undefined", 1468
1462 ["Number.prototype.toExponential"]); 1469 if (NUMBER_IS_NAN(x)) return "NaN";
1470 if (x == 1/0) return "Infinity";
1471 if (x == -1/0) return "-Infinity";
1472
1473 if (IS_UNDEFINED(f)) {
1474 f = -1; // Signal for runtime function that f is not defined.
1475 } else if (f < 0 || f > 20) {
1476 throw new $RangeError("toExponential() argument must be between 0 and 20");
1463 } 1477 }
1464 var x = ToNumber(this);
1465 return %NumberToExponential(x, f); 1478 return %NumberToExponential(x, f);
1466 } 1479 }
1467 1480
1468 1481
1469 // ECMA-262 section 15.7.4.7 1482 // ECMA-262 section 15.7.4.7
1470 function NumberToPrecision(precision) { 1483 function NumberToPrecision(precision) {
1471 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 1484 var x = this;
1472 throw MakeTypeError("called_on_null_or_undefined", 1485 if (!IS_NUMBER(this)) {
1473 ["Number.prototype.toPrecision"]); 1486 if (!IS_NUMBER_WRAPPER(this)) {
1487 throw MakeTypeError("incompatible_method_receiver",
1488 ["Number.prototype.toPrecision", this]);
1489 }
1490 // Get the value of this number in case it's an object.
1491 x = %_ValueOf(this);
1474 } 1492 }
1475 if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); 1493 if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this));
1476 var p = TO_INTEGER(precision); 1494 var p = TO_INTEGER(precision);
1495
1496 if (NUMBER_IS_NAN(x)) return "NaN";
1497 if (x == 1/0) return "Infinity";
1498 if (x == -1/0) return "-Infinity";
1499
1477 if (p < 1 || p > 21) { 1500 if (p < 1 || p > 21) {
1478 throw new $RangeError("toPrecision() argument must be between 1 and 21"); 1501 throw new $RangeError("toPrecision() argument must be between 1 and 21");
1479 } 1502 }
1480 var x = ToNumber(this);
1481 return %NumberToPrecision(x, p); 1503 return %NumberToPrecision(x, p);
1482 } 1504 }
1483 1505
1484 1506
1485 // Harmony isFinite. 1507 // Harmony isFinite.
1486 function NumberIsFinite(number) { 1508 function NumberIsFinite(number) {
1487 return IS_NUMBER(number) && NUMBER_IS_FINITE(number); 1509 return IS_NUMBER(number) && NUMBER_IS_FINITE(number);
1488 } 1510 }
1489 1511
1490 1512
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 1699
1678 function SetUpFunction() { 1700 function SetUpFunction() {
1679 %CheckIsBootstrapping(); 1701 %CheckIsBootstrapping();
1680 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1702 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1681 "bind", FunctionBind, 1703 "bind", FunctionBind,
1682 "toString", FunctionToString 1704 "toString", FunctionToString
1683 )); 1705 ));
1684 } 1706 }
1685 1707
1686 SetUpFunction(); 1708 SetUpFunction();
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/function-call.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698