OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 // Flags: --expose-debug-as debug --allow-natives-syntax |
| 29 |
| 30 // Get the Debug object exposed from the debug context global object. |
| 31 var Debug = debug.Debug; |
| 32 |
| 33 function CheckScope(scope_mirror, scope_expectations, expected_scope_type) { |
| 34 assertEquals(expected_scope_type, scope_mirror.scopeType()); |
| 35 |
| 36 var scope_object = scope_mirror.scopeObject().value(); |
| 37 |
| 38 for (var name in scope_expectations) { |
| 39 var actual = scope_object[name]; |
| 40 var expected = scope_expectations[name]; |
| 41 assertEquals(expected, actual); |
| 42 } |
| 43 } |
| 44 |
| 45 // A copy of the scope types from mirror-debugger.js. |
| 46 var ScopeType = { Global: 0, |
| 47 Local: 1, |
| 48 With: 2, |
| 49 Closure: 3, |
| 50 Catch: 4, |
| 51 Block: 5 }; |
| 52 |
| 53 var f1 = (function F1(x) { |
| 54 function F2(y) { |
| 55 var z = x + y; |
| 56 with ({w: 5, v: "Capybara"}) { |
| 57 var F3 = function(a, b) { |
| 58 function F4(p) { |
| 59 return p + a + b + z + w + v.length; |
| 60 } |
| 61 return F4; |
| 62 } |
| 63 return F3(4, 5); |
| 64 } |
| 65 } |
| 66 return F2(17); |
| 67 })(5); |
| 68 |
| 69 var mirror = Debug.MakeMirror(f1); |
| 70 |
| 71 assertEquals(5, mirror.scopeCount()); |
| 72 |
| 73 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(2), { y: 17, z: 22 }, ScopeType.Closure); |
| 76 CheckScope(mirror.scope(3), { x: 5 }, ScopeType.Closure); |
| 77 CheckScope(mirror.scope(4), {}, ScopeType.Global); |
| 78 |
| 79 var f2 = function() { return 5; } |
| 80 |
| 81 var mirror = Debug.MakeMirror(f2); |
| 82 |
| 83 assertEquals(1, mirror.scopeCount()); |
| 84 |
| 85 CheckScope(mirror.scope(0), {}, ScopeType.Global); |
| 86 |
| 87 // TODO: should we check internal functions like eval or Number? |
OLD | NEW |