| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 array[array.length] = arguments[i]; | 53 array[array.length] = arguments[i]; |
| 54 } | 54 } |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * @param {*} obj | 57 * @param {*} obj |
| 58 * @return {string} | 58 * @return {string} |
| 59 * @suppress {uselessCode} | 59 * @suppress {uselessCode} |
| 60 */ | 60 */ |
| 61 function toString(obj) | 61 function toString(obj) |
| 62 { | 62 { |
| 63 // We don't use String(obj) because String16 could be overridden. | 63 // We don't use String(obj) because String could be overridden. |
| 64 // Also the ("" + obj) expression may throw. | 64 // Also the ("" + obj) expression may throw. |
| 65 try { | 65 try { |
| 66 return "" + obj; | 66 return "" + obj; |
| 67 } catch (e) { | 67 } catch (e) { |
| 68 var name = InjectedScriptHost.internalConstructorName(obj) || InjectedSc
riptHost.subtype(obj) || (typeof obj); | 68 var name = InjectedScriptHost.internalConstructorName(obj) || InjectedSc
riptHost.subtype(obj) || (typeof obj); |
| 69 return "#<" + name + ">"; | 69 return "#<" + name + ">"; |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 /** | 73 /** |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 164 |
| 165 /** | 165 /** |
| 166 * @param {!Object} object | 166 * @param {!Object} object |
| 167 * @param {string} attribute | 167 * @param {string} attribute |
| 168 * @return {boolean} | 168 * @return {boolean} |
| 169 */ | 169 */ |
| 170 function doesAttributeHaveObservableSideEffectOnGet(object, attribute) | 170 function doesAttributeHaveObservableSideEffectOnGet(object, attribute) |
| 171 { | 171 { |
| 172 for (var interfaceName in domAttributesWithObservableSideEffectOnGet) { | 172 for (var interfaceName in domAttributesWithObservableSideEffectOnGet) { |
| 173 var interfaceFunction = inspectedGlobalObject[interfaceName]; | 173 var interfaceFunction = inspectedGlobalObject[interfaceName]; |
| 174 var isInstance = typeof interfaceFunction === "function" && object insta
nceof interfaceFunction; | 174 // instanceof call looks safe after typeof check. |
| 175 var isInstance = typeof interfaceFunction === "function" && /* suppressB
lacklist */ object instanceof interfaceFunction; |
| 175 if (isInstance) | 176 if (isInstance) |
| 176 return attribute in domAttributesWithObservableSideEffectOnGet[inter
faceName]; | 177 return attribute in domAttributesWithObservableSideEffectOnGet[inter
faceName]; |
| 177 } | 178 } |
| 178 return false; | 179 return false; |
| 179 } | 180 } |
| 180 | 181 |
| 181 /** | 182 /** |
| 182 * @constructor | 183 * @constructor |
| 183 */ | 184 */ |
| 184 var InjectedScript = function() | 185 var InjectedScript = function() |
| 185 { | 186 { |
| 186 } | 187 } |
| 187 | 188 |
| 188 /** | 189 /** |
| 189 * @type {!Object.<string, boolean>} | 190 * @type {!Object.<string, boolean>} |
| 190 * @const | 191 * @const |
| 191 */ | 192 */ |
| 192 InjectedScript.primitiveTypes = { | 193 InjectedScript.primitiveTypes = { |
| 193 "undefined": true, | 194 "undefined": true, |
| 194 "boolean": true, | 195 "boolean": true, |
| 195 "number": true, | 196 "number": true, |
| 196 "string": true, | 197 "string": true, |
| 197 __proto__: null | 198 __proto__: null |
| 198 } | 199 } |
| 199 | 200 |
| 200 /** | 201 /** |
| 201 * @type {!Map<string, string>} | 202 * @type {!Object<string, string>} |
| 202 * @const | 203 * @const |
| 203 */ | 204 */ |
| 204 InjectedScript.closureTypes = new Map([ | 205 InjectedScript.closureTypes = { __proto__: null }; |
| 205 ["local", "Local"], | 206 InjectedScript.closureTypes["local"] = "Local"; |
| 206 ["closure", "Closure"], | 207 InjectedScript.closureTypes["closure"] = "Closure"; |
| 207 ["catch", "Catch"], | 208 InjectedScript.closureTypes["catch"] = "Catch"; |
| 208 ["block", "Block"], | 209 InjectedScript.closureTypes["block"] = "Block"; |
| 209 ["script", "Script"], | 210 InjectedScript.closureTypes["script"] = "Script"; |
| 210 ["with", "With Block"], | 211 InjectedScript.closureTypes["with"] = "With Block"; |
| 211 ["global", "Global"] | 212 InjectedScript.closureTypes["global"] = "Global"; |
| 212 ]); | |
| 213 | 213 |
| 214 InjectedScript.prototype = { | 214 InjectedScript.prototype = { |
| 215 /** | 215 /** |
| 216 * @param {*} object | 216 * @param {*} object |
| 217 * @return {boolean} | 217 * @return {boolean} |
| 218 */ | 218 */ |
| 219 isPrimitiveValue: function(object) | 219 isPrimitiveValue: function(object) |
| 220 { | 220 { |
| 221 // FIXME(33716): typeof document.all is always 'undefined'. | 221 // FIXME(33716): typeof document.all is always 'undefined'. |
| 222 return InjectedScript.primitiveTypes[typeof object] && !this._isHTMLAllC
ollection(object); | 222 return InjectedScript.primitiveTypes[typeof object] && !this._isHTMLAllC
ollection(object); |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 if (typeof obj.length === "number") | 630 if (typeof obj.length === "number") |
| 631 className += "[" + obj.length + "]"; | 631 className += "[" + obj.length + "]"; |
| 632 return className; | 632 return className; |
| 633 } | 633 } |
| 634 | 634 |
| 635 if (typeof obj === "function") | 635 if (typeof obj === "function") |
| 636 return toString(obj); | 636 return toString(obj); |
| 637 | 637 |
| 638 if (isSymbol(obj)) { | 638 if (isSymbol(obj)) { |
| 639 try { | 639 try { |
| 640 return obj.toString() || "Symbol"; | 640 // It isn't safe, because Symbol.prototype.toString can be overr
iden. |
| 641 return /* suppressBlacklist */ obj.toString() || "Symbol"; |
| 641 } catch (e) { | 642 } catch (e) { |
| 642 return "Symbol"; | 643 return "Symbol"; |
| 643 } | 644 } |
| 644 } | 645 } |
| 645 | 646 |
| 646 if (InjectedScriptHost.subtype(obj) === "error") { | 647 if (InjectedScriptHost.subtype(obj) === "error") { |
| 647 try { | 648 try { |
| 648 var stack = obj.stack; | 649 var stack = obj.stack; |
| 649 var message = obj.message && obj.message.length ? ": " + obj.mes
sage : ""; | 650 var message = obj.message && obj.message.length ? ": " + obj.mes
sage : ""; |
| 650 var firstCallFrame = /^\s+at\s/m.exec(stack); | 651 var firstCallFrame = /^\s+at\s/m.exec(stack); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 661 if (subtype === "internal#entry") { | 662 if (subtype === "internal#entry") { |
| 662 if ("key" in obj) | 663 if ("key" in obj) |
| 663 return "{" + this._describeIncludingPrimitives(obj.key) + " => "
+ this._describeIncludingPrimitives(obj.value) + "}"; | 664 return "{" + this._describeIncludingPrimitives(obj.key) + " => "
+ this._describeIncludingPrimitives(obj.value) + "}"; |
| 664 return this._describeIncludingPrimitives(obj.value); | 665 return this._describeIncludingPrimitives(obj.value); |
| 665 } | 666 } |
| 666 | 667 |
| 667 if (subtype === "internal#scopeList") | 668 if (subtype === "internal#scopeList") |
| 668 return "Scopes[" + obj.length + "]"; | 669 return "Scopes[" + obj.length + "]"; |
| 669 | 670 |
| 670 if (subtype === "internal#scope") | 671 if (subtype === "internal#scope") |
| 671 return (InjectedScript.closureTypes.get(obj.type) || "Unknown") + (o
bj.name ? " (" + obj.name + ")" : ""); | 672 return (InjectedScript.closureTypes[obj.type] || "Unknown") + (obj.n
ame ? " (" + obj.name + ")" : ""); |
| 672 | 673 |
| 673 return className; | 674 return className; |
| 674 }, | 675 }, |
| 675 | 676 |
| 676 /** | 677 /** |
| 677 * @param {*} value | 678 * @param {*} value |
| 678 * @return {string} | 679 * @return {string} |
| 679 */ | 680 */ |
| 680 _describeIncludingPrimitives: function(value) | 681 _describeIncludingPrimitives: function(value) |
| 681 { | 682 { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 * @param {*=} customObjectConfig | 787 * @param {*=} customObjectConfig |
| 787 * @return {?RuntimeAgent.CustomPreview} | 788 * @return {?RuntimeAgent.CustomPreview} |
| 788 */ | 789 */ |
| 789 _customPreview: function(object, objectGroupName, customObjectConfig) | 790 _customPreview: function(object, objectGroupName, customObjectConfig) |
| 790 { | 791 { |
| 791 /** | 792 /** |
| 792 * @param {!Error} error | 793 * @param {!Error} error |
| 793 */ | 794 */ |
| 794 function logError(error) | 795 function logError(error) |
| 795 { | 796 { |
| 796 Promise.resolve().then(inspectedGlobalObject.console.error.bind(insp
ectedGlobalObject.console, "Custom Formatter Failed: " + error.message)); | 797 // We use user code to generate custom output for object, we can use
user code for reporting error too. |
| 798 Promise.resolve().then(/* suppressBlacklist */ inspectedGlobalObject
.console.error.bind(inspectedGlobalObject.console, "Custom Formatter Failed: " +
error.message)); |
| 797 } | 799 } |
| 798 | 800 |
| 799 /** | 801 /** |
| 800 * @suppressReceiverCheck | 802 * @suppressReceiverCheck |
| 801 * @param {*} object | 803 * @param {*} object |
| 802 * @param {*=} customObjectConfig | 804 * @param {*=} customObjectConfig |
| 803 * @return {*} | 805 * @return {*} |
| 804 */ | 806 */ |
| 805 function wrap(object, customObjectConfig) | 807 function wrap(object, customObjectConfig) |
| 806 { | 808 { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 return string.substr(0, leftHalf) + "\u2026" + string.substr(string.
length - rightHalf, rightHalf); | 1067 return string.substr(0, leftHalf) + "\u2026" + string.substr(string.
length - rightHalf, rightHalf); |
| 1066 } | 1068 } |
| 1067 return string.substr(0, maxLength) + "\u2026"; | 1069 return string.substr(0, maxLength) + "\u2026"; |
| 1068 }, | 1070 }, |
| 1069 | 1071 |
| 1070 __proto__: null | 1072 __proto__: null |
| 1071 } | 1073 } |
| 1072 | 1074 |
| 1073 return injectedScript; | 1075 return injectedScript; |
| 1074 }) | 1076 }) |
| OLD | NEW |