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

Side by Side Diff: src/debug/mirrors.js

Issue 1498593006: [proxies] Use JSReceiver::GetKeys() for more purposes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | src/isolate.h » ('j') | src/objects.cc » ('J')
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 (function(global, utils) { 5 (function(global, utils) {
6 "use strict"; 6 "use strict";
7 7
8 // ---------------------------------------------------------------------------- 8 // ----------------------------------------------------------------------------
9 // Imports 9 // Imports
10 10
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 var tempCtor = function(){}; 232 var tempCtor = function(){};
233 tempCtor.prototype = superCtor.prototype; 233 tempCtor.prototype = superCtor.prototype;
234 ctor.super_ = superCtor.prototype; 234 ctor.super_ = superCtor.prototype;
235 ctor.prototype = new tempCtor(); 235 ctor.prototype = new tempCtor();
236 ctor.prototype.constructor = ctor; 236 ctor.prototype.constructor = ctor;
237 } 237 }
238 238
239 // Maximum length when sending strings through the JSON protocol. 239 // Maximum length when sending strings through the JSON protocol.
240 var kMaxProtocolStringLength = 80; 240 var kMaxProtocolStringLength = 80;
241 241
242 // Different kind of properties.
243 var PropertyKind = {};
244 PropertyKind.Named = 1;
245 PropertyKind.Indexed = 2;
246
247 242
248 // A copy of the PropertyType enum from property-details.h 243 // A copy of the PropertyType enum from property-details.h
249 var PropertyType = {}; 244 var PropertyType = {};
250 PropertyType.Data = 0; 245 PropertyType.Data = 0;
251 PropertyType.DataConstant = 2; 246 PropertyType.DataConstant = 2;
252 PropertyType.AccessorConstant = 3; 247 PropertyType.AccessorConstant = 3;
253 248
254 249
255 // Different attributes for a property. 250 // Different attributes for a property.
256 var PropertyAttribute = {}; 251 var PropertyAttribute = {};
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 }; 738 };
744 739
745 740
746 ObjectMirror.prototype.hasIndexedInterceptor = function() { 741 ObjectMirror.prototype.hasIndexedInterceptor = function() {
747 // Get information on interceptors for this object. 742 // Get information on interceptors for this object.
748 var x = %GetInterceptorInfo(this.value_); 743 var x = %GetInterceptorInfo(this.value_);
749 return (x & 1) != 0; 744 return (x & 1) != 0;
750 }; 745 };
751 746
752 747
753 // Get all own property names except for private symbols.
754 function TryGetPropertyNames(object) {
755 try {
756 // TODO(yangguo): Should there be a special debugger implementation of
757 // %GetOwnPropertyNames that doesn't perform access checks?
758 return %GetOwnPropertyNames(object, PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL);
759 } catch (e) {
760 // Might have hit a failed access check.
761 return [];
762 }
763 }
764
765
766 /** 748 /**
767 * Return the property names for this object. 749 * Return the property names for this object.
768 * @param {number} kind Indicate whether named, indexed or both kinds of 750 * @param {number} kind Indicate whether named, indexed or both kinds of
769 * properties are requested 751 * properties are requested
770 * @param {number} limit Limit the number of names returend to the specified 752 * @param {number} limit Limit the number of names returend to the specified
771 value 753 value
772 * @return {Array} Property names for this object 754 * @return {Array} Property names for this object
773 */ 755 */
774 ObjectMirror.prototype.propertyNames = function(kind, limit) { 756 ObjectMirror.prototype.propertyNames = function() {
775 // Find kind and limit and allocate array for the result 757 return %GetOwnPropertyKeys(this.value_, PROPERTY_FILTER_NONE);
776 kind = kind || PropertyKind.Named | PropertyKind.Indexed;
777
778 var propertyNames;
779 var elementNames;
780 var total = 0;
781
782 // Find all the named properties.
783 if (kind & PropertyKind.Named) {
784 propertyNames = TryGetPropertyNames(this.value_);
785 total += propertyNames.length;
786
787 // Get names for named interceptor properties if any.
788 if (this.hasNamedInterceptor() && (kind & PropertyKind.Named)) {
789 var namedInterceptorNames =
790 %GetNamedInterceptorPropertyNames(this.value_);
791 if (namedInterceptorNames) {
792 propertyNames = propertyNames.concat(namedInterceptorNames);
793 total += namedInterceptorNames.length;
794 }
795 }
796 }
797
798 // Find all the indexed properties.
799 if (kind & PropertyKind.Indexed) {
800 // Get own element names.
801 elementNames = %GetOwnElementNames(this.value_);
802 total += elementNames.length;
803
804 // Get names for indexed interceptor properties.
805 if (this.hasIndexedInterceptor() && (kind & PropertyKind.Indexed)) {
806 var indexedInterceptorNames =
807 %GetIndexedInterceptorElementNames(this.value_);
808 if (indexedInterceptorNames) {
809 elementNames = elementNames.concat(indexedInterceptorNames);
810 total += indexedInterceptorNames.length;
811 }
812 }
813 }
814 limit = MathMin(limit || total, total);
815
816 var names = new GlobalArray(limit);
817 var index = 0;
818
819 // Copy names for named properties.
820 if (kind & PropertyKind.Named) {
821 for (var i = 0; index < limit && i < propertyNames.length; i++) {
822 names[index++] = propertyNames[i];
823 }
824 }
825
826 // Copy names for indexed properties.
827 if (kind & PropertyKind.Indexed) {
828 for (var i = 0; index < limit && i < elementNames.length; i++) {
829 names[index++] = elementNames[i];
830 }
831 }
832
833 return names;
834 }; 758 };
835 759
836 760
837 /** 761 /**
838 * Return the properties for this object as an array of PropertyMirror objects. 762 * Return the properties for this object as an array of PropertyMirror objects.
839 * @param {number} kind Indicate whether named, indexed or both kinds of 763 * @param {number} kind Indicate whether named, indexed or both kinds of
840 * properties are requested 764 * properties are requested
841 * @param {number} limit Limit the number of properties returned to the 765 * @param {number} limit Limit the number of properties returned to the
842 specified value 766 specified value
843 * @return {Array} Property mirrors for this object 767 * @return {Array} Property mirrors for this object
844 */ 768 */
845 ObjectMirror.prototype.properties = function(kind, limit) { 769 ObjectMirror.prototype.properties = function() {
846 var names = this.propertyNames(kind, limit); 770 var names = this.propertyNames();
847 var properties = new GlobalArray(names.length); 771 var properties = new GlobalArray(names.length);
848 for (var i = 0; i < names.length; i++) { 772 for (var i = 0; i < names.length; i++) {
849 properties[i] = this.property(names[i]); 773 properties[i] = this.property(names[i]);
850 } 774 }
851 775
852 return properties; 776 return properties;
853 }; 777 };
854 778
855 779
856 /** 780 /**
(...skipping 23 matching lines...) Expand all
880 * @param {Mirror} value The property value to look for 804 * @param {Mirror} value The property value to look for
881 * @return {PropertyMirror} The property with the specified value. If no 805 * @return {PropertyMirror} The property with the specified value. If no
882 * property was found with the specified value UndefinedMirror is returned 806 * property was found with the specified value UndefinedMirror is returned
883 */ 807 */
884 ObjectMirror.prototype.lookupProperty = function(value) { 808 ObjectMirror.prototype.lookupProperty = function(value) {
885 var properties = this.properties(); 809 var properties = this.properties();
886 810
887 // Look for property value in properties. 811 // Look for property value in properties.
888 for (var i = 0; i < properties.length; i++) { 812 for (var i = 0; i < properties.length; i++) {
889 813
890 // Skip properties which are defined through assessors. 814 // Skip properties which are defined through accessors.
891 var property = properties[i]; 815 var property = properties[i];
892 if (property.propertyType() != PropertyType.AccessorConstant) { 816 if (property.propertyType() != PropertyType.AccessorConstant) {
893 if (%_ObjectEquals(property.value_, value.value_)) { 817 if (%_ObjectEquals(property.value_, value.value_)) {
894 return property; 818 return property;
895 } 819 }
896 } 820 }
897 } 821 }
898 822
899 // Nothing found. 823 // Nothing found.
900 return GetUndefinedMirror(); 824 return GetUndefinedMirror();
(...skipping 1975 matching lines...) Expand 10 before | Expand all | Expand 10 after
2876 content.value = mirror.value(); 2800 content.value = mirror.value();
2877 } 2801 }
2878 2802
2879 if (mirror.isPromise()) { 2803 if (mirror.isPromise()) {
2880 // Add promise specific properties. 2804 // Add promise specific properties.
2881 content.status = mirror.status(); 2805 content.status = mirror.status();
2882 content.promiseValue = this.serializeReference(mirror.promiseValue()); 2806 content.promiseValue = this.serializeReference(mirror.promiseValue());
2883 } 2807 }
2884 2808
2885 // Add actual properties - named properties followed by indexed properties. 2809 // Add actual properties - named properties followed by indexed properties.
2886 var propertyNames = mirror.propertyNames(PropertyKind.Named); 2810 var properties = mirror.propertyNames();
2887 var propertyIndexes = mirror.propertyNames(PropertyKind.Indexed); 2811 for (var i = 0; i < properties.length; i++) {
2888 var p = new GlobalArray(propertyNames.length + propertyIndexes.length); 2812 var propertyMirror = mirror.property(properties[i]);
2889 for (var i = 0; i < propertyNames.length; i++) { 2813 properties[i] = this.serializeProperty_(propertyMirror);
2890 var propertyMirror = mirror.property(propertyNames[i]);
2891 p[i] = this.serializeProperty_(propertyMirror);
2892 if (details) { 2814 if (details) {
2893 this.add_(propertyMirror.value()); 2815 this.add_(propertyMirror.value());
2894 } 2816 }
2895 } 2817 }
2896 for (var i = 0; i < propertyIndexes.length; i++) { 2818 content.properties = properties;
2897 var propertyMirror = mirror.property(propertyIndexes[i]);
2898 p[propertyNames.length + i] = this.serializeProperty_(propertyMirror);
2899 if (details) {
2900 this.add_(propertyMirror.value());
2901 }
2902 }
2903 content.properties = p;
2904 2819
2905 var internalProperties = mirror.internalProperties(); 2820 var internalProperties = mirror.internalProperties();
2906 if (internalProperties.length > 0) { 2821 if (internalProperties.length > 0) {
2907 var ip = []; 2822 var ip = [];
2908 for (var i = 0; i < internalProperties.length; i++) { 2823 for (var i = 0; i < internalProperties.length; i++) {
2909 ip.push(this.serializeInternalProperty_(internalProperties[i])); 2824 ip.push(this.serializeInternalProperty_(internalProperties[i]));
2910 } 2825 }
2911 content.internalProperties = ip; 2826 content.internalProperties = ip;
2912 } 2827 }
2913 }; 2828 };
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
3091 utils.InstallFunctions(global, DONT_ENUM, [ 3006 utils.InstallFunctions(global, DONT_ENUM, [
3092 "MakeMirror", MakeMirror, 3007 "MakeMirror", MakeMirror,
3093 "MakeMirrorSerializer", MakeMirrorSerializer, 3008 "MakeMirrorSerializer", MakeMirrorSerializer,
3094 "LookupMirror", LookupMirror, 3009 "LookupMirror", LookupMirror,
3095 "ToggleMirrorCache", ToggleMirrorCache, 3010 "ToggleMirrorCache", ToggleMirrorCache,
3096 "MirrorCacheIsEmpty", MirrorCacheIsEmpty, 3011 "MirrorCacheIsEmpty", MirrorCacheIsEmpty,
3097 ]); 3012 ]);
3098 3013
3099 utils.InstallConstants(global, [ 3014 utils.InstallConstants(global, [
3100 "ScopeType", ScopeType, 3015 "ScopeType", ScopeType,
3101 "PropertyKind", PropertyKind,
3102 "PropertyType", PropertyType, 3016 "PropertyType", PropertyType,
3103 "PropertyAttribute", PropertyAttribute, 3017 "PropertyAttribute", PropertyAttribute,
3104 "Mirror", Mirror, 3018 "Mirror", Mirror,
3105 "ValueMirror", ValueMirror, 3019 "ValueMirror", ValueMirror,
3106 "UndefinedMirror", UndefinedMirror, 3020 "UndefinedMirror", UndefinedMirror,
3107 "NullMirror", NullMirror, 3021 "NullMirror", NullMirror,
3108 "BooleanMirror", BooleanMirror, 3022 "BooleanMirror", BooleanMirror,
3109 "NumberMirror", NumberMirror, 3023 "NumberMirror", NumberMirror,
3110 "StringMirror", StringMirror, 3024 "StringMirror", StringMirror,
3111 "SymbolMirror", SymbolMirror, 3025 "SymbolMirror", SymbolMirror,
(...skipping 20 matching lines...) Expand all
3132 // Functions needed by the debugger runtime. 3046 // Functions needed by the debugger runtime.
3133 utils.InstallFunctions(utils, DONT_ENUM, [ 3047 utils.InstallFunctions(utils, DONT_ENUM, [
3134 "ClearMirrorCache", ClearMirrorCache 3048 "ClearMirrorCache", ClearMirrorCache
3135 ]); 3049 ]);
3136 3050
3137 // Export to debug.js 3051 // Export to debug.js
3138 utils.Export(function(to) { 3052 utils.Export(function(to) {
3139 to.MirrorType = MirrorType; 3053 to.MirrorType = MirrorType;
3140 }); 3054 });
3141 }) 3055 })
OLDNEW
« no previous file with comments | « no previous file | src/isolate.h » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698