1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_8/extensions/regress-394709.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,60 @@ 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 = 394709; 1.11 +var summary = 'Do not leak with object.watch and closure'; 1.12 +var actual = 'No Leak'; 1.13 +var expect = 'No Leak'; 1.14 + 1.15 +if (typeof countHeap == 'undefined') 1.16 +{ 1.17 + countHeap = function () { 1.18 + print('This test requires countHeap which is not supported'); 1.19 + return 0; 1.20 + }; 1.21 +} 1.22 + 1.23 +//----------------------------------------------------------------------------- 1.24 +test(); 1.25 +//----------------------------------------------------------------------------- 1.26 + 1.27 +function test() 1.28 +{ 1.29 + enterFunc ('test'); 1.30 + printBugNumber(BUGNUMBER); 1.31 + printStatus (summary); 1.32 + 1.33 + // Ensure that we flush all values so that gc() collects all objects that 1.34 + // the user cannot reach from JS. 1.35 + eval(); 1.36 + 1.37 + runtest(); 1.38 + gc(); 1.39 + var count1 = countHeap(); 1.40 + runtest(); 1.41 + gc(); 1.42 + var count2 = countHeap(); 1.43 + runtest(); 1.44 + gc(); 1.45 + var count3 = countHeap(); 1.46 + /* Try to be tolerant of conservative GC noise: we want a steady leak. */ 1.47 + if (count1 < count2 && count2 < count3) 1.48 + throw "A leaky watch point is detected"; 1.49 + 1.50 + function runtest () { 1.51 + var obj = { b: 0 }; 1.52 + obj.watch('b', watcher); 1.53 + 1.54 + function watcher(id, old, value) { 1.55 + ++obj.n; 1.56 + return value; 1.57 + } 1.58 + } 1.59 + 1.60 + reportCompare(expect, actual, summary); 1.61 + 1.62 + exitFunc ('test'); 1.63 +}