|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 //----------------------------------------------------------------------------- |
|
7 var BUGNUMBER = 341956; |
|
8 var summary = 'GC Hazards in jsarray.c - unshift'; |
|
9 var actual = 'No Crash'; |
|
10 var expect = 'No Crash'; |
|
11 |
|
12 //----------------------------------------------------------------------------- |
|
13 test(); |
|
14 //----------------------------------------------------------------------------- |
|
15 |
|
16 function test() |
|
17 { |
|
18 enterFunc ('test'); |
|
19 printBugNumber(BUGNUMBER); |
|
20 printStatus (summary); |
|
21 |
|
22 var N = 0xFFFFFFFF; |
|
23 |
|
24 var a = []; |
|
25 a[N - 1] = 1; |
|
26 a.__defineGetter__(N - 1, function() { |
|
27 var tmp = []; |
|
28 tmp[N - 2] = 0; |
|
29 if (typeof gc == 'function') |
|
30 gc(); |
|
31 for (var i = 0; i != 50000; ++i) { |
|
32 var tmp = 1 / 3; |
|
33 tmp /= 10; |
|
34 } |
|
35 for (var i = 0; i != 1000; ++i) { |
|
36 // Make string with 11 characters that would take |
|
37 // (11 + 1) * 2 bytes or sizeof(JSAtom) so eventually |
|
38 // malloc will ovewrite just freed atoms. |
|
39 var tmp2 = Array(12).join(' '); |
|
40 } |
|
41 return 10; |
|
42 }); |
|
43 |
|
44 |
|
45 // The following always-throw getter is to stop unshift from doing |
|
46 // 2^32 iterations. |
|
47 var toStop = "stringToStop"; |
|
48 a[N - 3] = 0; |
|
49 a.__defineGetter__(N - 3, function() { throw toStop; }); |
|
50 |
|
51 var good = false; |
|
52 |
|
53 try { |
|
54 a.unshift(1); |
|
55 } catch (e) { |
|
56 if (e === toStop) |
|
57 good = true; |
|
58 } |
|
59 |
|
60 expect = true; |
|
61 actual = good; |
|
62 |
|
63 reportCompare(expect, actual, summary); |
|
64 |
|
65 print('Done'); |
|
66 |
|
67 exitFunc ('test'); |
|
68 } |