|
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 = 394709; |
|
8 var summary = 'Do not leak with object.watch and closure'; |
|
9 var actual = 'No Leak'; |
|
10 var expect = 'No Leak'; |
|
11 |
|
12 if (typeof countHeap == 'undefined') |
|
13 { |
|
14 countHeap = function () { |
|
15 print('This test requires countHeap which is not supported'); |
|
16 return 0; |
|
17 }; |
|
18 } |
|
19 |
|
20 //----------------------------------------------------------------------------- |
|
21 test(); |
|
22 //----------------------------------------------------------------------------- |
|
23 |
|
24 function test() |
|
25 { |
|
26 enterFunc ('test'); |
|
27 printBugNumber(BUGNUMBER); |
|
28 printStatus (summary); |
|
29 |
|
30 // Ensure that we flush all values so that gc() collects all objects that |
|
31 // the user cannot reach from JS. |
|
32 eval(); |
|
33 |
|
34 runtest(); |
|
35 gc(); |
|
36 var count1 = countHeap(); |
|
37 runtest(); |
|
38 gc(); |
|
39 var count2 = countHeap(); |
|
40 runtest(); |
|
41 gc(); |
|
42 var count3 = countHeap(); |
|
43 /* Try to be tolerant of conservative GC noise: we want a steady leak. */ |
|
44 if (count1 < count2 && count2 < count3) |
|
45 throw "A leaky watch point is detected"; |
|
46 |
|
47 function runtest () { |
|
48 var obj = { b: 0 }; |
|
49 obj.watch('b', watcher); |
|
50 |
|
51 function watcher(id, old, value) { |
|
52 ++obj.n; |
|
53 return value; |
|
54 } |
|
55 } |
|
56 |
|
57 reportCompare(expect, actual, summary); |
|
58 |
|
59 exitFunc ('test'); |
|
60 } |