js/src/tests/test262/intl402/ch13/13.2/13.2.1_1.js

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 // Copyright 2012 Mozilla Corporation. All rights reserved.
michael@0 2 // This code is governed by the BSD license found in the LICENSE file.
michael@0 3
michael@0 4 /**
michael@0 5 * @description Tests that toLocaleString handles "this Number value" correctly.
michael@0 6 * @author Norbert Lindenberg
michael@0 7 */
michael@0 8
michael@0 9 var invalidValues = [undefined, null, "5", false, {valueOf: function () { return 5; }}];
michael@0 10 var validValues = [5, NaN, -1234567.89, -Infinity];
michael@0 11
michael@0 12 invalidValues.forEach(function (value) {
michael@0 13 var error;
michael@0 14 try {
michael@0 15 var result = Number.prototype.toLocaleString.call(value);
michael@0 16 } catch (e) {
michael@0 17 error = e;
michael@0 18 }
michael@0 19 if (error === undefined) {
michael@0 20 $ERROR("Number.prototype.toLocaleString did not reject this = " + value + ".");
michael@0 21 } else if (error.name !== "TypeError") {
michael@0 22 $ERROR("Number.prototype.toLocaleString rejected this = " + value + " with wrong error " + error.name + ".");
michael@0 23 }
michael@0 24 });
michael@0 25
michael@0 26 // for valid values, just check that a Number value and the corresponding
michael@0 27 // Number object get the same result.
michael@0 28 validValues.forEach(function (value) {
michael@0 29 var Constructor = Number; // to keep jshint happy
michael@0 30 var valueResult = Number.prototype.toLocaleString.call(value);
michael@0 31 var objectResult = Number.prototype.toLocaleString.call(new Constructor(value));
michael@0 32 if (valueResult !== objectResult) {
michael@0 33 $ERROR("Number.prototype.toLocaleString produces different results for Number value " +
michael@0 34 value + " and corresponding Number object: " + valueResult + " vs. " + objectResult + ".");
michael@0 35 }
michael@0 36 });
michael@0 37

mercurial