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

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

Issue 297513006: Implement Mirror object for Symbols. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/es6/mirror-symbols.js » ('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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 if (IS_UNDEFINED(value)) { 61 if (IS_UNDEFINED(value)) {
62 mirror = new UndefinedMirror(); 62 mirror = new UndefinedMirror();
63 } else if (IS_NULL(value)) { 63 } else if (IS_NULL(value)) {
64 mirror = new NullMirror(); 64 mirror = new NullMirror();
65 } else if (IS_BOOLEAN(value)) { 65 } else if (IS_BOOLEAN(value)) {
66 mirror = new BooleanMirror(value); 66 mirror = new BooleanMirror(value);
67 } else if (IS_NUMBER(value)) { 67 } else if (IS_NUMBER(value)) {
68 mirror = new NumberMirror(value); 68 mirror = new NumberMirror(value);
69 } else if (IS_STRING(value)) { 69 } else if (IS_STRING(value)) {
70 mirror = new StringMirror(value); 70 mirror = new StringMirror(value);
71 } else if (IS_SYMBOL(value)) {
72 mirror = new SymbolMirror(value);
71 } else if (IS_ARRAY(value)) { 73 } else if (IS_ARRAY(value)) {
72 mirror = new ArrayMirror(value); 74 mirror = new ArrayMirror(value);
73 } else if (IS_DATE(value)) { 75 } else if (IS_DATE(value)) {
74 mirror = new DateMirror(value); 76 mirror = new DateMirror(value);
75 } else if (IS_FUNCTION(value)) { 77 } else if (IS_FUNCTION(value)) {
76 mirror = new FunctionMirror(value); 78 mirror = new FunctionMirror(value);
77 } else if (IS_REGEXP(value)) { 79 } else if (IS_REGEXP(value)) {
78 mirror = new RegExpMirror(value); 80 mirror = new RegExpMirror(value);
79 } else if (IS_ERROR(value)) { 81 } else if (IS_ERROR(value)) {
80 mirror = new ErrorMirror(value); 82 mirror = new ErrorMirror(value);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 ctor.prototype.constructor = ctor; 136 ctor.prototype.constructor = ctor;
135 } 137 }
136 138
137 139
138 // Type names of the different mirrors. 140 // Type names of the different mirrors.
139 var UNDEFINED_TYPE = 'undefined'; 141 var UNDEFINED_TYPE = 'undefined';
140 var NULL_TYPE = 'null'; 142 var NULL_TYPE = 'null';
141 var BOOLEAN_TYPE = 'boolean'; 143 var BOOLEAN_TYPE = 'boolean';
142 var NUMBER_TYPE = 'number'; 144 var NUMBER_TYPE = 'number';
143 var STRING_TYPE = 'string'; 145 var STRING_TYPE = 'string';
146 var SYMBOL_TYPE = 'symbol';
144 var OBJECT_TYPE = 'object'; 147 var OBJECT_TYPE = 'object';
145 var FUNCTION_TYPE = 'function'; 148 var FUNCTION_TYPE = 'function';
146 var REGEXP_TYPE = 'regexp'; 149 var REGEXP_TYPE = 'regexp';
147 var ERROR_TYPE = 'error'; 150 var ERROR_TYPE = 'error';
148 var PROPERTY_TYPE = 'property'; 151 var PROPERTY_TYPE = 'property';
149 var INTERNAL_PROPERTY_TYPE = 'internalProperty'; 152 var INTERNAL_PROPERTY_TYPE = 'internalProperty';
150 var FRAME_TYPE = 'frame'; 153 var FRAME_TYPE = 'frame';
151 var SCRIPT_TYPE = 'script'; 154 var SCRIPT_TYPE = 'script';
152 var CONTEXT_TYPE = 'context'; 155 var CONTEXT_TYPE = 'context';
153 var SCOPE_TYPE = 'scope'; 156 var SCOPE_TYPE = 'scope';
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 Block: 5 }; 194 Block: 5 };
192 195
193 196
194 // Mirror hierarchy: 197 // Mirror hierarchy:
195 // - Mirror 198 // - Mirror
196 // - ValueMirror 199 // - ValueMirror
197 // - UndefinedMirror 200 // - UndefinedMirror
198 // - NullMirror 201 // - NullMirror
199 // - NumberMirror 202 // - NumberMirror
200 // - StringMirror 203 // - StringMirror
204 // - SymbolMirror
201 // - ObjectMirror 205 // - ObjectMirror
202 // - FunctionMirror 206 // - FunctionMirror
203 // - UnresolvedFunctionMirror 207 // - UnresolvedFunctionMirror
204 // - ArrayMirror 208 // - ArrayMirror
205 // - DateMirror 209 // - DateMirror
206 // - RegExpMirror 210 // - RegExpMirror
207 // - ErrorMirror 211 // - ErrorMirror
208 // - PromiseMirror 212 // - PromiseMirror
209 // - PropertyMirror 213 // - PropertyMirror
210 // - InternalPropertyMirror 214 // - InternalPropertyMirror
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 /** 279 /**
276 * Check whether the mirror reflects a string value. 280 * Check whether the mirror reflects a string value.
277 * @returns {boolean} True if the mirror reflects a string value 281 * @returns {boolean} True if the mirror reflects a string value
278 */ 282 */
279 Mirror.prototype.isString = function() { 283 Mirror.prototype.isString = function() {
280 return this instanceof StringMirror; 284 return this instanceof StringMirror;
281 }; 285 };
282 286
283 287
284 /** 288 /**
289 * Check whether the mirror reflects a symbol.
290 * @returns {boolean} True if the mirror reflects a symbol
291 */
292 Mirror.prototype.isSymbol = function() {
293 return this instanceof SymbolMirror;
294 };
295
296
297 /**
285 * Check whether the mirror reflects an object. 298 * Check whether the mirror reflects an object.
286 * @returns {boolean} True if the mirror reflects an object 299 * @returns {boolean} True if the mirror reflects an object
287 */ 300 */
288 Mirror.prototype.isObject = function() { 301 Mirror.prototype.isObject = function() {
289 return this instanceof ObjectMirror; 302 return this instanceof ObjectMirror;
290 }; 303 };
291 304
292 305
293 /** 306 /**
294 * Check whether the mirror reflects a function. 307 * Check whether the mirror reflects a function.
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 /** 472 /**
460 * Check whether this is a primitive value. 473 * Check whether this is a primitive value.
461 * @return {boolean} True if the mirror reflects a primitive value 474 * @return {boolean} True if the mirror reflects a primitive value
462 */ 475 */
463 ValueMirror.prototype.isPrimitive = function() { 476 ValueMirror.prototype.isPrimitive = function() {
464 var type = this.type(); 477 var type = this.type();
465 return type === 'undefined' || 478 return type === 'undefined' ||
466 type === 'null' || 479 type === 'null' ||
467 type === 'boolean' || 480 type === 'boolean' ||
468 type === 'number' || 481 type === 'number' ||
469 type === 'string'; 482 type === 'string' ||
483 type === 'symbol';
470 }; 484 };
471 485
472 486
473 /** 487 /**
474 * Get the actual value reflected by this mirror. 488 * Get the actual value reflected by this mirror.
475 * @return {value} The value reflected by this mirror 489 * @return {value} The value reflected by this mirror
476 */ 490 */
477 ValueMirror.prototype.value = function() { 491 ValueMirror.prototype.value = function() {
478 return this.value_; 492 return this.value_;
479 }; 493 };
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 } 582 }
569 return this.value_; 583 return this.value_;
570 }; 584 };
571 585
572 StringMirror.prototype.toText = function() { 586 StringMirror.prototype.toText = function() {
573 return this.getTruncatedValue(kMaxProtocolStringLength); 587 return this.getTruncatedValue(kMaxProtocolStringLength);
574 }; 588 };
575 589
576 590
577 /** 591 /**
592 * Mirror object for a Symbol
593 * @param {Object} value The Symbol
594 * @constructor
595 * @extends Mirror
596 */
597 function SymbolMirror(value) {
598 %_CallFunction(this, SYMBOL_TYPE, value, ValueMirror);
599 }
600 inherits(SymbolMirror, ValueMirror);
601
602
603 SymbolMirror.prototype.description = function() {
604 return %SymbolDescription(%_ValueOf(this.value_));
605 }
606
607
608 SymbolMirror.prototype.toText = function() {
609 return %_CallFunction(this.value_, builtins.SymbolToString);
610 }
611
612
613 /**
578 * Mirror object for objects. 614 * Mirror object for objects.
579 * @param {object} value The object reflected by this mirror 615 * @param {object} value The object reflected by this mirror
580 * @param {boolean} transient indicate whether this object is transient with a 616 * @param {boolean} transient indicate whether this object is transient with a
581 * transient handle 617 * transient handle
582 * @constructor 618 * @constructor
583 * @extends ValueMirror 619 * @extends ValueMirror
584 */ 620 */
585 function ObjectMirror(value, type, transient) { 621 function ObjectMirror(value, type, transient) {
586 %_CallFunction(this, type || OBJECT_TYPE, value, transient, ValueMirror); 622 %_CallFunction(this, type || OBJECT_TYPE, value, transient, ValueMirror);
587 } 623 }
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 str = %_CallFunction(this.value_, builtins.ErrorToString); 1213 str = %_CallFunction(this.value_, builtins.ErrorToString);
1178 } catch (e) { 1214 } catch (e) {
1179 str = '#<Error>'; 1215 str = '#<Error>';
1180 } 1216 }
1181 return str; 1217 return str;
1182 }; 1218 };
1183 1219
1184 1220
1185 /** 1221 /**
1186 * Mirror object for a Promise object. 1222 * Mirror object for a Promise object.
1187 * @param {Object} data The Promise object 1223 * @param {Object} value The Promise object
1188 * @constructor 1224 * @constructor
1189 * @extends Mirror 1225 * @extends ObjectMirror
1190 */ 1226 */
1191 function PromiseMirror(value) { 1227 function PromiseMirror(value) {
1192 %_CallFunction(this, value, PROMISE_TYPE, ObjectMirror); 1228 %_CallFunction(this, value, PROMISE_TYPE, ObjectMirror);
1193 } 1229 }
1194 inherits(PromiseMirror, ObjectMirror); 1230 inherits(PromiseMirror, ObjectMirror);
1195 1231
1196 1232
1197 function PromiseGetStatus_(value) { 1233 function PromiseGetStatus_(value) {
1198 var status = %DebugGetProperty(value, builtins.promiseStatus); 1234 var status = %DebugGetProperty(value, builtins.promiseStatus);
1199 if (status == 0) return "pending"; 1235 if (status == 0) return "pending";
(...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after
2311 switch (mirror.type()) { 2347 switch (mirror.type()) {
2312 case UNDEFINED_TYPE: 2348 case UNDEFINED_TYPE:
2313 case NULL_TYPE: 2349 case NULL_TYPE:
2314 case BOOLEAN_TYPE: 2350 case BOOLEAN_TYPE:
2315 case NUMBER_TYPE: 2351 case NUMBER_TYPE:
2316 o.value = mirror.value(); 2352 o.value = mirror.value();
2317 break; 2353 break;
2318 case STRING_TYPE: 2354 case STRING_TYPE:
2319 o.value = mirror.getTruncatedValue(this.maxStringLength_()); 2355 o.value = mirror.getTruncatedValue(this.maxStringLength_());
2320 break; 2356 break;
2357 case SYMBOL_TYPE:
2358 o.description = mirror.description();
2359 break;
2321 case FUNCTION_TYPE: 2360 case FUNCTION_TYPE:
2322 o.name = mirror.name(); 2361 o.name = mirror.name();
2323 o.inferredName = mirror.inferredName(); 2362 o.inferredName = mirror.inferredName();
2324 if (mirror.script()) { 2363 if (mirror.script()) {
2325 o.scriptId = mirror.script().id(); 2364 o.scriptId = mirror.script().id();
2326 } 2365 }
2327 break; 2366 break;
2328 case ERROR_TYPE: 2367 case ERROR_TYPE:
2329 case REGEXP_TYPE: 2368 case REGEXP_TYPE:
2330 o.value = mirror.toText(); 2369 o.value = mirror.toText();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2385 var str = mirror.getTruncatedValue(this.maxStringLength_()); 2424 var str = mirror.getTruncatedValue(this.maxStringLength_());
2386 content.value = str; 2425 content.value = str;
2387 content.fromIndex = 0; 2426 content.fromIndex = 0;
2388 content.toIndex = this.maxStringLength_(); 2427 content.toIndex = this.maxStringLength_();
2389 } else { 2428 } else {
2390 content.value = mirror.value(); 2429 content.value = mirror.value();
2391 } 2430 }
2392 content.length = mirror.length(); 2431 content.length = mirror.length();
2393 break; 2432 break;
2394 2433
2434 case SYMBOL_TYPE:
2435 content.description = mirror.description();
2436 break;
2437
2395 case OBJECT_TYPE: 2438 case OBJECT_TYPE:
2396 case FUNCTION_TYPE: 2439 case FUNCTION_TYPE:
2397 case ERROR_TYPE: 2440 case ERROR_TYPE:
2398 case REGEXP_TYPE: 2441 case REGEXP_TYPE:
2399 case PROMISE_TYPE: 2442 case PROMISE_TYPE:
2400 // Add object representation. 2443 // Add object representation.
2401 this.serializeObject_(mirror, content, details); 2444 this.serializeObject_(mirror, content, details);
2402 break; 2445 break;
2403 2446
2404 case PROPERTY_TYPE: 2447 case PROPERTY_TYPE:
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
2735 } 2778 }
2736 if (!NUMBER_IS_FINITE(value)) { 2779 if (!NUMBER_IS_FINITE(value)) {
2737 if (value > 0) { 2780 if (value > 0) {
2738 return 'Infinity'; 2781 return 'Infinity';
2739 } else { 2782 } else {
2740 return '-Infinity'; 2783 return '-Infinity';
2741 } 2784 }
2742 } 2785 }
2743 return value; 2786 return value;
2744 } 2787 }
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/es6/mirror-symbols.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698