Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Unified Diff: src/mirror-debugger.js

Issue 398513005: Expose the content of Maps and WeakMaps through MapMirror. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: REBASE Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/runtime.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698