Index: src/mirror-debugger.js |
diff --git a/src/mirror-debugger.js b/src/mirror-debugger.js |
index 897413cfda535284fefe7b5fc2361108c20fb958..e717f6e0706fc232a2c252deb848b51243871b6e 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 = %_CallFunction(this.value_, builtins.MapEntries); |
+ 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 |