OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 26 matching lines...) Expand all Loading... | |
37 | 37 |
38 for (var name in scope_expectations) { | 38 for (var name in scope_expectations) { |
39 var actual = scope_object[name]; | 39 var actual = scope_object[name]; |
40 var expected = scope_expectations[name]; | 40 var expected = scope_expectations[name]; |
41 assertEquals(expected, actual); | 41 assertEquals(expected, actual); |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 // A copy of the scope types from mirror-debugger.js. | 45 // A copy of the scope types from mirror-debugger.js. |
46 var ScopeType = { Global: 0, | 46 var ScopeType = { Global: 0, |
47 Local: 1, | 47 Script: 1, |
aandrey
2014/11/14 15:58:47
please update this also
Dmitry Lomov (no reviews)
2014/11/14 16:37:27
All updated in patch set 3
| |
48 With: 2, | 48 Local: 2, |
49 Closure: 3, | 49 With: 3, |
50 Catch: 4, | 50 Closure: 4, |
51 Block: 5 }; | 51 Catch: 5, |
52 Block: 6 }; | |
52 | 53 |
53 var f1 = (function F1(x) { | 54 var f1 = (function F1(x) { |
54 function F2(y) { | 55 function F2(y) { |
55 var z = x + y; | 56 var z = x + y; |
56 with ({w: 5, v: "Capybara"}) { | 57 with ({w: 5, v: "Capybara"}) { |
57 var F3 = function(a, b) { | 58 var F3 = function(a, b) { |
58 function F4(p) { | 59 function F4(p) { |
59 return p + a + b + z + w + v.length; | 60 return p + a + b + z + w + v.length; |
60 } | 61 } |
61 return F4; | 62 return F4; |
62 } | 63 } |
63 return F3(4, 5); | 64 return F3(4, 5); |
64 } | 65 } |
65 } | 66 } |
66 return F2(17); | 67 return F2(17); |
67 })(5); | 68 })(5); |
68 | 69 |
69 var mirror = Debug.MakeMirror(f1); | 70 var mirror = Debug.MakeMirror(f1); |
70 | 71 |
71 assertEquals(5, mirror.scopeCount()); | 72 assertEquals(6, mirror.scopeCount()); |
72 | 73 |
73 CheckScope(mirror.scope(0), { a: 4, b: 5 }, ScopeType.Closure); | 74 CheckScope(mirror.scope(0), { a: 4, b: 5 }, ScopeType.Closure); |
74 CheckScope(mirror.scope(1), { w: 5, v: "Capybara" }, ScopeType.With); | 75 CheckScope(mirror.scope(1), { w: 5, v: "Capybara" }, ScopeType.With); |
75 CheckScope(mirror.scope(2), { y: 17, z: 22 }, ScopeType.Closure); | 76 CheckScope(mirror.scope(2), { y: 17, z: 22 }, ScopeType.Closure); |
76 CheckScope(mirror.scope(3), { x: 5 }, ScopeType.Closure); | 77 CheckScope(mirror.scope(3), { x: 5 }, ScopeType.Closure); |
77 CheckScope(mirror.scope(4), {}, ScopeType.Global); | 78 CheckScope(mirror.scope(4), {}, ScopeType.Script); |
79 CheckScope(mirror.scope(5), {}, ScopeType.Global); | |
78 | 80 |
79 var f2 = function() { return 5; } | 81 var f2 = function() { return 5; } |
80 | 82 |
81 var mirror = Debug.MakeMirror(f2); | 83 var mirror = Debug.MakeMirror(f2); |
82 | 84 |
83 assertEquals(1, mirror.scopeCount()); | 85 assertEquals(2, mirror.scopeCount()); |
84 | 86 |
85 CheckScope(mirror.scope(0), {}, ScopeType.Global); | 87 CheckScope(mirror.scope(0), {}, ScopeType.Script); |
88 CheckScope(mirror.scope(1), {}, ScopeType.Global); | |
86 | 89 |
87 var f3 = (function F1(invisible_parameter) { | 90 var f3 = (function F1(invisible_parameter) { |
88 var invisible1 = 1; | 91 var invisible1 = 1; |
89 var visible1 = 10; | 92 var visible1 = 10; |
90 return (function F2() { | 93 return (function F2() { |
91 var invisible2 = 2; | 94 var invisible2 = 2; |
92 return (function F3() { | 95 return (function F3() { |
93 var visible2 = 20; | 96 var visible2 = 20; |
94 var invisible2 = 3; | 97 var invisible2 = 3; |
95 return (function () {return visible1 + visible2 + visible1a;}); | 98 return (function () {return visible1 + visible2 + visible1a;}); |
96 })(); | 99 })(); |
97 })(); | 100 })(); |
98 })(5); | 101 })(5); |
99 | 102 |
100 var mirror = Debug.MakeMirror(f3); | 103 var mirror = Debug.MakeMirror(f3); |
101 | 104 |
102 assertEquals(3, mirror.scopeCount()); | 105 assertEquals(4, mirror.scopeCount()); |
103 | 106 |
104 CheckScope(mirror.scope(0), { visible2: 20 }, ScopeType.Closure); | 107 CheckScope(mirror.scope(0), { visible2: 20 }, ScopeType.Closure); |
105 CheckScope(mirror.scope(1), { visible1: 10 }, ScopeType.Closure); | 108 CheckScope(mirror.scope(1), { visible1: 10 }, ScopeType.Closure); |
106 CheckScope(mirror.scope(2), {}, ScopeType.Global); | 109 CheckScope(mirror.scope(2), {}, ScopeType.Script); |
110 CheckScope(mirror.scope(3), {}, ScopeType.Global); | |
107 | 111 |
108 | 112 |
109 var f4 = (function One() { | 113 var f4 = (function One() { |
110 try { | 114 try { |
111 throw "I'm error 1"; | 115 throw "I'm error 1"; |
112 } catch (e1) { | 116 } catch (e1) { |
113 try { | 117 try { |
114 throw "I'm error 2"; | 118 throw "I'm error 2"; |
115 } catch (e2) { | 119 } catch (e2) { |
116 return function GetError() { | 120 return function GetError() { |
117 return e1 + e2; | 121 return e1 + e2; |
118 }; | 122 }; |
119 } | 123 } |
120 } | 124 } |
121 })(); | 125 })(); |
122 | 126 |
123 var mirror = Debug.MakeMirror(f4); | 127 var mirror = Debug.MakeMirror(f4); |
124 | 128 |
125 assertEquals(3, mirror.scopeCount()); | 129 assertEquals(4, mirror.scopeCount()); |
126 | 130 |
127 CheckScope(mirror.scope(0), { e2: "I'm error 2" }, ScopeType.Catch); | 131 CheckScope(mirror.scope(0), { e2: "I'm error 2" }, ScopeType.Catch); |
128 CheckScope(mirror.scope(1), { e1: "I'm error 1" }, ScopeType.Catch); | 132 CheckScope(mirror.scope(1), { e1: "I'm error 1" }, ScopeType.Catch); |
129 CheckScope(mirror.scope(2), {}, ScopeType.Global); | 133 CheckScope(mirror.scope(2), {}, ScopeType.Script); |
134 CheckScope(mirror.scope(3), {}, ScopeType.Global); | |
130 | 135 |
131 | 136 |
132 var f5 = (function Raz(p1, p2) { | 137 var f5 = (function Raz(p1, p2) { |
133 var p3 = p1 + p2; | 138 var p3 = p1 + p2; |
134 return (function() { | 139 return (function() { |
135 var p4 = 20; | 140 var p4 = 20; |
136 var p5 = 21; | 141 var p5 = 21; |
137 var p6 = 22; | 142 var p6 = 22; |
138 return eval("(function(p7){return p1 + p4 + p6 + p7})"); | 143 return eval("(function(p7){return p1 + p4 + p6 + p7})"); |
139 })(); | 144 })(); |
140 })(1,2); | 145 })(1,2); |
141 | 146 |
142 var mirror = Debug.MakeMirror(f5); | 147 var mirror = Debug.MakeMirror(f5); |
143 | 148 |
144 assertEquals(3, mirror.scopeCount()); | 149 assertEquals(4, mirror.scopeCount()); |
145 | 150 |
146 CheckScope(mirror.scope(0), { p4: 20, p6: 22 }, ScopeType.Closure); | 151 CheckScope(mirror.scope(0), { p4: 20, p6: 22 }, ScopeType.Closure); |
147 CheckScope(mirror.scope(1), { p1: 1 }, ScopeType.Closure); | 152 CheckScope(mirror.scope(1), { p1: 1 }, ScopeType.Closure); |
148 CheckScope(mirror.scope(2), {}, ScopeType.Global); | 153 CheckScope(mirror.scope(2), {}, ScopeType.Script); |
154 CheckScope(mirror.scope(3), {}, ScopeType.Global); | |
149 | 155 |
150 | 156 |
151 function CheckNoScopeVisible(f) { | 157 function CheckNoScopeVisible(f) { |
152 var mirror = Debug.MakeMirror(f); | 158 var mirror = Debug.MakeMirror(f); |
153 assertEquals(0, mirror.scopeCount()); | 159 assertEquals(0, mirror.scopeCount()); |
154 } | 160 } |
155 | 161 |
156 CheckNoScopeVisible(Number); | 162 CheckNoScopeVisible(Number); |
157 | 163 |
158 CheckNoScopeVisible(Function.toString); | 164 CheckNoScopeVisible(Function.toString); |
159 | 165 |
160 // This getter is known to be implemented as closure. | 166 // This getter is known to be implemented as closure. |
161 CheckNoScopeVisible(new Error().__lookupGetter__("stack")); | 167 CheckNoScopeVisible(new Error().__lookupGetter__("stack")); |
OLD | NEW |