Chromium Code Reviews| Index: src/runtime.cc |
| diff --git a/src/runtime.cc b/src/runtime.cc |
| index 17bc34ac7dd13f93b183c0b3e755233b07a9dbb6..208365aa4c4ba1ea5e0624d4d4f121c8bd01647d 100644 |
| --- a/src/runtime.cc |
| +++ b/src/runtime.cc |
| @@ -14897,6 +14897,45 @@ RUNTIME_FUNCTION(Runtime_InternalArrayConstructor) { |
| } |
| +RUNTIME_FUNCTION(Runtime_GrowArrayElements) { |
| + HandleScope scope(isolate); |
| + ASSERT(args.length() == 3); |
| + CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| + CONVERT_SMI_ARG_CHECKED(key, 1); |
| + |
| + Handle<FixedArrayBase> elements(object->elements()); |
|
danno
2014/07/21 10:31:43
I guess this is function is OK, but it bothers me
|
| + uint32_t capacity = static_cast<uint32_t>(elements->length()); |
| + uint32_t unsigned_key = static_cast<uint32_t>(key); |
| + |
| + if (unsigned_key >= capacity) { |
| + if ((unsigned_key - capacity) < JSObject::kMaxGap) { |
| + uint32_t new_capacity = JSObject::NewElementsCapacity(capacity); |
| + if (object->ShouldConvertToSlowElements(new_capacity)) { |
| + JSObject::NormalizeElements(object); |
| + return Smi::FromInt(0); |
| + } |
| + Handle<FixedArrayBase> new_elems; |
| + ElementsKind kind = object->GetElementsKind(); |
| + if (IsFastDoubleElementsKind(kind)) { |
| + new_elems = isolate->factory()->NewFixedDoubleArray(new_capacity); |
| + } else { |
| + new_elems = isolate->factory()->NewFixedArray(new_capacity); |
| + } |
| + ElementsAccessor* accessor = object->GetElementsAccessor(); |
| + accessor->CopyElements(object, new_elems, kind); |
| + Handle<Map> same_map = JSObject::GetElementsTransitionMap(object, kind); |
| + object->SetMapAndElements(object, same_map, new_elems); |
| + } else { |
| + JSObject::NormalizeElements(object); |
| + return Smi::FromInt(0); |
| + } |
| + } |
| + |
| + // On success, return the fixed array elements. |
| + return object->elements(); |
| +} |
| + |
| + |
| RUNTIME_FUNCTION(Runtime_MaxSmi) { |
| ASSERT(args.length() == 0); |
| return Smi::FromInt(Smi::kMaxValue); |