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 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 * @param {!Array.<!Object>=} scopeChain | 843 * @param {!Array.<!Object>=} scopeChain |
844 * @return {*} | 844 * @return {*} |
845 */ | 845 */ |
846 _evaluateOn: function(callFrame, objectGroup, expression, injectCommandLineA
PI, scopeChain) | 846 _evaluateOn: function(callFrame, objectGroup, expression, injectCommandLineA
PI, scopeChain) |
847 { | 847 { |
848 // Only install command line api object for the time of evaluation. | 848 // Only install command line api object for the time of evaluation. |
849 // Surround the expression in with statements to inject our command line
API so that | 849 // Surround the expression in with statements to inject our command line
API so that |
850 // the window object properties still take more precedent than our API f
unctions. | 850 // the window object properties still take more precedent than our API f
unctions. |
851 | 851 |
852 var scopeExtensionForEval = (callFrame && injectCommandLineAPI) ? new Co
mmandLineAPI(this._commandLineAPIImpl, callFrame) : undefined; | 852 var scopeExtensionForEval = (callFrame && injectCommandLineAPI) ? new Co
mmandLineAPI(this._commandLineAPIImpl, callFrame) : undefined; |
853 | |
854 injectCommandLineAPI = !scopeExtensionForEval && !callFrame && injectCom
mandLineAPI && !("__commandLineAPI" in inspectedGlobalObject); | |
855 var injectScopeChain = scopeChain && scopeChain.length && !("__scopeChai
nForEval" in inspectedGlobalObject); | 853 var injectScopeChain = scopeChain && scopeChain.length && !("__scopeChai
nForEval" in inspectedGlobalObject); |
856 | 854 |
857 try { | 855 try { |
858 var prefix = ""; | 856 var prefix = ""; |
859 var suffix = ""; | 857 var suffix = ""; |
860 if (injectCommandLineAPI) { | |
861 InjectedScriptHost.setNonEnumProperty(inspectedGlobalObject, "__
commandLineAPI", new CommandLineAPI(this._commandLineAPIImpl, callFrame)); | |
862 prefix = "with (typeof __commandLineAPI !== 'undefined' ? __comm
andLineAPI : { __proto__: null }) {"; | |
863 suffix = "}"; | |
864 } | |
865 if (injectScopeChain) { | 858 if (injectScopeChain) { |
866 InjectedScriptHost.setNonEnumProperty(inspectedGlobalObject, "__
scopeChainForEval", scopeChain); | 859 InjectedScriptHost.setNonEnumProperty(inspectedGlobalObject, "__
scopeChainForEval", scopeChain); |
867 for (var i = 0; i < scopeChain.length; ++i) { | 860 for (var i = 0; i < scopeChain.length; ++i) { |
868 prefix = "with (typeof __scopeChainForEval !== 'undefined' ?
__scopeChainForEval[" + i + "] : { __proto__: null }) {" + (suffix ? " " : "")
+ prefix; | 861 prefix = "with (typeof __scopeChainForEval !== 'undefined' ?
__scopeChainForEval[" + i + "] : { __proto__: null }) {" + (suffix ? " " : "")
+ prefix; |
869 if (suffix) | 862 if (suffix) |
870 suffix += " }"; | 863 suffix += " }"; |
871 else | 864 else |
872 suffix = "}"; | 865 suffix = "}"; |
873 } | 866 } |
874 } | 867 } |
875 | 868 |
876 if (prefix) | 869 if (prefix) |
877 expression = prefix + "\n" + expression + "\n" + suffix; | 870 expression = prefix + "\n" + expression + "\n" + suffix; |
878 var wrappedResult = callFrame ? callFrame.evaluateWithExceptionDetai
ls(expression, scopeExtensionForEval) : InjectedScriptHost.evaluateWithException
Details(expression); | 871 var wrappedResult = callFrame ? callFrame.evaluateWithExceptionDetai
ls(expression, scopeExtensionForEval) : InjectedScriptHost.evaluateWithException
Details(expression, injectCommandLineAPI ? new CommandLineAPI(this._commandLineA
PIImpl, callFrame) : undefined); |
879 if (objectGroup === "console" && !wrappedResult.exceptionDetails) | 872 if (objectGroup === "console" && !wrappedResult.exceptionDetails) |
880 this._lastResult = wrappedResult.result; | 873 this._lastResult = wrappedResult.result; |
881 return wrappedResult; | 874 return wrappedResult; |
882 } finally { | 875 } finally { |
883 if (injectCommandLineAPI) { | |
884 try { | |
885 delete inspectedGlobalObject["__commandLineAPI"]; | |
886 } catch(e) { | |
887 } | |
888 } | |
889 if (injectScopeChain) { | 876 if (injectScopeChain) { |
890 try { | 877 try { |
891 delete inspectedGlobalObject["__scopeChainForEval"]; | 878 delete inspectedGlobalObject["__scopeChainForEval"]; |
892 } catch(e) { | 879 } catch(e) { |
893 } | 880 } |
894 } | 881 } |
895 } | 882 } |
896 }, | 883 }, |
897 | 884 |
898 /** | 885 /** |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1648 continue; | 1635 continue; |
1649 | 1636 |
1650 this.__defineGetter__("$" + i, bind(commandLineAPIImpl._inspectedObject,
commandLineAPIImpl, i)); | 1637 this.__defineGetter__("$" + i, bind(commandLineAPIImpl._inspectedObject,
commandLineAPIImpl, i)); |
1651 } | 1638 } |
1652 | 1639 |
1653 this.$_ = injectedScript._lastResult; | 1640 this.$_ = injectedScript._lastResult; |
1654 | 1641 |
1655 this.__proto__ = null; | 1642 this.__proto__ = null; |
1656 } | 1643 } |
1657 | 1644 |
1658 // NOTE: Please keep the list of API methods below snchronized to that in WebIns
pector.RuntimeModel! | 1645 // NOTE: Please keep the list of API methods below synchronized to that in WebIn
spector.RuntimeModel |
| 1646 // and V8InjectedScriptHost! |
1659 // NOTE: Argument names of these methods will be printed in the console, so use
pretty names! | 1647 // NOTE: Argument names of these methods will be printed in the console, so use
pretty names! |
1660 /** | 1648 /** |
1661 * @type {!Array.<string>} | 1649 * @type {!Array.<string>} |
1662 * @const | 1650 * @const |
1663 */ | 1651 */ |
1664 CommandLineAPI.members_ = [ | 1652 CommandLineAPI.members_ = [ |
1665 "$", "$$", "$x", "dir", "dirxml", "keys", "values", "profile", "profileEnd", | 1653 "$", "$$", "$x", "dir", "dirxml", "keys", "values", "profile", "profileEnd", |
1666 "monitorEvents", "unmonitorEvents", "inspect", "copy", "clear", "getEventLis
teners", | 1654 "monitorEvents", "unmonitorEvents", "inspect", "copy", "clear", "getEventLis
teners", |
1667 "debug", "undebug", "monitor", "unmonitor", "table" | 1655 "debug", "undebug", "monitor", "unmonitor", "table" |
1668 ]; | 1656 ]; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 */ | 1926 */ |
1939 _logEvent: function(event) | 1927 _logEvent: function(event) |
1940 { | 1928 { |
1941 inspectedGlobalObject.console.log(event.type, event); | 1929 inspectedGlobalObject.console.log(event.type, event); |
1942 } | 1930 } |
1943 } | 1931 } |
1944 | 1932 |
1945 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); | 1933 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); |
1946 return injectedScript; | 1934 return injectedScript; |
1947 }) | 1935 }) |
OLD | NEW |