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

Side by Side Diff: src/runtime.cc

Issue 246077: Changed Object.keys to return strings for element indices. (Closed)
Patch Set: Created 11 years, 2 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
« no previous file with comments | « src/heap.cc ('k') | test/mjsunit/third_party/object-keys.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 3002 matching lines...) Expand 10 before | Expand all | Expand 10 after
3013 static Object* Runtime_LocalKeys(Arguments args) { 3013 static Object* Runtime_LocalKeys(Arguments args) {
3014 ASSERT_EQ(args.length(), 1); 3014 ASSERT_EQ(args.length(), 1);
3015 CONVERT_CHECKED(JSObject, raw_object, args[0]); 3015 CONVERT_CHECKED(JSObject, raw_object, args[0]);
3016 HandleScope scope; 3016 HandleScope scope;
3017 Handle<JSObject> object(raw_object); 3017 Handle<JSObject> object(raw_object);
3018 Handle<FixedArray> contents = GetKeysInFixedArrayFor(object, 3018 Handle<FixedArray> contents = GetKeysInFixedArrayFor(object,
3019 LOCAL_ONLY); 3019 LOCAL_ONLY);
3020 // Some fast paths through GetKeysInFixedArrayFor reuse a cached 3020 // Some fast paths through GetKeysInFixedArrayFor reuse a cached
3021 // property array and since the result is mutable we have to create 3021 // property array and since the result is mutable we have to create
3022 // a fresh clone on each invocation. 3022 // a fresh clone on each invocation.
3023 Handle<FixedArray> copy = Factory::NewFixedArray(contents->length()); 3023 int length = contents->length();
3024 contents->CopyTo(0, *copy, 0, contents->length()); 3024 Handle<FixedArray> copy = Factory::NewFixedArray(length);
3025 for (int i = 0; i < length; i++) {
3026 Object* entry = contents->get(i);
3027 if (entry->IsString()) {
3028 copy->set(i, entry);
3029 } else {
3030 ASSERT(entry->IsNumber());
3031 HandleScope scope;
3032 Handle<Object> entry_handle(entry);
3033 Handle<Object> entry_str = Factory::NumberToString(entry_handle);
3034 copy->set(i, *entry_str);
3035 }
3036 }
3025 return *Factory::NewJSArrayWithElements(copy); 3037 return *Factory::NewJSArrayWithElements(copy);
3026 } 3038 }
3027 3039
3028 3040
3029 static Object* Runtime_GetArgumentsProperty(Arguments args) { 3041 static Object* Runtime_GetArgumentsProperty(Arguments args) {
3030 NoHandleAllocation ha; 3042 NoHandleAllocation ha;
3031 ASSERT(args.length() == 1); 3043 ASSERT(args.length() == 1);
3032 3044
3033 // Compute the frame holding the arguments. 3045 // Compute the frame holding the arguments.
3034 JavaScriptFrameIterator it; 3046 JavaScriptFrameIterator it;
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
3580 } 3592 }
3581 3593
3582 3594
3583 static Object* Runtime_NumberToString(Arguments args) { 3595 static Object* Runtime_NumberToString(Arguments args) {
3584 NoHandleAllocation ha; 3596 NoHandleAllocation ha;
3585 ASSERT(args.length() == 1); 3597 ASSERT(args.length() == 1);
3586 3598
3587 Object* number = args[0]; 3599 Object* number = args[0];
3588 RUNTIME_ASSERT(number->IsNumber()); 3600 RUNTIME_ASSERT(number->IsNumber());
3589 3601
3590 Object* cached = Heap::GetNumberStringCache(number); 3602 return Heap::NumberToString(number);
3591 if (cached != Heap::undefined_value()) {
3592 return cached;
3593 }
3594
3595 char arr[100];
3596 Vector<char> buffer(arr, ARRAY_SIZE(arr));
3597 const char* str;
3598 if (number->IsSmi()) {
3599 int num = Smi::cast(number)->value();
3600 str = IntToCString(num, buffer);
3601 } else {
3602 double num = HeapNumber::cast(number)->value();
3603 str = DoubleToCString(num, buffer);
3604 }
3605 Object* result = Heap::AllocateStringFromAscii(CStrVector(str));
3606
3607 if (!result->IsFailure()) {
3608 Heap::SetNumberStringCache(number, String::cast(result));
3609 }
3610 return result;
3611 } 3603 }
3612 3604
3613 3605
3614 static Object* Runtime_NumberToInteger(Arguments args) { 3606 static Object* Runtime_NumberToInteger(Arguments args) {
3615 NoHandleAllocation ha; 3607 NoHandleAllocation ha;
3616 ASSERT(args.length() == 1); 3608 ASSERT(args.length() == 1);
3617 3609
3618 Object* obj = args[0]; 3610 Object* obj = args[0];
3619 if (obj->IsSmi()) return obj; 3611 if (obj->IsSmi()) return obj;
3620 CONVERT_DOUBLE_CHECKED(number, obj); 3612 CONVERT_DOUBLE_CHECKED(number, obj);
(...skipping 4109 matching lines...) Expand 10 before | Expand all | Expand 10 after
7730 } else { 7722 } else {
7731 // Handle last resort GC and make sure to allow future allocations 7723 // Handle last resort GC and make sure to allow future allocations
7732 // to grow the heap without causing GCs (if possible). 7724 // to grow the heap without causing GCs (if possible).
7733 Counters::gc_last_resort_from_js.Increment(); 7725 Counters::gc_last_resort_from_js.Increment();
7734 Heap::CollectAllGarbage(false); 7726 Heap::CollectAllGarbage(false);
7735 } 7727 }
7736 } 7728 }
7737 7729
7738 7730
7739 } } // namespace v8::internal 7731 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | test/mjsunit/third_party/object-keys.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698