michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: * Contributor: michael@0: * Jeff Walden michael@0: */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 657298; michael@0: var summary = 'Various quirks of setting array length properties to objects'; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: function invokeConversionTwice1() michael@0: { michael@0: var count = 0; michael@0: [].length = { valueOf: function() { count++; return 1; } }; michael@0: assertEq(count, 2); michael@0: } michael@0: invokeConversionTwice1(); michael@0: michael@0: function invokeConversionTwice2() michael@0: { michael@0: var count = 0; michael@0: [].length = { toString: function() { count++; return 1; }, valueOf: null }; michael@0: assertEq(count, 2); michael@0: } michael@0: invokeConversionTwice2(); michael@0: michael@0: function dontOverwriteError1() michael@0: { michael@0: try michael@0: { michael@0: [].length = { valueOf: {}, toString: {} }; michael@0: throw new Error("didn't throw a TypeError"); michael@0: } michael@0: catch (e) michael@0: { michael@0: assertEq(e instanceof TypeError, true, michael@0: "expected a TypeError running out of conversion options, got " + e); michael@0: } michael@0: } michael@0: dontOverwriteError1(); michael@0: michael@0: function dontOverwriteError2() michael@0: { michael@0: try michael@0: { michael@0: [].length = { valueOf: function() { throw "error"; } }; michael@0: throw new Error("didn't throw a TypeError"); michael@0: } michael@0: catch (e) michael@0: { michael@0: assertEq(e, "error", "expected 'error' from failed conversion, got " + e); michael@0: } michael@0: } michael@0: dontOverwriteError2(); michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("All tests passed!");