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

Unified Diff: src/mirror-debugger.js

Issue 712083002: Add optional max elements limit for Map/Set mirror iterator preview. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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/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 da031d3383b55321827fee2d8bbb8e14477e7049..c8d2461d6bf46f30c608b836adba3a78f2ed191f 100644
--- a/src/mirror-debugger.js
+++ b/src/mirror-debugger.js
@@ -1322,13 +1322,14 @@ inherits(MapMirror, ObjectMirror);
* Returns an array of key/value pairs of a map.
* This will keep keys alive for WeakMaps.
*
+ * @param {number=} opt_limit Max elements to return.
* @returns {Array.<Object>} Array of key/value pairs of a map.
*/
-MapMirror.prototype.entries = function() {
+MapMirror.prototype.entries = function(opt_limit) {
var result = [];
if (IS_WEAKMAP(this.value_)) {
- var entries = %GetWeakMapEntries(this.value_);
+ var entries = %GetWeakMapEntries(this.value_, opt_limit || 0);
for (var i = 0; i < entries.length; i += 2) {
result.push({
key: entries[i],
@@ -1340,7 +1341,8 @@ MapMirror.prototype.entries = function() {
var iter = %_CallFunction(this.value_, builtins.MapEntries);
var next;
- while (!(next = iter.next()).done) {
+ while ((!opt_limit || result.length < opt_limit) &&
+ !(next = iter.next()).done) {
result.push({
key: next.value[0],
value: next.value[1]
@@ -1356,10 +1358,11 @@ function SetMirror(value) {
inherits(SetMirror, ObjectMirror);
-function IteratorGetValues_(iter, next_function) {
+function IteratorGetValues_(iter, next_function, opt_limit) {
var result = [];
var next;
- while (!(next = %_CallFunction(iter, next_function)).done) {
+ while ((!opt_limit || result.length < opt_limit) &&
+ !(next = %_CallFunction(iter, next_function)).done) {
result.push(next.value);
}
return result;
@@ -1370,15 +1373,16 @@ function IteratorGetValues_(iter, next_function) {
* Returns an array of elements of a set.
* This will keep elements alive for WeakSets.
*
+ * @param {number=} opt_limit Max elements to return.
* @returns {Array.<Object>} Array of elements of a set.
*/
-SetMirror.prototype.values = function() {
+SetMirror.prototype.values = function(opt_limit) {
if (IS_WEAKSET(this.value_)) {
- return %GetWeakSetValues(this.value_);
+ return %GetWeakSetValues(this.value_, opt_limit || 0);
}
var iter = %_CallFunction(this.value_, builtins.SetValues);
- return IteratorGetValues_(iter, builtins.SetIteratorNextJS);
+ return IteratorGetValues_(iter, builtins.SetIteratorNextJS, opt_limit);
};
@@ -1392,15 +1396,18 @@ inherits(IteratorMirror, ObjectMirror);
* Returns a preview of elements of an iterator.
* Does not change the backing iterator state.
*
+ * @param {number=} opt_limit Max elements to return.
* @returns {Array.<Object>} Array of elements of an iterator.
*/
-IteratorMirror.prototype.preview = function() {
+IteratorMirror.prototype.preview = function(opt_limit) {
if (IS_MAP_ITERATOR(this.value_)) {
return IteratorGetValues_(%MapIteratorClone(this.value_),
- builtins.MapIteratorNextJS);
+ builtins.MapIteratorNextJS,
+ opt_limit);
} else if (IS_SET_ITERATOR(this.value_)) {
return IteratorGetValues_(%SetIteratorClone(this.value_),
- builtins.SetIteratorNextJS);
+ builtins.SetIteratorNextJS,
+ opt_limit);
}
};
« no previous file with comments | « no previous file | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698