Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 4 | * Contributor: |
michael@0 | 5 | * Jeff Walden <jwalden+code@mit.edu> |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | //----------------------------------------------------------------------------- |
michael@0 | 9 | var BUGNUMBER = 657298; |
michael@0 | 10 | var summary = 'Various quirks of setting array length properties to objects'; |
michael@0 | 11 | |
michael@0 | 12 | print(BUGNUMBER + ": " + summary); |
michael@0 | 13 | |
michael@0 | 14 | /************** |
michael@0 | 15 | * BEGIN TEST * |
michael@0 | 16 | **************/ |
michael@0 | 17 | |
michael@0 | 18 | function invokeConversionTwice1() |
michael@0 | 19 | { |
michael@0 | 20 | var count = 0; |
michael@0 | 21 | [].length = { valueOf: function() { count++; return 1; } }; |
michael@0 | 22 | assertEq(count, 2); |
michael@0 | 23 | } |
michael@0 | 24 | invokeConversionTwice1(); |
michael@0 | 25 | |
michael@0 | 26 | function invokeConversionTwice2() |
michael@0 | 27 | { |
michael@0 | 28 | var count = 0; |
michael@0 | 29 | [].length = { toString: function() { count++; return 1; }, valueOf: null }; |
michael@0 | 30 | assertEq(count, 2); |
michael@0 | 31 | } |
michael@0 | 32 | invokeConversionTwice2(); |
michael@0 | 33 | |
michael@0 | 34 | function dontOverwriteError1() |
michael@0 | 35 | { |
michael@0 | 36 | try |
michael@0 | 37 | { |
michael@0 | 38 | [].length = { valueOf: {}, toString: {} }; |
michael@0 | 39 | throw new Error("didn't throw a TypeError"); |
michael@0 | 40 | } |
michael@0 | 41 | catch (e) |
michael@0 | 42 | { |
michael@0 | 43 | assertEq(e instanceof TypeError, true, |
michael@0 | 44 | "expected a TypeError running out of conversion options, got " + e); |
michael@0 | 45 | } |
michael@0 | 46 | } |
michael@0 | 47 | dontOverwriteError1(); |
michael@0 | 48 | |
michael@0 | 49 | function dontOverwriteError2() |
michael@0 | 50 | { |
michael@0 | 51 | try |
michael@0 | 52 | { |
michael@0 | 53 | [].length = { valueOf: function() { throw "error"; } }; |
michael@0 | 54 | throw new Error("didn't throw a TypeError"); |
michael@0 | 55 | } |
michael@0 | 56 | catch (e) |
michael@0 | 57 | { |
michael@0 | 58 | assertEq(e, "error", "expected 'error' from failed conversion, got " + e); |
michael@0 | 59 | } |
michael@0 | 60 | } |
michael@0 | 61 | dontOverwriteError2(); |
michael@0 | 62 | |
michael@0 | 63 | /******************************************************************************/ |
michael@0 | 64 | |
michael@0 | 65 | if (typeof reportCompare === "function") |
michael@0 | 66 | reportCompare(true, true); |
michael@0 | 67 | |
michael@0 | 68 | print("All tests passed!"); |