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

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

Powered by Google App Engine
This is Rietveld 408576698