OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 25 matching lines...) Expand all Loading... | |
36 /** @type {!Map<!ScopeType, string>} */ | 36 /** @type {!Map<!ScopeType, string>} */ |
37 DebuggerScript._scopeTypeNames = new Map(); | 37 DebuggerScript._scopeTypeNames = new Map(); |
38 DebuggerScript._scopeTypeNames.set(ScopeType.Global, "global"); | 38 DebuggerScript._scopeTypeNames.set(ScopeType.Global, "global"); |
39 DebuggerScript._scopeTypeNames.set(ScopeType.Local, "local"); | 39 DebuggerScript._scopeTypeNames.set(ScopeType.Local, "local"); |
40 DebuggerScript._scopeTypeNames.set(ScopeType.With, "with"); | 40 DebuggerScript._scopeTypeNames.set(ScopeType.With, "with"); |
41 DebuggerScript._scopeTypeNames.set(ScopeType.Closure, "closure"); | 41 DebuggerScript._scopeTypeNames.set(ScopeType.Closure, "closure"); |
42 DebuggerScript._scopeTypeNames.set(ScopeType.Catch, "catch"); | 42 DebuggerScript._scopeTypeNames.set(ScopeType.Catch, "catch"); |
43 DebuggerScript._scopeTypeNames.set(ScopeType.Block, "block"); | 43 DebuggerScript._scopeTypeNames.set(ScopeType.Block, "block"); |
44 DebuggerScript._scopeTypeNames.set(ScopeType.Script, "script"); | 44 DebuggerScript._scopeTypeNames.set(ScopeType.Script, "script"); |
45 DebuggerScript._scopeTypeNames.set(ScopeType.Eval, "eval"); | 45 DebuggerScript._scopeTypeNames.set(ScopeType.Eval, "eval"); |
46 DebuggerScript._scopeTypeNames.set(ScopeType.Module, "module"); | |
46 | 47 |
47 /** | 48 /** |
48 * @param {function()} fun | 49 * @param {function()} fun |
49 * @return {?Array<!Scope>} | 50 * @return {?Array<!Scope>} |
50 */ | 51 */ |
51 DebuggerScript.getFunctionScopes = function(fun) | 52 DebuggerScript.getFunctionScopes = function(fun) |
52 { | 53 { |
53 var mirror = MakeMirror(fun); | 54 var mirror = MakeMirror(fun); |
54 if (!mirror.isFunction()) | 55 if (!mirror.isFunction()) |
55 return null; | 56 return null; |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 DebuggerScript._buildScopeObject = function(scopeType, scopeObject) | 554 DebuggerScript._buildScopeObject = function(scopeType, scopeObject) |
554 { | 555 { |
555 var result; | 556 var result; |
556 switch (scopeType) { | 557 switch (scopeType) { |
557 case ScopeType.Local: | 558 case ScopeType.Local: |
558 case ScopeType.Closure: | 559 case ScopeType.Closure: |
559 case ScopeType.Catch: | 560 case ScopeType.Catch: |
560 case ScopeType.Block: | 561 case ScopeType.Block: |
561 case ScopeType.Script: | 562 case ScopeType.Script: |
562 case ScopeType.Eval: | 563 case ScopeType.Eval: |
564 case ScopeType.Module: | |
563 // For transient objects we create a "persistent" copy that contains | 565 // For transient objects we create a "persistent" copy that contains |
564 // the same properties. | 566 // the same properties. |
565 // Reset scope object prototype to null so that the proto properties | 567 // Reset scope object prototype to null so that the proto properties |
566 // don't appear in the local scope section. | 568 // don't appear in the local scope section. |
567 var properties = /** @type {!ObjectMirror} */(MakeMirror(scopeObject, tr ue /* transient */)).properties(); | 569 var properties = /** @type {!ObjectMirror} */(MakeMirror(scopeObject, tr ue /* transient */)).properties(); |
568 // Almost always Script scope will be empty, so just filter out that noi se. | 570 // Almost always Script scope will be empty, so just filter out that noi se. |
569 // Also drop empty Block, Eval and Script scopes, should we get any. | 571 // Also drop empty Block, Eval and Script scopes, should we get any. |
jgruber
2016/12/12 13:23:48
Nit: Update comment.
| |
570 if (!properties.length && (scopeType === ScopeType.Script || | 572 if (!properties.length && (scopeType === ScopeType.Script || |
571 scopeType === ScopeType.Block || | 573 scopeType === ScopeType.Block || |
572 scopeType === ScopeType.Eval)) { | 574 scopeType === ScopeType.Eval || |
575 scopeType === ScopeType.Module)) { | |
573 break; | 576 break; |
574 } | 577 } |
575 result = { __proto__: null }; | 578 result = { __proto__: null }; |
576 for (var j = 0; j < properties.length; j++) { | 579 for (var j = 0; j < properties.length; j++) { |
577 var name = properties[j].name(); | 580 var name = properties[j].name(); |
578 if (name.length === 0 || name.charAt(0) === ".") | 581 if (name.length === 0 || name.charAt(0) === ".") |
579 continue; // Skip internal variables like ".arguments" and varia bles with empty name | 582 continue; // Skip internal variables like ".arguments" and varia bles with empty name |
580 result[name] = properties[j].value_; | 583 result[name] = properties[j].value_; |
581 } | 584 } |
582 break; | 585 break; |
583 case ScopeType.Global: | 586 case ScopeType.Global: |
584 case ScopeType.With: | 587 case ScopeType.With: |
585 result = scopeObject; | 588 result = scopeObject; |
586 break; | 589 break; |
587 } | 590 } |
588 return result; | 591 return result; |
589 } | 592 } |
590 | 593 |
591 // We never resolve Mirror by its handle so to avoid memory leaks caused by Mirr ors in the cache we disable it. | 594 // We never resolve Mirror by its handle so to avoid memory leaks caused by Mirr ors in the cache we disable it. |
592 ToggleMirrorCache(false); | 595 ToggleMirrorCache(false); |
593 | 596 |
594 return DebuggerScript; | 597 return DebuggerScript; |
595 })(); | 598 })(); |
OLD | NEW |