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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 * @param {...} var_args | 47 * @param {...} var_args |
48 * @template T | 48 * @template T |
49 */ | 49 */ |
50 function push(array, var_args) | 50 function push(array, var_args) |
51 { | 51 { |
52 for (var i = 1; i < arguments.length; ++i) | 52 for (var i = 1; i < arguments.length; ++i) |
53 array[array.length] = arguments[i]; | 53 array[array.length] = arguments[i]; |
54 } | 54 } |
55 | 55 |
56 /** | 56 /** |
57 * @param {(!Arguments.<T>|!NodeList)} array | |
58 * @param {number=} index | |
59 * @return {!Array.<T>} | |
60 * @template T | |
61 */ | |
62 function slice(array, index) | |
63 { | |
64 var result = []; | |
65 for (var i = index || 0, j = 0; i < array.length; ++i, ++j) | |
66 result[j] = array[i]; | |
67 return result; | |
68 } | |
69 | |
70 /** | |
71 * @param {*} obj | 57 * @param {*} obj |
72 * @return {string} | 58 * @return {string} |
73 * @suppress {uselessCode} | 59 * @suppress {uselessCode} |
74 */ | 60 */ |
75 function toString(obj) | 61 function toString(obj) |
76 { | 62 { |
77 // We don't use String(obj) because String16 could be overridden. | 63 // We don't use String(obj) because String16 could be overridden. |
78 // Also the ("" + obj) expression may throw. | 64 // Also the ("" + obj) expression may throw. |
79 try { | 65 try { |
80 return "" + obj; | 66 return "" + obj; |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 }, | 521 }, |
536 | 522 |
537 /** | 523 /** |
538 * @param {!Object} nativeCommandLineAPI | 524 * @param {!Object} nativeCommandLineAPI |
539 * @return {!Object} | 525 * @return {!Object} |
540 */ | 526 */ |
541 installCommandLineAPI: function(nativeCommandLineAPI) | 527 installCommandLineAPI: function(nativeCommandLineAPI) |
542 { | 528 { |
543 // NOTE: This list contains only not native Command Line API methods. Fo
r full list: V8Console. | 529 // NOTE: This list contains only not native Command Line API methods. Fo
r full list: V8Console. |
544 // NOTE: Argument names of these methods will be printed in the console,
so use pretty names! | 530 // NOTE: Argument names of these methods will be printed in the console,
so use pretty names! |
545 var members = [ "$", "$$", "$x", "monitorEvents", "unmonitorEvents", "ge
tEventListeners" ]; | 531 var members = [ "$x", "monitorEvents", "unmonitorEvents", "getEventListe
ners" ]; |
546 for (var member of members) | 532 for (var member of members) |
547 nativeCommandLineAPI[member] = CommandLineAPIImpl[member]; | 533 nativeCommandLineAPI[member] = CommandLineAPIImpl[member]; |
548 var functionToStringMap = new Map([ | 534 var functionToStringMap = new Map([ |
549 ["$", "function $(selector, [startNode]) { [Command Line AP
I] }"], | 535 ["$", "function $(selector, [startNode]) { [Command Line AP
I] }"], |
550 ["$$", "function $$(selector, [startNode]) { [Command Line A
PI] }"], | 536 ["$$", "function $$(selector, [startNode]) { [Command Line A
PI] }"], |
551 ["$x", "function $x(xpath, [startNode]) { [Command Line API]
}"], | 537 ["$x", "function $x(xpath, [startNode]) { [Command Line API]
}"], |
552 ["dir", "function dir(value) { [Command Line API] }"], | 538 ["dir", "function dir(value) { [Command Line API] }"], |
553 ["dirxml", "function dirxml(value) { [Command Line API] }"], | 539 ["dirxml", "function dirxml(value) { [Command Line API] }"], |
554 ["keys", "function keys(object) { [Command Line API] }"], | 540 ["keys", "function keys(object) { [Command Line API] }"], |
555 ["values", "function values(object) { [Command Line API] }"], | 541 ["values", "function values(object) { [Command Line API] }"], |
556 ["inspect", "function inspect(object) { [Command Line API] }"], | 542 ["inspect", "function inspect(object) { [Command Line API] }"], |
557 ["copy", "function copy(value) { [Command Line API] }"], | 543 ["copy", "function copy(value) { [Command Line API] }"], |
558 ["clear", "function clear() { [Command Line API] }"], | 544 ["clear", "function clear() { [Command Line API] }"], |
559 ["debug", "function debug(function) { [Command Line API] }"], | 545 ["debug", "function debug(function) { [Command Line API] }"], |
560 ["undebug", "function undebug(function) { [Command Line API] }"], | 546 ["undebug", "function undebug(function) { [Command Line API] }"], |
561 ["monitor", "function monitor(function) { [Command Line API] }"], | 547 ["monitor", "function monitor(function) { [Command Line API] }"], |
562 ["unmonitor", "function unmonitor(function) { [Command Line API] }"
], | 548 ["unmonitor", "function unmonitor(function) { [Command Line API] }"
], |
563 ["table", "function table(data, [columns]) { [Command Line API]
}"], | 549 ["table", "function table(data, [columns]) { [Command Line API]
}"], |
564 ["profile", "function profile(title) { [Command Line API] }"], | 550 ["profile", "function profile(title) { [Command Line API] }"], |
565 ["profileEnd", "function profileEnd(title) { [Command Line API] }"], | 551 ["profileEnd", "function profileEnd(title) { [Command Line API] }"], |
566 ["monitorEvents", "function monitorEvents(object, [types]) { [Comm
and Line API] }"], | 552 ["monitorEvents", "function monitorEvents(object, [types]) { [Comm
and Line API] }"], |
567 ["unmonitorEvents", "function unmonitorEvents(object, [types]) { [Co
mmand Line API] }"], | 553 ["unmonitorEvents", "function unmonitorEvents(object, [types]) { [Co
mmand Line API] }"], |
568 ["getEventListeners", "function getEventListeners(node) { [Command L
ine API] }"] | 554 ["getEventListeners", "function getEventListeners(node) { [Command L
ine API] }"] |
569 ]); | 555 ]); |
570 for (let entry of functionToStringMap) | 556 for (let func in nativeCommandLineAPI) |
571 nativeCommandLineAPI[entry[0]].toString = (() => entry[1]); | 557 nativeCommandLineAPI[func].toString = (() => functionToStringMap.get
(func)); |
572 return nativeCommandLineAPI; | 558 return nativeCommandLineAPI; |
573 }, | 559 }, |
574 | 560 |
575 /** | 561 /** |
576 * @param {*} object | 562 * @param {*} object |
577 * @return {boolean} | 563 * @return {boolean} |
578 */ | 564 */ |
579 _isDefined: function(object) | 565 _isDefined: function(object) |
580 { | 566 { |
581 return !!object || this._isHTMLAllCollection(object); | 567 return !!object || this._isHTMLAllCollection(object); |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 } | 1070 } |
1085 return string.substr(0, maxLength) + "\u2026"; | 1071 return string.substr(0, maxLength) + "\u2026"; |
1086 }, | 1072 }, |
1087 | 1073 |
1088 __proto__: null | 1074 __proto__: null |
1089 } | 1075 } |
1090 | 1076 |
1091 var CommandLineAPIImpl = { __proto__: null } | 1077 var CommandLineAPIImpl = { __proto__: null } |
1092 | 1078 |
1093 /** | 1079 /** |
1094 * @param {string} selector | |
1095 * @param {!Node=} opt_startNode | |
1096 * @return {*} | |
1097 */ | |
1098 CommandLineAPIImpl.$ = function (selector, opt_startNode) | |
1099 { | |
1100 if (CommandLineAPIImpl._canQuerySelectorOnNode(opt_startNode)) | |
1101 return opt_startNode.querySelector(selector); | |
1102 | |
1103 return inspectedGlobalObject.document.querySelector(selector); | |
1104 } | |
1105 | |
1106 /** | |
1107 * @param {string} selector | |
1108 * @param {!Node=} opt_startNode | |
1109 * @return {*} | |
1110 */ | |
1111 CommandLineAPIImpl.$$ = function (selector, opt_startNode) | |
1112 { | |
1113 if (CommandLineAPIImpl._canQuerySelectorOnNode(opt_startNode)) | |
1114 return slice(opt_startNode.querySelectorAll(selector)); | |
1115 return slice(inspectedGlobalObject.document.querySelectorAll(selector)); | |
1116 } | |
1117 | |
1118 /** | |
1119 * @param {!Node=} node | |
1120 * @return {boolean} | |
1121 */ | |
1122 CommandLineAPIImpl._canQuerySelectorOnNode = function(node) | |
1123 { | |
1124 return !!node && InjectedScriptHost.subtype(node) === "node" && (node.nodeTy
pe === Node.ELEMENT_NODE || node.nodeType === Node.DOCUMENT_NODE || node.nodeTyp
e === Node.DOCUMENT_FRAGMENT_NODE); | |
1125 } | |
1126 | |
1127 /** | |
1128 * @param {string} xpath | 1080 * @param {string} xpath |
1129 * @param {!Node=} opt_startNode | 1081 * @param {!Node=} opt_startNode |
1130 * @return {*} | 1082 * @return {*} |
1131 */ | 1083 */ |
1132 CommandLineAPIImpl.$x = function(xpath, opt_startNode) | 1084 CommandLineAPIImpl.$x = function(xpath, opt_startNode) |
1133 { | 1085 { |
1134 var doc = (opt_startNode && opt_startNode.ownerDocument) || inspectedGlobalO
bject.document; | 1086 var doc = (opt_startNode && opt_startNode.ownerDocument) || inspectedGlobalO
bject.document; |
1135 var result = doc.evaluate(xpath, opt_startNode || doc, null, XPathResult.ANY
_TYPE, null); | 1087 var result = doc.evaluate(xpath, opt_startNode || doc, null, XPathResult.ANY
_TYPE, null); |
1136 switch (result.resultType) { | 1088 switch (result.resultType) { |
1137 case XPathResult.NUMBER_TYPE: | 1089 case XPathResult.NUMBER_TYPE: |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 /** | 1209 /** |
1258 * @param {!Event} event | 1210 * @param {!Event} event |
1259 */ | 1211 */ |
1260 CommandLineAPIImpl._logEvent = function(event) | 1212 CommandLineAPIImpl._logEvent = function(event) |
1261 { | 1213 { |
1262 inspectedGlobalObject.console.log(event.type, event); | 1214 inspectedGlobalObject.console.log(event.type, event); |
1263 } | 1215 } |
1264 | 1216 |
1265 return injectedScript; | 1217 return injectedScript; |
1266 }) | 1218 }) |
OLD | NEW |