Chromium Code Reviews| Index: src/mirror-debugger.js |
| diff --git a/src/mirror-debugger.js b/src/mirror-debugger.js |
| index 897413cfda535284fefe7b5fc2361108c20fb958..c21992e4b662a847f7d855e81bca3cd736af6645 100644 |
| --- a/src/mirror-debugger.js |
| +++ b/src/mirror-debugger.js |
| @@ -81,6 +81,8 @@ function MakeMirror(value, opt_transient) { |
| mirror = new ErrorMirror(value); |
| } else if (IS_SCRIPT(value)) { |
| mirror = new ScriptMirror(value); |
| + } else if (IS_MAP(value) || IS_WEAKMAP(value)) { |
| + mirror = new MapMirror(value); |
| } else if (ObjectIsPromise(value)) { |
| mirror = new PromiseMirror(value); |
| } else { |
| @@ -155,6 +157,7 @@ var SCRIPT_TYPE = 'script'; |
| var CONTEXT_TYPE = 'context'; |
| var SCOPE_TYPE = 'scope'; |
| var PROMISE_TYPE = 'promise'; |
| +var MAP_TYPE = 'map'; |
| // Maximum length when sending strings through the JSON protocol. |
| var kMaxProtocolStringLength = 80; |
| @@ -210,6 +213,7 @@ var ScopeType = { Global: 0, |
| // - RegExpMirror |
| // - ErrorMirror |
| // - PromiseMirror |
| +// - MapMirror |
| // - PropertyMirror |
| // - InternalPropertyMirror |
| // - FrameMirror |
| @@ -421,6 +425,15 @@ Mirror.prototype.isScope = function() { |
| /** |
| + * Check whether the mirror reflects a map. |
| + * @returns {boolean} True if the mirror reflects a map |
| + */ |
| +Mirror.prototype.isMap = function() { |
| + return this instanceof MapMirror; |
| +}; |
| + |
| + |
| +/** |
| * Allocate a handle id for this object. |
| */ |
| Mirror.prototype.allocateHandle_ = function() { |
| @@ -1253,6 +1266,44 @@ PromiseMirror.prototype.promiseValue = function() { |
| }; |
| +function MapMirror(value) { |
| + %_CallFunction(this, value, MAP_TYPE, ObjectMirror); |
| +} |
| +inherits(MapMirror, ObjectMirror); |
| + |
| + |
| +/** |
| + * Returns an array of key/value pairs of a map. |
| + * This will keep keys alive for WeakMaps. |
| + * |
| + * @returns {Array.<Object>} Array of key/value pairs of a map. |
| + */ |
| +MapMirror.prototype.entries = function() { |
| + var result = []; |
| + |
| + if (IS_WEAKMAP(this.value_)) { |
| + var entries = %GetWeakMapEntries(this.value_); |
| + for (var i = 0; i < entries.length; i += 2) { |
| + result.push({ |
| + key: entries[i], |
| + value: entries[i + 1] |
| + }); |
| + } |
| + return result; |
| + } |
| + |
| + var iter = this.value_.entries(); |
|
arv (Not doing code reviews)
2014/07/16 19:17:20
Do we need to ensure we are calling the original e
Yang
2014/07/17 08:49:29
That is right. We need to use %_CallFunction(this.
Alexandra Mikhaylova
2014/07/17 09:16:21
Thanks, fixed it.
|
| + var next; |
| + while (!(next = iter.next()).done) { |
| + result.push({ |
| + key: next.value[0], |
| + value: next.value[1] |
| + }); |
| + } |
| + return result; |
| +}; |
| + |
| + |
| /** |
| * Base mirror object for properties. |
| * @param {ObjectMirror} mirror The mirror object having this property |