Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 | |
| 28 // How crappy is it that I have to implement completely basic stuff | |
| 29 // like this myself? Answer: very. | |
| 30 String.prototype.startsWith = function (str) { | |
| 31 if (str.length > this.length) | |
| 32 return false; | |
| 33 for (var i = 0; i < str.length; i++) { | |
|
Kasper Lund
2008/10/21 08:26:56
How about using substring and string equality chec
| |
| 34 if (str.charAt(i) != this.charAt(i)) | |
| 35 return false; | |
| 36 } | |
| 37 return true; | |
| 38 }; | |
| 39 | |
| 40 function ToInspectableObject(obj) { | |
| 41 if (!obj && typeof obj === 'object') { | |
| 42 return undefined; | |
|
Kasper Lund
2008/10/21 08:26:56
I don't trust undefined not to be overwritten by u
| |
| 43 } else { | |
| 44 return Object(obj); | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 function GetCompletions(global, last, full) { | |
| 49 var full_tokens = full.split(); | |
| 50 full = full_tokens.pop(); | |
| 51 var parts = full.split('.'); | |
| 52 parts.pop(); | |
| 53 var current = global; | |
| 54 for (var i in parts) { | |
|
Kasper Lund
2008/10/21 08:26:56
This looks weird. Do you really want all the keys
| |
| 55 var part = parts[i]; | |
| 56 var next = current[part]; | |
| 57 if (!next) | |
| 58 return []; | |
| 59 current = next; | |
| 60 } | |
| 61 var result = []; | |
| 62 current = ToInspectableObject(current); | |
| 63 while (current !== undefined) { | |
|
Kasper Lund
2008/10/21 08:26:56
I would use a typeof check against 'undefined' her
| |
| 64 var mirror = new $debug.ObjectMirror(current); | |
| 65 var properties = mirror.properties(); | |
| 66 for (var i in properties) { | |
|
Kasper Lund
2008/10/21 08:26:56
Do you really want to use for-in here too?
| |
| 67 var name = properties[i].name(); | |
| 68 if (typeof name === 'string' && name.startsWith(last)) | |
| 69 result.push(name); | |
| 70 } | |
| 71 current = ToInspectableObject(current.__proto__); | |
| 72 } | |
| 73 return result; | |
| 74 } | |
| OLD | NEW |