| 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 | var gTestfile = 'regress-360681-02.js'; |
| 7 | //----------------------------------------------------------------------------- |
| 8 | var BUGNUMBER = 360681; |
| 9 | var summary = 'Regression from bug 224128'; |
| 10 | var actual = ''; |
| 11 | var expect = ''; |
| 12 | |
| 13 | |
| 14 | //----------------------------------------------------------------------------- |
| 15 | test(); |
| 16 | //----------------------------------------------------------------------------- |
| 17 | |
| 18 | function test() |
| 19 | { |
| 20 | enterFunc ('test'); |
| 21 | printBugNumber(BUGNUMBER); |
| 22 | printStatus (summary); |
| 23 | |
| 24 | expect = actual = 'No Crash'; |
| 25 | |
| 26 | var N = 1000; |
| 27 | |
| 28 | // Make an array with a hole at the end |
| 29 | var a = Array(N); |
| 30 | for (i = 0; i < N - 1; ++i) |
| 31 | a[i] = 1; |
| 32 | |
| 33 | // array_sort due for array with N elements with allocates a temporary vector |
| 34 | // with 2*N. Lets create strings that on 32 and 64 bit CPU cause allocation |
| 35 | // of the same amount of memory + 1 word for their char arrays. After we GC |
| 36 | // strings with a reasonable malloc implementation that memory will be most |
| 37 | // likely reused in array_sort for the temporary vector. Then the bug causes |
| 38 | // accessing the one-beyond-the-aloocation word and re-interpretation of |
| 39 | // 0xFFF0FFF0 as GC thing. |
| 40 | |
| 41 | var str1 = Array(2*(2*N + 1) + 1).join(String.fromCharCode(0xFFF0)); |
| 42 | var str2 = Array(4*(2*N + 1) + 1).join(String.fromCharCode(0xFFF0)); |
| 43 | gc(); |
| 44 | str1 = str2 = null; |
| 45 | gc(); |
| 46 | |
| 47 | var firstCall = true; |
| 48 | a.sort(function (a, b) { |
| 49 | if (firstCall) { |
| 50 | firstCall = false; |
| 51 | gc(); |
| 52 | } |
| 53 | return a - b; |
| 54 | }); |
| 55 | |
| 56 | reportCompare(expect, actual, summary); |
| 57 | |
| 58 | exitFunc ('test'); |
| 59 | } |