Chromium Code Reviews| 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; |
|
pfeldman
2016/01/22 18:26:30
Can we fix this as well?
kozy
2016/01/22 19:48:23
Yes, I'd like to make it in separate CL. Because w
| |
| 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 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1938 */ | 1925 */ |
| 1939 _logEvent: function(event) | 1926 _logEvent: function(event) |
| 1940 { | 1927 { |
| 1941 inspectedGlobalObject.console.log(event.type, event); | 1928 inspectedGlobalObject.console.log(event.type, event); |
| 1942 } | 1929 } |
| 1943 } | 1930 } |
| 1944 | 1931 |
| 1945 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); | 1932 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); |
| 1946 return injectedScript; | 1933 return injectedScript; |
| 1947 }) | 1934 }) |
| OLD | NEW |