|
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 = 422269; |
|
8 var summary = 'Compile-time let block should not capture runtime references'; |
|
9 var actual = 'referenced only by stack and closure'; |
|
10 var expect = 'referenced only by stack and closure'; |
|
11 |
|
12 |
|
13 //----------------------------------------------------------------------------- |
|
14 test(); |
|
15 |
|
16 //----------------------------------------------------------------------------- |
|
17 |
|
18 function test() |
|
19 { |
|
20 enterFunc ('test'); |
|
21 printBugNumber(BUGNUMBER); |
|
22 printStatus (summary); |
|
23 |
|
24 function f() |
|
25 { |
|
26 let m = {sin: Math.sin}; |
|
27 (function holder() { m.sin(1); })(); |
|
28 return m; |
|
29 } |
|
30 |
|
31 if (typeof findReferences == 'undefined') |
|
32 { |
|
33 expect = actual = 'Test skipped'; |
|
34 print('Test skipped. Requires findReferences function.'); |
|
35 } |
|
36 else |
|
37 { |
|
38 var x = f(); |
|
39 var refs = findReferences(x); |
|
40 |
|
41 // At this point, x should only be referenced from the stack --- the |
|
42 // variable 'x' itself, and any random things the conservative scanner |
|
43 // finds --- and possibly from the 'holder' closure, which could itself |
|
44 // be held alive for random reasons. Remove those from the refs list, and |
|
45 // then complain if anything is left. |
|
46 for (var edge in refs) { |
|
47 // Remove references from roots, like the stack. |
|
48 if (refs[edge].every(function (r) r === null)) |
|
49 delete refs[edge]; |
|
50 // Remove references from the closure, which could be held alive for |
|
51 // random reasons. |
|
52 else if (refs[edge].length === 1 && |
|
53 typeof refs[edge][0] === "function" && |
|
54 refs[edge][0].name === "holder") |
|
55 delete refs[edge]; |
|
56 } |
|
57 |
|
58 if (Object.keys(refs).length != 0) |
|
59 actual = "unexpected references to the result of f: " + Object.keys(refs).join(", "); |
|
60 } |
|
61 reportCompare(expect, actual, summary); |
|
62 |
|
63 exitFunc ('test'); |
|
64 } |