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

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

Issue 19064004: Support re-reading scope variables in protocol and on backed. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: follow code review Created 7 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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 var descriptors = []; 332 var descriptors = [];
333 var internalProperties = InjectedScriptHost.getInternalProperties(object ); 333 var internalProperties = InjectedScriptHost.getInternalProperties(object );
334 if (internalProperties) { 334 if (internalProperties) {
335 for (var i = 0; i < internalProperties.length; i++) { 335 for (var i = 0; i < internalProperties.length; i++) {
336 var property = internalProperties[i]; 336 var property = internalProperties[i];
337 var descriptor = { 337 var descriptor = {
338 name: property.name, 338 name: property.name,
339 value: this._wrapObject(property.value, objectGroupName) 339 value: this._wrapObject(property.value, objectGroupName)
340 }; 340 };
341 descriptors.push(descriptor); 341 descriptors.push(descriptor);
342 } 342 }
343 } 343 }
344 return descriptors; 344 return descriptors;
345 }, 345 },
346 346
347 /** 347 /**
348 * @param {string} functionId 348 * @param {string} functionId
349 * @return {!DebuggerAgent.FunctionDetails|string} 349 * @return {!DebuggerAgent.FunctionDetails|string}
350 */ 350 */
351 getFunctionDetails: function(functionId) 351 getFunctionDetails: function(functionId)
352 { 352 {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 var descriptor = Object.getOwnPropertyDescriptor(/** @type { !Object} */ (o), name); 408 var descriptor = Object.getOwnPropertyDescriptor(/** @type { !Object} */ (o), name);
409 if (descriptor) { 409 if (descriptor) {
410 if (accessorPropertiesOnly && !("get" in descriptor || " set" in descriptor)) 410 if (accessorPropertiesOnly && !("get" in descriptor || " set" in descriptor))
411 continue; 411 continue;
412 } else { 412 } else {
413 // Not all bindings provide proper descriptors. Fall bac k to the writable, configurable property. 413 // Not all bindings provide proper descriptors. Fall bac k to the writable, configurable property.
414 if (accessorPropertiesOnly) 414 if (accessorPropertiesOnly)
415 continue; 415 continue;
416 try { 416 try {
417 descriptor = { name: name, value: o[name], writable: false, configurable: false, enumerable: false}; 417 descriptor = { name: name, value: o[name], writable: false, configurable: false, enumerable: false};
418 if (o === object) 418 if (o === object)
419 descriptor.isOwn = true; 419 descriptor.isOwn = true;
420 descriptors.push(descriptor); 420 descriptors.push(descriptor);
421 } catch (e) { 421 } catch (e) {
422 // Silent catch. 422 // Silent catch.
423 } 423 }
424 continue; 424 continue;
425 } 425 }
426 } catch (e) { 426 } catch (e) {
427 if (accessorPropertiesOnly) 427 if (accessorPropertiesOnly)
428 continue; 428 continue;
429 var descriptor = {}; 429 var descriptor = {};
430 descriptor.value = e; 430 descriptor.value = e;
431 descriptor.wasThrown = true; 431 descriptor.wasThrown = true;
432 } 432 }
433 433
434 descriptor.name = name; 434 descriptor.name = name;
435 if (o === object) 435 if (o === object)
436 descriptor.isOwn = true; 436 descriptor.isOwn = true;
437 descriptors.push(descriptor); 437 descriptors.push(descriptor);
438 } 438 }
439 if (ownProperties) { 439 if (ownProperties) {
440 if (object.__proto__ && !accessorPropertiesOnly) 440 if (object.__proto__ && !accessorPropertiesOnly)
441 descriptors.push({ name: "__proto__", value: object.__proto_ _, writable: true, configurable: true, enumerable: false, isOwn: true}); 441 descriptors.push({ name: "__proto__", value: object.__proto_ _, writable: true, configurable: true, enumerable: false, isOwn: true});
442 break; 442 break;
443 } 443 }
444 } 444 }
445 return descriptors; 445 return descriptors;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 var func = InjectedScriptHost.evaluate("(" + expression + ")"); 490 var func = InjectedScriptHost.evaluate("(" + expression + ")");
491 if (typeof func !== "function") 491 if (typeof func !== "function")
492 return "Given expression does not evaluate to a function"; 492 return "Given expression does not evaluate to a function";
493 493
494 return { wasThrown: false, 494 return { wasThrown: false,
495 result: this._wrapObject(func.apply(object, resolvedArgs), objectGroup, returnByValue) }; 495 result: this._wrapObject(func.apply(object, resolvedArgs), objectGroup, returnByValue) };
496 } catch (e) { 496 } catch (e) {
497 return this._createThrownValue(e, objectGroup); 497 return this._createThrownValue(e, objectGroup);
498 } 498 }
499 }, 499 },
500 500
501 /** 501 /**
502 * Resolves a value from CallArgument description. 502 * Resolves a value from CallArgument description.
503 * @param {RuntimeAgent.CallArgument} callArgumentJson 503 * @param {RuntimeAgent.CallArgument} callArgumentJson
504 * @return {*} resolved value 504 * @return {*} resolved value
505 * @throws {string} error message 505 * @throws {string} error message
506 */ 506 */
507 _resolveCallArgument: function(callArgumentJson) { 507 _resolveCallArgument: function(callArgumentJson) {
508 var objectId = callArgumentJson.objectId; 508 var objectId = callArgumentJson.objectId;
509 if (objectId) { 509 if (objectId) {
510 var parsedArgId = this._parseObjectId(objectId); 510 var parsedArgId = this._parseObjectId(objectId);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 * @param {string} callFrameId 628 * @param {string} callFrameId
629 * @return {*} 629 * @return {*}
630 */ 630 */
631 restartFrame: function(topCallFrame, callFrameId) 631 restartFrame: function(topCallFrame, callFrameId)
632 { 632 {
633 var callFrame = this._callFrameForId(topCallFrame, callFrameId); 633 var callFrame = this._callFrameForId(topCallFrame, callFrameId);
634 if (!callFrame) 634 if (!callFrame)
635 return "Could not find call frame with given id"; 635 return "Could not find call frame with given id";
636 var result = callFrame.restart(); 636 var result = callFrame.restart();
637 if (result === false) 637 if (result === false)
638 result = "Restart frame is not supported"; 638 result = "Restart frame is not supported";
639 return result; 639 return result;
640 }, 640 },
641 641
642 /** 642 /**
643 * Either callFrameId or functionObjectId must be specified. 643 * Either callFrameId or functionObjectId must be specified.
644 * @param {Object} topCallFrame 644 * @param {Object} topCallFrame
645 * @param {string|boolean} callFrameId or false 645 * @param {string|boolean} callFrameId or false
646 * @param {string|boolean} functionObjectId or false 646 * @param {string|boolean} functionObjectId or false
647 * @param {number} scopeNumber 647 * @param {number} scopeNumber
648 * @param {string} variableName 648 * @param {string} variableName
649 * @param {string} newValueJsonString RuntimeAgent.CallArgument structure se rialized as string 649 * @param {string} newValueJsonString RuntimeAgent.CallArgument structure se rialized as string
650 * @return {string|undefined} undefined if success or an error message 650 * @return {string|undefined} undefined if success or an error message
651 */ 651 */
652 setVariableValue: function(topCallFrame, callFrameId, functionObjectId, scop eNumber, variableName, newValueJsonString) 652 setVariableValue: function(topCallFrame, callFrameId, functionObjectId, scop eNumber, variableName, newValueJsonString)
653 { 653 {
654 var setter; 654 var setter;
655 if (typeof callFrameId === "string") { 655 if (typeof callFrameId === "string") {
656 var callFrame = this._callFrameForId(topCallFrame, callFrameId); 656 var callFrame = this._callFrameForId(topCallFrame, callFrameId);
657 if (!callFrame) 657 if (!callFrame)
658 return "Could not find call frame with given id"; 658 return "Could not find call frame with given id";
659 setter = callFrame.setVariableValue.bind(callFrame); 659 setter = callFrame.setVariableValue.bind(callFrame);
660 } else { 660 } else {
661 var parsedFunctionId = this._parseObjectId(/** @type {string} */ (fu nctionObjectId)); 661 var parsedFunctionId = this._parseObjectId(/** @type {string} */ (fu nctionObjectId));
662 var func = this._objectForId(parsedFunctionId); 662 var func = this._objectForId(parsedFunctionId);
663 if (typeof func !== "function") 663 if (typeof func !== "function")
664 return "Cannot resolve function by id."; 664 return "Cannot resolve function by id.";
665 setter = InjectedScriptHost.setFunctionVariableValue.bind(InjectedSc riptHost, func); 665 setter = InjectedScriptHost.setFunctionVariableValue.bind(InjectedSc riptHost, func);
666 } 666 }
667 var newValueJson; 667 var newValueJson;
668 try { 668 try {
669 newValueJson = InjectedScriptHost.evaluate("(" + newValueJsonString + ")"); 669 newValueJson = InjectedScriptHost.evaluate("(" + newValueJsonString + ")");
670 } catch (e) { 670 } catch (e) {
671 return "Failed to parse new value JSON " + newValueJsonString + " : " + e; 671 return "Failed to parse new value JSON " + newValueJsonString + " : " + e;
672 } 672 }
673 var resolvedValue; 673 var resolvedValue;
674 try { 674 try {
675 resolvedValue = this._resolveCallArgument(newValueJson); 675 resolvedValue = this._resolveCallArgument(newValueJson);
676 } catch (e) { 676 } catch (e) {
677 return String(e); 677 return String(e);
678 } 678 }
679 try { 679 try {
680 setter(scopeNumber, variableName, resolvedValue); 680 setter(scopeNumber, variableName, resolvedValue);
681 } catch (e) { 681 } catch (e) {
682 return "Failed to change variable value: " + e; 682 return "Failed to change variable value: " + e;
683 } 683 }
684 return undefined; 684 return undefined;
685 }, 685 },
686 686
687 getCallFrameScopes: function(topCallFrame, callFrameId)
688 {
689 var callFrame = this._callFrameForId(topCallFrame, callFrameId);
690 if (!callFrame)
691 return "Could not find call frame with given id";
692 callFrame.rereadScopes();
693 return InjectedScript.CallFrameProxy._wrapScopeChain(callFrame);
694 },
695
687 /** 696 /**
688 * @param {Object} topCallFrame 697 * @param {Object} topCallFrame
689 * @param {string} callFrameId 698 * @param {string} callFrameId
690 * @return {Object} 699 * @return {Object}
691 */ 700 */
692 _callFrameForId: function(topCallFrame, callFrameId) 701 _callFrameForId: function(topCallFrame, callFrameId)
693 { 702 {
694 var parsedCallFrameId = InjectedScriptHost.evaluate("(" + callFrameId + ")"); 703 var parsedCallFrameId = InjectedScriptHost.evaluate("(" + callFrameId + ")");
695 var ordinal = parsedCallFrameId["ordinal"]; 704 var ordinal = parsedCallFrameId["ordinal"];
696 var callFrame = topCallFrame; 705 var callFrame = topCallFrame;
(...skipping 29 matching lines...) Expand all
726 { 735 {
727 var object = this.findObjectById(objectId); 736 var object = this.findObjectById(objectId);
728 if (!object || this._subtype(object) !== "node") 737 if (!object || this._subtype(object) !== "node")
729 return null; 738 return null;
730 return /** @type {Node} */ (object); 739 return /** @type {Node} */ (object);
731 }, 740 },
732 741
733 /** 742 /**
734 * @param {string} name 743 * @param {string} name
735 * @return {Object} 744 * @return {Object}
736 */ 745 */
737 module: function(name) 746 module: function(name)
738 { 747 {
739 return this._modules[name]; 748 return this._modules[name];
740 }, 749 },
741 750
742 /** 751 /**
743 * @param {string} name 752 * @param {string} name
744 * @param {string} source 753 * @param {string} source
745 * @return {Object} 754 * @return {Object}
746 */ 755 */
747 injectModule: function(name, source) 756 injectModule: function(name, source)
748 { 757 {
749 delete this._modules[name]; 758 delete this._modules[name];
750 var moduleFunction = InjectedScriptHost.evaluate("(" + source + ")"); 759 var moduleFunction = InjectedScriptHost.evaluate("(" + source + ")");
751 if (typeof moduleFunction !== "function") { 760 if (typeof moduleFunction !== "function") {
752 inspectedWindow.console.error("Web Inspector error: A function was e xpected for module %s evaluation", name); 761 inspectedWindow.console.error("Web Inspector error: A function was e xpected for module %s evaluation", name);
753 return null; 762 return null;
754 } 763 }
755 var module = moduleFunction.call(inspectedWindow, InjectedScriptHost, in spectedWindow, injectedScriptId, this); 764 var module = moduleFunction.call(inspectedWindow, InjectedScriptHost, in spectedWindow, injectedScriptId, this);
756 this._modules[name] = module; 765 this._modules[name] = module;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 if (!("value" in descriptor) || !descriptor.enumerable) { 978 if (!("value" in descriptor) || !descriptor.enumerable) {
970 preview.lossless = false; 979 preview.lossless = false;
971 continue; 980 continue;
972 } 981 }
973 982
974 var value = descriptor.value; 983 var value = descriptor.value;
975 if (value === null) { 984 if (value === null) {
976 this._appendPropertyPreview(preview, { name: name, type: "ob ject", value: "null" }, propertiesThreshold); 985 this._appendPropertyPreview(preview, { name: name, type: "ob ject", value: "null" }, propertiesThreshold);
977 continue; 986 continue;
978 } 987 }
979 988
980 const maxLength = 100; 989 const maxLength = 100;
981 var type = typeof value; 990 var type = typeof value;
982 991
983 if (InjectedScript.primitiveTypes[type]) { 992 if (InjectedScript.primitiveTypes[type]) {
984 if (type === "string") { 993 if (type === "string") {
985 if (value.length > maxLength) { 994 if (value.length > maxLength) {
986 value = this._abbreviateString(value, maxLength, tru e); 995 value = this._abbreviateString(value, maxLength, tru e);
987 preview.lossless = false; 996 preview.lossless = false;
988 } 997 }
989 value = value.replace(/\n/g, "\u21B5"); 998 value = value.replace(/\n/g, "\u21B5");
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 /** 1063 /**
1055 * @constructor 1064 * @constructor
1056 * @param {number} ordinal 1065 * @param {number} ordinal
1057 * @param {Object} callFrame 1066 * @param {Object} callFrame
1058 */ 1067 */
1059 InjectedScript.CallFrameProxy = function(ordinal, callFrame) 1068 InjectedScript.CallFrameProxy = function(ordinal, callFrame)
1060 { 1069 {
1061 this.callFrameId = "{\"ordinal\":" + ordinal + ",\"injectedScriptId\":" + in jectedScriptId + "}"; 1070 this.callFrameId = "{\"ordinal\":" + ordinal + ",\"injectedScriptId\":" + in jectedScriptId + "}";
1062 this.functionName = (callFrame.type === "function" ? callFrame.functionName : ""); 1071 this.functionName = (callFrame.type === "function" ? callFrame.functionName : "");
1063 this.location = { scriptId: String(callFrame.sourceID), lineNumber: callFram e.line, columnNumber: callFrame.column }; 1072 this.location = { scriptId: String(callFrame.sourceID), lineNumber: callFram e.line, columnNumber: callFrame.column };
1064 this.scopeChain = this._wrapScopeChain(callFrame); 1073 this.scopeChain = InjectedScript.CallFrameProxy._wrapScopeChain(callFrame);
1065 this.this = injectedScript._wrapObject(callFrame.thisObject, "backtrace"); 1074 this.this = injectedScript._wrapObject(callFrame.thisObject, "backtrace");
1066 } 1075 }
1067 1076
1068 InjectedScript.CallFrameProxy.prototype = { 1077 InjectedScript.CallFrameProxy.prototype = {
1069 /** 1078 }
1070 * @param {Object} callFrame 1079
1071 * @return {!Array.<DebuggerAgent.Scope>} 1080 /**
1072 */ 1081 * @param {Object} callFrame
1073 _wrapScopeChain: function(callFrame) 1082 * @return {!Array.<DebuggerAgent.Scope>}
1074 { 1083 */
1075 var scopeChain = callFrame.scopeChain; 1084 InjectedScript.CallFrameProxy._wrapScopeChain = function(callFrame)
1076 var scopeChainProxy = []; 1085 {
1077 for (var i = 0; i < scopeChain.length; i++) { 1086 var scopeChain = callFrame.scopeChain;
1078 var scope = InjectedScript.CallFrameProxy._createScopeJson(callFrame .scopeType(i), scopeChain[i], "backtrace"); 1087 var scopeChainProxy = [];
1079 scopeChainProxy.push(scope); 1088 for (var i = 0; i < scopeChain.length; i++) {
1080 } 1089 var scope = InjectedScript.CallFrameProxy._createScopeJson(callFrame.sco peType(i), scopeChain[i], "backtrace");
1081 return scopeChainProxy; 1090 scopeChainProxy.push(scope);
1082 } 1091 }
1083 } 1092 return scopeChainProxy;
1093 };
1084 1094
1085 /** 1095 /**
1086 * @param {number} scopeTypeCode 1096 * @param {number} scopeTypeCode
1087 * @param {*} scopeObject 1097 * @param {*} scopeObject
1088 * @param {string} groupId 1098 * @param {string} groupId
1089 * @return {!DebuggerAgent.Scope} 1099 * @return {!DebuggerAgent.Scope}
1090 */ 1100 */
1091 InjectedScript.CallFrameProxy._createScopeJson = function(scopeTypeCode, scopeOb ject, groupId) { 1101 InjectedScript.CallFrameProxy._createScopeJson = function(scopeTypeCode, scopeOb ject, groupId) {
1092 const GLOBAL_SCOPE = 0; 1102 const GLOBAL_SCOPE = 0;
1093 const LOCAL_SCOPE = 1; 1103 const LOCAL_SCOPE = 1;
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 */ 1401 */
1392 _logEvent: function(event) 1402 _logEvent: function(event)
1393 { 1403 {
1394 inspectedWindow.console.log(event.type, event); 1404 inspectedWindow.console.log(event.type, event);
1395 } 1405 }
1396 } 1406 }
1397 1407
1398 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); 1408 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl();
1399 return injectedScript; 1409 return injectedScript;
1400 }) 1410 })
OLDNEW
« no previous file with comments | « Source/core/inspector/InjectedScriptExterns.js ('k') | Source/core/inspector/InspectorDebuggerAgent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698