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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/InjectedScriptSource.js

Issue 1809073003: [DevTools] Move callFunctionOn to native (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-evaluate-v2
Patch Set: Created 4 years, 9 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 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 } 639 }
640 if (ownProperties) { 640 if (ownProperties) {
641 if (object.__proto__ && !accessorPropertiesOnly) 641 if (object.__proto__ && !accessorPropertiesOnly)
642 yield { name: "__proto__", value: object.__proto__, writable : true, configurable: true, enumerable: false, isOwn: true, __proto__: null }; 642 yield { name: "__proto__", value: object.__proto__, writable : true, configurable: true, enumerable: false, isOwn: true, __proto__: null };
643 break; 643 break;
644 } 644 }
645 } 645 }
646 }, 646 },
647 647
648 /** 648 /**
649 * @param {string} objectId
650 * @param {string} expression
651 * @param {string} args
652 * @param {boolean} returnByValue
653 * @return {!Object|string}
654 */
655 callFunctionOn: function(objectId, expression, args, returnByValue)
656 {
657 var parsedObjectId = this._parseObjectId(objectId);
658 var object = this._objectForId(parsedObjectId);
659 if (!this._isDefined(object))
660 return "Could not find object with given id";
661
662 if (args) {
663 var resolvedArgs = [];
664 var callArgs = /** @type {!Array.<!RuntimeAgent.CallArgument>} */ (I njectedScriptHost.eval(args));
665 for (var i = 0; i < callArgs.length; ++i) {
666 try {
667 resolvedArgs[i] = this._resolveCallArgument(callArgs[i]);
668 } catch (e) {
669 return toString(e);
670 }
671 }
672 }
673
674 var objectGroup = InjectedScriptHost.idToObjectGroupName(parsedObjectId. id);
675
676 /**
677 * @suppressReceiverCheck
678 * @param {*} object
679 * @param {boolean=} forceValueType
680 * @param {boolean=} generatePreview
681 * @param {?Array.<string>=} columnNames
682 * @param {boolean=} isTable
683 * @param {*=} customObjectConfig
684 * @return {!RuntimeAgent.RemoteObject}
685 * @this {InjectedScript}
686 */
687 function wrap(object, forceValueType, generatePreview, columnNames, isTa ble, customObjectConfig)
688 {
689 return this._wrapObject(object, objectGroup, forceValueType, generat ePreview, columnNames, isTable, false, customObjectConfig);
690 }
691
692 try {
693
694 var remoteObjectAPI = { bindRemoteObject: bind(wrap, this), __proto_ _: null};
695 InjectedScriptHost.setNonEnumProperty(inspectedGlobalObject, "__remo teObjectAPI", remoteObjectAPI);
696
697 var func = InjectedScriptHost.eval("with (typeof __remoteObjectAPI ! == 'undefined' ? __remoteObjectAPI : { __proto__: null }) {(" + expression + ")} ");
698 if (typeof func !== "function")
699 return "Given expression does not evaluate to a function";
700
701 return { wasThrown: false,
702 result: this._wrapObject(InjectedScriptHost.callFunction(fu nc, object, resolvedArgs), objectGroup, returnByValue),
703 __proto__: null };
704 } catch (e) {
705 return this._createThrownValue(e, objectGroup, false);
706 } finally {
707 try {
708 delete inspectedGlobalObject["__remoteObjectAPI"];
709 } catch(e) {
710 }
711 }
712 },
713
714 /**
715 * @param {string|undefined} objectGroupName 649 * @param {string|undefined} objectGroupName
716 * @param {*} jsonMLObject 650 * @param {*} jsonMLObject
717 * @throws {string} error message 651 * @throws {string} error message
718 */ 652 */
719 _substituteObjectTagsInCustomPreview: function(objectGroupName, jsonMLObject ) 653 _substituteObjectTagsInCustomPreview: function(objectGroupName, jsonMLObject )
720 { 654 {
721 var maxCustomPreviewRecursionDepth = 20; 655 var maxCustomPreviewRecursionDepth = 20;
722 this._customPreviewRecursionDepth = (this._customPreviewRecursionDepth | | 0) + 1 656 this._customPreviewRecursionDepth = (this._customPreviewRecursionDepth | | 0) + 1
723 try { 657 try {
724 if (this._customPreviewRecursionDepth >= maxCustomPreviewRecursionDe pth) 658 if (this._customPreviewRecursionDepth >= maxCustomPreviewRecursionDe pth)
(...skipping 14 matching lines...) Expand all
739 } 673 }
740 674
741 for (var i = 0; i < jsonMLObject.length; ++i) 675 for (var i = 0; i < jsonMLObject.length; ++i)
742 this._substituteObjectTagsInCustomPreview(objectGroupName, jsonM LObject[i]); 676 this._substituteObjectTagsInCustomPreview(objectGroupName, jsonM LObject[i]);
743 } finally { 677 } finally {
744 this._customPreviewRecursionDepth--; 678 this._customPreviewRecursionDepth--;
745 } 679 }
746 }, 680 },
747 681
748 /** 682 /**
749 * Resolves a value from CallArgument description.
750 * @param {!RuntimeAgent.CallArgument} callArgumentJson
751 * @return {*} resolved value
752 * @throws {string} error message
753 */
754 _resolveCallArgument: function(callArgumentJson)
755 {
756 callArgumentJson = nullifyObjectProto(callArgumentJson);
757 var objectId = callArgumentJson.objectId;
758 if (objectId) {
759 var parsedArgId = this._parseObjectId(objectId);
760 if (!parsedArgId || parsedArgId["injectedScriptId"] !== injectedScri ptId)
761 throw "Arguments should belong to the same JavaScript world as t he target object.";
762
763 var resolvedArg = this._objectForId(parsedArgId);
764 if (!this._isDefined(resolvedArg))
765 throw "Could not find object with given id";
766
767 return resolvedArg;
768 } else if ("value" in callArgumentJson) {
769 var value = callArgumentJson.value;
770 if (callArgumentJson.type === "number" && typeof value !== "number")
771 value = Number(value);
772 return value;
773 }
774 return undefined;
775 },
776
777 /**
778 * @param {*} value
779 * @param {string|undefined} objectGroup
780 * @param {boolean} generatePreview
781 * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails
782 * @return {!Object}
783 */
784 _createThrownValue: function(value, objectGroup, generatePreview, exceptionD etails)
785 {
786 var remoteObject = this._wrapObject(value, objectGroup, false, generateP review && InjectedScriptHost.subtype(value) !== "error");
787 if (!remoteObject.description){
788 try {
789 remoteObject.description = toStringDescription(value);
790 } catch (e) {}
791 }
792 return { wasThrown: true, result: remoteObject, exceptionDetails: except ionDetails, __proto__: null };
793 },
794
795 /**
796 * @param {?Object} callFrame 683 * @param {?Object} callFrame
797 * @return {!Array.<!InjectedScript.CallFrameProxy>|boolean} 684 * @return {!Array.<!InjectedScript.CallFrameProxy>|boolean}
798 */ 685 */
799 wrapCallFrames: function(callFrame) 686 wrapCallFrames: function(callFrame)
800 { 687 {
801 if (!callFrame) 688 if (!callFrame)
802 return false; 689 return false;
803 690
804 var result = []; 691 var result = [];
805 var depth = 0; 692 var depth = 0;
806 do { 693 do {
807 result[depth] = new InjectedScript.CallFrameProxy(depth, callFrame); 694 result[depth] = new InjectedScript.CallFrameProxy(depth, callFrame);
808 callFrame = callFrame.caller; 695 callFrame = callFrame.caller;
809 ++depth; 696 ++depth;
810 } while (callFrame); 697 } while (callFrame);
811 return result; 698 return result;
812 }, 699 },
813 700
814 /** 701 /**
815 * @return {!CommandLineAPI} 702 * @return {!CommandLineAPI}
816 */ 703 */
817 commandLineAPI: function() 704 commandLineAPI: function()
818 { 705 {
819 return new CommandLineAPI(this._commandLineAPIImpl); 706 return new CommandLineAPI(this._commandLineAPIImpl);
820 }, 707 },
821 708
822 /** 709 /**
710 * @return {!Object}
711 */
712 remoteObjectAPI: function()
dgozman 2016/03/18 00:38:32 Should pass objectGroup. Can we have a test?
kozy 2016/03/18 06:01:55 Done.
713 {
714 /**
715 * @suppressReceiverCheck
716 * @param {*} object
717 * @param {boolean=} forceValueType
718 * @param {boolean=} generatePreview
719 * @param {?Array.<string>=} columnNames
720 * @param {boolean=} isTable
721 * @param {*=} customObjectConfig
722 * @return {!RuntimeAgent.RemoteObject}
723 * @this {InjectedScript}
724 */
725 function wrap(object, forceValueType, generatePreview, columnNames, isTa ble, customObjectConfig)
726 {
727 return this._wrapObject(object, objectGroup, forceValueType, generat ePreview, columnNames, isTable, false, customObjectConfig);
728 }
729 return { bindRemoteObject: bind(wrap, this), __proto__: null};
730 },
731
732 /**
823 * @param {!Object} objectId 733 * @param {!Object} objectId
824 * @return {!Object|symbol|undefined} 734 * @return {!Object|symbol|undefined}
825 */ 735 */
826 _objectForId: function(objectId) 736 _objectForId: function(objectId)
827 { 737 {
828 return objectId.injectedScriptId === injectedScriptId ? /** @type{!Objec t|symbol|undefined} */ (InjectedScriptHost.objectForId(objectId.id)) : void 0; 738 return objectId.injectedScriptId === injectedScriptId ? /** @type{!Objec t|symbol|undefined} */ (InjectedScriptHost.objectForId(objectId.id)) : void 0;
829 }, 739 },
830 740
831 /** 741 /**
832 * @param {*} object 742 * @param {*} object
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 */ 1638 */
1729 _logEvent: function(event) 1639 _logEvent: function(event)
1730 { 1640 {
1731 inspectedGlobalObject.console.log(event.type, event); 1641 inspectedGlobalObject.console.log(event.type, event);
1732 } 1642 }
1733 } 1643 }
1734 1644
1735 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); 1645 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl();
1736 return injectedScript; 1646 return injectedScript;
1737 }) 1647 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698