| 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.exceptionDetails) |
| 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 |
| 672 return this._createThrownValue(e, objectGroup); | 673 return this._createThrownValue(wrappedResult.result, objectGroup, wr
appedResult.exceptionDetails); |
| 673 } | |
| 674 }, | 674 }, |
| 675 | 675 |
| 676 /** | 676 /** |
| 677 * @param {string} expression |
| 678 * @param {string} objectGroup |
| 679 * @param {boolean} isEvalOnCallFrame |
| 680 * @param {boolean} injectCommandLineAPI |
| 681 * @param {boolean} returnByValue |
| 682 * @param {boolean} generatePreview |
| 683 * @param {!Array.<!Object>=} scopeChain |
| 684 * @return {!Object} |
| 685 */ |
| 686 _evaluateOrThrow: function(expression, objectGroup, isEvalOnCallFrame, injec
tCommandLineAPI, returnByValue, generatePreview, scopeChain) |
| 687 { |
| 688 var wrappedResult = InjectedScriptHost.evaluate(expression); |
| 689 if (wrappedResult.exceptionDetails) |
| 690 throw wrappedResult.result; |
| 691 return wrappedResult.result; |
| 692 }, |
| 693 |
| 694 /** |
| 677 * @param {*} value | 695 * @param {*} value |
| 678 * @param {string} objectGroup | 696 * @param {string} objectGroup |
| 679 * @return {!Object} | 697 * @return {!Object} |
| 680 */ | 698 */ |
| 681 _createThrownValue: function(value, objectGroup) | 699 _createThrownValue: function(value, objectGroup, exceptionDetails) |
| 682 { | 700 { |
| 683 var remoteObject = this._wrapObject(value, objectGroup); | 701 var remoteObject = this._wrapObject(value, objectGroup); |
| 684 try { | 702 try { |
| 685 remoteObject.description = toStringDescription(value); | 703 remoteObject.description = toStringDescription(value); |
| 686 } catch (e) {} | 704 } catch (e) {} |
| 687 return { wasThrown: true, result: remoteObject, __proto__: null }; | 705 return { wasThrown: true, result: remoteObject, exceptionDetails: except
ionDetails, __proto__: null }; |
| 688 }, | 706 }, |
| 689 | 707 |
| 690 /** | 708 /** |
| 691 * @param {!Function} evalFunction | 709 * @param {!Function} evalFunction |
| 692 * @param {!Object} object | 710 * @param {!Object} object |
| 693 * @param {string} objectGroup | 711 * @param {string} objectGroup |
| 694 * @param {string} expression | 712 * @param {string} expression |
| 695 * @param {boolean} isEvalOnCallFrame | 713 * @param {boolean} isEvalOnCallFrame |
| 696 * @param {boolean} injectCommandLineAPI | 714 * @param {boolean} injectCommandLineAPI |
| 697 * @param {!Array.<!Object>=} scopeChain | 715 * @param {!Array.<!Object>=} scopeChain |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 * @param {string} callFrameId | 783 * @param {string} callFrameId |
| 766 * @param {string} expression | 784 * @param {string} expression |
| 767 * @param {string} objectGroup | 785 * @param {string} objectGroup |
| 768 * @param {boolean} injectCommandLineAPI | 786 * @param {boolean} injectCommandLineAPI |
| 769 * @param {boolean} returnByValue | 787 * @param {boolean} returnByValue |
| 770 * @param {boolean} generatePreview | 788 * @param {boolean} generatePreview |
| 771 * @return {*} | 789 * @return {*} |
| 772 */ | 790 */ |
| 773 evaluateOnCallFrame: function(topCallFrame, asyncCallStacks, callFrameId, ex
pression, objectGroup, injectCommandLineAPI, returnByValue, generatePreview) | 791 evaluateOnCallFrame: function(topCallFrame, asyncCallStacks, callFrameId, ex
pression, objectGroup, injectCommandLineAPI, returnByValue, generatePreview) |
| 774 { | 792 { |
| 775 var parsedCallFrameId = nullifyObjectProto(InjectedScriptHost.evaluate("
(" + callFrameId + ")")); | 793 var parsedCallFrameId = nullifyObjectProto(this._evaluateOrThrow("(" + c
allFrameId + ")")); |
| 776 var callFrame = this._callFrameForParsedId(topCallFrame, parsedCallFrame
Id, asyncCallStacks); | 794 var callFrame = this._callFrameForParsedId(topCallFrame, parsedCallFrame
Id, asyncCallStacks); |
| 777 if (!callFrame) | 795 if (!callFrame) |
| 778 return "Could not find call frame with given id"; | 796 return "Could not find call frame with given id"; |
| 779 if (parsedCallFrameId["asyncOrdinal"]) | 797 if (parsedCallFrameId["asyncOrdinal"]) |
| 780 return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedSc
riptHost, expression, objectGroup, false, injectCommandLineAPI, returnByValue, g
eneratePreview, callFrame.scopeChain); | 798 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); | 799 return this._evaluateAndWrap(callFrame.evaluate, callFrame, expression,
objectGroup, true, injectCommandLineAPI, returnByValue, generatePreview); |
| 782 }, | 800 }, |
| 783 | 801 |
| 784 /** | 802 /** |
| 785 * @param {!Object} topCallFrame | 803 * @param {!Object} topCallFrame |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 setter = bind(callFrame.setVariableValue, callFrame); | 851 setter = bind(callFrame.setVariableValue, callFrame); |
| 834 } else { | 852 } else { |
| 835 var parsedFunctionId = this._parseObjectId(/** @type {string} */ (fu
nctionObjectId)); | 853 var parsedFunctionId = this._parseObjectId(/** @type {string} */ (fu
nctionObjectId)); |
| 836 var func = this._objectForId(parsedFunctionId); | 854 var func = this._objectForId(parsedFunctionId); |
| 837 if (typeof func !== "function") | 855 if (typeof func !== "function") |
| 838 return "Cannot resolve function by id."; | 856 return "Cannot resolve function by id."; |
| 839 setter = bind(InjectedScriptHost.setFunctionVariableValue, InjectedS
criptHost, func); | 857 setter = bind(InjectedScriptHost.setFunctionVariableValue, InjectedS
criptHost, func); |
| 840 } | 858 } |
| 841 var newValueJson; | 859 var newValueJson; |
| 842 try { | 860 try { |
| 843 newValueJson = InjectedScriptHost.evaluate("(" + newValueJsonString
+ ")"); | 861 newValueJson = this._evaluateOrThrow("(" + newValueJsonString + ")")
; |
| 844 } catch (e) { | 862 } catch (e) { |
| 845 return "Failed to parse new value JSON " + newValueJsonString + " :
" + e; | 863 return "Failed to parse new value JSON " + newValueJsonString + " :
" + e; |
| 846 } | 864 } |
| 847 var resolvedValue; | 865 var resolvedValue; |
| 848 try { | 866 try { |
| 849 resolvedValue = this._resolveCallArgument(newValueJson); | 867 resolvedValue = this._resolveCallArgument(newValueJson); |
| 850 } catch (e) { | 868 } catch (e) { |
| 851 return toString(e); | 869 return toString(e); |
| 852 } | 870 } |
| 853 try { | 871 try { |
| 854 setter(scopeNumber, variableName, resolvedValue); | 872 setter(scopeNumber, variableName, resolvedValue); |
| 855 } catch (e) { | 873 } catch (e) { |
| 856 return "Failed to change variable value: " + e; | 874 return "Failed to change variable value: " + e; |
| 857 } | 875 } |
| 858 return undefined; | 876 return undefined; |
| 859 }, | 877 }, |
| 860 | 878 |
| 861 /** | 879 /** |
| 862 * @param {!Object} topCallFrame | 880 * @param {!Object} topCallFrame |
| 863 * @param {string} callFrameId | 881 * @param {string} callFrameId |
| 864 * @return {?Object} | 882 * @return {?Object} |
| 865 */ | 883 */ |
| 866 _callFrameForId: function(topCallFrame, callFrameId) | 884 _callFrameForId: function(topCallFrame, callFrameId) |
| 867 { | 885 { |
| 868 var parsedCallFrameId = nullifyObjectProto(InjectedScriptHost.evaluate("
(" + callFrameId + ")")); | 886 var parsedCallFrameId = nullifyObjectProto(this._evaluateOrThrow("(" + c
allFrameId + ")")); |
| 869 return this._callFrameForParsedId(topCallFrame, parsedCallFrameId, []); | 887 return this._callFrameForParsedId(topCallFrame, parsedCallFrameId, []); |
| 870 }, | 888 }, |
| 871 | 889 |
| 872 /** | 890 /** |
| 873 * @param {!Object} topCallFrame | 891 * @param {!Object} topCallFrame |
| 874 * @param {!Object} parsedCallFrameId | 892 * @param {!Object} parsedCallFrameId |
| 875 * @param {!Array.<!Object>} asyncCallStacks | 893 * @param {!Array.<!Object>} asyncCallStacks |
| 876 * @return {?Object} | 894 * @return {?Object} |
| 877 */ | 895 */ |
| 878 _callFrameForParsedId: function(topCallFrame, parsedCallFrameId, asyncCallSt
acks) | 896 _callFrameForParsedId: function(topCallFrame, parsedCallFrameId, asyncCallSt
acks) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 }, | 946 }, |
| 929 | 947 |
| 930 /** | 948 /** |
| 931 * @param {string} name | 949 * @param {string} name |
| 932 * @param {string} source | 950 * @param {string} source |
| 933 * @return {?Object} | 951 * @return {?Object} |
| 934 */ | 952 */ |
| 935 injectModule: function(name, source) | 953 injectModule: function(name, source) |
| 936 { | 954 { |
| 937 delete this._modules[name]; | 955 delete this._modules[name]; |
| 938 var moduleFunction = InjectedScriptHost.evaluate("(" + source + ")"); | 956 var moduleFunction = this._evaluateOrThrow("(" + source + ")"); |
| 939 if (typeof moduleFunction !== "function") { | 957 if (typeof moduleFunction !== "function") { |
| 940 inspectedWindow.console.error("Web Inspector error: A function was e
xpected for module %s evaluation", name); | 958 inspectedWindow.console.error("Web Inspector error: A function was e
xpected for module %s evaluation", name); |
| 941 return null; | 959 return null; |
| 942 } | 960 } |
| 943 var module = moduleFunction.call(inspectedWindow, InjectedScriptHost, in
spectedWindow, injectedScriptId, this); | 961 var module = moduleFunction.call(inspectedWindow, InjectedScriptHost, in
spectedWindow, injectedScriptId, this); |
| 944 this._modules[name] = module; | 962 this._modules[name] = module; |
| 945 return module; | 963 return module; |
| 946 }, | 964 }, |
| 947 | 965 |
| 948 /** | 966 /** |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1699 */ | 1717 */ |
| 1700 _logEvent: function(event) | 1718 _logEvent: function(event) |
| 1701 { | 1719 { |
| 1702 inspectedWindow.console.log(event.type, event); | 1720 inspectedWindow.console.log(event.type, event); |
| 1703 } | 1721 } |
| 1704 } | 1722 } |
| 1705 | 1723 |
| 1706 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); | 1724 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); |
| 1707 return injectedScript; | 1725 return injectedScript; |
| 1708 }) | 1726 }) |
| OLD | NEW |