|
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 = 657298; |
|
10 var summary = 'Various quirks of setting array length properties to objects'; |
|
11 |
|
12 print(BUGNUMBER + ": " + summary); |
|
13 |
|
14 /************** |
|
15 * BEGIN TEST * |
|
16 **************/ |
|
17 |
|
18 function invokeConversionTwice1() |
|
19 { |
|
20 var count = 0; |
|
21 [].length = { valueOf: function() { count++; return 1; } }; |
|
22 assertEq(count, 2); |
|
23 } |
|
24 invokeConversionTwice1(); |
|
25 |
|
26 function invokeConversionTwice2() |
|
27 { |
|
28 var count = 0; |
|
29 [].length = { toString: function() { count++; return 1; }, valueOf: null }; |
|
30 assertEq(count, 2); |
|
31 } |
|
32 invokeConversionTwice2(); |
|
33 |
|
34 function dontOverwriteError1() |
|
35 { |
|
36 try |
|
37 { |
|
38 [].length = { valueOf: {}, toString: {} }; |
|
39 throw new Error("didn't throw a TypeError"); |
|
40 } |
|
41 catch (e) |
|
42 { |
|
43 assertEq(e instanceof TypeError, true, |
|
44 "expected a TypeError running out of conversion options, got " + e); |
|
45 } |
|
46 } |
|
47 dontOverwriteError1(); |
|
48 |
|
49 function dontOverwriteError2() |
|
50 { |
|
51 try |
|
52 { |
|
53 [].length = { valueOf: function() { throw "error"; } }; |
|
54 throw new Error("didn't throw a TypeError"); |
|
55 } |
|
56 catch (e) |
|
57 { |
|
58 assertEq(e, "error", "expected 'error' from failed conversion, got " + e); |
|
59 } |
|
60 } |
|
61 dontOverwriteError2(); |
|
62 |
|
63 /******************************************************************************/ |
|
64 |
|
65 if (typeof reportCompare === "function") |
|
66 reportCompare(true, true); |
|
67 |
|
68 print("All tests passed!"); |