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