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

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

Issue 10834376: Introduce InternalProperty type and expose internal properties for bound functions (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: mjsunit skip Created 8 years, 3 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/mirror-object.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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 var UNDEFINED_TYPE = 'undefined'; 147 var UNDEFINED_TYPE = 'undefined';
148 var NULL_TYPE = 'null'; 148 var NULL_TYPE = 'null';
149 var BOOLEAN_TYPE = 'boolean'; 149 var BOOLEAN_TYPE = 'boolean';
150 var NUMBER_TYPE = 'number'; 150 var NUMBER_TYPE = 'number';
151 var STRING_TYPE = 'string'; 151 var STRING_TYPE = 'string';
152 var OBJECT_TYPE = 'object'; 152 var OBJECT_TYPE = 'object';
153 var FUNCTION_TYPE = 'function'; 153 var FUNCTION_TYPE = 'function';
154 var REGEXP_TYPE = 'regexp'; 154 var REGEXP_TYPE = 'regexp';
155 var ERROR_TYPE = 'error'; 155 var ERROR_TYPE = 'error';
156 var PROPERTY_TYPE = 'property'; 156 var PROPERTY_TYPE = 'property';
157 var INTERNAL_PROPERTY_TYPE = 'internalProperty';
157 var FRAME_TYPE = 'frame'; 158 var FRAME_TYPE = 'frame';
158 var SCRIPT_TYPE = 'script'; 159 var SCRIPT_TYPE = 'script';
159 var CONTEXT_TYPE = 'context'; 160 var CONTEXT_TYPE = 'context';
160 var SCOPE_TYPE = 'scope'; 161 var SCOPE_TYPE = 'scope';
161 162
162 // Maximum length when sending strings through the JSON protocol. 163 // Maximum length when sending strings through the JSON protocol.
163 var kMaxProtocolStringLength = 80; 164 var kMaxProtocolStringLength = 80;
164 165
165 // Different kind of properties. 166 // Different kind of properties.
166 var PropertyKind = {}; 167 var PropertyKind = {};
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // - NumberMirror 206 // - NumberMirror
206 // - StringMirror 207 // - StringMirror
207 // - ObjectMirror 208 // - ObjectMirror
208 // - FunctionMirror 209 // - FunctionMirror
209 // - UnresolvedFunctionMirror 210 // - UnresolvedFunctionMirror
210 // - ArrayMirror 211 // - ArrayMirror
211 // - DateMirror 212 // - DateMirror
212 // - RegExpMirror 213 // - RegExpMirror
213 // - ErrorMirror 214 // - ErrorMirror
214 // - PropertyMirror 215 // - PropertyMirror
216 // - InternalPropertyMirror
215 // - FrameMirror 217 // - FrameMirror
216 // - ScriptMirror 218 // - ScriptMirror
217 219
218 220
219 /** 221 /**
220 * Base class for all mirror objects. 222 * Base class for all mirror objects.
221 * @param {string} type The type of the mirror 223 * @param {string} type The type of the mirror
222 * @constructor 224 * @constructor
223 */ 225 */
224 function Mirror(type) { 226 function Mirror(type) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 /** 353 /**
352 * Check whether the mirror reflects a property. 354 * Check whether the mirror reflects a property.
353 * @returns {boolean} True if the mirror reflects a property 355 * @returns {boolean} True if the mirror reflects a property
354 */ 356 */
355 Mirror.prototype.isProperty = function() { 357 Mirror.prototype.isProperty = function() {
356 return this instanceof PropertyMirror; 358 return this instanceof PropertyMirror;
357 }; 359 };
358 360
359 361
360 /** 362 /**
363 * Check whether the mirror reflects an internal property.
364 * @returns {boolean} True if the mirror reflects an internal property
365 */
366 Mirror.prototype.isInternalProperty = function() {
367 return this instanceof InternalPropertyMirror;
368 };
369
370
371 /**
361 * Check whether the mirror reflects a stack frame. 372 * Check whether the mirror reflects a stack frame.
362 * @returns {boolean} True if the mirror reflects a stack frame 373 * @returns {boolean} True if the mirror reflects a stack frame
363 */ 374 */
364 Mirror.prototype.isFrame = function() { 375 Mirror.prototype.isFrame = function() {
365 return this instanceof FrameMirror; 376 return this instanceof FrameMirror;
366 }; 377 };
367 378
368 379
369 /** 380 /**
370 * Check whether the mirror reflects a script. 381 * Check whether the mirror reflects a script.
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 ObjectMirror.prototype.prototypeObject = function() { 598 ObjectMirror.prototype.prototypeObject = function() {
588 return MakeMirror(%DebugGetProperty(this.value_, 'prototype')); 599 return MakeMirror(%DebugGetProperty(this.value_, 'prototype'));
589 }; 600 };
590 601
591 602
592 ObjectMirror.prototype.protoObject = function() { 603 ObjectMirror.prototype.protoObject = function() {
593 return MakeMirror(%DebugGetPrototype(this.value_)); 604 return MakeMirror(%DebugGetPrototype(this.value_));
594 }; 605 };
595 606
596 607
597 /**
598 * Return the primitive value if this is object of Boolean, Number or String
599 * type (but not Date). Otherwise return undefined.
600 */
601 ObjectMirror.prototype.primitiveValue = function() {
602 if (!IS_STRING_WRAPPER(this.value_) && !IS_NUMBER_WRAPPER(this.value_) &&
603 !IS_BOOLEAN_WRAPPER(this.value_)) {
604 return void 0;
605 }
606 var primitiveValue = %_ValueOf(this.value_);
607 if (IS_UNDEFINED(primitiveValue)) {
608 return void 0;
609 }
610 return MakeMirror(primitiveValue);
611 };
612
613
614 ObjectMirror.prototype.hasNamedInterceptor = function() { 608 ObjectMirror.prototype.hasNamedInterceptor = function() {
615 // Get information on interceptors for this object. 609 // Get information on interceptors for this object.
616 var x = %GetInterceptorInfo(this.value_); 610 var x = %GetInterceptorInfo(this.value_);
617 return (x & 2) != 0; 611 return (x & 2) != 0;
618 }; 612 };
619 613
620 614
621 ObjectMirror.prototype.hasIndexedInterceptor = function() { 615 ObjectMirror.prototype.hasIndexedInterceptor = function() {
622 // Get information on interceptors for this object. 616 // Get information on interceptors for this object.
623 var x = %GetInterceptorInfo(this.value_); 617 var x = %GetInterceptorInfo(this.value_);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 } 688 }
695 689
696 return names; 690 return names;
697 }; 691 };
698 692
699 693
700 /** 694 /**
701 * Return the properties for this object as an array of PropertyMirror objects. 695 * Return the properties for this object as an array of PropertyMirror objects.
702 * @param {number} kind Indicate whether named, indexed or both kinds of 696 * @param {number} kind Indicate whether named, indexed or both kinds of
703 * properties are requested 697 * properties are requested
704 * @param {number} limit Limit the number of properties returend to the 698 * @param {number} limit Limit the number of properties returned to the
705 specified value 699 specified value
706 * @return {Array} Property mirrors for this object 700 * @return {Array} Property mirrors for this object
707 */ 701 */
708 ObjectMirror.prototype.properties = function(kind, limit) { 702 ObjectMirror.prototype.properties = function(kind, limit) {
709 var names = this.propertyNames(kind, limit); 703 var names = this.propertyNames(kind, limit);
710 var properties = new Array(names.length); 704 var properties = new Array(names.length);
711 for (var i = 0; i < names.length; i++) { 705 for (var i = 0; i < names.length; i++) {
712 properties[i] = this.property(names[i]); 706 properties[i] = this.property(names[i]);
713 } 707 }
714 708
715 return properties; 709 return properties;
716 }; 710 };
717 711
718 712
713 /**
714 * Return the internal properties for this object as an array of
715 * InternalPropertyMirror objects.
716 * @return {Array} Property mirrors for this object
717 */
718 ObjectMirror.prototype.internalProperties = function() {
719 return ObjectMirror.GetInternalProperties(this.value_);
720 }
721
722
719 ObjectMirror.prototype.property = function(name) { 723 ObjectMirror.prototype.property = function(name) {
720 var details = %DebugGetPropertyDetails(this.value_, %ToString(name)); 724 var details = %DebugGetPropertyDetails(this.value_, %ToString(name));
721 if (details) { 725 if (details) {
722 return new PropertyMirror(this, name, details); 726 return new PropertyMirror(this, name, details);
723 } 727 }
724 728
725 // Nothing found. 729 // Nothing found.
726 return GetUndefinedMirror(); 730 return GetUndefinedMirror();
727 }; 731 };
728 732
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 name = ctor.name(); 787 name = ctor.name();
784 if (!name) { 788 if (!name) {
785 name = this.className(); 789 name = this.className();
786 } 790 }
787 } 791 }
788 return '#<' + name + '>'; 792 return '#<' + name + '>';
789 }; 793 };
790 794
791 795
792 /** 796 /**
797 * Return the internal properties of the value, such as [[PrimitiveValue]] of
798 * scalar wrapper objects and properties of the bound function.
799 * This method is done static to be accessible from Debug API with the bare
800 * values without mirrors.
801 * @return {Array} array (possibly empty) of InternalProperty instances
802 */
803 ObjectMirror.GetInternalProperties = function(value) {
804 if (IS_STRING_WRAPPER(value) || IS_NUMBER_WRAPPER(value) ||
805 IS_BOOLEAN_WRAPPER(value)) {
806 var primitiveValue = %_ValueOf(value);
807 return [new InternalPropertyMirror("[[PrimitiveValue]]", primitiveValue)];
808 } else if (IS_FUNCTION(value)) {
809 var bindings = %BoundFunctionGetBindings(value);
810 var result = [];
811 if (bindings && IS_ARRAY(bindings)) {
812 result.push(new InternalPropertyMirror("[[TargetFunction]]",
813 bindings[0]));
814 result.push(new InternalPropertyMirror("[[BoundThis]]", bindings[1]));
815 var boundArgs = [];
816 for (var i = 2; i < bindings.length; i++) {
817 boundArgs.push(bindings[i]);
818 }
819 result.push(new InternalPropertyMirror("[[BoundArgs]]", boundArgs));
820 }
821 return result;
822 }
823 return [];
824 }
825
826
827 /**
793 * Mirror object for functions. 828 * Mirror object for functions.
794 * @param {function} value The function object reflected by this mirror. 829 * @param {function} value The function object reflected by this mirror.
795 * @constructor 830 * @constructor
796 * @extends ObjectMirror 831 * @extends ObjectMirror
797 */ 832 */
798 function FunctionMirror(value) { 833 function FunctionMirror(value) {
799 %_CallFunction(this, value, FUNCTION_TYPE, ObjectMirror); 834 %_CallFunction(this, value, FUNCTION_TYPE, ObjectMirror);
800 this.resolved_ = true; 835 this.resolved_ = true;
801 } 836 }
802 inherits(FunctionMirror, ObjectMirror); 837 inherits(FunctionMirror, ObjectMirror);
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 * @return {boolean} True if the property is 1296 * @return {boolean} True if the property is
1262 * UndefinedMirror if there is no setter for this property 1297 * UndefinedMirror if there is no setter for this property
1263 */ 1298 */
1264 PropertyMirror.prototype.isNative = function() { 1299 PropertyMirror.prototype.isNative = function() {
1265 return (this.propertyType() == PropertyType.Interceptor) || 1300 return (this.propertyType() == PropertyType.Interceptor) ||
1266 ((this.propertyType() == PropertyType.Callbacks) && 1301 ((this.propertyType() == PropertyType.Callbacks) &&
1267 !this.hasGetter() && !this.hasSetter()); 1302 !this.hasGetter() && !this.hasSetter());
1268 }; 1303 };
1269 1304
1270 1305
1306 /**
1307 * Mirror object for internal properties. Internal property reflects properties
1308 * not accessible from user code such as [[BoundThis]] in bound function.
1309 * Their names are merely symbolic.
1310 * @param {string} name The name of the property
1311 * @param {value} property value
1312 * @constructor
1313 * @extends Mirror
1314 */
1315 function InternalPropertyMirror(name, value) {
1316 %_CallFunction(this, INTERNAL_PROPERTY_TYPE, Mirror);
1317 this.name_ = name;
1318 this.value_ = value;
1319 }
1320 inherits(InternalPropertyMirror, Mirror);
1321
1322
1323 InternalPropertyMirror.prototype.name = function() {
1324 return this.name_;
1325 };
1326
1327
1328 InternalPropertyMirror.prototype.value = function() {
1329 return MakeMirror(this.value_, false);
1330 };
1331
1332
1271 var kFrameDetailsFrameIdIndex = 0; 1333 var kFrameDetailsFrameIdIndex = 0;
1272 var kFrameDetailsReceiverIndex = 1; 1334 var kFrameDetailsReceiverIndex = 1;
1273 var kFrameDetailsFunctionIndex = 2; 1335 var kFrameDetailsFunctionIndex = 2;
1274 var kFrameDetailsArgumentCountIndex = 3; 1336 var kFrameDetailsArgumentCountIndex = 3;
1275 var kFrameDetailsLocalCountIndex = 4; 1337 var kFrameDetailsLocalCountIndex = 4;
1276 var kFrameDetailsSourcePositionIndex = 5; 1338 var kFrameDetailsSourcePositionIndex = 5;
1277 var kFrameDetailsConstructCallIndex = 6; 1339 var kFrameDetailsConstructCallIndex = 6;
1278 var kFrameDetailsAtReturnIndex = 7; 1340 var kFrameDetailsAtReturnIndex = 7;
1279 var kFrameDetailsFlagsIndex = 8; 1341 var kFrameDetailsFlagsIndex = 8;
1280 var kFrameDetailsFirstDynamicIndex = 9; 1342 var kFrameDetailsFirstDynamicIndex = 9;
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after
2195 2257
2196 case OBJECT_TYPE: 2258 case OBJECT_TYPE:
2197 case FUNCTION_TYPE: 2259 case FUNCTION_TYPE:
2198 case ERROR_TYPE: 2260 case ERROR_TYPE:
2199 case REGEXP_TYPE: 2261 case REGEXP_TYPE:
2200 // Add object representation. 2262 // Add object representation.
2201 this.serializeObject_(mirror, content, details); 2263 this.serializeObject_(mirror, content, details);
2202 break; 2264 break;
2203 2265
2204 case PROPERTY_TYPE: 2266 case PROPERTY_TYPE:
2205 throw new Error('PropertyMirror cannot be serialized independeltly'); 2267 case INTERNAL_PROPERTY_TYPE:
2268 throw new Error('PropertyMirror cannot be serialized independently');
2206 break; 2269 break;
2207 2270
2208 case FRAME_TYPE: 2271 case FRAME_TYPE:
2209 // Add object representation. 2272 // Add object representation.
2210 this.serializeFrame_(mirror, content); 2273 this.serializeFrame_(mirror, content);
2211 break; 2274 break;
2212 2275
2213 case SCOPE_TYPE: 2276 case SCOPE_TYPE:
2214 // Add object representation. 2277 // Add object representation.
2215 this.serializeScope_(mirror, content); 2278 this.serializeScope_(mirror, content);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2271 2334
2272 /** 2335 /**
2273 * Serialize object information to the following JSON format. 2336 * Serialize object information to the following JSON format.
2274 * 2337 *
2275 * {"className":"<class name>", 2338 * {"className":"<class name>",
2276 * "constructorFunction":{"ref":<number>}, 2339 * "constructorFunction":{"ref":<number>},
2277 * "protoObject":{"ref":<number>}, 2340 * "protoObject":{"ref":<number>},
2278 * "prototypeObject":{"ref":<number>}, 2341 * "prototypeObject":{"ref":<number>},
2279 * "namedInterceptor":<boolean>, 2342 * "namedInterceptor":<boolean>,
2280 * "indexedInterceptor":<boolean>, 2343 * "indexedInterceptor":<boolean>,
2281 * "properties":[<properties>]} 2344 * "properties":[<properties>],
2345 * "internalProperties":[<internal properties>]}
2282 */ 2346 */
2283 JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content, 2347 JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content,
2284 details) { 2348 details) {
2285 // Add general object properties. 2349 // Add general object properties.
2286 content.className = mirror.className(); 2350 content.className = mirror.className();
2287 content.constructorFunction = 2351 content.constructorFunction =
2288 this.serializeReference(mirror.constructorFunction()); 2352 this.serializeReference(mirror.constructorFunction());
2289 content.protoObject = this.serializeReference(mirror.protoObject()); 2353 content.protoObject = this.serializeReference(mirror.protoObject());
2290 content.prototypeObject = this.serializeReference(mirror.prototypeObject()); 2354 content.prototypeObject = this.serializeReference(mirror.prototypeObject());
2291 2355
2292 var primitiveValue = mirror.primitiveValue();
2293 if (!IS_UNDEFINED(primitiveValue)) {
2294 content.primitiveValue = this.serializeReference(primitiveValue);
2295 }
2296
2297 // Add flags to indicate whether there are interceptors. 2356 // Add flags to indicate whether there are interceptors.
2298 if (mirror.hasNamedInterceptor()) { 2357 if (mirror.hasNamedInterceptor()) {
2299 content.namedInterceptor = true; 2358 content.namedInterceptor = true;
2300 } 2359 }
2301 if (mirror.hasIndexedInterceptor()) { 2360 if (mirror.hasIndexedInterceptor()) {
2302 content.indexedInterceptor = true; 2361 content.indexedInterceptor = true;
2303 } 2362 }
2304 2363
2305 // Add function specific properties. 2364 // Add function specific properties.
2306 if (mirror.isFunction()) { 2365 if (mirror.isFunction()) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2348 } 2407 }
2349 } 2408 }
2350 for (var i = 0; i < propertyIndexes.length; i++) { 2409 for (var i = 0; i < propertyIndexes.length; i++) {
2351 var propertyMirror = mirror.property(propertyIndexes[i]); 2410 var propertyMirror = mirror.property(propertyIndexes[i]);
2352 p[propertyNames.length + i] = this.serializeProperty_(propertyMirror); 2411 p[propertyNames.length + i] = this.serializeProperty_(propertyMirror);
2353 if (details) { 2412 if (details) {
2354 this.add_(propertyMirror.value()); 2413 this.add_(propertyMirror.value());
2355 } 2414 }
2356 } 2415 }
2357 content.properties = p; 2416 content.properties = p;
2417
2418 var internalProperties = mirror.internalProperties();
2419 if (internalProperties.length > 0) {
2420 var ip = [];
2421 for (var i = 0; i < internalProperties.length; i++) {
2422 ip.push(this.serializeInternalProperty_(internalProperties[i]));
2423 }
2424 content.internalProperties = ip;
2425 }
2358 }; 2426 };
2359 2427
2360 2428
2361 /** 2429 /**
2362 * Serialize location information to the following JSON format: 2430 * Serialize location information to the following JSON format:
2363 * 2431 *
2364 * "position":"<position>", 2432 * "position":"<position>",
2365 * "line":"<line>", 2433 * "line":"<line>",
2366 * "column":"<column>", 2434 * "column":"<column>",
2367 * 2435 *
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2415 } 2483 }
2416 if (propertyMirror.propertyType() != PropertyType.Normal) { 2484 if (propertyMirror.propertyType() != PropertyType.Normal) {
2417 result.propertyType = propertyMirror.propertyType(); 2485 result.propertyType = propertyMirror.propertyType();
2418 } 2486 }
2419 result.ref = propertyValue.handle(); 2487 result.ref = propertyValue.handle();
2420 } 2488 }
2421 return result; 2489 return result;
2422 }; 2490 };
2423 2491
2424 2492
2493 /**
2494 * Serialize internal property information to the following JSON format for
2495 * building the array of properties.
2496 *
2497 * {"name":"<property name>",
2498 * "ref":<number>}
2499 *
2500 * {"name":"[[BoundThis]]","ref":117}
2501 *
2502 * @param {InternalPropertyMirror} propertyMirror The property to serialize.
2503 * @returns {Object} Protocol object representing the property.
2504 */
2505 JSONProtocolSerializer.prototype.serializeInternalProperty_ =
2506 function(propertyMirror) {
2507 var result = {};
2508
2509 result.name = propertyMirror.name();
2510 var propertyValue = propertyMirror.value();
2511 if (this.inlineRefs_() && propertyValue.isValue()) {
2512 result.value = this.serializeReferenceWithDisplayData_(propertyValue);
2513 } else {
2514 result.ref = propertyValue.handle();
2515 }
2516 return result;
2517 };
2518
2519
2425 JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) { 2520 JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) {
2426 content.index = mirror.index(); 2521 content.index = mirror.index();
2427 content.receiver = this.serializeReference(mirror.receiver()); 2522 content.receiver = this.serializeReference(mirror.receiver());
2428 var func = mirror.func(); 2523 var func = mirror.func();
2429 content.func = this.serializeReference(func); 2524 content.func = this.serializeReference(func);
2430 if (func.script()) { 2525 if (func.script()) {
2431 content.script = this.serializeReference(func.script()); 2526 content.script = this.serializeReference(func.script());
2432 } 2527 }
2433 content.constructCall = mirror.isConstructCall(); 2528 content.constructCall = mirror.isConstructCall();
2434 content.atReturn = mirror.isAtReturn(); 2529 content.atReturn = mirror.isAtReturn();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2497 } 2592 }
2498 if (!NUMBER_IS_FINITE(value)) { 2593 if (!NUMBER_IS_FINITE(value)) {
2499 if (value > 0) { 2594 if (value > 0) {
2500 return 'Infinity'; 2595 return 'Infinity';
2501 } else { 2596 } else {
2502 return '-Infinity'; 2597 return '-Infinity';
2503 } 2598 }
2504 } 2599 }
2505 return value; 2600 return value;
2506 } 2601 }
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/mirror-object.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698