2
* Any copyright is dedicated to the Public Domain.
3
* http://creativecommons.org/licenses/publicdomain/
6
var gTestfile = 'toLocaleString.js';
7
var BUGNUMBER = 653789;
8
var summary = "Object.prototype.toLocaleString";
10
print(BUGNUMBER + ": " + summary);
16
function expectThrowTypeError(fun)
21
throw "didn't throw TypeError, returned " + r;
25
assertEq(e instanceof TypeError, true,
26
"didn't throw TypeError, got: " + e);
30
var toLocaleString = Object.prototype.toLocaleString;
33
* 1. Let O be the result of calling ToObject passing the this value as the
36
expectThrowTypeError(function() { toLocaleString.call(null); });
37
expectThrowTypeError(function() { toLocaleString.call(undefined); });
38
expectThrowTypeError(function() { toLocaleString.apply(null); });
39
expectThrowTypeError(function() { toLocaleString.apply(undefined); });
43
* 2. Let toString be the result of calling the [[Get]] internal method of O
44
* passing "toString" as the argument.
48
toLocaleString.call({ get toString() { throw 17; } });
49
throw new Error("didn't throw");
57
/* 3. If IsCallable(toString) is false, throw a TypeError exception. */
58
expectThrowTypeError(function() { toLocaleString.call({ toString: 12 }); });
59
expectThrowTypeError(function() { toLocaleString.call({ toString: 0.3423423452352e9 }); });
60
expectThrowTypeError(function() { toLocaleString.call({ toString: undefined }); });
61
expectThrowTypeError(function() { toLocaleString.call({ toString: false }); });
62
expectThrowTypeError(function() { toLocaleString.call({ toString: [] }); });
63
expectThrowTypeError(function() { toLocaleString.call({ toString: {} }); });
64
expectThrowTypeError(function() { toLocaleString.call({ toString: new String }); });
65
expectThrowTypeError(function() { toLocaleString.call({ toString: new Number(7.7) }); });
66
expectThrowTypeError(function() { toLocaleString.call({ toString: new Boolean(true) }); });
67
expectThrowTypeError(function() { toLocaleString.call({ toString: JSON }); });
69
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: 12 }); });
70
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: 0.3423423452352e9 }); });
71
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: undefined }); });
72
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: false }); });
73
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: [] }); });
74
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: {} }); });
75
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: new String }); });
76
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: new Number(7.7) }); });
77
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: new Boolean(true) }); });
78
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: JSON }); });
82
* 4. Return the result of calling the [[Call]] internal method of toString
83
* passing O as the this value and no arguments.
85
assertEq(toLocaleString.call({ get toString() { return function() { return "foo"; } } }),
88
var obj = { toString: function() { assertEq(this, obj); assertEq(arguments.length, 0); return 5; } };
89
assertEq(toLocaleString.call(obj), 5);
91
assertEq(toLocaleString.call({ toString: function() { return obj; } }), obj);
93
assertEq(toLocaleString.call({ toString: function() { return obj; },
94
valueOf: function() { return "abc"; } }),
97
/******************************************************************************/
99
if (typeof reportCompare === "function")
100
reportCompare(true, true);
102
print("All tests passed!");