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

Side by Side Diff: src/mirror-debugger.js

Issue 693813002: Add debug mirror support for ES6 Map/Set iterators. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: added TODO 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/factory.cc ('k') | src/runtime/runtime.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2012 the V8 project authors. All rights reserved. 1 // Copyright 2006-2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Handle id counters. 5 // Handle id counters.
6 var next_handle_ = 0; 6 var next_handle_ = 0;
7 var next_transient_handle_ = -1; 7 var next_transient_handle_ = -1;
8 8
9 // Mirror cache. 9 // Mirror cache.
10 var mirror_cache_ = []; 10 var mirror_cache_ = [];
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } else if (IS_REGEXP(value)) { 78 } else if (IS_REGEXP(value)) {
79 mirror = new RegExpMirror(value); 79 mirror = new RegExpMirror(value);
80 } else if (IS_ERROR(value)) { 80 } else if (IS_ERROR(value)) {
81 mirror = new ErrorMirror(value); 81 mirror = new ErrorMirror(value);
82 } else if (IS_SCRIPT(value)) { 82 } else if (IS_SCRIPT(value)) {
83 mirror = new ScriptMirror(value); 83 mirror = new ScriptMirror(value);
84 } else if (IS_MAP(value) || IS_WEAKMAP(value)) { 84 } else if (IS_MAP(value) || IS_WEAKMAP(value)) {
85 mirror = new MapMirror(value); 85 mirror = new MapMirror(value);
86 } else if (IS_SET(value) || IS_WEAKSET(value)) { 86 } else if (IS_SET(value) || IS_WEAKSET(value)) {
87 mirror = new SetMirror(value); 87 mirror = new SetMirror(value);
88 } else if (IS_MAP_ITERATOR(value) || IS_SET_ITERATOR(value)) {
89 mirror = new IteratorMirror(value);
88 } else if (ObjectIsPromise(value)) { 90 } else if (ObjectIsPromise(value)) {
89 mirror = new PromiseMirror(value); 91 mirror = new PromiseMirror(value);
90 } else if (IS_GENERATOR(value)) { 92 } else if (IS_GENERATOR(value)) {
91 mirror = new GeneratorMirror(value); 93 mirror = new GeneratorMirror(value);
92 } else { 94 } else {
93 mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient); 95 mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient);
94 } 96 }
95 97
96 if (mirror_cache_enabled_) mirror_cache_[mirror.handle()] = mirror; 98 if (mirror_cache_enabled_) mirror_cache_[mirror.handle()] = mirror;
97 return mirror; 99 return mirror;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 var ERROR_TYPE = 'error'; 158 var ERROR_TYPE = 'error';
157 var PROPERTY_TYPE = 'property'; 159 var PROPERTY_TYPE = 'property';
158 var INTERNAL_PROPERTY_TYPE = 'internalProperty'; 160 var INTERNAL_PROPERTY_TYPE = 'internalProperty';
159 var FRAME_TYPE = 'frame'; 161 var FRAME_TYPE = 'frame';
160 var SCRIPT_TYPE = 'script'; 162 var SCRIPT_TYPE = 'script';
161 var CONTEXT_TYPE = 'context'; 163 var CONTEXT_TYPE = 'context';
162 var SCOPE_TYPE = 'scope'; 164 var SCOPE_TYPE = 'scope';
163 var PROMISE_TYPE = 'promise'; 165 var PROMISE_TYPE = 'promise';
164 var MAP_TYPE = 'map'; 166 var MAP_TYPE = 'map';
165 var SET_TYPE = 'set'; 167 var SET_TYPE = 'set';
168 var ITERATOR_TYPE = 'iterator';
166 var GENERATOR_TYPE = 'generator'; 169 var GENERATOR_TYPE = 'generator';
167 170
168 // Maximum length when sending strings through the JSON protocol. 171 // Maximum length when sending strings through the JSON protocol.
169 var kMaxProtocolStringLength = 80; 172 var kMaxProtocolStringLength = 80;
170 173
171 // Different kind of properties. 174 // Different kind of properties.
172 var PropertyKind = {}; 175 var PropertyKind = {};
173 PropertyKind.Named = 1; 176 PropertyKind.Named = 1;
174 PropertyKind.Indexed = 2; 177 PropertyKind.Indexed = 2;
175 178
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 // - ObjectMirror 213 // - ObjectMirror
211 // - FunctionMirror 214 // - FunctionMirror
212 // - UnresolvedFunctionMirror 215 // - UnresolvedFunctionMirror
213 // - ArrayMirror 216 // - ArrayMirror
214 // - DateMirror 217 // - DateMirror
215 // - RegExpMirror 218 // - RegExpMirror
216 // - ErrorMirror 219 // - ErrorMirror
217 // - PromiseMirror 220 // - PromiseMirror
218 // - MapMirror 221 // - MapMirror
219 // - SetMirror 222 // - SetMirror
223 // - IteratorMirror
220 // - GeneratorMirror 224 // - GeneratorMirror
221 // - PropertyMirror 225 // - PropertyMirror
222 // - InternalPropertyMirror 226 // - InternalPropertyMirror
223 // - FrameMirror 227 // - FrameMirror
224 // - ScriptMirror 228 // - ScriptMirror
225 229
226 230
227 /** 231 /**
228 * Base class for all mirror objects. 232 * Base class for all mirror objects.
229 * @param {string} type The type of the mirror 233 * @param {string} type The type of the mirror
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 /** 453 /**
450 * Check whether the mirror reflects a set. 454 * Check whether the mirror reflects a set.
451 * @returns {boolean} True if the mirror reflects a set 455 * @returns {boolean} True if the mirror reflects a set
452 */ 456 */
453 Mirror.prototype.isSet = function() { 457 Mirror.prototype.isSet = function() {
454 return this instanceof SetMirror; 458 return this instanceof SetMirror;
455 }; 459 };
456 460
457 461
458 /** 462 /**
463 * Check whether the mirror reflects an iterator.
464 * @returns {boolean} True if the mirror reflects an iterator
465 */
466 Mirror.prototype.isIterator = function() {
467 return this instanceof IteratorMirror;
468 };
469
470
471 /**
459 * Allocate a handle id for this object. 472 * Allocate a handle id for this object.
460 */ 473 */
461 Mirror.prototype.allocateHandle_ = function() { 474 Mirror.prototype.allocateHandle_ = function() {
462 if (mirror_cache_enabled_) this.handle_ = next_handle_++; 475 if (mirror_cache_enabled_) this.handle_ = next_handle_++;
463 }; 476 };
464 477
465 478
466 /** 479 /**
467 * Allocate a transient handle id for this object. Transient handles are 480 * Allocate a transient handle id for this object. Transient handles are
468 * negative. 481 * negative.
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 return result; 1349 return result;
1337 }; 1350 };
1338 1351
1339 1352
1340 function SetMirror(value) { 1353 function SetMirror(value) {
1341 %_CallFunction(this, value, SET_TYPE, ObjectMirror); 1354 %_CallFunction(this, value, SET_TYPE, ObjectMirror);
1342 } 1355 }
1343 inherits(SetMirror, ObjectMirror); 1356 inherits(SetMirror, ObjectMirror);
1344 1357
1345 1358
1359 function IteratorGetValues_(iter, next_function) {
1360 var result = [];
1361 var next;
1362 while (!(next = %_CallFunction(iter, next_function)).done) {
1363 result.push(next.value);
1364 }
1365 return result;
1366 }
1367
1368
1346 /** 1369 /**
1347 * Returns an array of elements of a set. 1370 * Returns an array of elements of a set.
1348 * This will keep elements alive for WeakSets. 1371 * This will keep elements alive for WeakSets.
1349 * 1372 *
1350 * @returns {Array.<Object>} Array of elements of a set. 1373 * @returns {Array.<Object>} Array of elements of a set.
1351 */ 1374 */
1352 SetMirror.prototype.values = function() { 1375 SetMirror.prototype.values = function() {
1353 if (IS_WEAKSET(this.value_)) { 1376 if (IS_WEAKSET(this.value_)) {
1354 return %GetWeakSetValues(this.value_); 1377 return %GetWeakSetValues(this.value_);
1355 } 1378 }
1356 1379
1357 var result = [];
1358 var iter = %_CallFunction(this.value_, builtins.SetValues); 1380 var iter = %_CallFunction(this.value_, builtins.SetValues);
1359 var next; 1381 return IteratorGetValues_(iter, builtins.SetIteratorNextJS);
1360 while (!(next = iter.next()).done) {
1361 result.push(next.value);
1362 }
1363 return result;
1364 }; 1382 };
1365 1383
1366 1384
1385 function IteratorMirror(value) {
1386 %_CallFunction(this, value, ITERATOR_TYPE, ObjectMirror);
1387 }
1388 inherits(IteratorMirror, ObjectMirror);
1389
1390
1391 /**
1392 * Returns a preview of elements of an iterator.
1393 * Does not change the backing iterator state.
1394 *
1395 * @returns {Array.<Object>} Array of elements of an iterator.
1396 */
1397 IteratorMirror.prototype.preview = function() {
1398 if (IS_MAP_ITERATOR(this.value_)) {
1399 return IteratorGetValues_(%MapIteratorClone(this.value_),
1400 builtins.MapIteratorNextJS);
1401 } else if (IS_SET_ITERATOR(this.value_)) {
1402 return IteratorGetValues_(%SetIteratorClone(this.value_),
1403 builtins.SetIteratorNextJS);
1404 }
1405 };
1406
1407
1367 /** 1408 /**
1368 * Mirror object for a Generator object. 1409 * Mirror object for a Generator object.
1369 * @param {Object} data The Generator object 1410 * @param {Object} data The Generator object
1370 * @constructor 1411 * @constructor
1371 * @extends Mirror 1412 * @extends Mirror
1372 */ 1413 */
1373 function GeneratorMirror(value) { 1414 function GeneratorMirror(value) {
1374 %_CallFunction(this, value, GENERATOR_TYPE, ObjectMirror); 1415 %_CallFunction(this, value, GENERATOR_TYPE, ObjectMirror);
1375 } 1416 }
1376 inherits(GeneratorMirror, ObjectMirror); 1417 inherits(GeneratorMirror, ObjectMirror);
(...skipping 1589 matching lines...) Expand 10 before | Expand all | Expand 10 after
2966 } 3007 }
2967 if (!NUMBER_IS_FINITE(value)) { 3008 if (!NUMBER_IS_FINITE(value)) {
2968 if (value > 0) { 3009 if (value > 0) {
2969 return 'Infinity'; 3010 return 'Infinity';
2970 } else { 3011 } else {
2971 return '-Infinity'; 3012 return '-Infinity';
2972 } 3013 }
2973 } 3014 }
2974 return value; 3015 return value;
2975 } 3016 }
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698