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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 } | 344 } |
| 345 return objectId; | 345 return objectId; |
| 346 }, | 346 }, |
| 347 | 347 |
| 348 /** | 348 /** |
| 349 * @param {string} objectId | 349 * @param {string} objectId |
| 350 * @return {!Object} | 350 * @return {!Object} |
| 351 */ | 351 */ |
| 352 _parseObjectId: function(objectId) | 352 _parseObjectId: function(objectId) |
| 353 { | 353 { |
| 354 return nullifyObjectProto(InjectedScriptHost.evaluate("(" + objectId + " )")); | 354 return nullifyObjectProto(this._evaluateOrThrow("(" + objectId + ")")); |
| 355 }, | 355 }, |
| 356 | 356 |
| 357 /** | 357 /** |
| 358 * @param {string} objectGroupName | 358 * @param {string} objectGroupName |
| 359 */ | 359 */ |
| 360 releaseObjectGroup: function(objectGroupName) | 360 releaseObjectGroup: function(objectGroupName) |
| 361 { | 361 { |
| 362 var group = this._objectGroups[objectGroupName]; | 362 var group = this._objectGroups[objectGroupName]; |
| 363 if (!group) | 363 if (!group) |
| 364 return; | 364 return; |
| 365 for (var i = 0; i < group.length; i++) | 365 for (var i = 0; i < group.length; i++) |
| 366 this._releaseObject(group[i]); | 366 this._releaseObject(group[i]); |
| 367 delete this._objectGroups[objectGroupName]; | 367 delete this._objectGroups[objectGroupName]; |
| 368 }, | 368 }, |
| 369 | 369 |
| 370 /** | 370 /** |
| 371 * @param {string} methodName | 371 * @param {string} methodName |
| 372 * @param {string} args | 372 * @param {string} args |
| 373 * @return {*} | 373 * @return {*} |
| 374 */ | 374 */ |
| 375 dispatch: function(methodName, args) | 375 dispatch: function(methodName, args) |
| 376 { | 376 { |
| 377 var argsArray = InjectedScriptHost.evaluate("(" + args + ")"); | 377 var argsArray = this._evaluateOrThrow("(" + args + ")"); |
| 378 var result = this[methodName].apply(this, argsArray); | 378 var result = this[methodName].apply(this, argsArray); |
| 379 if (typeof result === "undefined") { | 379 if (typeof result === "undefined") { |
| 380 inspectedWindow.console.error("Web Inspector error: InjectedScript.% s returns undefined", methodName); | 380 inspectedWindow.console.error("Web Inspector error: InjectedScript.% s returns undefined", methodName); |
| 381 result = null; | 381 result = null; |
| 382 } | 382 } |
| 383 return result; | 383 return result; |
| 384 }, | 384 }, |
| 385 | 385 |
| 386 /** | 386 /** |
| 387 * @param {string} objectId | 387 * @param {string} objectId |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 */ | 590 */ |
| 591 callFunctionOn: function(objectId, expression, args, returnByValue) | 591 callFunctionOn: function(objectId, expression, args, returnByValue) |
| 592 { | 592 { |
| 593 var parsedObjectId = this._parseObjectId(objectId); | 593 var parsedObjectId = this._parseObjectId(objectId); |
| 594 var object = this._objectForId(parsedObjectId); | 594 var object = this._objectForId(parsedObjectId); |
| 595 if (!this._isDefined(object)) | 595 if (!this._isDefined(object)) |
| 596 return "Could not find object with given id"; | 596 return "Could not find object with given id"; |
| 597 | 597 |
| 598 if (args) { | 598 if (args) { |
| 599 var resolvedArgs = []; | 599 var resolvedArgs = []; |
| 600 args = InjectedScriptHost.evaluate(args); | 600 args = this._evaluateOrThrow(args); |
| 601 for (var i = 0; i < args.length; ++i) { | 601 for (var i = 0; i < args.length; ++i) { |
| 602 try { | 602 try { |
| 603 resolvedArgs[i] = this._resolveCallArgument(args[i]); | 603 resolvedArgs[i] = this._resolveCallArgument(args[i]); |
| 604 } catch (e) { | 604 } catch (e) { |
| 605 return toString(e); | 605 return toString(e); |
| 606 } | 606 } |
| 607 } | 607 } |
| 608 } | 608 } |
| 609 | 609 |
| 610 try { | 610 try { |
| 611 var objectGroup = this._idToObjectGroupName[parsedObjectId.id]; | 611 var objectGroup = this._idToObjectGroupName[parsedObjectId.id]; |
| 612 var func = InjectedScriptHost.evaluate("(" + expression + ")"); | 612 var func = this._evaluateOrThrow("(" + expression + ")"); |
| 613 if (typeof func !== "function") | 613 if (typeof func !== "function") |
| 614 return "Given expression does not evaluate to a function"; | 614 return "Given expression does not evaluate to a function"; |
| 615 | 615 |
| 616 return { wasThrown: false, | 616 return { wasThrown: false, |
| 617 result: this._wrapObject(func.apply(object, resolvedArgs), objectGroup, returnByValue), | 617 result: this._wrapObject(func.apply(object, resolvedArgs), objectGroup, returnByValue), |
| 618 __proto__: null }; | 618 __proto__: null }; |
| 619 } catch (e) { | 619 } catch (e) { |
| 620 return this._createThrownValue(e, objectGroup); | 620 return this._createThrownValue(e, objectGroup); |
| 621 } | 621 } |
| 622 }, | 622 }, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 657 * @param {string} objectGroup | 657 * @param {string} objectGroup |
| 658 * @param {boolean} isEvalOnCallFrame | 658 * @param {boolean} isEvalOnCallFrame |
| 659 * @param {boolean} injectCommandLineAPI | 659 * @param {boolean} injectCommandLineAPI |
| 660 * @param {boolean} returnByValue | 660 * @param {boolean} returnByValue |
| 661 * @param {boolean} generatePreview | 661 * @param {boolean} generatePreview |
| 662 * @param {!Array.<!Object>=} scopeChain | 662 * @param {!Array.<!Object>=} scopeChain |
| 663 * @return {!Object} | 663 * @return {!Object} |
| 664 */ | 664 */ |
| 665 _evaluateAndWrap: function(evalFunction, object, expression, objectGroup, is EvalOnCallFrame, injectCommandLineAPI, returnByValue, generatePreview, scopeChai n) | 665 _evaluateAndWrap: function(evalFunction, object, expression, objectGroup, is EvalOnCallFrame, injectCommandLineAPI, returnByValue, generatePreview, scopeChai n) |
| 666 { | 666 { |
| 667 try { | 667 var wrappedResult = this._evaluateOn(evalFunction, object, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI, scopeChain); |
| 668 if (!wrappedResult || !wrappedResult.exceptionDetails) { | |
|
aandrey
2014/07/04 19:01:22
wrong condition. you should not throw iff wrappedR
kozyatinskiy1
2014/07/05 10:52:46
Done.
| |
| 668 return { wasThrown: false, | 669 return { wasThrown: false, |
| 669 result: this._wrapObject(this._evaluateOn(evalFunction, obj ect, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI, scopeChai n), objectGroup, returnByValue, generatePreview), | 670 result: this._wrapObject(wrappedResult.result, objectGroup, returnByValue, generatePreview), |
| 670 __proto__: null }; | 671 __proto__: null }; |
| 671 } catch (e) { | 672 } else |
|
aandrey
2014/07/04 19:01:22
we also use brackets for one-liner else- block, if
kozyatinskiy1
2014/07/05 10:52:46
Done.
| |
| 672 return this._createThrownValue(e, objectGroup); | 673 return this._createThrownValue(wrappedResult.result, objectGroup, wr appedResult.exceptionDetails); |
| 673 } | 674 }, |
| 675 | |
| 676 /** | |
| 677 * @param {string} expression | |
| 678 * @return {?} | |
| 679 */ | |
| 680 _evaluateOrThrow: function(expression) | |
| 681 { | |
| 682 var wrappedResult = InjectedScriptHost.evaluate(expression); | |
| 683 if (wrappedResult.exceptionDetails) | |
| 684 throw wrappedResult.result; | |
| 685 return wrappedResult.result; | |
| 674 }, | 686 }, |
| 675 | 687 |
| 676 /** | 688 /** |
| 677 * @param {*} value | 689 * @param {*} value |
| 678 * @param {string} objectGroup | 690 * @param {string} objectGroup |
| 691 * @param {!DebuggerAgent.ExceptionDetails=} exceptionDetails | |
| 679 * @return {!Object} | 692 * @return {!Object} |
| 680 */ | 693 */ |
| 681 _createThrownValue: function(value, objectGroup) | 694 _createThrownValue: function(value, objectGroup, exceptionDetails) |
| 682 { | 695 { |
| 683 var remoteObject = this._wrapObject(value, objectGroup); | 696 var remoteObject = this._wrapObject(value, objectGroup); |
| 684 try { | 697 try { |
| 685 remoteObject.description = toStringDescription(value); | 698 remoteObject.description = toStringDescription(value); |
| 686 } catch (e) {} | 699 } catch (e) {} |
| 687 return { wasThrown: true, result: remoteObject, __proto__: null }; | 700 return { wasThrown: true, result: remoteObject, exceptionDetails: except ionDetails, __proto__: null }; |
| 688 }, | 701 }, |
| 689 | 702 |
| 690 /** | 703 /** |
| 691 * @param {!Function} evalFunction | 704 * @param {!Function} evalFunction |
| 692 * @param {!Object} object | 705 * @param {!Object} object |
| 693 * @param {string} objectGroup | 706 * @param {string} objectGroup |
| 694 * @param {string} expression | 707 * @param {string} expression |
| 695 * @param {boolean} isEvalOnCallFrame | 708 * @param {boolean} isEvalOnCallFrame |
| 696 * @param {boolean} injectCommandLineAPI | 709 * @param {boolean} injectCommandLineAPI |
| 697 * @param {!Array.<!Object>=} scopeChain | 710 * @param {!Array.<!Object>=} scopeChain |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 765 * @param {string} callFrameId | 778 * @param {string} callFrameId |
| 766 * @param {string} expression | 779 * @param {string} expression |
| 767 * @param {string} objectGroup | 780 * @param {string} objectGroup |
| 768 * @param {boolean} injectCommandLineAPI | 781 * @param {boolean} injectCommandLineAPI |
| 769 * @param {boolean} returnByValue | 782 * @param {boolean} returnByValue |
| 770 * @param {boolean} generatePreview | 783 * @param {boolean} generatePreview |
| 771 * @return {*} | 784 * @return {*} |
| 772 */ | 785 */ |
| 773 evaluateOnCallFrame: function(topCallFrame, asyncCallStacks, callFrameId, ex pression, objectGroup, injectCommandLineAPI, returnByValue, generatePreview) | 786 evaluateOnCallFrame: function(topCallFrame, asyncCallStacks, callFrameId, ex pression, objectGroup, injectCommandLineAPI, returnByValue, generatePreview) |
| 774 { | 787 { |
| 775 var parsedCallFrameId = nullifyObjectProto(InjectedScriptHost.evaluate(" (" + callFrameId + ")")); | 788 var parsedCallFrameId = nullifyObjectProto(this._evaluateOrThrow("(" + c allFrameId + ")")); |
| 776 var callFrame = this._callFrameForParsedId(topCallFrame, parsedCallFrame Id, asyncCallStacks); | 789 var callFrame = this._callFrameForParsedId(topCallFrame, parsedCallFrame Id, asyncCallStacks); |
| 777 if (!callFrame) | 790 if (!callFrame) |
| 778 return "Could not find call frame with given id"; | 791 return "Could not find call frame with given id"; |
| 779 if (parsedCallFrameId["asyncOrdinal"]) | 792 if (parsedCallFrameId["asyncOrdinal"]) |
| 780 return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedSc riptHost, expression, objectGroup, false, injectCommandLineAPI, returnByValue, g eneratePreview, callFrame.scopeChain); | 793 return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedSc riptHost, expression, objectGroup, false, injectCommandLineAPI, returnByValue, g eneratePreview, callFrame.scopeChain); |
| 781 return this._evaluateAndWrap(callFrame.evaluate, callFrame, expression, objectGroup, true, injectCommandLineAPI, returnByValue, generatePreview); | 794 return this._evaluateAndWrap(callFrame.evaluate, callFrame, expression, objectGroup, true, injectCommandLineAPI, returnByValue, generatePreview); |
| 782 }, | 795 }, |
| 783 | 796 |
| 784 /** | 797 /** |
| 785 * @param {!Object} topCallFrame | 798 * @param {!Object} topCallFrame |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 833 setter = bind(callFrame.setVariableValue, callFrame); | 846 setter = bind(callFrame.setVariableValue, callFrame); |
| 834 } else { | 847 } else { |
| 835 var parsedFunctionId = this._parseObjectId(/** @type {string} */ (fu nctionObjectId)); | 848 var parsedFunctionId = this._parseObjectId(/** @type {string} */ (fu nctionObjectId)); |
| 836 var func = this._objectForId(parsedFunctionId); | 849 var func = this._objectForId(parsedFunctionId); |
| 837 if (typeof func !== "function") | 850 if (typeof func !== "function") |
| 838 return "Cannot resolve function by id."; | 851 return "Cannot resolve function by id."; |
| 839 setter = bind(InjectedScriptHost.setFunctionVariableValue, InjectedS criptHost, func); | 852 setter = bind(InjectedScriptHost.setFunctionVariableValue, InjectedS criptHost, func); |
| 840 } | 853 } |
| 841 var newValueJson; | 854 var newValueJson; |
| 842 try { | 855 try { |
| 843 newValueJson = InjectedScriptHost.evaluate("(" + newValueJsonString + ")"); | 856 newValueJson = this._evaluateOrThrow("(" + newValueJsonString + ")") ; |
| 844 } catch (e) { | 857 } catch (e) { |
| 845 return "Failed to parse new value JSON " + newValueJsonString + " : " + e; | 858 return "Failed to parse new value JSON " + newValueJsonString + " : " + e; |
| 846 } | 859 } |
| 847 var resolvedValue; | 860 var resolvedValue; |
| 848 try { | 861 try { |
| 849 resolvedValue = this._resolveCallArgument(newValueJson); | 862 resolvedValue = this._resolveCallArgument(newValueJson); |
| 850 } catch (e) { | 863 } catch (e) { |
| 851 return toString(e); | 864 return toString(e); |
| 852 } | 865 } |
| 853 try { | 866 try { |
| 854 setter(scopeNumber, variableName, resolvedValue); | 867 setter(scopeNumber, variableName, resolvedValue); |
| 855 } catch (e) { | 868 } catch (e) { |
| 856 return "Failed to change variable value: " + e; | 869 return "Failed to change variable value: " + e; |
| 857 } | 870 } |
| 858 return undefined; | 871 return undefined; |
| 859 }, | 872 }, |
| 860 | 873 |
| 861 /** | 874 /** |
| 862 * @param {!Object} topCallFrame | 875 * @param {!Object} topCallFrame |
| 863 * @param {string} callFrameId | 876 * @param {string} callFrameId |
| 864 * @return {?Object} | 877 * @return {?Object} |
| 865 */ | 878 */ |
| 866 _callFrameForId: function(topCallFrame, callFrameId) | 879 _callFrameForId: function(topCallFrame, callFrameId) |
| 867 { | 880 { |
| 868 var parsedCallFrameId = nullifyObjectProto(InjectedScriptHost.evaluate(" (" + callFrameId + ")")); | 881 var parsedCallFrameId = nullifyObjectProto(this._evaluateOrThrow("(" + c allFrameId + ")")); |
| 869 return this._callFrameForParsedId(topCallFrame, parsedCallFrameId, []); | 882 return this._callFrameForParsedId(topCallFrame, parsedCallFrameId, []); |
| 870 }, | 883 }, |
| 871 | 884 |
| 872 /** | 885 /** |
| 873 * @param {!Object} topCallFrame | 886 * @param {!Object} topCallFrame |
| 874 * @param {!Object} parsedCallFrameId | 887 * @param {!Object} parsedCallFrameId |
| 875 * @param {!Array.<!Object>} asyncCallStacks | 888 * @param {!Array.<!Object>} asyncCallStacks |
| 876 * @return {?Object} | 889 * @return {?Object} |
| 877 */ | 890 */ |
| 878 _callFrameForParsedId: function(topCallFrame, parsedCallFrameId, asyncCallSt acks) | 891 _callFrameForParsedId: function(topCallFrame, parsedCallFrameId, asyncCallSt acks) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 928 }, | 941 }, |
| 929 | 942 |
| 930 /** | 943 /** |
| 931 * @param {string} name | 944 * @param {string} name |
| 932 * @param {string} source | 945 * @param {string} source |
| 933 * @return {?Object} | 946 * @return {?Object} |
| 934 */ | 947 */ |
| 935 injectModule: function(name, source) | 948 injectModule: function(name, source) |
| 936 { | 949 { |
| 937 delete this._modules[name]; | 950 delete this._modules[name]; |
| 938 var moduleFunction = InjectedScriptHost.evaluate("(" + source + ")"); | 951 var moduleFunction = this._evaluateOrThrow("(" + source + ")"); |
| 939 if (typeof moduleFunction !== "function") { | 952 if (typeof moduleFunction !== "function") { |
| 940 inspectedWindow.console.error("Web Inspector error: A function was e xpected for module %s evaluation", name); | 953 inspectedWindow.console.error("Web Inspector error: A function was e xpected for module %s evaluation", name); |
| 941 return null; | 954 return null; |
| 942 } | 955 } |
| 943 var module = moduleFunction.call(inspectedWindow, InjectedScriptHost, in spectedWindow, injectedScriptId, this); | 956 var module = moduleFunction.call(inspectedWindow, InjectedScriptHost, in spectedWindow, injectedScriptId, this); |
| 944 this._modules[name] = module; | 957 this._modules[name] = module; |
| 945 return module; | 958 return module; |
| 946 }, | 959 }, |
| 947 | 960 |
| 948 /** | 961 /** |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1699 */ | 1712 */ |
| 1700 _logEvent: function(event) | 1713 _logEvent: function(event) |
| 1701 { | 1714 { |
| 1702 inspectedWindow.console.log(event.type, event); | 1715 inspectedWindow.console.log(event.type, event); |
| 1703 } | 1716 } |
| 1704 } | 1717 } |
| 1705 | 1718 |
| 1706 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); | 1719 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); |
| 1707 return injectedScript; | 1720 return injectedScript; |
| 1708 }) | 1721 }) |
| OLD | NEW |