| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 "use strict"; | 5 "use strict"; |
| 6 | 6 |
| 7 String.prototype.startsWith = function (str) { | |
| 8 if (str.length > this.length) { | |
| 9 return false; | |
| 10 } | |
| 11 return this.substr(0, str.length) == str; | |
| 12 }; | |
| 13 | |
| 14 function ToInspectableObject(obj) { | |
| 15 if (!obj && typeof obj === 'object') { | |
| 16 return UNDEFINED; | |
| 17 } else { | |
| 18 return Object(obj); | |
| 19 } | |
| 20 } | |
| 21 | |
| 22 function GetCompletions(global, last, full) { | |
| 23 var full_tokens = full.split(); | |
| 24 full = full_tokens.pop(); | |
| 25 var parts = full.split('.'); | |
| 26 parts.pop(); | |
| 27 var current = global; | |
| 28 for (var i = 0; i < parts.length; i++) { | |
| 29 var part = parts[i]; | |
| 30 var next = current[part]; | |
| 31 if (!next) { | |
| 32 return []; | |
| 33 } | |
| 34 current = next; | |
| 35 } | |
| 36 var result = []; | |
| 37 current = ToInspectableObject(current); | |
| 38 while (typeof current !== 'undefined') { | |
| 39 var mirror = new $debug.ObjectMirror(current); | |
| 40 var properties = mirror.properties(); | |
| 41 for (var i = 0; i < properties.length; i++) { | |
| 42 var name = properties[i].name(); | |
| 43 if (typeof name === 'string' && name.startsWith(last)) { | |
| 44 result.push(name); | |
| 45 } | |
| 46 } | |
| 47 current = ToInspectableObject(Object.getPrototypeOf(current)); | |
| 48 } | |
| 49 return result; | |
| 50 } | |
| 51 | |
| 52 // A more universal stringify that supports more types than JSON. | 7 // A more universal stringify that supports more types than JSON. |
| 53 // Used by the d8 shell to output results. | 8 // Used by the d8 shell to output results. |
| 54 var stringifyDepthLimit = 4; // To avoid crashing on cyclic objects | 9 var stringifyDepthLimit = 4; // To avoid crashing on cyclic objects |
| 55 | 10 |
| 56 function Stringify(x, depth) { | 11 function Stringify(x, depth) { |
| 57 if (depth === undefined) | 12 if (depth === undefined) |
| 58 depth = stringifyDepthLimit; | 13 depth = stringifyDepthLimit; |
| 59 else if (depth === 0) | 14 else if (depth === 0) |
| 60 return "*"; | 15 return "*"; |
| 61 switch (typeof x) { | 16 switch (typeof x) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 if (desc.set) { | 56 if (desc.set) { |
| 102 var setter = Stringify(desc.set); | 57 var setter = Stringify(desc.set); |
| 103 props.push("set " + name + setter.slice(setter.indexOf('('))); | 58 props.push("set " + name + setter.slice(setter.indexOf('('))); |
| 104 } | 59 } |
| 105 } | 60 } |
| 106 return "{" + props.join(", ") + "}"; | 61 return "{" + props.join(", ") + "}"; |
| 107 default: | 62 default: |
| 108 return "[crazy non-standard value]"; | 63 return "[crazy non-standard value]"; |
| 109 } | 64 } |
| 110 } | 65 } |
| OLD | NEW |