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