Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: Source/core/inspector/InjectedScriptSource.js

Issue 289423002: DevTools: added injectedScript.evaluateWithDetails, that return exception details if it occured (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/bindings/core/v8/custom/V8InjectedScriptHostCustom.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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._injectedScriptHostEvaluateThrowable("(" + 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._injectedScriptHostEvaluateThrowable("(" + 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 /** 571 /**
572 * @param {string} expression 572 * @param {string} expression
573 * @param {string} objectGroup 573 * @param {string} objectGroup
574 * @param {boolean} injectCommandLineAPI 574 * @param {boolean} injectCommandLineAPI
575 * @param {boolean} returnByValue 575 * @param {boolean} returnByValue
576 * @param {boolean} generatePreview 576 * @param {boolean} generatePreview
577 * @return {*} 577 * @return {*}
578 */ 578 */
579 evaluate: function(expression, objectGroup, injectCommandLineAPI, returnByVa lue, generatePreview) 579 evaluate: function(expression, objectGroup, injectCommandLineAPI, returnByVa lue, generatePreview)
580 { 580 {
581 return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedScript Host, expression, objectGroup, false, injectCommandLineAPI, returnByValue, gener atePreview); 581 return this._evaluateAndWrapWithDetails(InjectedScriptHost.evaluate, Inj ectedScriptHost, expression, objectGroup, false, injectCommandLineAPI, returnByV alue, generatePreview);
582 }, 582 },
583 583
584 /** 584 /**
585 * @param {string} objectId 585 * @param {string} objectId
586 * @param {string} expression 586 * @param {string} expression
587 * @param {string} args 587 * @param {string} args
588 * @param {boolean} returnByValue 588 * @param {boolean} returnByValue
589 * @return {!Object|string} 589 * @return {!Object|string}
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._injectedScriptHostEvaluateThrowable(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 = InjectedScriptHost.evaluate("(" + expression + ")");
613 if (func.exceptionDetails)
vsevik 2014/07/04 06:54:58 Everything except func.apply could me moved out of
614 return this._createThrownValue(func.result, objectGroup, func.ex ceptionDetails);
615 func = func.result;
613 if (typeof func !== "function") 616 if (typeof func !== "function")
614 return "Given expression does not evaluate to a function"; 617 return "Given expression does not evaluate to a function";
615 618
616 return { wasThrown: false, 619 return { wasThrown: false,
617 result: this._wrapObject(func.apply(object, resolvedArgs), objectGroup, returnByValue), 620 result: this._wrapObject(func.apply(object, resolvedArgs), objectGroup, returnByValue),
618 __proto__: null }; 621 __proto__: null };
619 } catch (e) { 622 } catch (e) {
620 return this._createThrownValue(e, objectGroup); 623 return this._createThrownValue(e, objectGroup);
621 } 624 }
622 }, 625 },
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 * @param {!Object} object 658 * @param {!Object} object
656 * @param {string} expression 659 * @param {string} expression
657 * @param {string} objectGroup 660 * @param {string} objectGroup
658 * @param {boolean} isEvalOnCallFrame 661 * @param {boolean} isEvalOnCallFrame
659 * @param {boolean} injectCommandLineAPI 662 * @param {boolean} injectCommandLineAPI
660 * @param {boolean} returnByValue 663 * @param {boolean} returnByValue
661 * @param {boolean} generatePreview 664 * @param {boolean} generatePreview
662 * @param {!Array.<!Object>=} scopeChain 665 * @param {!Array.<!Object>=} scopeChain
663 * @return {!Object} 666 * @return {!Object}
664 */ 667 */
665 _evaluateAndWrap: function(evalFunction, object, expression, objectGroup, is EvalOnCallFrame, injectCommandLineAPI, returnByValue, generatePreview, scopeChai n) 668 _evaluateAndWrap: function(evalFunction, object, expression, objectGroup, is EvalOnCallFrame, injectCommandLineAPI, returnByValue, generatePreview, scopeChai n)
vsevik 2014/07/04 06:54:58 Now that this one is only called for evaluation on
666 { 669 {
667 try { 670 try {
668 return { wasThrown: false, 671 return { wasThrown: false,
669 result: this._wrapObject(this._evaluateOn(evalFunction, obj ect, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI, scopeChai n), objectGroup, returnByValue, generatePreview), 672 result: this._wrapObject(this._evaluateOn(evalFunction, obj ect, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI, scopeChai n), objectGroup, returnByValue, generatePreview),
670 __proto__: null }; 673 __proto__: null };
671 } catch (e) { 674 } catch (e) {
672 return this._createThrownValue(e, objectGroup); 675 return this._createThrownValue(e, objectGroup);
673 } 676 }
674 }, 677 },
675 678
676 /** 679 /**
680 * @param {!Function} evalFunction
681 * @param {!Object} object
682 * @param {string} expression
683 * @param {string} objectGroup
684 * @param {boolean} isEvalOnCallFrame
685 * @param {boolean} injectCommandLineAPI
686 * @param {boolean} returnByValue
687 * @param {boolean} generatePreview
688 * @param {!Array.<!Object>=} scopeChain
689 * @return {!Object}
690 */
691 _evaluateAndWrapWithDetails: function(evalFunction, object, expression, obje ctGroup, isEvalOnCallFrame, injectCommandLineAPI, returnByValue, generatePreview , scopeChain)
vsevik 2014/07/04 06:54:58 This one could be changed accordingly, making it _
692 {
693 var result = this._evaluateOn(evalFunction, object, objectGroup, express ion, isEvalOnCallFrame, injectCommandLineAPI, scopeChain), objectGroup, returnBy Value, generatePreview;
694 if (!result.exceptionDetails)
695 return { wasThrown: false,
696 result: this._wrapObject(result.result),
697 __proto__: null };
698 else
699 return this._createThrownValue(result.result, objectGroup, result.ex ceptionDetails);
700 },
701
702 /**
677 * @param {*} value 703 * @param {*} value
678 * @param {string} objectGroup 704 * @param {string} objectGroup
705 * @param {!Object=} exceptionDetails
679 * @return {!Object} 706 * @return {!Object}
680 */ 707 */
681 _createThrownValue: function(value, objectGroup) 708 _createThrownValue: function(value, objectGroup, exceptionDetails)
682 { 709 {
683 var remoteObject = this._wrapObject(value, objectGroup); 710 var remoteObject = this._wrapObject(value, objectGroup);
684 try { 711 try {
685 remoteObject.description = toStringDescription(value); 712 remoteObject.description = toStringDescription(value);
686 } catch (e) {} 713 } catch (e) {}
687 return { wasThrown: true, result: remoteObject, __proto__: null }; 714 return { wasThrown: true, result: remoteObject, __proto__: null, excepti onDetails: exceptionDetails, objectGroup };
688 }, 715 },
689 716
690 /** 717 /**
691 * @param {!Function} evalFunction 718 * @param {!Function} evalFunction
692 * @param {!Object} object 719 * @param {!Object} object
693 * @param {string} objectGroup 720 * @param {string} objectGroup
694 * @param {string} expression 721 * @param {string} expression
695 * @param {boolean} isEvalOnCallFrame 722 * @param {boolean} isEvalOnCallFrame
696 * @param {boolean} injectCommandLineAPI 723 * @param {boolean} injectCommandLineAPI
697 * @param {!Array.<!Object>=} scopeChain 724 * @param {!Array.<!Object>=} scopeChain
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 * @param {string} callFrameId 792 * @param {string} callFrameId
766 * @param {string} expression 793 * @param {string} expression
767 * @param {string} objectGroup 794 * @param {string} objectGroup
768 * @param {boolean} injectCommandLineAPI 795 * @param {boolean} injectCommandLineAPI
769 * @param {boolean} returnByValue 796 * @param {boolean} returnByValue
770 * @param {boolean} generatePreview 797 * @param {boolean} generatePreview
771 * @return {*} 798 * @return {*}
772 */ 799 */
773 evaluateOnCallFrame: function(topCallFrame, asyncCallStacks, callFrameId, ex pression, objectGroup, injectCommandLineAPI, returnByValue, generatePreview) 800 evaluateOnCallFrame: function(topCallFrame, asyncCallStacks, callFrameId, ex pression, objectGroup, injectCommandLineAPI, returnByValue, generatePreview)
774 { 801 {
775 var parsedCallFrameId = nullifyObjectProto(InjectedScriptHost.evaluate(" (" + callFrameId + ")")); 802 var parsedCallFrameId = nullifyObjectProto(this._injectedScriptHostEvalu ateThrowable("(" + callFrameId + ")"));
776 var callFrame = this._callFrameForParsedId(topCallFrame, parsedCallFrame Id, asyncCallStacks); 803 var callFrame = this._callFrameForParsedId(topCallFrame, parsedCallFrame Id, asyncCallStacks);
777 if (!callFrame) 804 if (!callFrame)
778 return "Could not find call frame with given id"; 805 return "Could not find call frame with given id";
779 if (parsedCallFrameId["asyncOrdinal"]) 806 if (parsedCallFrameId["asyncOrdinal"])
780 return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedSc riptHost, expression, objectGroup, false, injectCommandLineAPI, returnByValue, g eneratePreview, callFrame.scopeChain); 807 return this._evaluateAndWrapWithDetails(InjectedScriptHost.evaluate, InjectedScriptHost, expression, objectGroup, false, injectCommandLineAPI, retur nByValue, generatePreview, callFrame.scopeChain);
781 return this._evaluateAndWrap(callFrame.evaluate, callFrame, expression, objectGroup, true, injectCommandLineAPI, returnByValue, generatePreview); 808 return this._evaluateAndWrap(callFrame.evaluate, callFrame, expression, objectGroup, true, injectCommandLineAPI, returnByValue, generatePreview);
vsevik 2014/07/04 06:54:58 So we are still missing exceptionDetails in case o
782 }, 809 },
783 810
784 /** 811 /**
785 * @param {!Object} topCallFrame 812 * @param {!Object} topCallFrame
786 * @param {string} callFrameId 813 * @param {string} callFrameId
787 * @return {*} 814 * @return {*}
788 */ 815 */
789 restartFrame: function(topCallFrame, callFrameId) 816 restartFrame: function(topCallFrame, callFrameId)
790 { 817 {
791 var callFrame = this._callFrameForId(topCallFrame, callFrameId); 818 var callFrame = this._callFrameForId(topCallFrame, callFrameId);
(...skipping 15 matching lines...) Expand all
807 var callFrame = this._callFrameForId(topCallFrame, callFrameId); 834 var callFrame = this._callFrameForId(topCallFrame, callFrameId);
808 if (!callFrame) 835 if (!callFrame)
809 return "Could not find call frame with given id"; 836 return "Could not find call frame with given id";
810 var stepInPositionsUnpacked = JSON.parse(callFrame.stepInPositions); 837 var stepInPositionsUnpacked = JSON.parse(callFrame.stepInPositions);
811 if (typeof stepInPositionsUnpacked !== "object") 838 if (typeof stepInPositionsUnpacked !== "object")
812 return "Step in positions not available"; 839 return "Step in positions not available";
813 return stepInPositionsUnpacked; 840 return stepInPositionsUnpacked;
814 }, 841 },
815 842
816 /** 843 /**
844 * @param {string} expression
845 * @return {*} expression result value
846 */
847 _injectedScriptHostEvaluateThrowable: function(expression) {
vsevik 2014/07/04 06:54:59 We could probably name this one _evaluateOrThrow
848 var wrappedResult = InjectedScriptHost.evaluate(expression);
849 return wrappedResult.result;
vsevik 2014/07/04 06:54:58 Return early? :)
850 if (wrappedResult.exceptionDetails)
851 throw wrappedResult.result;
852 return wrappedResult.result;
853 },
854
855 /**
817 * Either callFrameId or functionObjectId must be specified. 856 * Either callFrameId or functionObjectId must be specified.
818 * @param {!Object} topCallFrame 857 * @param {!Object} topCallFrame
819 * @param {string|boolean} callFrameId or false 858 * @param {string|boolean} callFrameId or false
820 * @param {string|boolean} functionObjectId or false 859 * @param {string|boolean} functionObjectId or false
821 * @param {number} scopeNumber 860 * @param {number} scopeNumber
822 * @param {string} variableName 861 * @param {string} variableName
823 * @param {string} newValueJsonString RuntimeAgent.CallArgument structure se rialized as string 862 * @param {string} newValueJsonString RuntimeAgent.CallArgument structure se rialized as string
824 * @return {string|undefined} undefined if success or an error message 863 * @return {string|undefined} undefined if success or an error message
825 */ 864 */
826 setVariableValue: function(topCallFrame, callFrameId, functionObjectId, scop eNumber, variableName, newValueJsonString) 865 setVariableValue: function(topCallFrame, callFrameId, functionObjectId, scop eNumber, variableName, newValueJsonString)
827 { 866 {
828 var setter; 867 var setter;
829 if (typeof callFrameId === "string") { 868 if (typeof callFrameId === "string") {
830 var callFrame = this._callFrameForId(topCallFrame, callFrameId); 869 var callFrame = this._callFrameForId(topCallFrame, callFrameId);
831 if (!callFrame) 870 if (!callFrame)
832 return "Could not find call frame with given id"; 871 return "Could not find call frame with given id";
833 setter = bind(callFrame.setVariableValue, callFrame); 872 setter = bind(callFrame.setVariableValue, callFrame);
834 } else { 873 } else {
835 var parsedFunctionId = this._parseObjectId(/** @type {string} */ (fu nctionObjectId)); 874 var parsedFunctionId = this._parseObjectId(/** @type {string} */ (fu nctionObjectId));
836 var func = this._objectForId(parsedFunctionId); 875 var func = this._objectForId(parsedFunctionId);
837 if (typeof func !== "function") 876 if (typeof func !== "function")
838 return "Cannot resolve function by id."; 877 return "Cannot resolve function by id.";
839 setter = bind(InjectedScriptHost.setFunctionVariableValue, InjectedS criptHost, func); 878 setter = bind(InjectedScriptHost.setFunctionVariableValue, InjectedS criptHost, func);
840 } 879 }
841 var newValueJson; 880 var newValueJson;
842 try { 881 try {
843 newValueJson = InjectedScriptHost.evaluate("(" + newValueJsonString + ")"); 882 newValueJson = this._injectedScriptHostEvaluateThrowable("(" + newVa lueJsonString + ")");
844 } catch (e) { 883 } catch (e) {
845 return "Failed to parse new value JSON " + newValueJsonString + " : " + e; 884 return "Failed to parse new value JSON " + newValueJsonString + " : " + e;
846 } 885 }
847 var resolvedValue; 886 var resolvedValue;
848 try { 887 try {
849 resolvedValue = this._resolveCallArgument(newValueJson); 888 resolvedValue = this._resolveCallArgument(newValueJson);
850 } catch (e) { 889 } catch (e) {
851 return toString(e); 890 return toString(e);
852 } 891 }
853 try { 892 try {
854 setter(scopeNumber, variableName, resolvedValue); 893 setter(scopeNumber, variableName, resolvedValue);
855 } catch (e) { 894 } catch (e) {
856 return "Failed to change variable value: " + e; 895 return "Failed to change variable value: " + e;
857 } 896 }
858 return undefined; 897 return undefined;
859 }, 898 },
860 899
861 /** 900 /**
862 * @param {!Object} topCallFrame 901 * @param {!Object} topCallFrame
863 * @param {string} callFrameId 902 * @param {string} callFrameId
864 * @return {?Object} 903 * @return {?Object}
865 */ 904 */
866 _callFrameForId: function(topCallFrame, callFrameId) 905 _callFrameForId: function(topCallFrame, callFrameId)
867 { 906 {
868 var parsedCallFrameId = nullifyObjectProto(InjectedScriptHost.evaluate(" (" + callFrameId + ")")); 907 var parsedCallFrameId = nullifyObjectProto(this._injectedScriptHostEvalu ateThrowable("(" + callFrameId + ")"));
869 return this._callFrameForParsedId(topCallFrame, parsedCallFrameId, []); 908 return this._callFrameForParsedId(topCallFrame, parsedCallFrameId, []);
870 }, 909 },
871 910
872 /** 911 /**
873 * @param {!Object} topCallFrame 912 * @param {!Object} topCallFrame
874 * @param {!Object} parsedCallFrameId 913 * @param {!Object} parsedCallFrameId
875 * @param {!Array.<!Object>} asyncCallStacks 914 * @param {!Array.<!Object>} asyncCallStacks
876 * @return {?Object} 915 * @return {?Object}
877 */ 916 */
878 _callFrameForParsedId: function(topCallFrame, parsedCallFrameId, asyncCallSt acks) 917 _callFrameForParsedId: function(topCallFrame, parsedCallFrameId, asyncCallSt acks)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 }, 967 },
929 968
930 /** 969 /**
931 * @param {string} name 970 * @param {string} name
932 * @param {string} source 971 * @param {string} source
933 * @return {?Object} 972 * @return {?Object}
934 */ 973 */
935 injectModule: function(name, source) 974 injectModule: function(name, source)
936 { 975 {
937 delete this._modules[name]; 976 delete this._modules[name];
938 var moduleFunction = InjectedScriptHost.evaluate("(" + source + ")"); 977 var moduleFunction = this._injectedScriptHostEvaluateThrowable("(" + sou rce + ")");
939 if (typeof moduleFunction !== "function") { 978 if (typeof moduleFunction !== "function") {
940 inspectedWindow.console.error("Web Inspector error: A function was e xpected for module %s evaluation", name); 979 inspectedWindow.console.error("Web Inspector error: A function was e xpected for module %s evaluation", name);
941 return null; 980 return null;
942 } 981 }
943 var module = moduleFunction.call(inspectedWindow, InjectedScriptHost, in spectedWindow, injectedScriptId, this); 982 var module = moduleFunction.call(inspectedWindow, InjectedScriptHost, in spectedWindow, injectedScriptId, this);
944 this._modules[name] = module; 983 this._modules[name] = module;
945 return module; 984 return module;
946 }, 985 },
947 986
948 /** 987 /**
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 */ 1738 */
1700 _logEvent: function(event) 1739 _logEvent: function(event)
1701 { 1740 {
1702 inspectedWindow.console.log(event.type, event); 1741 inspectedWindow.console.log(event.type, event);
1703 } 1742 }
1704 } 1743 }
1705 1744
1706 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); 1745 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl();
1707 return injectedScript; 1746 return injectedScript;
1708 }) 1747 })
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/custom/V8InjectedScriptHostCustom.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698