| 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 isPrimitiveValue: function(object) | 282 isPrimitiveValue: function(object) |
| 283 { | 283 { |
| 284 // FIXME(33716): typeof document.all is always 'undefined'. | 284 // FIXME(33716): typeof document.all is always 'undefined'. |
| 285 return InjectedScript.primitiveTypes[typeof object] && !this._isHTMLAllC
ollection(object); | 285 return InjectedScript.primitiveTypes[typeof object] && !this._isHTMLAllC
ollection(object); |
| 286 }, | 286 }, |
| 287 | 287 |
| 288 /** | 288 /** |
| 289 * @param {*} object | 289 * @param {*} object |
| 290 * @param {string} groupName | 290 * @param {string} groupName |
| 291 * @param {boolean} canAccessInspectedGlobalObject | 291 * @param {boolean} canAccessInspectedGlobalObject |
| 292 * @param {boolean} forceValueType |
| 292 * @param {boolean} generatePreview | 293 * @param {boolean} generatePreview |
| 293 * @return {!RuntimeAgent.RemoteObject} | 294 * @return {!RuntimeAgent.RemoteObject} |
| 294 */ | 295 */ |
| 295 wrapObject: function(object, groupName, canAccessInspectedGlobalObject, gene
ratePreview) | 296 wrapObject: function(object, groupName, canAccessInspectedGlobalObject, forc
eValueType, generatePreview) |
| 296 { | 297 { |
| 297 if (canAccessInspectedGlobalObject) | 298 if (canAccessInspectedGlobalObject) |
| 298 return this._wrapObject(object, groupName, false, generatePreview); | 299 return this._wrapObject(object, groupName, forceValueType, generateP
review); |
| 299 return this._fallbackWrapper(object); | 300 return this._fallbackWrapper(object); |
| 300 }, | 301 }, |
| 301 | 302 |
| 302 /** | 303 /** |
| 303 * @param {*} object | 304 * @param {*} object |
| 304 * @return {!RuntimeAgent.RemoteObject} | 305 * @return {!RuntimeAgent.RemoteObject} |
| 305 */ | 306 */ |
| 306 _fallbackWrapper: function(object) | 307 _fallbackWrapper: function(object) |
| 307 { | 308 { |
| 308 var result = { __proto__: null }; | 309 var result = { __proto__: null }; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 { | 398 { |
| 398 return nullifyObjectProto(/** @type {!Object} */ (InjectedScriptHost.eva
l("(" + objectId + ")"))); | 399 return nullifyObjectProto(/** @type {!Object} */ (InjectedScriptHost.eva
l("(" + objectId + ")"))); |
| 399 }, | 400 }, |
| 400 | 401 |
| 401 clearLastEvaluationResult: function() | 402 clearLastEvaluationResult: function() |
| 402 { | 403 { |
| 403 delete this._lastResult; | 404 delete this._lastResult; |
| 404 }, | 405 }, |
| 405 | 406 |
| 406 /** | 407 /** |
| 408 * @param {*} result |
| 409 */ |
| 410 setLastEvaluationResult: function(result) |
| 411 { |
| 412 this._lastResult = result; |
| 413 }, |
| 414 |
| 415 /** |
| 407 * @param {string} objectId | 416 * @param {string} objectId |
| 408 * @param {boolean} ownProperties | 417 * @param {boolean} ownProperties |
| 409 * @param {boolean} accessorPropertiesOnly | 418 * @param {boolean} accessorPropertiesOnly |
| 410 * @param {boolean} generatePreview | 419 * @param {boolean} generatePreview |
| 411 * @return {!Array.<!RuntimeAgent.PropertyDescriptor>|boolean} | 420 * @return {!Array.<!RuntimeAgent.PropertyDescriptor>|boolean} |
| 412 */ | 421 */ |
| 413 getProperties: function(objectId, ownProperties, accessorPropertiesOnly, gen
eratePreview) | 422 getProperties: function(objectId, ownProperties, accessorPropertiesOnly, gen
eratePreview) |
| 414 { | 423 { |
| 415 var parsedObjectId = this._parseObjectId(objectId); | 424 var parsedObjectId = this._parseObjectId(objectId); |
| 416 var object = this._objectForId(parsedObjectId); | 425 var object = this._objectForId(parsedObjectId); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 /** | 648 /** |
| 640 * @param {string} expression | 649 * @param {string} expression |
| 641 * @param {string} objectGroup | 650 * @param {string} objectGroup |
| 642 * @param {boolean} injectCommandLineAPI | 651 * @param {boolean} injectCommandLineAPI |
| 643 * @param {boolean} returnByValue | 652 * @param {boolean} returnByValue |
| 644 * @param {boolean} generatePreview | 653 * @param {boolean} generatePreview |
| 645 * @return {*} | 654 * @return {*} |
| 646 */ | 655 */ |
| 647 evaluate: function(expression, objectGroup, injectCommandLineAPI, returnByVa
lue, generatePreview) | 656 evaluate: function(expression, objectGroup, injectCommandLineAPI, returnByVa
lue, generatePreview) |
| 648 { | 657 { |
| 649 return this._evaluateAndWrap(null, expression, objectGroup, injectComman
dLineAPI, returnByValue, generatePreview); | 658 var scopeExtensionForEval = injectCommandLineAPI ? new CommandLineAPI(th
is._commandLineAPIImpl) : undefined; |
| 659 var wrappedResult = InjectedScriptHost.evaluateWithExceptionDetails(expr
ession, scopeExtensionForEval); |
| 660 if (objectGroup === "console" && !wrappedResult.exceptionDetails) |
| 661 this._lastResult = wrappedResult.result; |
| 662 if (!wrappedResult.exceptionDetails) { |
| 663 return { wasThrown: false, |
| 664 result: this._wrapObject(wrappedResult.result, objectGroup,
returnByValue, generatePreview), |
| 665 __proto__: null }; |
| 666 } |
| 667 return this._createThrownValue(wrappedResult.result, objectGroup, genera
tePreview, wrappedResult.exceptionDetails); |
| 650 }, | 668 }, |
| 651 | 669 |
| 652 /** | 670 /** |
| 653 * @param {string} objectId | 671 * @param {string} objectId |
| 654 * @param {string} expression | 672 * @param {string} expression |
| 655 * @param {string} args | 673 * @param {string} args |
| 656 * @param {boolean} returnByValue | 674 * @param {boolean} returnByValue |
| 657 * @return {!Object|string} | 675 * @return {!Object|string} |
| 658 */ | 676 */ |
| 659 callFunctionOn: function(objectId, expression, args, returnByValue) | 677 callFunctionOn: function(objectId, expression, args, returnByValue) |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 } else if ("value" in callArgumentJson) { | 790 } else if ("value" in callArgumentJson) { |
| 773 var value = callArgumentJson.value; | 791 var value = callArgumentJson.value; |
| 774 if (callArgumentJson.type === "number" && typeof value !== "number") | 792 if (callArgumentJson.type === "number" && typeof value !== "number") |
| 775 value = Number(value); | 793 value = Number(value); |
| 776 return value; | 794 return value; |
| 777 } | 795 } |
| 778 return undefined; | 796 return undefined; |
| 779 }, | 797 }, |
| 780 | 798 |
| 781 /** | 799 /** |
| 782 * @param {?JavaScriptCallFrame} callFrame | |
| 783 * @param {string} expression | |
| 784 * @param {string} objectGroup | |
| 785 * @param {boolean} injectCommandLineAPI | |
| 786 * @param {boolean} returnByValue | |
| 787 * @param {boolean} generatePreview | |
| 788 * @return {!Object} | |
| 789 */ | |
| 790 _evaluateAndWrap: function(callFrame, expression, objectGroup, injectCommand
LineAPI, returnByValue, generatePreview) | |
| 791 { | |
| 792 var wrappedResult = this._evaluateOn(callFrame, objectGroup, expression,
injectCommandLineAPI); | |
| 793 if (!wrappedResult.exceptionDetails) { | |
| 794 return { wasThrown: false, | |
| 795 result: this._wrapObject(wrappedResult.result, objectGroup,
returnByValue, generatePreview), | |
| 796 __proto__: null }; | |
| 797 } | |
| 798 return this._createThrownValue(wrappedResult.result, objectGroup, genera
tePreview, wrappedResult.exceptionDetails); | |
| 799 }, | |
| 800 | |
| 801 /** | |
| 802 * @param {*} value | 800 * @param {*} value |
| 803 * @param {string|undefined} objectGroup | 801 * @param {string|undefined} objectGroup |
| 804 * @param {boolean} generatePreview | 802 * @param {boolean} generatePreview |
| 805 * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails | 803 * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails |
| 806 * @return {!Object} | 804 * @return {!Object} |
| 807 */ | 805 */ |
| 808 _createThrownValue: function(value, objectGroup, generatePreview, exceptionD
etails) | 806 _createThrownValue: function(value, objectGroup, generatePreview, exceptionD
etails) |
| 809 { | 807 { |
| 810 var remoteObject = this._wrapObject(value, objectGroup, false, generateP
review && InjectedScriptHost.subtype(value) !== "error"); | 808 var remoteObject = this._wrapObject(value, objectGroup, false, generateP
review && InjectedScriptHost.subtype(value) !== "error"); |
| 811 if (!remoteObject.description){ | 809 if (!remoteObject.description){ |
| 812 try { | 810 try { |
| 813 remoteObject.description = toStringDescription(value); | 811 remoteObject.description = toStringDescription(value); |
| 814 } catch (e) {} | 812 } catch (e) {} |
| 815 } | 813 } |
| 816 return { wasThrown: true, result: remoteObject, exceptionDetails: except
ionDetails, __proto__: null }; | 814 return { wasThrown: true, result: remoteObject, exceptionDetails: except
ionDetails, __proto__: null }; |
| 817 }, | 815 }, |
| 818 | 816 |
| 819 /** | 817 /** |
| 820 * @param {?JavaScriptCallFrame} callFrame | |
| 821 * @param {string} objectGroup | |
| 822 * @param {string} expression | |
| 823 * @param {boolean} injectCommandLineAPI | |
| 824 * @return {*} | |
| 825 */ | |
| 826 _evaluateOn: function(callFrame, objectGroup, expression, injectCommandLineA
PI) | |
| 827 { | |
| 828 // Only install command line api object for the time of evaluation. | |
| 829 // Surround the expression in with statements to inject our command line
API so that | |
| 830 // the window object properties still take more precedent than our API f
unctions. | |
| 831 | |
| 832 var scopeExtensionForEval = (callFrame && injectCommandLineAPI) ? new Co
mmandLineAPI(this._commandLineAPIImpl, callFrame) : undefined; | |
| 833 var wrappedResult = callFrame ? callFrame.evaluateWithExceptionDetails(e
xpression, scopeExtensionForEval) : InjectedScriptHost.evaluateWithExceptionDeta
ils(expression, injectCommandLineAPI ? new CommandLineAPI(this._commandLineAPIIm
pl, callFrame) : undefined); | |
| 834 if (objectGroup === "console" && !wrappedResult.exceptionDetails) | |
| 835 this._lastResult = wrappedResult.result; | |
| 836 return wrappedResult; | |
| 837 | |
| 838 }, | |
| 839 | |
| 840 /** | |
| 841 * @param {?Object} callFrame | 818 * @param {?Object} callFrame |
| 842 * @return {!Array.<!InjectedScript.CallFrameProxy>|boolean} | 819 * @return {!Array.<!InjectedScript.CallFrameProxy>|boolean} |
| 843 */ | 820 */ |
| 844 wrapCallFrames: function(callFrame) | 821 wrapCallFrames: function(callFrame) |
| 845 { | 822 { |
| 846 if (!callFrame) | 823 if (!callFrame) |
| 847 return false; | 824 return false; |
| 848 | 825 |
| 849 var result = []; | 826 var result = []; |
| 850 var depth = 0; | 827 var depth = 0; |
| 851 do { | 828 do { |
| 852 result[depth] = new InjectedScript.CallFrameProxy(depth, callFrame); | 829 result[depth] = new InjectedScript.CallFrameProxy(depth, callFrame); |
| 853 callFrame = callFrame.caller; | 830 callFrame = callFrame.caller; |
| 854 ++depth; | 831 ++depth; |
| 855 } while (callFrame); | 832 } while (callFrame); |
| 856 return result; | 833 return result; |
| 857 }, | 834 }, |
| 858 | 835 |
| 859 /** | 836 /** |
| 860 * @param {!JavaScriptCallFrame} topCallFrame | |
| 861 * @param {string} callFrameId | |
| 862 * @param {string} expression | |
| 863 * @param {string} objectGroup | |
| 864 * @param {boolean} injectCommandLineAPI | |
| 865 * @param {boolean} returnByValue | |
| 866 * @param {boolean} generatePreview | |
| 867 * @return {*} | |
| 868 */ | |
| 869 evaluateOnCallFrame: function(topCallFrame, callFrameId, expression, objectG
roup, injectCommandLineAPI, returnByValue, generatePreview) | |
| 870 { | |
| 871 var callFrame = this._callFrameForId(topCallFrame, callFrameId); | |
| 872 if (!callFrame) | |
| 873 return "Could not find call frame with given id"; | |
| 874 return this._evaluateAndWrap(callFrame, expression, objectGroup, injectC
ommandLineAPI, returnByValue, generatePreview); | |
| 875 }, | |
| 876 | |
| 877 /** | |
| 878 * @return {!CommandLineAPI} | 837 * @return {!CommandLineAPI} |
| 879 */ | 838 */ |
| 880 commandLineAPI: function() | 839 commandLineAPI: function() |
| 881 { | 840 { |
| 882 return new CommandLineAPI(this._commandLineAPIImpl, null); | 841 return new CommandLineAPI(this._commandLineAPIImpl); |
| 883 }, | 842 }, |
| 884 | 843 |
| 885 /** | 844 /** |
| 886 * @param {!JavaScriptCallFrame} topCallFrame | 845 * @param {!JavaScriptCallFrame} topCallFrame |
| 887 * @param {string} callFrameId | 846 * @param {string} callFrameId |
| 888 * @return {?JavaScriptCallFrame} | 847 * @return {?JavaScriptCallFrame} |
| 889 */ | 848 */ |
| 890 _callFrameForId: function(topCallFrame, callFrameId) | 849 _callFrameForId: function(topCallFrame, callFrameId) |
| 891 { | 850 { |
| 892 var parsedCallFrameId = nullifyObjectProto(/** @type {!Object} */ (Injec
tedScriptHost.eval("(" + callFrameId + ")"))); | 851 var parsedCallFrameId = nullifyObjectProto(/** @type {!Object} */ (Injec
tedScriptHost.eval("(" + callFrameId + ")"))); |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1474 scope.startLocation = startLocation; | 1433 scope.startLocation = startLocation; |
| 1475 if (endLocation) | 1434 if (endLocation) |
| 1476 scope.endLocation = endLocation; | 1435 scope.endLocation = endLocation; |
| 1477 | 1436 |
| 1478 return scope; | 1437 return scope; |
| 1479 } | 1438 } |
| 1480 | 1439 |
| 1481 /** | 1440 /** |
| 1482 * @constructor | 1441 * @constructor |
| 1483 * @param {!CommandLineAPIImpl} commandLineAPIImpl | 1442 * @param {!CommandLineAPIImpl} commandLineAPIImpl |
| 1484 * @param {?JavaScriptCallFrame} callFrame | |
| 1485 */ | 1443 */ |
| 1486 function CommandLineAPI(commandLineAPIImpl, callFrame) | 1444 function CommandLineAPI(commandLineAPIImpl) |
| 1487 { | 1445 { |
| 1488 /** | 1446 /** |
| 1489 * @param {string} member | |
| 1490 * @return {boolean} | |
| 1491 */ | |
| 1492 function inScopeVariables(member) | |
| 1493 { | |
| 1494 var scopeChain = callFrame.scopeChain; | |
| 1495 for (var i = 0; i < scopeChain.length; ++i) { | |
| 1496 if (member in scopeChain[i]) | |
| 1497 return true; | |
| 1498 } | |
| 1499 return false; | |
| 1500 } | |
| 1501 | |
| 1502 /** | |
| 1503 * @param {string} name The name of the method for which a toString method s
hould be generated. | 1447 * @param {string} name The name of the method for which a toString method s
hould be generated. |
| 1504 * @return {function():string} | 1448 * @return {function():string} |
| 1505 */ | 1449 */ |
| 1506 function customToStringMethod(name) | 1450 function customToStringMethod(name) |
| 1507 { | 1451 { |
| 1508 return function() | 1452 return function() |
| 1509 { | 1453 { |
| 1510 var funcArgsSyntax = ""; | 1454 var funcArgsSyntax = ""; |
| 1511 try { | 1455 try { |
| 1512 var funcSyntax = "" + commandLineAPIImpl[name]; | 1456 var funcSyntax = "" + commandLineAPIImpl[name]; |
| 1513 funcSyntax = funcSyntax.replace(/\n/g, " "); | 1457 funcSyntax = funcSyntax.replace(/\n/g, " "); |
| 1514 funcSyntax = funcSyntax.replace(/^function[^\(]*\(([^\)]*)\).*$/
, "$1"); | 1458 funcSyntax = funcSyntax.replace(/^function[^\(]*\(([^\)]*)\).*$/
, "$1"); |
| 1515 funcSyntax = funcSyntax.replace(/\s*,\s*/g, ", "); | 1459 funcSyntax = funcSyntax.replace(/\s*,\s*/g, ", "); |
| 1516 funcSyntax = funcSyntax.replace(/\bopt_(\w+)\b/g, "[$1]"); | 1460 funcSyntax = funcSyntax.replace(/\bopt_(\w+)\b/g, "[$1]"); |
| 1517 funcArgsSyntax = funcSyntax.trim(); | 1461 funcArgsSyntax = funcSyntax.trim(); |
| 1518 } catch (e) { | 1462 } catch (e) { |
| 1519 } | 1463 } |
| 1520 return "function " + name + "(" + funcArgsSyntax + ") { [Command Lin
e API] }"; | 1464 return "function " + name + "(" + funcArgsSyntax + ") { [Command Lin
e API] }"; |
| 1521 }; | 1465 }; |
| 1522 } | 1466 } |
| 1523 | 1467 |
| 1524 for (var i = 0; i < CommandLineAPI.members_.length; ++i) { | 1468 for (var i = 0; i < CommandLineAPI.members_.length; ++i) { |
| 1525 var member = CommandLineAPI.members_[i]; | 1469 var member = CommandLineAPI.members_[i]; |
| 1526 if (callFrame && inScopeVariables(member)) | |
| 1527 continue; | |
| 1528 | |
| 1529 this[member] = bind(commandLineAPIImpl[member], commandLineAPIImpl); | 1470 this[member] = bind(commandLineAPIImpl[member], commandLineAPIImpl); |
| 1530 this[member].toString = customToStringMethod(member); | 1471 this[member].toString = customToStringMethod(member); |
| 1531 } | 1472 } |
| 1532 | 1473 |
| 1533 for (var i = 0; i < 5; ++i) { | 1474 for (var i = 0; i < 5; ++i) { |
| 1534 var member = "$" + i; | 1475 var member = "$" + i; |
| 1535 if (callFrame && inScopeVariables(member)) | |
| 1536 continue; | |
| 1537 | |
| 1538 this[member] = bind(commandLineAPIImpl._inspectedObject, commandLineAPII
mpl, i); | 1476 this[member] = bind(commandLineAPIImpl._inspectedObject, commandLineAPII
mpl, i); |
| 1539 } | 1477 } |
| 1540 | 1478 |
| 1541 this.$_ = injectedScript._lastResult; | 1479 this.$_ = injectedScript._lastResult; |
| 1542 | 1480 |
| 1543 this.__proto__ = null; | 1481 this.__proto__ = null; |
| 1544 } | 1482 } |
| 1545 | 1483 |
| 1546 // NOTE: Please keep the list of API methods below synchronized to that in WebIn
spector.RuntimeModel | 1484 // NOTE: Please keep the list of API methods below synchronized to that in WebIn
spector.RuntimeModel |
| 1547 // and V8InjectedScriptHost! | 1485 // and V8InjectedScriptHost! |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1827 */ | 1765 */ |
| 1828 _logEvent: function(event) | 1766 _logEvent: function(event) |
| 1829 { | 1767 { |
| 1830 inspectedGlobalObject.console.log(event.type, event); | 1768 inspectedGlobalObject.console.log(event.type, event); |
| 1831 } | 1769 } |
| 1832 } | 1770 } |
| 1833 | 1771 |
| 1834 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); | 1772 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); |
| 1835 return injectedScript; | 1773 return injectedScript; |
| 1836 }) | 1774 }) |
| OLD | NEW |