Chromium Code Reviews| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 */ | 61 */ |
| 62 function slice(array, index) | 62 function slice(array, index) |
| 63 { | 63 { |
| 64 var result = []; | 64 var result = []; |
| 65 for (var i = index || 0, j = 0; i < array.length; ++i, ++j) | 65 for (var i = index || 0, j = 0; i < array.length; ++i, ++j) |
| 66 result[j] = array[i]; | 66 result[j] = array[i]; |
| 67 return result; | 67 return result; |
| 68 } | 68 } |
| 69 | 69 |
| 70 /** | 70 /** |
| 71 * @param {!Array.<T>} array1 | |
| 72 * @param {!Array.<T>} array2 | |
| 73 * @return {!Array.<T>} | |
| 74 * @template T | |
| 75 */ | |
| 76 function concat(array1, array2) | |
| 77 { | |
| 78 var result = []; | |
| 79 for (var i = 0; i < array1.length; ++i) | |
| 80 push(result, array1[i]); | |
| 81 for (var i = 0; i < array2.length; ++i) | |
| 82 push(result, array2[i]); | |
| 83 return result; | |
| 84 } | |
| 85 | |
| 86 /** | |
| 87 * @param {*} obj | 71 * @param {*} obj |
| 88 * @return {string} | 72 * @return {string} |
| 89 * @suppress {uselessCode} | 73 * @suppress {uselessCode} |
| 90 */ | 74 */ |
| 91 function toString(obj) | 75 function toString(obj) |
| 92 { | 76 { |
| 93 // We don't use String(obj) because String16 could be overridden. | 77 // We don't use String(obj) because String16 could be overridden. |
| 94 // Also the ("" + obj) expression may throw. | 78 // Also the ("" + obj) expression may throw. |
| 95 try { | 79 try { |
| 96 return "" + obj; | 80 return "" + obj; |
| 97 } catch (e) { | 81 } catch (e) { |
| 98 var name = InjectedScriptHost.internalConstructorName(obj) || InjectedSc riptHost.subtype(obj) || (typeof obj); | 82 var name = InjectedScriptHost.internalConstructorName(obj) || InjectedSc riptHost.subtype(obj) || (typeof obj); |
| 99 return "#<" + name + ">"; | 83 return "#<" + name + ">"; |
| 100 } | 84 } |
| 101 } | 85 } |
| 102 | 86 |
| 103 /** | 87 /** |
| 104 * @param {*} obj | 88 * @param {*} obj |
| 105 * @return {string} | 89 * @return {string} |
| 106 */ | 90 */ |
| 107 function toStringDescription(obj) | 91 function toStringDescription(obj) |
| 108 { | 92 { |
| 109 if (typeof obj === "number" && obj === 0 && 1 / obj < 0) | 93 if (typeof obj === "number" && obj === 0 && 1 / obj < 0) |
| 110 return "-0"; // Negative zero. | 94 return "-0"; // Negative zero. |
| 111 return toString(obj); | 95 return toString(obj); |
| 112 } | 96 } |
| 113 | 97 |
| 114 /** | 98 /** |
| 115 * Please use this bind, not the one from Function.prototype | |
| 116 * @param {function(...)} func | |
| 117 * @param {?Object} thisObject | |
| 118 * @param {...} var_args | |
| 119 * @return {function(...)} | |
| 120 */ | |
| 121 function bind(func, thisObject, var_args) | |
| 122 { | |
| 123 var args = slice(arguments, 2); | |
| 124 | |
| 125 /** | |
| 126 * @param {...} var_args | |
| 127 */ | |
| 128 function bound(var_args) | |
| 129 { | |
| 130 return InjectedScriptHost.suppressWarningsAndCallFunction(func, thisObje ct, concat(args, slice(arguments))); | |
| 131 } | |
| 132 bound.toString = function() | |
| 133 { | |
| 134 return "bound: " + toString(func); | |
| 135 }; | |
| 136 return bound; | |
| 137 } | |
| 138 | |
| 139 /** | |
| 140 * @param {T} obj | 99 * @param {T} obj |
| 141 * @return {T} | 100 * @return {T} |
| 142 * @template T | 101 * @template T |
| 143 */ | 102 */ |
| 144 function nullifyObjectProto(obj) | 103 function nullifyObjectProto(obj) |
| 145 { | 104 { |
| 146 if (obj && typeof obj === "object") | 105 if (obj && typeof obj === "object") |
| 147 obj.__proto__ = null; | 106 obj.__proto__ = null; |
| 148 return obj; | 107 return obj; |
| 149 } | 108 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 * @param {*} obj | 154 * @param {*} obj |
| 196 * @return {boolean} | 155 * @return {boolean} |
| 197 */ | 156 */ |
| 198 function isSymbol(obj) | 157 function isSymbol(obj) |
| 199 { | 158 { |
| 200 var type = typeof obj; | 159 var type = typeof obj; |
| 201 return (type === "symbol"); | 160 return (type === "symbol"); |
| 202 } | 161 } |
| 203 | 162 |
| 204 /** | 163 /** |
| 205 * @param {string} str | |
| 206 * @param {string} searchElement | |
| 207 * @param {number=} fromIndex | |
| 208 * @return {number} | |
| 209 */ | |
| 210 function indexOf(str, searchElement, fromIndex) | |
| 211 { | |
| 212 var len = str.length; | |
| 213 var n = fromIndex || 0; | |
| 214 var k = max(n >= 0 ? n : len + n, 0); | |
| 215 | |
| 216 while (k < len) { | |
| 217 if (str[k] === searchElement) | |
| 218 return k; | |
| 219 ++k; | |
| 220 } | |
| 221 return -1; | |
| 222 } | |
| 223 | |
| 224 /** | |
| 225 * DOM Attributes which have observable side effect on getter, in the form of | 164 * DOM Attributes which have observable side effect on getter, in the form of |
| 226 * {interfaceName1: {attributeName1: true, | 165 * {interfaceName1: {attributeName1: true, |
| 227 * attributeName2: true, | 166 * attributeName2: true, |
| 228 * ...}, | 167 * ...}, |
| 229 * interfaceName2: {...}, | 168 * interfaceName2: {...}, |
| 230 * ...} | 169 * ...} |
| 231 * @type {!Object<string, !Object<string, boolean>>} | 170 * @type {!Object<string, !Object<string, boolean>>} |
| 232 * @const | 171 * @const |
| 233 */ | 172 */ |
| 234 var domAttributesWithObservableSideEffectOnGet = nullifyObjectProto({}); | 173 var domAttributesWithObservableSideEffectOnGet = nullifyObjectProto({}); |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 ["monitorEvents", "function monitorEvents(object, [types]) { [Comm and Line API] }"], | 566 ["monitorEvents", "function monitorEvents(object, [types]) { [Comm and Line API] }"], |
| 628 ["unmonitorEvents", "function unmonitorEvents(object, [types]) { [Co mmand Line API] }"], | 567 ["unmonitorEvents", "function unmonitorEvents(object, [types]) { [Co mmand Line API] }"], |
| 629 ["getEventListeners", "function getEventListeners(node) { [Command L ine API] }"] | 568 ["getEventListeners", "function getEventListeners(node) { [Command L ine API] }"] |
| 630 ]); | 569 ]); |
| 631 for (let entry of functionToStringMap) | 570 for (let entry of functionToStringMap) |
| 632 nativeCommandLineAPI[entry[0]].toString = (() => entry[1]); | 571 nativeCommandLineAPI[entry[0]].toString = (() => entry[1]); |
| 633 return nativeCommandLineAPI; | 572 return nativeCommandLineAPI; |
| 634 }, | 573 }, |
| 635 | 574 |
| 636 /** | 575 /** |
| 637 * @param {string} objectGroup | |
| 638 * @return {!Object} | |
| 639 */ | |
| 640 remoteObjectAPI: function(objectGroup) | |
| 641 { | |
| 642 /** | |
| 643 * @suppressReceiverCheck | |
| 644 * @param {*} object | |
| 645 * @param {boolean=} forceValueType | |
| 646 * @param {boolean=} generatePreview | |
| 647 * @param {?Array.<string>=} columnNames | |
| 648 * @param {boolean=} isTable | |
| 649 * @param {*=} customObjectConfig | |
| 650 * @return {!RuntimeAgent.RemoteObject} | |
| 651 * @this {InjectedScript} | |
| 652 */ | |
| 653 function wrap(object, forceValueType, generatePreview, columnNames, isTa ble, customObjectConfig) | |
| 654 { | |
| 655 return this._wrapObject(object, objectGroup, forceValueType, generat ePreview, columnNames, isTable, false, customObjectConfig); | |
| 656 } | |
| 657 return { bindRemoteObject: bind(wrap, this), __proto__: null}; | |
| 658 }, | |
| 659 | |
| 660 /** | |
| 661 * @param {*} object | 576 * @param {*} object |
| 662 * @return {boolean} | 577 * @return {boolean} |
| 663 */ | 578 */ |
| 664 _isDefined: function(object) | 579 _isDefined: function(object) |
| 665 { | 580 { |
| 666 return !!object || this._isHTMLAllCollection(object); | 581 return !!object || this._isHTMLAllCollection(object); |
| 667 }, | 582 }, |
| 668 | 583 |
| 669 /** | 584 /** |
| 670 * @param {*} object | 585 * @param {*} object |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 868 _customPreview: function(object, objectGroupName, customObjectConfig) | 783 _customPreview: function(object, objectGroupName, customObjectConfig) |
| 869 { | 784 { |
| 870 /** | 785 /** |
| 871 * @param {!Error} error | 786 * @param {!Error} error |
| 872 */ | 787 */ |
| 873 function logError(error) | 788 function logError(error) |
| 874 { | 789 { |
| 875 Promise.resolve().then(inspectedGlobalObject.console.error.bind(insp ectedGlobalObject.console, "Custom Formatter Failed: " + error.message)); | 790 Promise.resolve().then(inspectedGlobalObject.console.error.bind(insp ectedGlobalObject.console, "Custom Formatter Failed: " + error.message)); |
| 876 } | 791 } |
| 877 | 792 |
| 793 /** | |
| 794 * @suppressReceiverCheck | |
| 795 * @param {*} object | |
| 796 * @param {*=} customObjectConfig | |
| 797 * @return {*} | |
| 798 */ | |
| 799 function wrap(object, customObjectConfig) | |
| 800 { | |
| 801 return InjectedScriptHost.suppressWarningsAndCallFunction(injectedSc ript._wrapObject, injectedScript, [ object, objectGroupName, false, false, null, false, false, customObjectConfig ]); | |
| 802 } | |
| 803 | |
| 878 try { | 804 try { |
| 879 var formatters = inspectedGlobalObject["devtoolsFormatters"]; | 805 var formatters = inspectedGlobalObject["devtoolsFormatters"]; |
| 880 if (!formatters || !isArrayLike(formatters)) | 806 if (!formatters || !isArrayLike(formatters)) |
| 881 return null; | 807 return null; |
| 882 | 808 |
| 883 for (var i = 0; i < formatters.length; ++i) { | 809 for (var i = 0; i < formatters.length; ++i) { |
| 884 try { | 810 try { |
| 885 var formatted = formatters[i].header(object, customObjectCon fig); | 811 var formatted = formatters[i].header(object, customObjectCon fig); |
| 886 if (!formatted) | 812 if (!formatted) |
| 887 continue; | 813 continue; |
| 888 | 814 |
| 889 var hasBody = formatters[i].hasBody(object, customObjectConf ig); | 815 var hasBody = formatters[i].hasBody(object, customObjectConf ig); |
| 890 injectedScript._substituteObjectTagsInCustomPreview(objectGr oupName, formatted); | 816 injectedScript._substituteObjectTagsInCustomPreview(objectGr oupName, formatted); |
| 891 var formatterObjectId = injectedScript._bind(formatters[i], objectGroupName); | 817 var formatterObjectId = injectedScript._bind(formatters[i], objectGroupName); |
| 892 var result = {header: JSON.stringify(formatted), hasBody: !! hasBody, formatterObjectId: formatterObjectId}; | 818 var bindRemoteObjectFunctionId = injectedScript._bind(wrap, objectGroupName); |
|
dgozman
2016/05/17 22:05:38
Let's store this on InjectedScript.
kozy
2016/05/17 22:35:26
We can't do it.
I need to bind it to objectGroupNa
| |
| 819 var result = {header: JSON.stringify(formatted), hasBody: !! hasBody, formatterObjectId: formatterObjectId, bindRemoteObjectFunctionId: bindR emoteObjectFunctionId}; | |
| 893 if (customObjectConfig) | 820 if (customObjectConfig) |
| 894 result["configObjectId"] = injectedScript._bind(customOb jectConfig, objectGroupName); | 821 result["configObjectId"] = injectedScript._bind(customOb jectConfig, objectGroupName); |
| 895 return result; | 822 return result; |
| 896 } catch (e) { | 823 } catch (e) { |
| 897 logError(e); | 824 logError(e); |
| 898 } | 825 } |
| 899 } | 826 } |
| 900 } catch (e) { | 827 } catch (e) { |
| 901 logError(e); | 828 logError(e); |
| 902 } | 829 } |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1330 /** | 1257 /** |
| 1331 * @param {!Event} event | 1258 * @param {!Event} event |
| 1332 */ | 1259 */ |
| 1333 CommandLineAPIImpl._logEvent = function(event) | 1260 CommandLineAPIImpl._logEvent = function(event) |
| 1334 { | 1261 { |
| 1335 inspectedGlobalObject.console.log(event.type, event); | 1262 inspectedGlobalObject.console.log(event.type, event); |
| 1336 } | 1263 } |
| 1337 | 1264 |
| 1338 return injectedScript; | 1265 return injectedScript; |
| 1339 }) | 1266 }) |
| OLD | NEW |