OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 * @param {boolean} injectCommandLineAPI | 607 * @param {boolean} injectCommandLineAPI |
608 * @param {!Array.<!Object>=} scopeChain | 608 * @param {!Array.<!Object>=} scopeChain |
609 * @return {*} | 609 * @return {*} |
610 */ | 610 */ |
611 _evaluateOn: function(evalFunction, object, objectGroup, expression, isEvalO
nCallFrame, injectCommandLineAPI, scopeChain) | 611 _evaluateOn: function(evalFunction, object, objectGroup, expression, isEvalO
nCallFrame, injectCommandLineAPI, scopeChain) |
612 { | 612 { |
613 // Only install command line api object for the time of evaluation. | 613 // Only install command line api object for the time of evaluation. |
614 // Surround the expression in with statements to inject our command line
API so that | 614 // Surround the expression in with statements to inject our command line
API so that |
615 // the window object properties still take more precedent than our API f
unctions. | 615 // the window object properties still take more precedent than our API f
unctions. |
616 | 616 |
617 var injectScopeChain = scopeChain && scopeChain.length; | 617 injectCommandLineAPI = injectCommandLineAPI && !("__commandLineAPI" in i
nspectedWindow); |
| 618 var injectScopeChain = scopeChain && scopeChain.length && !("__scopeChai
nForEval" in inspectedWindow); |
618 | 619 |
619 try { | 620 try { |
620 var prefix = ""; | 621 var prefix = ""; |
621 var suffix = ""; | 622 var suffix = ""; |
622 if (injectCommandLineAPI && inspectedWindow.console) { | 623 if (injectCommandLineAPI) { |
623 inspectedWindow.console._commandLineAPI = new CommandLineAPI(thi
s._commandLineAPIImpl, isEvalOnCallFrame ? object : null); | 624 inspectedWindow.__commandLineAPI = new CommandLineAPI(this._comm
andLineAPIImpl, isEvalOnCallFrame ? object : null); |
624 prefix = "with ((console && console._commandLineAPI) || { __prot
o__: null }) {"; | 625 prefix = "with (__commandLineAPI || { __proto__: null }) {"; |
625 suffix = "}"; | 626 suffix = "}"; |
626 } | 627 } |
627 if (injectScopeChain && inspectedWindow.console) { | 628 if (injectScopeChain) { |
628 inspectedWindow.console._scopeChainForEval = scopeChain; | 629 inspectedWindow.__scopeChainForEval = scopeChain; |
629 for (var i = 0; i < scopeChain.length; ++i) { | 630 for (var i = 0; i < scopeChain.length; ++i) { |
630 prefix = "with ((console && console._scopeChainForEval[" + i
+ "]) || { __proto__: null }) {" + (suffix ? " " : "") + prefix; | 631 prefix = "with (__scopeChainForEval[" + i + "] || { __proto_
_: null }) {" + (suffix ? " " : "") + prefix; |
631 if (suffix) | 632 if (suffix) |
632 suffix += " }"; | 633 suffix += " }"; |
633 else | 634 else |
634 suffix = "}"; | 635 suffix = "}"; |
635 } | 636 } |
636 } | 637 } |
637 | 638 |
638 if (prefix) | 639 if (prefix) |
639 expression = prefix + "\n" + expression + "\n" + suffix; | 640 expression = prefix + "\n" + expression + "\n" + suffix; |
640 var result = evalFunction.call(object, expression); | 641 var result = evalFunction.call(object, expression); |
641 if (objectGroup === "console") | 642 if (objectGroup === "console") |
642 this._lastResult = result; | 643 this._lastResult = result; |
643 return result; | 644 return result; |
644 } finally { | 645 } finally { |
645 if (injectCommandLineAPI && inspectedWindow.console) | 646 if (injectCommandLineAPI) |
646 delete inspectedWindow.console._commandLineAPI; | 647 delete inspectedWindow.__commandLineAPI; |
647 if (injectScopeChain && inspectedWindow.console) | 648 if (injectScopeChain) |
648 delete inspectedWindow.console._scopeChainForEval; | 649 delete inspectedWindow.__scopeChainForEval; |
649 } | 650 } |
650 }, | 651 }, |
651 | 652 |
652 /** | 653 /** |
653 * @param {?Object} callFrame | 654 * @param {?Object} callFrame |
654 * @param {number} asyncOrdinal | 655 * @param {number} asyncOrdinal |
655 * @return {!Array.<!InjectedScript.CallFrameProxy>|boolean} | 656 * @return {!Array.<!InjectedScript.CallFrameProxy>|boolean} |
656 */ | 657 */ |
657 wrapCallFrames: function(callFrame, asyncOrdinal) | 658 wrapCallFrames: function(callFrame, asyncOrdinal) |
658 { | 659 { |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1553 */ | 1554 */ |
1554 _logEvent: function(event) | 1555 _logEvent: function(event) |
1555 { | 1556 { |
1556 inspectedWindow.console.log(event.type, event); | 1557 inspectedWindow.console.log(event.type, event); |
1557 } | 1558 } |
1558 } | 1559 } |
1559 | 1560 |
1560 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); | 1561 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); |
1561 return injectedScript; | 1562 return injectedScript; |
1562 }) | 1563 }) |
OLD | NEW |