1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_5/extensions/regress-341956-01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,68 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +//----------------------------------------------------------------------------- 1.10 +var BUGNUMBER = 341956; 1.11 +var summary = 'GC Hazards in jsarray.c - unshift'; 1.12 +var actual = 'No Crash'; 1.13 +var expect = 'No Crash'; 1.14 + 1.15 +//----------------------------------------------------------------------------- 1.16 +test(); 1.17 +//----------------------------------------------------------------------------- 1.18 + 1.19 +function test() 1.20 +{ 1.21 + enterFunc ('test'); 1.22 + printBugNumber(BUGNUMBER); 1.23 + printStatus (summary); 1.24 + 1.25 + var N = 0xFFFFFFFF; 1.26 + 1.27 + var a = []; 1.28 + a[N - 1] = 1; 1.29 + a.__defineGetter__(N - 1, function() { 1.30 + var tmp = []; 1.31 + tmp[N - 2] = 0; 1.32 + if (typeof gc == 'function') 1.33 + gc(); 1.34 + for (var i = 0; i != 50000; ++i) { 1.35 + var tmp = 1 / 3; 1.36 + tmp /= 10; 1.37 + } 1.38 + for (var i = 0; i != 1000; ++i) { 1.39 + // Make string with 11 characters that would take 1.40 + // (11 + 1) * 2 bytes or sizeof(JSAtom) so eventually 1.41 + // malloc will ovewrite just freed atoms. 1.42 + var tmp2 = Array(12).join(' '); 1.43 + } 1.44 + return 10; 1.45 + }); 1.46 + 1.47 + 1.48 +// The following always-throw getter is to stop unshift from doing 1.49 +// 2^32 iterations. 1.50 + var toStop = "stringToStop"; 1.51 + a[N - 3] = 0; 1.52 + a.__defineGetter__(N - 3, function() { throw toStop; }); 1.53 + 1.54 + var good = false; 1.55 + 1.56 + try { 1.57 + a.unshift(1); 1.58 + } catch (e) { 1.59 + if (e === toStop) 1.60 + good = true; 1.61 + } 1.62 + 1.63 + expect = true; 1.64 + actual = good; 1.65 + 1.66 + reportCompare(expect, actual, summary); 1.67 + 1.68 + print('Done'); 1.69 + 1.70 + exitFunc ('test'); 1.71 +}