| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 completionsReadyCallback([]); | 504 completionsReadyCallback([]); |
| 505 return; | 505 return; |
| 506 } | 506 } |
| 507 | 507 |
| 508 if (!prefix && !expressionString && !force) { | 508 if (!prefix && !expressionString && !force) { |
| 509 completionsReadyCallback([]); | 509 completionsReadyCallback([]); |
| 510 return; | 510 return; |
| 511 } | 511 } |
| 512 | 512 |
| 513 if (!expressionString && this.debuggerModel.selectedCallFrame()) | 513 if (!expressionString && this.debuggerModel.selectedCallFrame()) |
| 514 this.debuggerModel.selectedCallFrame().variableNames(receivedPropert
yNames.bind(this)); | 514 this.debuggerModel.selectedCallFrame().variableNames((names) => rece
ivedPropertyNames.call(this, Object.keys(names))); |
| 515 else | 515 else |
| 516 this.evaluate(expressionString, "completion", true, true, false, fal
se, false, evaluated.bind(this)); | 516 this.evaluate(expressionString, "completion", true, true, false, fal
se, false, evaluated.bind(this)); |
| 517 | 517 |
| 518 /** | 518 /** |
| 519 * @param {?WebInspector.RemoteObject} result |
| 520 * @param {boolean} wasThrown |
| 519 * @this {WebInspector.ExecutionContext} | 521 * @this {WebInspector.ExecutionContext} |
| 520 */ | 522 */ |
| 521 function evaluated(result, wasThrown) | 523 function evaluated(result, wasThrown) |
| 522 { | 524 { |
| 523 if (!result || wasThrown) { | 525 if (!result || wasThrown) { |
| 524 completionsReadyCallback([]); | 526 completionsReadyCallback([]); |
| 525 return; | 527 return; |
| 526 } | 528 } |
| 527 | 529 result.getCompletionsPromise().then(receivedPropertyNames.bind(this)
); |
| 528 /** | |
| 529 * @param {string=} type | |
| 530 * @suppressReceiverCheck | |
| 531 * @this {WebInspector.ExecutionContext} | |
| 532 */ | |
| 533 function getCompletions(type) | |
| 534 { | |
| 535 var object; | |
| 536 if (type === "string") | |
| 537 object = new String(""); | |
| 538 else if (type === "number") | |
| 539 object = new Number(0); | |
| 540 else if (type === "boolean") | |
| 541 object = new Boolean(false); | |
| 542 else | |
| 543 object = this; | |
| 544 | |
| 545 var resultSet = {}; | |
| 546 try { | |
| 547 for (var o = object; o; o = o.__proto__) { | |
| 548 if (type === "array" && o === object && ArrayBuffer.isVi
ew(o) && o.length > 9999) | |
| 549 continue; | |
| 550 var names = Object.getOwnPropertyNames(o); | |
| 551 var isArray = Array.isArray(o); | |
| 552 for (var i = 0; i < names.length; ++i) { | |
| 553 // Skip array elements indexes. | |
| 554 if (isArray && /^[0-9]/.test(names[i])) | |
| 555 continue; | |
| 556 resultSet[names[i]] = true; | |
| 557 } | |
| 558 } | |
| 559 } catch (e) { | |
| 560 } | |
| 561 return resultSet; | |
| 562 } | |
| 563 | |
| 564 if (result.type === "object" || result.type === "function") | |
| 565 result.callFunctionJSON(getCompletions, [WebInspector.RemoteObje
ct.toCallArgument(result.subtype)], receivedPropertyNames.bind(this)); | |
| 566 else if (result.type === "string" || result.type === "number" || res
ult.type === "boolean") | |
| 567 this.evaluate("(" + getCompletions + ")(\"" + result.type + "\")
", "completion", false, true, true, false, false, receivedPropertyNamesFromEval.
bind(this)); | |
| 568 } | 530 } |
| 569 | 531 |
| 570 /** | 532 /** |
| 571 * @param {?WebInspector.RemoteObject} notRelevant | 533 * @param {?Array<string>} propertyNames |
| 572 * @param {boolean} wasThrown | |
| 573 * @param {?RuntimeAgent.RemoteObject=} result | |
| 574 * @this {WebInspector.ExecutionContext} | |
| 575 */ | |
| 576 function receivedPropertyNamesFromEval(notRelevant, wasThrown, result) | |
| 577 { | |
| 578 if (result && !wasThrown) | |
| 579 receivedPropertyNames.call(this, result.value); | |
| 580 else | |
| 581 completionsReadyCallback([]); | |
| 582 } | |
| 583 | |
| 584 /** | |
| 585 * @this {WebInspector.ExecutionContext} | 534 * @this {WebInspector.ExecutionContext} |
| 586 */ | 535 */ |
| 587 function receivedPropertyNames(propertyNames) | 536 function receivedPropertyNames(propertyNames) |
| 588 { | 537 { |
| 589 this.target().runtimeAgent().releaseObjectGroup("completion"); | 538 this.target().runtimeAgent().releaseObjectGroup("completion"); |
| 590 if (!propertyNames) { | 539 if (!propertyNames) { |
| 591 completionsReadyCallback([]); | 540 completionsReadyCallback([]); |
| 592 return; | 541 return; |
| 593 } | 542 } |
| 594 var includeCommandLineAPI = (!dotNotation && !bracketNotation); | 543 var includeCommandLineAPI = (!dotNotation && !bracketNotation); |
| 595 if (includeCommandLineAPI) { | 544 if (includeCommandLineAPI) { |
| 596 const commandLineAPI = ["dir", "dirxml", "keys", "values", "prof
ile", "profileEnd", "monitorEvents", "unmonitorEvents", "inspect", "copy", "clea
r", | 545 const commandLineAPI = ["dir", "dirxml", "keys", "values", "prof
ile", "profileEnd", "monitorEvents", "unmonitorEvents", "inspect", "copy", "clea
r", |
| 597 "getEventListeners", "debug", "undebug", "monitor", "unmonit
or", "table", "$", "$$", "$x"]; | 546 "getEventListeners", "debug", "undebug", "monitor", "unmonit
or", "table", "$", "$$", "$x"]; |
| 598 for (var i = 0; i < commandLineAPI.length; ++i) | 547 for (var i = 0; i < commandLineAPI.length; ++i) |
| 599 propertyNames[commandLineAPI[i]] = true; | 548 propertyNames.push(commandLineAPI[i]); |
| 600 } | 549 } |
| 601 this._reportCompletions(completionsReadyCallback, dotNotation, brack
etNotation, expressionString, prefix, Object.keys(propertyNames)); | 550 propertyNames.sort(); |
| 551 this._reportCompletions(completionsReadyCallback, dotNotation, brack
etNotation, expressionString, prefix, propertyNames); |
| 602 } | 552 } |
| 603 }, | 553 }, |
| 604 | 554 |
| 605 /** | 555 /** |
| 606 * @param {function(!Array.<string>, number=)} completionsReadyCallback | 556 * @param {function(!Array.<string>, number=)} completionsReadyCallback |
| 607 * @param {boolean} dotNotation | 557 * @param {boolean} dotNotation |
| 608 * @param {boolean} bracketNotation | 558 * @param {boolean} bracketNotation |
| 609 * @param {string} expressionString | 559 * @param {string} expressionString |
| 610 * @param {string} prefix | 560 * @param {string} prefix |
| 611 * @param {!Array.<string>} properties | 561 * @param {!Array.<string>} properties |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 /** | 763 /** |
| 814 * @param {string} listenerType | 764 * @param {string} listenerType |
| 815 */ | 765 */ |
| 816 setListenerType: function(listenerType) | 766 setListenerType: function(listenerType) |
| 817 { | 767 { |
| 818 this._listenerType = listenerType; | 768 this._listenerType = listenerType; |
| 819 }, | 769 }, |
| 820 | 770 |
| 821 __proto__: WebInspector.SDKObject.prototype | 771 __proto__: WebInspector.SDKObject.prototype |
| 822 } | 772 } |
| OLD | NEW |