ObjectPropertiesSection.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. /*
  2. * Copyright (C) 2008 Apple Inc. All Rights Reserved.
  3. * Copyright (C) 2009 Joseph Pecoraro
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  15. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  18. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  22. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. /**
  27. * @constructor
  28. * @extends {WebInspector.PropertiesSection}
  29. * @param {WebInspector.RemoteObject} object
  30. * @param {?string|Element=} title
  31. * @param {string=} subtitle
  32. * @param {?string=} emptyPlaceholder
  33. * @param {boolean=} ignoreHasOwnProperty
  34. * @param {Array.<WebInspector.RemoteObjectProperty>=} extraProperties
  35. * @param {function(new:TreeElement, WebInspector.RemoteObjectProperty)=} treeElementConstructor
  36. */
  37. WebInspector.ObjectPropertiesSection = function(object, title, subtitle, emptyPlaceholder, ignoreHasOwnProperty, extraProperties, treeElementConstructor)
  38. {
  39. this.emptyPlaceholder = (emptyPlaceholder || WebInspector.UIString("No Properties"));
  40. this.object = object;
  41. this.ignoreHasOwnProperty = ignoreHasOwnProperty;
  42. this.extraProperties = extraProperties;
  43. this.treeElementConstructor = treeElementConstructor || WebInspector.ObjectPropertyTreeElement;
  44. this.editable = true;
  45. this.skipProto = false;
  46. WebInspector.PropertiesSection.call(this, title || "", subtitle);
  47. }
  48. WebInspector.ObjectPropertiesSection._arrayLoadThreshold = 100;
  49. WebInspector.ObjectPropertiesSection.prototype = {
  50. enableContextMenu: function()
  51. {
  52. this.element.addEventListener("contextmenu", this._contextMenuEventFired.bind(this), false);
  53. },
  54. _contextMenuEventFired: function(event)
  55. {
  56. var contextMenu = new WebInspector.ContextMenu(event);
  57. contextMenu.appendApplicableItems(this.object);
  58. contextMenu.show();
  59. },
  60. onpopulate: function()
  61. {
  62. this.update();
  63. },
  64. update: function()
  65. {
  66. if (this.object.arrayLength() > WebInspector.ObjectPropertiesSection._arrayLoadThreshold) {
  67. this.propertiesTreeOutline.removeChildren();
  68. WebInspector.ArrayGroupingTreeElement._populateArray(this.propertiesTreeOutline, this.object, 0, this.object.arrayLength() - 1);
  69. return;
  70. }
  71. /**
  72. * @param {?Array.<WebInspector.RemoteObjectProperty>} properties
  73. * @param {?Array.<WebInspector.RemoteObjectProperty>} internalProperties
  74. */
  75. function callback(properties, internalProperties)
  76. {
  77. if (!properties)
  78. return;
  79. this.updateProperties(properties, internalProperties);
  80. }
  81. WebInspector.RemoteObject.loadFromObject(this.object, !!this.ignoreHasOwnProperty, callback.bind(this));
  82. },
  83. updateProperties: function(properties, internalProperties, rootTreeElementConstructor, rootPropertyComparer)
  84. {
  85. if (!rootTreeElementConstructor)
  86. rootTreeElementConstructor = this.treeElementConstructor;
  87. if (!rootPropertyComparer)
  88. rootPropertyComparer = WebInspector.ObjectPropertiesSection.CompareProperties;
  89. if (this.extraProperties) {
  90. for (var i = 0; i < this.extraProperties.length; ++i)
  91. properties.push(this.extraProperties[i]);
  92. }
  93. this.propertiesTreeOutline.removeChildren();
  94. WebInspector.ObjectPropertyTreeElement.populateWithProperties(this.propertiesTreeOutline,
  95. properties, internalProperties,
  96. rootTreeElementConstructor, rootPropertyComparer,
  97. this.skipProto, this.object);
  98. this.propertiesForTest = properties;
  99. if (!this.propertiesTreeOutline.children.length) {
  100. var title = document.createElement("div");
  101. title.className = "info";
  102. title.textContent = this.emptyPlaceholder;
  103. var infoElement = new TreeElement(title, null, false);
  104. this.propertiesTreeOutline.appendChild(infoElement);
  105. }
  106. },
  107. __proto__: WebInspector.PropertiesSection.prototype
  108. }
  109. /**
  110. * @param {WebInspector.RemoteObjectProperty} propertyA
  111. * @param {WebInspector.RemoteObjectProperty} propertyB
  112. * @return {number}
  113. */
  114. WebInspector.ObjectPropertiesSection.CompareProperties = function(propertyA, propertyB)
  115. {
  116. var a = propertyA.name;
  117. var b = propertyB.name;
  118. if (a === "__proto__")
  119. return 1;
  120. if (b === "__proto__")
  121. return -1;
  122. return String.naturalOrderComparator(a, b);
  123. }
  124. /**
  125. * @constructor
  126. * @extends {TreeElement}
  127. * @param {WebInspector.RemoteObjectProperty} property
  128. */
  129. WebInspector.ObjectPropertyTreeElement = function(property)
  130. {
  131. this.property = property;
  132. // Pass an empty title, the title gets made later in onattach.
  133. TreeElement.call(this, "", null, false);
  134. this.toggleOnClick = true;
  135. this.selectable = false;
  136. }
  137. WebInspector.ObjectPropertyTreeElement.prototype = {
  138. onpopulate: function()
  139. {
  140. return WebInspector.ObjectPropertyTreeElement.populate(this, this.property.value);
  141. },
  142. ondblclick: function(event)
  143. {
  144. if (this.property.writable || this.property.setter)
  145. this.startEditing(event);
  146. },
  147. onattach: function()
  148. {
  149. this.update();
  150. },
  151. update: function()
  152. {
  153. this.nameElement = document.createElement("span");
  154. this.nameElement.className = "name";
  155. this.nameElement.textContent = this.property.name;
  156. if (!this.property.enumerable)
  157. this.nameElement.addStyleClass("dimmed");
  158. if (this.property.isAccessorProperty())
  159. this.nameElement.addStyleClass("properties-accessor-property-name");
  160. var separatorElement = document.createElement("span");
  161. separatorElement.className = "separator";
  162. separatorElement.textContent = ": ";
  163. if (this.property.value) {
  164. this.valueElement = document.createElement("span");
  165. this.valueElement.className = "value";
  166. var description = this.property.value.description;
  167. // Render \n as a nice unicode cr symbol.
  168. if (this.property.wasThrown)
  169. this.valueElement.textContent = "[Exception: " + description + "]";
  170. else if (this.property.value.type === "string" && typeof description === "string") {
  171. this.valueElement.textContent = "\"" + description.replace(/\n/g, "\u21B5") + "\"";
  172. this.valueElement._originalTextContent = "\"" + description + "\"";
  173. } else if (this.property.value.type === "function" && typeof description === "string") {
  174. this.valueElement.textContent = /.*/.exec(description)[0].replace(/ +$/g, "");
  175. this.valueElement._originalTextContent = description;
  176. } else if (this.property.value.type !== "object" || this.property.value.subtype !== "node")
  177. this.valueElement.textContent = description;
  178. if (this.property.wasThrown)
  179. this.valueElement.addStyleClass("error");
  180. if (this.property.value.subtype)
  181. this.valueElement.addStyleClass("console-formatted-" + this.property.value.subtype);
  182. else if (this.property.value.type)
  183. this.valueElement.addStyleClass("console-formatted-" + this.property.value.type);
  184. this.valueElement.addEventListener("contextmenu", this._contextMenuFired.bind(this, this.property.value), false);
  185. if (this.property.value.type === "object" && this.property.value.subtype === "node" && this.property.value.description) {
  186. WebInspector.DOMPresentationUtils.createSpansForNodeTitle(this.valueElement, this.property.value.description);
  187. this.valueElement.addEventListener("mousemove", this._mouseMove.bind(this, this.property.value), false);
  188. this.valueElement.addEventListener("mouseout", this._mouseOut.bind(this, this.property.value), false);
  189. } else
  190. this.valueElement.title = description || "";
  191. this.listItemElement.removeChildren();
  192. this.hasChildren = this.property.value.hasChildren && !this.property.wasThrown;
  193. } else {
  194. if (this.property.getter) {
  195. this.valueElement = document.createElement("span");
  196. this.valueElement.addStyleClass("properties-calculate-value-button");
  197. this.valueElement.textContent = "(...)";
  198. this.valueElement.title = "Invoke property getter";
  199. this.valueElement.addEventListener("click", this._onInvokeGetterClick.bind(this), false);
  200. } else {
  201. this.valueElement = document.createElement("span");
  202. this.valueElement.textContent = "<unreadable>"
  203. }
  204. }
  205. this.listItemElement.appendChild(this.nameElement);
  206. this.listItemElement.appendChild(separatorElement);
  207. this.listItemElement.appendChild(this.valueElement);
  208. },
  209. _contextMenuFired: function(value, event)
  210. {
  211. var contextMenu = new WebInspector.ContextMenu(event);
  212. this.populateContextMenu(contextMenu);
  213. contextMenu.appendApplicableItems(value);
  214. contextMenu.show();
  215. },
  216. /**
  217. * @param {WebInspector.ContextMenu} contextMenu
  218. */
  219. populateContextMenu: function(contextMenu)
  220. {
  221. },
  222. _mouseMove: function(event)
  223. {
  224. this.property.value.highlightAsDOMNode();
  225. },
  226. _mouseOut: function(event)
  227. {
  228. this.property.value.hideDOMNodeHighlight();
  229. },
  230. updateSiblings: function()
  231. {
  232. if (this.parent.root)
  233. this.treeOutline.section.update();
  234. else
  235. this.parent.shouldRefreshChildren = true;
  236. },
  237. renderPromptAsBlock: function()
  238. {
  239. return false;
  240. },
  241. /**
  242. * @param {Event=} event
  243. */
  244. elementAndValueToEdit: function(event)
  245. {
  246. return [this.valueElement, (typeof this.valueElement._originalTextContent === "string") ? this.valueElement._originalTextContent : undefined];
  247. },
  248. startEditing: function(event)
  249. {
  250. var elementAndValueToEdit = this.elementAndValueToEdit(event);
  251. var elementToEdit = elementAndValueToEdit[0];
  252. var valueToEdit = elementAndValueToEdit[1];
  253. if (WebInspector.isBeingEdited(elementToEdit) || !this.treeOutline.section.editable || this._readOnly)
  254. return;
  255. // Edit original source.
  256. if (typeof valueToEdit !== "undefined")
  257. elementToEdit.textContent = valueToEdit;
  258. var context = { expanded: this.expanded, elementToEdit: elementToEdit, previousContent: elementToEdit.textContent };
  259. // Lie about our children to prevent expanding on double click and to collapse subproperties.
  260. this.hasChildren = false;
  261. this.listItemElement.addStyleClass("editing-sub-part");
  262. this._prompt = new WebInspector.ObjectPropertyPrompt(this.editingCommitted.bind(this, null, elementToEdit.textContent, context.previousContent, context), this.editingCancelled.bind(this, null, context), this.renderPromptAsBlock());
  263. function blurListener()
  264. {
  265. this.editingCommitted(null, elementToEdit.textContent, context.previousContent, context);
  266. }
  267. var proxyElement = this._prompt.attachAndStartEditing(elementToEdit, blurListener.bind(this));
  268. window.getSelection().setBaseAndExtent(elementToEdit, 0, elementToEdit, 1);
  269. proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this, context), false);
  270. },
  271. /**
  272. * @return {boolean}
  273. */
  274. isEditing: function()
  275. {
  276. return !!this._prompt;
  277. },
  278. editingEnded: function(context)
  279. {
  280. this._prompt.detach();
  281. delete this._prompt;
  282. this.listItemElement.scrollLeft = 0;
  283. this.listItemElement.removeStyleClass("editing-sub-part");
  284. if (context.expanded)
  285. this.expand();
  286. },
  287. editingCancelled: function(element, context)
  288. {
  289. this.editingEnded(context);
  290. this.update();
  291. },
  292. editingCommitted: function(element, userInput, previousContent, context)
  293. {
  294. if (userInput === previousContent)
  295. return this.editingCancelled(element, context); // nothing changed, so cancel
  296. this.editingEnded(context);
  297. this.applyExpression(userInput, true);
  298. },
  299. _promptKeyDown: function(context, event)
  300. {
  301. if (isEnterKey(event)) {
  302. event.consume(true);
  303. return this.editingCommitted(null, context.elementToEdit.textContent, context.previousContent, context);
  304. }
  305. if (event.keyIdentifier === "U+001B") { // Esc
  306. event.consume();
  307. return this.editingCancelled(null, context);
  308. }
  309. },
  310. applyExpression: function(expression, updateInterface)
  311. {
  312. expression = expression.trim();
  313. var expressionLength = expression.length;
  314. function callback(error)
  315. {
  316. if (!updateInterface)
  317. return;
  318. if (error)
  319. this.update();
  320. if (!expressionLength) {
  321. // The property was deleted, so remove this tree element.
  322. this.parent.removeChild(this);
  323. } else {
  324. // Call updateSiblings since their value might be based on the value that just changed.
  325. this.updateSiblings();
  326. }
  327. };
  328. this.property.parentObject.setPropertyValue(this.property.name, expression.trim(), callback.bind(this));
  329. },
  330. propertyPath: function()
  331. {
  332. if ("_cachedPropertyPath" in this)
  333. return this._cachedPropertyPath;
  334. var current = this;
  335. var result;
  336. do {
  337. if (current.property) {
  338. if (result)
  339. result = current.property.name + "." + result;
  340. else
  341. result = current.property.name;
  342. }
  343. current = current.parent;
  344. } while (current && !current.root);
  345. this._cachedPropertyPath = result;
  346. return result;
  347. },
  348. _onInvokeGetterClick: function(event)
  349. {
  350. /**
  351. * @param {?Protocol.Error} error
  352. * @param {RuntimeAgent.RemoteObject} result
  353. * @param {boolean=} wasThrown
  354. */
  355. function evaluateCallback(error, result, wasThrown)
  356. {
  357. if (error)
  358. return;
  359. var remoteObject = WebInspector.RemoteObject.fromPayload(result);
  360. this.property.value = remoteObject;
  361. this.property.wasThrown = wasThrown;
  362. this.update();
  363. this.shouldRefreshChildren = true;
  364. }
  365. event.consume();
  366. if (!this.property.getter)
  367. return;
  368. var functionText = "function(th){return this.call(th);}"
  369. var functionArguments = [ {objectId: this.property.parentObject.objectId} ]
  370. RuntimeAgent.callFunctionOn(this.property.getter.objectId, functionText, functionArguments,
  371. undefined, false, undefined, evaluateCallback.bind(this));
  372. },
  373. __proto__: TreeElement.prototype
  374. }
  375. /**
  376. * @param {TreeElement} treeElement
  377. * @param {WebInspector.RemoteObject} value
  378. */
  379. WebInspector.ObjectPropertyTreeElement.populate = function(treeElement, value) {
  380. if (treeElement.children.length && !treeElement.shouldRefreshChildren)
  381. return;
  382. if (value.arrayLength() > WebInspector.ObjectPropertiesSection._arrayLoadThreshold) {
  383. treeElement.removeChildren();
  384. WebInspector.ArrayGroupingTreeElement._populateArray(treeElement, value, 0, value.arrayLength() - 1);
  385. return;
  386. }
  387. /**
  388. * @param {Array.<WebInspector.RemoteObjectProperty>=} properties
  389. * @param {Array.<WebInspector.RemoteObjectProperty>=} internalProperties
  390. */
  391. function callback(properties, internalProperties)
  392. {
  393. treeElement.removeChildren();
  394. if (!properties)
  395. return;
  396. if (!internalProperties)
  397. internalProperties = [];
  398. WebInspector.ObjectPropertyTreeElement.populateWithProperties(treeElement, properties, internalProperties,
  399. treeElement.treeOutline.section.treeElementConstructor, WebInspector.ObjectPropertiesSection.CompareProperties,
  400. treeElement.treeOutline.section.skipProto, value);
  401. }
  402. WebInspector.RemoteObject.loadFromObjectPerProto(value, callback);
  403. }
  404. /**
  405. * @param {!TreeElement|!TreeOutline} treeElement
  406. * @param {Array.<!WebInspector.RemoteObjectProperty>} properties
  407. * @param {?Array.<!WebInspector.RemoteObjectProperty>} internalProperties
  408. * @param {function(new:TreeElement, WebInspector.RemoteObjectProperty)} treeElementConstructor
  409. * @param {function (WebInspector.RemoteObjectProperty, WebInspector.RemoteObjectProperty): number} comparator
  410. * @param {boolean} skipProto
  411. * @param {?WebInspector.RemoteObject} value
  412. */
  413. WebInspector.ObjectPropertyTreeElement.populateWithProperties = function(treeElement, properties, internalProperties, treeElementConstructor, comparator, skipProto, value) {
  414. properties.sort(comparator);
  415. for (var i = 0; i < properties.length; ++i) {
  416. var property = properties[i];
  417. if (skipProto && property.name === "__proto__")
  418. continue;
  419. if (property.isAccessorProperty()) {
  420. if (property.name !== "__proto__" && property.getter) {
  421. property.parentObject = value;
  422. treeElement.appendChild(new treeElementConstructor(property));
  423. }
  424. if (property.isOwn) {
  425. if (property.getter) {
  426. var getterProperty = new WebInspector.RemoteObjectProperty("get " + property.name, property.getter);
  427. getterProperty.parentObject = value;
  428. treeElement.appendChild(new treeElementConstructor(getterProperty));
  429. }
  430. if (property.setter) {
  431. var setterProperty = new WebInspector.RemoteObjectProperty("set " + property.name, property.setter);
  432. setterProperty.parentObject = value;
  433. treeElement.appendChild(new treeElementConstructor(setterProperty));
  434. }
  435. }
  436. } else {
  437. property.parentObject = value;
  438. treeElement.appendChild(new treeElementConstructor(property));
  439. }
  440. }
  441. if (value && value.type === "function") {
  442. // Whether function has TargetFunction internal property.
  443. // This is a simple way to tell that the function is actually a bound function (we are not told).
  444. // Bound function never has inner scope and doesn't need corresponding UI node.
  445. var hasTargetFunction = false;
  446. if (internalProperties) {
  447. for (var i = 0; i < internalProperties.length; i++) {
  448. if (internalProperties[i].name == "[[TargetFunction]]") {
  449. hasTargetFunction = true;
  450. break;
  451. }
  452. }
  453. }
  454. if (!hasTargetFunction)
  455. treeElement.appendChild(new WebInspector.FunctionScopeMainTreeElement(value));
  456. }
  457. if (internalProperties) {
  458. for (var i = 0; i < internalProperties.length; i++) {
  459. internalProperties[i].parentObject = value;
  460. treeElement.appendChild(new treeElementConstructor(internalProperties[i]));
  461. }
  462. }
  463. }
  464. /**
  465. * @constructor
  466. * @extends {TreeElement}
  467. * @param {WebInspector.RemoteObject} remoteObject
  468. */
  469. WebInspector.FunctionScopeMainTreeElement = function(remoteObject)
  470. {
  471. TreeElement.call(this, "<function scope>", null, false);
  472. this.toggleOnClick = true;
  473. this.selectable = false;
  474. this._remoteObject = remoteObject;
  475. this.hasChildren = true;
  476. }
  477. WebInspector.FunctionScopeMainTreeElement.prototype = {
  478. onpopulate: function()
  479. {
  480. if (this.children.length && !this.shouldRefreshChildren)
  481. return;
  482. function didGetDetails(error, response)
  483. {
  484. if (error) {
  485. console.error(error);
  486. return;
  487. }
  488. this.removeChildren();
  489. var scopeChain = response.scopeChain;
  490. if (!scopeChain)
  491. return;
  492. for (var i = 0; i < scopeChain.length; ++i) {
  493. var scope = scopeChain[i];
  494. var title = null;
  495. var isTrueObject;
  496. switch (scope.type) {
  497. case "local":
  498. // Not really expecting this scope type here.
  499. title = WebInspector.UIString("Local");
  500. isTrueObject = false;
  501. break;
  502. case "closure":
  503. title = WebInspector.UIString("Closure");
  504. isTrueObject = false;
  505. break;
  506. case "catch":
  507. title = WebInspector.UIString("Catch");
  508. isTrueObject = false;
  509. break;
  510. case "with":
  511. title = WebInspector.UIString("With Block");
  512. isTrueObject = true;
  513. break;
  514. case "global":
  515. title = WebInspector.UIString("Global");
  516. isTrueObject = true;
  517. break;
  518. default:
  519. console.error("Unknown scope type: " + scope.type);
  520. continue;
  521. }
  522. var scopeRef;
  523. if (isTrueObject)
  524. scopeRef = undefined;
  525. else
  526. scopeRef = new WebInspector.ScopeRef(i, undefined, this._remoteObject.objectId);
  527. var remoteObject = WebInspector.ScopeRemoteObject.fromPayload(scope.object, scopeRef);
  528. if (isTrueObject) {
  529. var property = WebInspector.RemoteObjectProperty.fromScopeValue(title, remoteObject);
  530. property.parentObject = null;
  531. this.appendChild(new this.treeOutline.section.treeElementConstructor(property));
  532. } else {
  533. var scopeTreeElement = new WebInspector.ScopeTreeElement(title, null, remoteObject);
  534. this.appendChild(scopeTreeElement);
  535. }
  536. }
  537. }
  538. DebuggerAgent.getFunctionDetails(this._remoteObject.objectId, didGetDetails.bind(this));
  539. },
  540. __proto__: TreeElement.prototype
  541. }
  542. /**
  543. * @constructor
  544. * @extends {TreeElement}
  545. * @param {WebInspector.RemoteObject} remoteObject
  546. */
  547. WebInspector.ScopeTreeElement = function(title, subtitle, remoteObject)
  548. {
  549. // TODO: use subtitle parameter.
  550. TreeElement.call(this, title, null, false);
  551. this.toggleOnClick = true;
  552. this.selectable = false;
  553. this._remoteObject = remoteObject;
  554. this.hasChildren = true;
  555. }
  556. WebInspector.ScopeTreeElement.prototype = {
  557. onpopulate: function()
  558. {
  559. return WebInspector.ObjectPropertyTreeElement.populate(this, this._remoteObject);
  560. },
  561. __proto__: TreeElement.prototype
  562. }
  563. /**
  564. * @constructor
  565. * @extends {TreeElement}
  566. * @param {WebInspector.RemoteObject} object
  567. * @param {number} fromIndex
  568. * @param {number} toIndex
  569. * @param {number} propertyCount
  570. */
  571. WebInspector.ArrayGroupingTreeElement = function(object, fromIndex, toIndex, propertyCount)
  572. {
  573. TreeElement.call(this, String.sprintf("[%d \u2026 %d]", fromIndex, toIndex), undefined, true);
  574. this._fromIndex = fromIndex;
  575. this._toIndex = toIndex;
  576. this._object = object;
  577. this._readOnly = true;
  578. this._propertyCount = propertyCount;
  579. this._populated = false;
  580. }
  581. WebInspector.ArrayGroupingTreeElement._bucketThreshold = 100;
  582. WebInspector.ArrayGroupingTreeElement._sparseIterationThreshold = 250000;
  583. /**
  584. * @param {TreeElement|TreeOutline} treeElement
  585. * @param {WebInspector.RemoteObject} object
  586. * @param {number} fromIndex
  587. * @param {number} toIndex
  588. */
  589. WebInspector.ArrayGroupingTreeElement._populateArray = function(treeElement, object, fromIndex, toIndex)
  590. {
  591. WebInspector.ArrayGroupingTreeElement._populateRanges(treeElement, object, fromIndex, toIndex, true);
  592. }
  593. /**
  594. * @param {TreeElement|TreeOutline} treeElement
  595. * @param {WebInspector.RemoteObject} object
  596. * @param {number} fromIndex
  597. * @param {number} toIndex
  598. * @param {boolean} topLevel
  599. */
  600. WebInspector.ArrayGroupingTreeElement._populateRanges = function(treeElement, object, fromIndex, toIndex, topLevel)
  601. {
  602. object.callFunctionJSON(packRanges, [{value: fromIndex}, {value: toIndex}, {value: WebInspector.ArrayGroupingTreeElement._bucketThreshold}, {value: WebInspector.ArrayGroupingTreeElement._sparseIterationThreshold}], callback.bind(this));
  603. /**
  604. * @this {Object}
  605. * @param {number=} fromIndex // must declare optional
  606. * @param {number=} toIndex // must declare optional
  607. * @param {number=} bucketThreshold // must declare optional
  608. * @param {number=} sparseIterationThreshold // must declare optional
  609. */
  610. function packRanges(fromIndex, toIndex, bucketThreshold, sparseIterationThreshold)
  611. {
  612. var ownPropertyNames = null;
  613. function doLoop(iterationCallback)
  614. {
  615. if (toIndex - fromIndex < sparseIterationThreshold) {
  616. for (var i = fromIndex; i <= toIndex; ++i) {
  617. if (i in this)
  618. iterationCallback(i);
  619. }
  620. } else {
  621. ownPropertyNames = ownPropertyNames || Object.getOwnPropertyNames(this);
  622. for (var i = 0; i < ownPropertyNames.length; ++i) {
  623. var name = ownPropertyNames[i];
  624. var index = name >>> 0;
  625. if (String(index) === name && fromIndex <= index && index <= toIndex)
  626. iterationCallback(index);
  627. }
  628. }
  629. }
  630. var count = 0;
  631. function countIterationCallback()
  632. {
  633. ++count;
  634. }
  635. doLoop.call(this, countIterationCallback);
  636. var bucketSize = count;
  637. if (count <= bucketThreshold)
  638. bucketSize = count;
  639. else
  640. bucketSize = Math.pow(bucketThreshold, Math.ceil(Math.log(count) / Math.log(bucketThreshold)) - 1);
  641. var ranges = [];
  642. count = 0;
  643. var groupStart = -1;
  644. var groupEnd = 0;
  645. function loopIterationCallback(i)
  646. {
  647. if (groupStart === -1)
  648. groupStart = i;
  649. groupEnd = i;
  650. if (++count === bucketSize) {
  651. ranges.push([groupStart, groupEnd, count]);
  652. count = 0;
  653. groupStart = -1;
  654. }
  655. }
  656. doLoop.call(this, loopIterationCallback);
  657. if (count > 0)
  658. ranges.push([groupStart, groupEnd, count]);
  659. return ranges;
  660. }
  661. function callback(ranges)
  662. {
  663. if (ranges.length == 1)
  664. WebInspector.ArrayGroupingTreeElement._populateAsFragment(treeElement, object, ranges[0][0], ranges[0][1]);
  665. else {
  666. for (var i = 0; i < ranges.length; ++i) {
  667. var fromIndex = ranges[i][0];
  668. var toIndex = ranges[i][1];
  669. var count = ranges[i][2];
  670. if (fromIndex == toIndex)
  671. WebInspector.ArrayGroupingTreeElement._populateAsFragment(treeElement, object, fromIndex, toIndex);
  672. else
  673. treeElement.appendChild(new WebInspector.ArrayGroupingTreeElement(object, fromIndex, toIndex, count));
  674. }
  675. }
  676. if (topLevel)
  677. WebInspector.ArrayGroupingTreeElement._populateNonIndexProperties(treeElement, object);
  678. }
  679. }
  680. /**
  681. * @param {TreeElement|TreeOutline} treeElement
  682. * @param {WebInspector.RemoteObject} object
  683. * @param {number} fromIndex
  684. * @param {number} toIndex
  685. */
  686. WebInspector.ArrayGroupingTreeElement._populateAsFragment = function(treeElement, object, fromIndex, toIndex)
  687. {
  688. object.callFunction(buildArrayFragment, [{value: fromIndex}, {value: toIndex}, {value: WebInspector.ArrayGroupingTreeElement._sparseIterationThreshold}], processArrayFragment.bind(this));
  689. /**
  690. * @this {Object}
  691. * @param {number=} fromIndex // must declare optional
  692. * @param {number=} toIndex // must declare optional
  693. * @param {number=} sparseIterationThreshold // must declare optional
  694. */
  695. function buildArrayFragment(fromIndex, toIndex, sparseIterationThreshold)
  696. {
  697. var result = Object.create(null);
  698. if (toIndex - fromIndex < sparseIterationThreshold) {
  699. for (var i = fromIndex; i <= toIndex; ++i) {
  700. if (i in this)
  701. result[i] = this[i];
  702. }
  703. } else {
  704. var ownPropertyNames = Object.getOwnPropertyNames(this);
  705. for (var i = 0; i < ownPropertyNames.length; ++i) {
  706. var name = ownPropertyNames[i];
  707. var index = name >>> 0;
  708. if (String(index) === name && fromIndex <= index && index <= toIndex)
  709. result[index] = this[index];
  710. }
  711. }
  712. return result;
  713. }
  714. /** @this {WebInspector.ArrayGroupingTreeElement} */
  715. function processArrayFragment(arrayFragment)
  716. {
  717. arrayFragment.getAllProperties(false, processProperties.bind(this));
  718. }
  719. /** @this {WebInspector.ArrayGroupingTreeElement} */
  720. function processProperties(properties, internalProperties)
  721. {
  722. if (!properties)
  723. return;
  724. properties.sort(WebInspector.ObjectPropertiesSection.CompareProperties);
  725. for (var i = 0; i < properties.length; ++i) {
  726. properties[i].parentObject = this._object;
  727. var childTreeElement = new treeElement.treeOutline.section.treeElementConstructor(properties[i]);
  728. childTreeElement._readOnly = true;
  729. treeElement.appendChild(childTreeElement);
  730. }
  731. }
  732. }
  733. /**
  734. * @param {TreeElement|TreeOutline} treeElement
  735. * @param {WebInspector.RemoteObject} object
  736. */
  737. WebInspector.ArrayGroupingTreeElement._populateNonIndexProperties = function(treeElement, object)
  738. {
  739. object.callFunction(buildObjectFragment, undefined, processObjectFragment.bind(this));
  740. /** @this {Object} */
  741. function buildObjectFragment()
  742. {
  743. var result = Object.create(this.__proto__);
  744. var names = Object.getOwnPropertyNames(this);
  745. for (var i = 0; i < names.length; ++i) {
  746. var name = names[i];
  747. // Array index check according to the ES5-15.4.
  748. if (String(name >>> 0) === name && name >>> 0 !== 0xffffffff)
  749. continue;
  750. var descriptor = Object.getOwnPropertyDescriptor(this, name);
  751. if (descriptor)
  752. Object.defineProperty(result, name, descriptor);
  753. }
  754. return result;
  755. }
  756. function processObjectFragment(arrayFragment)
  757. {
  758. arrayFragment.getOwnProperties(processProperties.bind(this));
  759. }
  760. /** @this {WebInspector.ArrayGroupingTreeElement} */
  761. function processProperties(properties, internalProperties)
  762. {
  763. if (!properties)
  764. return;
  765. properties.sort(WebInspector.ObjectPropertiesSection.CompareProperties);
  766. for (var i = 0; i < properties.length; ++i) {
  767. properties[i].parentObject = this._object;
  768. var childTreeElement = new treeElement.treeOutline.section.treeElementConstructor(properties[i]);
  769. childTreeElement._readOnly = true;
  770. treeElement.appendChild(childTreeElement);
  771. }
  772. }
  773. }
  774. WebInspector.ArrayGroupingTreeElement.prototype = {
  775. onpopulate: function()
  776. {
  777. if (this._populated)
  778. return;
  779. this._populated = true;
  780. if (this._propertyCount >= WebInspector.ArrayGroupingTreeElement._bucketThreshold) {
  781. WebInspector.ArrayGroupingTreeElement._populateRanges(this, this._object, this._fromIndex, this._toIndex, false);
  782. return;
  783. }
  784. WebInspector.ArrayGroupingTreeElement._populateAsFragment(this, this._object, this._fromIndex, this._toIndex);
  785. },
  786. onattach: function()
  787. {
  788. this.listItemElement.addStyleClass("name");
  789. },
  790. __proto__: TreeElement.prototype
  791. }
  792. /**
  793. * @constructor
  794. * @extends {WebInspector.TextPrompt}
  795. * @param {boolean=} renderAsBlock
  796. */
  797. WebInspector.ObjectPropertyPrompt = function(commitHandler, cancelHandler, renderAsBlock)
  798. {
  799. WebInspector.TextPrompt.call(this, WebInspector.runtimeModel.completionsForTextPrompt.bind(WebInspector.runtimeModel));
  800. this.setSuggestBoxEnabled("generic-suggest");
  801. if (renderAsBlock)
  802. this.renderAsBlock();
  803. }
  804. WebInspector.ObjectPropertyPrompt.prototype = {
  805. __proto__: WebInspector.TextPrompt.prototype
  806. }