|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/licenses/publicdomain/ |
|
4 * Contributor: |
|
5 * Jeff Walden <jwalden+code@mit.edu> |
|
6 */ |
|
7 |
|
8 //----------------------------------------------------------------------------- |
|
9 var BUGNUMBER = 562446; |
|
10 var summary = 'ES5: Array.prototype.toString'; |
|
11 |
|
12 print(BUGNUMBER + ": " + summary); |
|
13 |
|
14 /************** |
|
15 * BEGIN TEST * |
|
16 **************/ |
|
17 |
|
18 var o; |
|
19 |
|
20 o = { join: function() { assertEq(arguments.length, 0); return "ohai"; } }; |
|
21 assertEq(Array.prototype.toString.call(o), "ohai"); |
|
22 |
|
23 o = {}; |
|
24 assertEq(Array.prototype.toString.call(o), "[object Object]"); |
|
25 |
|
26 Array.prototype.join = function() { return "kthxbai"; }; |
|
27 assertEq(Array.prototype.toString.call([]), "kthxbai"); |
|
28 |
|
29 o = { join: 17 }; |
|
30 assertEq(Array.prototype.toString.call(o), "[object Object]"); |
|
31 |
|
32 o = { get join() { throw 42; } }; |
|
33 try |
|
34 { |
|
35 var str = Array.prototype.toString.call(o); |
|
36 assertEq(true, false, |
|
37 "expected an exception calling [].toString on an object with a " + |
|
38 "join getter that throws, got " + str + " instead"); |
|
39 } |
|
40 catch (e) |
|
41 { |
|
42 assertEq(e, 42, |
|
43 "expected thrown e === 42 when calling [].toString on an object " + |
|
44 "with a join getter that throws, got " + e); |
|
45 } |
|
46 |
|
47 /******************************************************************************/ |
|
48 |
|
49 if (typeof reportCompare === "function") |
|
50 reportCompare(true, true); |
|
51 |
|
52 print("All tests passed!"); |