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

Side by Side Diff: src/runtime.cc

Issue 549050: Implement Object.getOwnPropertyNames constructor property [ES5 section 15.2.3... (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: '' Created 10 years, 11 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 | « src/runtime.h ('k') | src/v8natives.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-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 3191 matching lines...) Expand 10 before | Expand all | Expand 10 after
3202 Handle<FixedArray> content = GetKeysInFixedArrayFor(object, 3202 Handle<FixedArray> content = GetKeysInFixedArrayFor(object,
3203 INCLUDE_PROTOS); 3203 INCLUDE_PROTOS);
3204 3204
3205 // Test again, since cache may have been built by preceding call. 3205 // Test again, since cache may have been built by preceding call.
3206 if (object->IsSimpleEnum()) return object->map(); 3206 if (object->IsSimpleEnum()) return object->map();
3207 3207
3208 return *content; 3208 return *content;
3209 } 3209 }
3210 3210
3211 3211
3212 // Find the length of the prototype chain that is to to handled as one. If a
3213 // prototype object is hidden it is to be viewed as part of the the object it
3214 // is prototype for.
3215 static int LocalPrototypeChainLength(JSObject* obj) {
3216 int count = 1;
3217 Object* proto = obj->GetPrototype();
3218 while (proto->IsJSObject() &&
3219 JSObject::cast(proto)->map()->is_hidden_prototype()) {
3220 count++;
3221 proto = JSObject::cast(proto)->GetPrototype();
3222 }
3223 return count;
3224 }
3225
3226
3227 // Return the names of the local named properties.
3228 // args[0]: object
3229 static Object* Runtime_GetLocalPropertyNames(Arguments args) {
3230 HandleScope scope;
3231 ASSERT(args.length() == 1);
3232 if (!args[0]->IsJSObject()) {
3233 return Heap::undefined_value();
3234 }
3235 CONVERT_ARG_CHECKED(JSObject, obj, 0);
3236
3237 // Skip the global proxy as it has no properties and always delegates to the
3238 // real global object.
3239 if (obj->IsJSGlobalProxy()) {
3240 obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype()));
3241 }
3242
3243 // Find the number of objects making up this.
3244 int length = LocalPrototypeChainLength(*obj);
3245
3246 // Find the number of local properties for each of the objects.
3247 int* local_property_count = NewArray<int>(length);
3248 int total_property_count = 0;
3249 Handle<JSObject> jsproto = obj;
3250 for (int i = 0; i < length; i++) {
3251 int n;
3252 n = jsproto->NumberOfLocalProperties(static_cast<PropertyAttributes>(NONE));
3253 local_property_count[i] = n;
3254 total_property_count += n;
3255 if (i < length - 1) {
3256 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype()));
3257 }
3258 }
3259
3260 // Allocate an array with storage for all the property names.
3261 Handle<FixedArray> names = Factory::NewFixedArray(total_property_count);
3262
3263 // Get the property names.
3264 jsproto = obj;
3265 int proto_with_hidden_properties = 0;
3266 for (int i = 0; i < length; i++) {
3267 jsproto->GetLocalPropertyNames(*names,
3268 i == 0 ? 0 : local_property_count[i - 1]);
3269 if (!GetHiddenProperties(jsproto, false)->IsUndefined()) {
3270 proto_with_hidden_properties++;
3271 }
3272 if (i < length - 1) {
3273 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype()));
3274 }
3275 }
3276
3277 // Filter out name of hidden propeties object.
3278 if (proto_with_hidden_properties > 0) {
3279 Handle<FixedArray> old_names = names;
3280 names = Factory::NewFixedArray(
3281 names->length() - proto_with_hidden_properties);
3282 int dest_pos = 0;
3283 for (int i = 0; i < total_property_count; i++) {
3284 Object* name = old_names->get(i);
3285 if (name == Heap::hidden_symbol()) {
3286 continue;
3287 }
3288 names->set(dest_pos++, name);
3289 }
3290 }
3291
3292 DeleteArray(local_property_count);
3293 return *Factory::NewJSArrayWithElements(names);
3294 }
3295
3296
3297 // Return the names of the local indexed properties.
3298 // args[0]: object
3299 static Object* Runtime_GetLocalElementNames(Arguments args) {
3300 HandleScope scope;
3301 ASSERT(args.length() == 1);
3302 if (!args[0]->IsJSObject()) {
3303 return Heap::undefined_value();
3304 }
3305 CONVERT_ARG_CHECKED(JSObject, obj, 0);
3306
3307 int n = obj->NumberOfLocalElements(static_cast<PropertyAttributes>(NONE));
3308 Handle<FixedArray> names = Factory::NewFixedArray(n);
3309 obj->GetLocalElementKeys(*names, static_cast<PropertyAttributes>(NONE));
3310 return *Factory::NewJSArrayWithElements(names);
3311 }
3312
3313
3314 // Return information on whether an object has a named or indexed interceptor.
3315 // args[0]: object
3316 static Object* Runtime_GetInterceptorInfo(Arguments args) {
3317 HandleScope scope;
3318 ASSERT(args.length() == 1);
3319 if (!args[0]->IsJSObject()) {
3320 return Smi::FromInt(0);
3321 }
3322 CONVERT_ARG_CHECKED(JSObject, obj, 0);
3323
3324 int result = 0;
3325 if (obj->HasNamedInterceptor()) result |= 2;
3326 if (obj->HasIndexedInterceptor()) result |= 1;
3327
3328 return Smi::FromInt(result);
3329 }
3330
3331
3332 // Return property names from named interceptor.
3333 // args[0]: object
3334 static Object* Runtime_GetNamedInterceptorPropertyNames(Arguments args) {
3335 HandleScope scope;
3336 ASSERT(args.length() == 1);
3337 CONVERT_ARG_CHECKED(JSObject, obj, 0);
3338
3339 if (obj->HasNamedInterceptor()) {
3340 v8::Handle<v8::Array> result = GetKeysForNamedInterceptor(obj, obj);
3341 if (!result.IsEmpty()) return *v8::Utils::OpenHandle(*result);
3342 }
3343 return Heap::undefined_value();
3344 }
3345
3346
3347 // Return element names from indexed interceptor.
3348 // args[0]: object
3349 static Object* Runtime_GetIndexedInterceptorElementNames(Arguments args) {
3350 HandleScope scope;
3351 ASSERT(args.length() == 1);
3352 CONVERT_ARG_CHECKED(JSObject, obj, 0);
3353
3354 if (obj->HasIndexedInterceptor()) {
3355 v8::Handle<v8::Array> result = GetKeysForIndexedInterceptor(obj, obj);
3356 if (!result.IsEmpty()) return *v8::Utils::OpenHandle(*result);
3357 }
3358 return Heap::undefined_value();
3359 }
3360
3361
3212 static Object* Runtime_LocalKeys(Arguments args) { 3362 static Object* Runtime_LocalKeys(Arguments args) {
3213 ASSERT_EQ(args.length(), 1); 3363 ASSERT_EQ(args.length(), 1);
3214 CONVERT_CHECKED(JSObject, raw_object, args[0]); 3364 CONVERT_CHECKED(JSObject, raw_object, args[0]);
3215 HandleScope scope; 3365 HandleScope scope;
3216 Handle<JSObject> object(raw_object); 3366 Handle<JSObject> object(raw_object);
3217 Handle<FixedArray> contents = GetKeysInFixedArrayFor(object, 3367 Handle<FixedArray> contents = GetKeysInFixedArrayFor(object,
3218 LOCAL_ONLY); 3368 LOCAL_ONLY);
3219 // Some fast paths through GetKeysInFixedArrayFor reuse a cached 3369 // Some fast paths through GetKeysInFixedArrayFor reuse a cached
3220 // property array and since the result is mutable we have to create 3370 // property array and since the result is mutable we have to create
3221 // a fresh clone on each invocation. 3371 // a fresh clone on each invocation.
(...skipping 2772 matching lines...) Expand 10 before | Expand all | Expand 10 after
5994 } 6144 }
5995 6145
5996 6146
5997 static Object* Runtime_Break(Arguments args) { 6147 static Object* Runtime_Break(Arguments args) {
5998 ASSERT(args.length() == 0); 6148 ASSERT(args.length() == 0);
5999 StackGuard::DebugBreak(); 6149 StackGuard::DebugBreak();
6000 return Heap::undefined_value(); 6150 return Heap::undefined_value();
6001 } 6151 }
6002 6152
6003 6153
6004 // Find the length of the prototype chain that is to to handled as one. If a
6005 // prototype object is hidden it is to be viewed as part of the the object it
6006 // is prototype for.
6007 static int LocalPrototypeChainLength(JSObject* obj) {
6008 int count = 1;
6009 Object* proto = obj->GetPrototype();
6010 while (proto->IsJSObject() &&
6011 JSObject::cast(proto)->map()->is_hidden_prototype()) {
6012 count++;
6013 proto = JSObject::cast(proto)->GetPrototype();
6014 }
6015 return count;
6016 }
6017
6018
6019 static Object* DebugLookupResultValue(Object* receiver, String* name, 6154 static Object* DebugLookupResultValue(Object* receiver, String* name,
6020 LookupResult* result, 6155 LookupResult* result,
6021 bool* caught_exception) { 6156 bool* caught_exception) {
6022 Object* value; 6157 Object* value;
6023 switch (result->type()) { 6158 switch (result->type()) {
6024 case NORMAL: 6159 case NORMAL:
6025 value = result->holder()->GetNormalizedProperty(result); 6160 value = result->holder()->GetNormalizedProperty(result);
6026 if (value->IsTheHole()) { 6161 if (value->IsTheHole()) {
6027 return Heap::undefined_value(); 6162 return Heap::undefined_value();
6028 } 6163 }
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
6178 6313
6179 LookupResult result; 6314 LookupResult result;
6180 obj->Lookup(*name, &result); 6315 obj->Lookup(*name, &result);
6181 if (result.IsProperty()) { 6316 if (result.IsProperty()) {
6182 return DebugLookupResultValue(*obj, *name, &result, NULL); 6317 return DebugLookupResultValue(*obj, *name, &result, NULL);
6183 } 6318 }
6184 return Heap::undefined_value(); 6319 return Heap::undefined_value();
6185 } 6320 }
6186 6321
6187 6322
6188 // Return the names of the local named properties.
6189 // args[0]: object
6190 static Object* Runtime_DebugLocalPropertyNames(Arguments args) {
6191 HandleScope scope;
6192 ASSERT(args.length() == 1);
6193 if (!args[0]->IsJSObject()) {
6194 return Heap::undefined_value();
6195 }
6196 CONVERT_ARG_CHECKED(JSObject, obj, 0);
6197
6198 // Skip the global proxy as it has no properties and always delegates to the
6199 // real global object.
6200 if (obj->IsJSGlobalProxy()) {
6201 obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype()));
6202 }
6203
6204 // Find the number of objects making up this.
6205 int length = LocalPrototypeChainLength(*obj);
6206
6207 // Find the number of local properties for each of the objects.
6208 int* local_property_count = NewArray<int>(length);
6209 int total_property_count = 0;
6210 Handle<JSObject> jsproto = obj;
6211 for (int i = 0; i < length; i++) {
6212 int n;
6213 n = jsproto->NumberOfLocalProperties(static_cast<PropertyAttributes>(NONE));
6214 local_property_count[i] = n;
6215 total_property_count += n;
6216 if (i < length - 1) {
6217 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype()));
6218 }
6219 }
6220
6221 // Allocate an array with storage for all the property names.
6222 Handle<FixedArray> names = Factory::NewFixedArray(total_property_count);
6223
6224 // Get the property names.
6225 jsproto = obj;
6226 int proto_with_hidden_properties = 0;
6227 for (int i = 0; i < length; i++) {
6228 jsproto->GetLocalPropertyNames(*names,
6229 i == 0 ? 0 : local_property_count[i - 1]);
6230 if (!GetHiddenProperties(jsproto, false)->IsUndefined()) {
6231 proto_with_hidden_properties++;
6232 }
6233 if (i < length - 1) {
6234 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype()));
6235 }
6236 }
6237
6238 // Filter out name of hidden propeties object.
6239 if (proto_with_hidden_properties > 0) {
6240 Handle<FixedArray> old_names = names;
6241 names = Factory::NewFixedArray(
6242 names->length() - proto_with_hidden_properties);
6243 int dest_pos = 0;
6244 for (int i = 0; i < total_property_count; i++) {
6245 Object* name = old_names->get(i);
6246 if (name == Heap::hidden_symbol()) {
6247 continue;
6248 }
6249 names->set(dest_pos++, name);
6250 }
6251 }
6252
6253 DeleteArray(local_property_count);
6254 return *Factory::NewJSArrayWithElements(names);
6255 }
6256
6257
6258 // Return the names of the local indexed properties.
6259 // args[0]: object
6260 static Object* Runtime_DebugLocalElementNames(Arguments args) {
6261 HandleScope scope;
6262 ASSERT(args.length() == 1);
6263 if (!args[0]->IsJSObject()) {
6264 return Heap::undefined_value();
6265 }
6266 CONVERT_ARG_CHECKED(JSObject, obj, 0);
6267
6268 int n = obj->NumberOfLocalElements(static_cast<PropertyAttributes>(NONE));
6269 Handle<FixedArray> names = Factory::NewFixedArray(n);
6270 obj->GetLocalElementKeys(*names, static_cast<PropertyAttributes>(NONE));
6271 return *Factory::NewJSArrayWithElements(names);
6272 }
6273
6274
6275 // Return the property type calculated from the property details. 6323 // Return the property type calculated from the property details.
6276 // args[0]: smi with property details. 6324 // args[0]: smi with property details.
6277 static Object* Runtime_DebugPropertyTypeFromDetails(Arguments args) { 6325 static Object* Runtime_DebugPropertyTypeFromDetails(Arguments args) {
6278 ASSERT(args.length() == 1); 6326 ASSERT(args.length() == 1);
6279 CONVERT_CHECKED(Smi, details, args[0]); 6327 CONVERT_CHECKED(Smi, details, args[0]);
6280 PropertyType type = PropertyDetails(details).type(); 6328 PropertyType type = PropertyDetails(details).type();
6281 return Smi::FromInt(static_cast<int>(type)); 6329 return Smi::FromInt(static_cast<int>(type));
6282 } 6330 }
6283 6331
6284 6332
(...skipping 10 matching lines...) Expand all
6295 // Return the property insertion index calculated from the property details. 6343 // Return the property insertion index calculated from the property details.
6296 // args[0]: smi with property details. 6344 // args[0]: smi with property details.
6297 static Object* Runtime_DebugPropertyIndexFromDetails(Arguments args) { 6345 static Object* Runtime_DebugPropertyIndexFromDetails(Arguments args) {
6298 ASSERT(args.length() == 1); 6346 ASSERT(args.length() == 1);
6299 CONVERT_CHECKED(Smi, details, args[0]); 6347 CONVERT_CHECKED(Smi, details, args[0]);
6300 int index = PropertyDetails(details).index(); 6348 int index = PropertyDetails(details).index();
6301 return Smi::FromInt(index); 6349 return Smi::FromInt(index);
6302 } 6350 }
6303 6351
6304 6352
6305 // Return information on whether an object has a named or indexed interceptor.
6306 // args[0]: object
6307 static Object* Runtime_DebugInterceptorInfo(Arguments args) {
6308 HandleScope scope;
6309 ASSERT(args.length() == 1);
6310 if (!args[0]->IsJSObject()) {
6311 return Smi::FromInt(0);
6312 }
6313 CONVERT_ARG_CHECKED(JSObject, obj, 0);
6314
6315 int result = 0;
6316 if (obj->HasNamedInterceptor()) result |= 2;
6317 if (obj->HasIndexedInterceptor()) result |= 1;
6318
6319 return Smi::FromInt(result);
6320 }
6321
6322
6323 // Return property names from named interceptor.
6324 // args[0]: object
6325 static Object* Runtime_DebugNamedInterceptorPropertyNames(Arguments args) {
6326 HandleScope scope;
6327 ASSERT(args.length() == 1);
6328 CONVERT_ARG_CHECKED(JSObject, obj, 0);
6329
6330 if (obj->HasNamedInterceptor()) {
6331 v8::Handle<v8::Array> result = GetKeysForNamedInterceptor(obj, obj);
6332 if (!result.IsEmpty()) return *v8::Utils::OpenHandle(*result);
6333 }
6334 return Heap::undefined_value();
6335 }
6336
6337
6338 // Return element names from indexed interceptor.
6339 // args[0]: object
6340 static Object* Runtime_DebugIndexedInterceptorElementNames(Arguments args) {
6341 HandleScope scope;
6342 ASSERT(args.length() == 1);
6343 CONVERT_ARG_CHECKED(JSObject, obj, 0);
6344
6345 if (obj->HasIndexedInterceptor()) {
6346 v8::Handle<v8::Array> result = GetKeysForIndexedInterceptor(obj, obj);
6347 if (!result.IsEmpty()) return *v8::Utils::OpenHandle(*result);
6348 }
6349 return Heap::undefined_value();
6350 }
6351
6352
6353 // Return property value from named interceptor. 6353 // Return property value from named interceptor.
6354 // args[0]: object 6354 // args[0]: object
6355 // args[1]: property name 6355 // args[1]: property name
6356 static Object* Runtime_DebugNamedInterceptorPropertyValue(Arguments args) { 6356 static Object* Runtime_DebugNamedInterceptorPropertyValue(Arguments args) {
6357 HandleScope scope; 6357 HandleScope scope;
6358 ASSERT(args.length() == 2); 6358 ASSERT(args.length() == 2);
6359 CONVERT_ARG_CHECKED(JSObject, obj, 0); 6359 CONVERT_ARG_CHECKED(JSObject, obj, 0);
6360 RUNTIME_ASSERT(obj->HasNamedInterceptor()); 6360 RUNTIME_ASSERT(obj->HasNamedInterceptor());
6361 CONVERT_ARG_CHECKED(String, name, 1); 6361 CONVERT_ARG_CHECKED(String, name, 1);
6362 6362
(...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after
8150 } else { 8150 } else {
8151 // Handle last resort GC and make sure to allow future allocations 8151 // Handle last resort GC and make sure to allow future allocations
8152 // to grow the heap without causing GCs (if possible). 8152 // to grow the heap without causing GCs (if possible).
8153 Counters::gc_last_resort_from_js.Increment(); 8153 Counters::gc_last_resort_from_js.Increment();
8154 Heap::CollectAllGarbage(false); 8154 Heap::CollectAllGarbage(false);
8155 } 8155 }
8156 } 8156 }
8157 8157
8158 8158
8159 } } // namespace v8::internal 8159 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698