michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 341956; michael@0: var summary = 'GC Hazards in jsarray.c - unshift'; michael@0: var actual = 'No Crash'; michael@0: var expect = 'No Crash'; michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: var N = 0xFFFFFFFF; michael@0: michael@0: var a = []; michael@0: a[N - 1] = 1; michael@0: a.__defineGetter__(N - 1, function() { michael@0: var tmp = []; michael@0: tmp[N - 2] = 0; michael@0: if (typeof gc == 'function') michael@0: gc(); michael@0: for (var i = 0; i != 50000; ++i) { michael@0: var tmp = 1 / 3; michael@0: tmp /= 10; michael@0: } michael@0: for (var i = 0; i != 1000; ++i) { michael@0: // Make string with 11 characters that would take michael@0: // (11 + 1) * 2 bytes or sizeof(JSAtom) so eventually michael@0: // malloc will ovewrite just freed atoms. michael@0: var tmp2 = Array(12).join(' '); michael@0: } michael@0: return 10; michael@0: }); michael@0: michael@0: michael@0: // The following always-throw getter is to stop unshift from doing michael@0: // 2^32 iterations. michael@0: var toStop = "stringToStop"; michael@0: a[N - 3] = 0; michael@0: a.__defineGetter__(N - 3, function() { throw toStop; }); michael@0: michael@0: var good = false; michael@0: michael@0: try { michael@0: a.unshift(1); michael@0: } catch (e) { michael@0: if (e === toStop) michael@0: good = true; michael@0: } michael@0: michael@0: expect = true; michael@0: actual = good; michael@0: michael@0: reportCompare(expect, actual, summary); michael@0: michael@0: print('Done'); michael@0: michael@0: exitFunc ('test'); michael@0: }