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

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

Issue 389363002: Revert of DevTools: added injectedScript.evaluateWithDetails, that return exception (...) (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
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.eval("(" + objectId + ")")) ; 354 return nullifyObjectProto(InjectedScriptHost.evaluate("(" + 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.eval("(" + args + ")"); 377 var argsArray = InjectedScriptHost.evaluate("(" + 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.evaluateWithExceptionDet ails, InjectedScriptHost, expression, objectGroup, false, injectCommandLineAPI, returnByValue, generatePreview); 581 return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedScript Host, expression, objectGroup, false, injectCommandLineAPI, returnByValue, gener atePreview);
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.eval(args); 600 args = InjectedScriptHost.evaluate(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.eval("(" + expression + ")"); 612 var func = InjectedScriptHost.evaluate("(" + 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 var wrappedResult = this._evaluateOn(evalFunction, object, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI, scopeChain); 667 try {
668 if (!wrappedResult.exceptionDetails) {
669 return { wasThrown: false, 668 return { wasThrown: false,
670 result: this._wrapObject(wrappedResult.result, objectGroup, returnByValue, generatePreview), 669 result: this._wrapObject(this._evaluateOn(evalFunction, obj ect, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI, scopeChai n), objectGroup, returnByValue, generatePreview),
671 __proto__: null }; 670 __proto__: null };
671 } catch (e) {
672 return this._createThrownValue(e, objectGroup);
672 } 673 }
673 return this._createThrownValue(wrappedResult.result, objectGroup, wrappe dResult.exceptionDetails);
674 }, 674 },
675 675
676 /** 676 /**
677 * @param {*} value 677 * @param {*} value
678 * @param {string} objectGroup 678 * @param {string} objectGroup
679 * @param {!DebuggerAgent.ExceptionDetails=} exceptionDetails
680 * @return {!Object} 679 * @return {!Object}
681 */ 680 */
682 _createThrownValue: function(value, objectGroup, exceptionDetails) 681 _createThrownValue: function(value, objectGroup)
683 { 682 {
684 var remoteObject = this._wrapObject(value, objectGroup); 683 var remoteObject = this._wrapObject(value, objectGroup);
685 try { 684 try {
686 remoteObject.description = toStringDescription(value); 685 remoteObject.description = toStringDescription(value);
687 } catch (e) {} 686 } catch (e) {}
688 return { wasThrown: true, result: remoteObject, exceptionDetails: except ionDetails, __proto__: null }; 687 return { wasThrown: true, result: remoteObject, __proto__: null };
689 }, 688 },
690 689
691 /** 690 /**
692 * @param {!Function} evalFunction 691 * @param {!Function} evalFunction
693 * @param {!Object} object 692 * @param {!Object} object
694 * @param {string} objectGroup 693 * @param {string} objectGroup
695 * @param {string} expression 694 * @param {string} expression
696 * @param {boolean} isEvalOnCallFrame 695 * @param {boolean} isEvalOnCallFrame
697 * @param {boolean} injectCommandLineAPI 696 * @param {boolean} injectCommandLineAPI
698 * @param {!Array.<!Object>=} scopeChain 697 * @param {!Array.<!Object>=} scopeChain
(...skipping 22 matching lines...) Expand all
721 prefix = "with (__scopeChainForEval[" + i + "] || { __proto_ _: null }) {" + (suffix ? " " : "") + prefix; 720 prefix = "with (__scopeChainForEval[" + i + "] || { __proto_ _: null }) {" + (suffix ? " " : "") + prefix;
722 if (suffix) 721 if (suffix)
723 suffix += " }"; 722 suffix += " }";
724 else 723 else
725 suffix = "}"; 724 suffix = "}";
726 } 725 }
727 } 726 }
728 727
729 if (prefix) 728 if (prefix)
730 expression = prefix + "\n" + expression + "\n" + suffix; 729 expression = prefix + "\n" + expression + "\n" + suffix;
731 var wrappedResult = evalFunction.call(object, expression); 730 var result = evalFunction.call(object, expression);
732 if (objectGroup === "console" && !wrappedResult.exceptionDetails) 731 if (objectGroup === "console")
733 this._lastResult = wrappedResult.result; 732 this._lastResult = result;
734 return wrappedResult; 733 return result;
735 } finally { 734 } finally {
736 if (injectCommandLineAPI) 735 if (injectCommandLineAPI)
737 delete inspectedWindow.__commandLineAPI; 736 delete inspectedWindow.__commandLineAPI;
738 if (injectScopeChain) 737 if (injectScopeChain)
739 delete inspectedWindow.__scopeChainForEval; 738 delete inspectedWindow.__scopeChainForEval;
740 } 739 }
741 }, 740 },
742 741
743 /** 742 /**
744 * @param {?Object} callFrame 743 * @param {?Object} callFrame
(...skipping 21 matching lines...) Expand all
766 * @param {string} callFrameId 765 * @param {string} callFrameId
767 * @param {string} expression 766 * @param {string} expression
768 * @param {string} objectGroup 767 * @param {string} objectGroup
769 * @param {boolean} injectCommandLineAPI 768 * @param {boolean} injectCommandLineAPI
770 * @param {boolean} returnByValue 769 * @param {boolean} returnByValue
771 * @param {boolean} generatePreview 770 * @param {boolean} generatePreview
772 * @return {*} 771 * @return {*}
773 */ 772 */
774 evaluateOnCallFrame: function(topCallFrame, asyncCallStacks, callFrameId, ex pression, objectGroup, injectCommandLineAPI, returnByValue, generatePreview) 773 evaluateOnCallFrame: function(topCallFrame, asyncCallStacks, callFrameId, ex pression, objectGroup, injectCommandLineAPI, returnByValue, generatePreview)
775 { 774 {
776 var parsedCallFrameId = nullifyObjectProto(InjectedScriptHost.eval("(" + callFrameId + ")")); 775 var parsedCallFrameId = nullifyObjectProto(InjectedScriptHost.evaluate(" (" + callFrameId + ")"));
777 var callFrame = this._callFrameForParsedId(topCallFrame, parsedCallFrame Id, asyncCallStacks); 776 var callFrame = this._callFrameForParsedId(topCallFrame, parsedCallFrame Id, asyncCallStacks);
778 if (!callFrame) 777 if (!callFrame)
779 return "Could not find call frame with given id"; 778 return "Could not find call frame with given id";
780 if (parsedCallFrameId["asyncOrdinal"]) 779 if (parsedCallFrameId["asyncOrdinal"])
781 return this._evaluateAndWrap(InjectedScriptHost.evaluateWithExceptio nDetails, InjectedScriptHost, expression, objectGroup, false, injectCommandLineA PI, returnByValue, generatePreview, callFrame.scopeChain); 780 return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedSc riptHost, expression, objectGroup, false, injectCommandLineAPI, returnByValue, g eneratePreview, callFrame.scopeChain);
782 return this._evaluateAndWrap(callFrame.evaluateWithExceptionDetails, cal lFrame, expression, objectGroup, true, injectCommandLineAPI, returnByValue, gene ratePreview); 781 return this._evaluateAndWrap(callFrame.evaluate, callFrame, expression, objectGroup, true, injectCommandLineAPI, returnByValue, generatePreview);
783 }, 782 },
784 783
785 /** 784 /**
786 * @param {!Object} topCallFrame 785 * @param {!Object} topCallFrame
787 * @param {string} callFrameId 786 * @param {string} callFrameId
788 * @return {*} 787 * @return {*}
789 */ 788 */
790 restartFrame: function(topCallFrame, callFrameId) 789 restartFrame: function(topCallFrame, callFrameId)
791 { 790 {
792 var callFrame = this._callFrameForId(topCallFrame, callFrameId); 791 var callFrame = this._callFrameForId(topCallFrame, callFrameId);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 setter = bind(callFrame.setVariableValue, callFrame); 833 setter = bind(callFrame.setVariableValue, callFrame);
835 } else { 834 } else {
836 var parsedFunctionId = this._parseObjectId(/** @type {string} */ (fu nctionObjectId)); 835 var parsedFunctionId = this._parseObjectId(/** @type {string} */ (fu nctionObjectId));
837 var func = this._objectForId(parsedFunctionId); 836 var func = this._objectForId(parsedFunctionId);
838 if (typeof func !== "function") 837 if (typeof func !== "function")
839 return "Cannot resolve function by id."; 838 return "Cannot resolve function by id.";
840 setter = bind(InjectedScriptHost.setFunctionVariableValue, InjectedS criptHost, func); 839 setter = bind(InjectedScriptHost.setFunctionVariableValue, InjectedS criptHost, func);
841 } 840 }
842 var newValueJson; 841 var newValueJson;
843 try { 842 try {
844 newValueJson = InjectedScriptHost.eval("(" + newValueJsonString + ") "); 843 newValueJson = InjectedScriptHost.evaluate("(" + newValueJsonString + ")");
845 } catch (e) { 844 } catch (e) {
846 return "Failed to parse new value JSON " + newValueJsonString + " : " + e; 845 return "Failed to parse new value JSON " + newValueJsonString + " : " + e;
847 } 846 }
848 var resolvedValue; 847 var resolvedValue;
849 try { 848 try {
850 resolvedValue = this._resolveCallArgument(newValueJson); 849 resolvedValue = this._resolveCallArgument(newValueJson);
851 } catch (e) { 850 } catch (e) {
852 return toString(e); 851 return toString(e);
853 } 852 }
854 try { 853 try {
855 setter(scopeNumber, variableName, resolvedValue); 854 setter(scopeNumber, variableName, resolvedValue);
856 } catch (e) { 855 } catch (e) {
857 return "Failed to change variable value: " + e; 856 return "Failed to change variable value: " + e;
858 } 857 }
859 return undefined; 858 return undefined;
860 }, 859 },
861 860
862 /** 861 /**
863 * @param {!Object} topCallFrame 862 * @param {!Object} topCallFrame
864 * @param {string} callFrameId 863 * @param {string} callFrameId
865 * @return {?Object} 864 * @return {?Object}
866 */ 865 */
867 _callFrameForId: function(topCallFrame, callFrameId) 866 _callFrameForId: function(topCallFrame, callFrameId)
868 { 867 {
869 var parsedCallFrameId = nullifyObjectProto(InjectedScriptHost.eval("(" + callFrameId + ")")); 868 var parsedCallFrameId = nullifyObjectProto(InjectedScriptHost.evaluate(" (" + callFrameId + ")"));
870 return this._callFrameForParsedId(topCallFrame, parsedCallFrameId, []); 869 return this._callFrameForParsedId(topCallFrame, parsedCallFrameId, []);
871 }, 870 },
872 871
873 /** 872 /**
874 * @param {!Object} topCallFrame 873 * @param {!Object} topCallFrame
875 * @param {!Object} parsedCallFrameId 874 * @param {!Object} parsedCallFrameId
876 * @param {!Array.<!Object>} asyncCallStacks 875 * @param {!Array.<!Object>} asyncCallStacks
877 * @return {?Object} 876 * @return {?Object}
878 */ 877 */
879 _callFrameForParsedId: function(topCallFrame, parsedCallFrameId, asyncCallSt acks) 878 _callFrameForParsedId: function(topCallFrame, parsedCallFrameId, asyncCallSt acks)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 }, 928 },
930 929
931 /** 930 /**
932 * @param {string} name 931 * @param {string} name
933 * @param {string} source 932 * @param {string} source
934 * @return {?Object} 933 * @return {?Object}
935 */ 934 */
936 injectModule: function(name, source) 935 injectModule: function(name, source)
937 { 936 {
938 delete this._modules[name]; 937 delete this._modules[name];
939 var moduleFunction = InjectedScriptHost.eval("(" + source + ")"); 938 var moduleFunction = InjectedScriptHost.evaluate("(" + source + ")");
940 if (typeof moduleFunction !== "function") { 939 if (typeof moduleFunction !== "function") {
941 inspectedWindow.console.error("Web Inspector error: A function was e xpected for module %s evaluation", name); 940 inspectedWindow.console.error("Web Inspector error: A function was e xpected for module %s evaluation", name);
942 return null; 941 return null;
943 } 942 }
944 var module = moduleFunction.call(inspectedWindow, InjectedScriptHost, in spectedWindow, injectedScriptId, this); 943 var module = moduleFunction.call(inspectedWindow, InjectedScriptHost, in spectedWindow, injectedScriptId, this);
945 this._modules[name] = module; 944 this._modules[name] = module;
946 return module; 945 return module;
947 }, 946 },
948 947
949 /** 948 /**
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 */ 1692 */
1694 _logEvent: function(event) 1693 _logEvent: function(event)
1695 { 1694 {
1696 inspectedWindow.console.log(event.type, event); 1695 inspectedWindow.console.log(event.type, event);
1697 } 1696 }
1698 } 1697 }
1699 1698
1700 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); 1699 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl();
1701 return injectedScript; 1700 return injectedScript;
1702 }) 1701 })
OLDNEW
« no previous file with comments | « Source/core/inspector/InjectedScriptHost.idl ('k') | Source/core/inspector/JavaScriptCallFrame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698