| Index: src/builtins.cc
|
| ===================================================================
|
| --- src/builtins.cc (revision 5559)
|
| +++ src/builtins.cc (working copy)
|
| @@ -188,9 +188,11 @@
|
| } else {
|
| // Allocate the JS Array
|
| JSFunction* constructor =
|
| + Object* obj;
|
| + { TryAllocation t = Heap::AllocateJSObject(constructor);
|
| + if (!t->ToObject(&obj)) return t;
|
| + }
|
| Top::context()->global_context()->array_function();
|
| - Object* obj = Heap::AllocateJSObject(constructor);
|
| - if (obj->IsFailure()) return obj;
|
| array = JSArray::cast(obj);
|
| }
|
|
|
| @@ -203,16 +205,19 @@
|
| Object* obj = args[1];
|
| if (obj->IsSmi()) {
|
| int len = Smi::cast(obj)->value();
|
| + Object* obj;
|
| + { TryAllocation t = Heap::AllocateFixedArrayWithHoles(len);
|
| + if (!t->ToObject(&obj)) return t;
|
| + }
|
| if (len >= 0 && len < JSObject::kInitialMaxFastElementArray) {
|
| - Object* obj = Heap::AllocateFixedArrayWithHoles(len);
|
| - if (obj->IsFailure()) return obj;
|
| array->SetContent(FixedArray::cast(obj));
|
| return array;
|
| }
|
| }
|
| + { TryAllocation t = array->Initialize(0);
|
| + if (!t->ToObject(&obj)) return t;
|
| + }
|
| // Take the argument as the length.
|
| - obj = array->Initialize(0);
|
| - if (obj->IsFailure()) return obj;
|
| return array->SetElementsLength(args[1]);
|
| }
|
|
|
| @@ -223,9 +228,11 @@
|
|
|
| // Take the arguments as elements.
|
| int number_of_elements = args.length() - 1;
|
| + Object* obj;
|
| + { TryAllocation t = Heap::AllocateFixedArrayWithHoles(len->value());
|
| + if (!t->ToObject(&obj)) return t;
|
| + }
|
| Smi* len = Smi::FromInt(number_of_elements);
|
| - Object* obj = Heap::AllocateFixedArrayWithHoles(len->value());
|
| - if (obj->IsFailure()) return obj;
|
|
|
| AssertNoAllocation no_gc;
|
| FixedArray* elms = FixedArray::cast(obj);
|
| @@ -245,16 +252,20 @@
|
|
|
| MUST_USE_RESULT static Object* AllocateJSArray() {
|
| JSFunction* array_function =
|
| + Object* result;
|
| + { TryAllocation t = Heap::AllocateJSObject(array_function);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| Top::context()->global_context()->array_function();
|
| - Object* result = Heap::AllocateJSObject(array_function);
|
| - if (result->IsFailure()) return result;
|
| return result;
|
| }
|
|
|
|
|
| + Object* result;
|
| + { TryAllocation t = AllocateJSArray();
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| MUST_USE_RESULT static Object* AllocateEmptyJSArray() {
|
| - Object* result = AllocateJSArray();
|
| - if (result->IsFailure()) return result;
|
| JSArray* result_array = JSArray::cast(result);
|
| result_array->set_length(Smi::FromInt(0));
|
| result_array->set_elements(Heap::empty_fixed_array());
|
| @@ -427,9 +438,11 @@
|
|
|
| if (new_length > elms->length()) {
|
| // New backing storage is needed.
|
| + Object* obj;
|
| + { TryAllocation t = Heap::AllocateUninitializedFixedArray(capacity);
|
| + if (!t->ToObject(&obj)) return t;
|
| + }
|
| int capacity = new_length + (new_length >> 1) + 16;
|
| - Object* obj = Heap::AllocateUninitializedFixedArray(capacity);
|
| - if (obj->IsFailure()) return obj;
|
| FixedArray* new_elms = FixedArray::cast(obj);
|
|
|
| AssertNoAllocation no_gc;
|
| @@ -485,9 +498,11 @@
|
|
|
|
|
| BUILTIN(ArrayShift) {
|
| + Object* elms_obj;
|
| + { TryAllocation t = EnsureJSArrayWithWritableFastElements(receiver);
|
| + if (!t->ToObject(&elms_obj)) return t;
|
| + }
|
| Object* receiver = *args.receiver();
|
| - Object* elms_obj = EnsureJSArrayWithWritableFastElements(receiver);
|
| - if (elms_obj->IsFailure()) return elms_obj;
|
| if (elms_obj == NULL ||
|
| !IsJSArrayFastElementMovingAllowed(JSArray::cast(receiver))) {
|
| return CallJsBuiltin("ArrayShift", args);
|
| @@ -524,9 +539,11 @@
|
|
|
|
|
| BUILTIN(ArrayUnshift) {
|
| + Object* elms_obj;
|
| + { TryAllocation t = EnsureJSArrayWithWritableFastElements(receiver);
|
| + if (!t->ToObject(&elms_obj)) return t;
|
| + }
|
| Object* receiver = *args.receiver();
|
| - Object* elms_obj = EnsureJSArrayWithWritableFastElements(receiver);
|
| - if (elms_obj->IsFailure()) return elms_obj;
|
| if (elms_obj == NULL ||
|
| !IsJSArrayFastElementMovingAllowed(JSArray::cast(receiver))) {
|
| return CallJsBuiltin("ArrayUnshift", args);
|
| @@ -544,9 +561,11 @@
|
|
|
| if (new_length > elms->length()) {
|
| // New backing storage is needed.
|
| + Object* obj;
|
| + { TryAllocation t = Heap::AllocateUninitializedFixedArray(capacity);
|
| + if (!t->ToObject(&obj)) return t;
|
| + }
|
| int capacity = new_length + (new_length >> 1) + 16;
|
| - Object* obj = Heap::AllocateUninitializedFixedArray(capacity);
|
| - if (obj->IsFailure()) return obj;
|
| FixedArray* new_elms = FixedArray::cast(obj);
|
|
|
| AssertNoAllocation no_gc;
|
| @@ -576,9 +595,11 @@
|
|
|
|
|
| BUILTIN(ArraySlice) {
|
| + Object* elms_obj;
|
| + { TryAllocation t = EnsureJSArrayWithWritableFastElements(receiver);
|
| + if (!t->ToObject(&elms_obj)) return t;
|
| + }
|
| Object* receiver = *args.receiver();
|
| - Object* elms_obj = EnsureJSArrayWithWritableFastElements(receiver);
|
| - if (elms_obj->IsFailure()) return elms_obj;
|
| if (elms_obj == NULL ||
|
| !IsJSArrayFastElementMovingAllowed(JSArray::cast(receiver))) {
|
| return CallJsBuiltin("ArraySlice", args);
|
| @@ -626,13 +647,16 @@
|
| if (result_len <= 0) {
|
| return AllocateEmptyJSArray();
|
| }
|
| + Object* result;
|
| + { TryAllocation t = AllocateJSArray();
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
|
|
| - Object* result = AllocateJSArray();
|
| - if (result->IsFailure()) return result;
|
| JSArray* result_array = JSArray::cast(result);
|
| + { TryAllocation t = Heap::AllocateUninitializedFixedArray(result_len);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
|
|
| - result = Heap::AllocateUninitializedFixedArray(result_len);
|
| - if (result->IsFailure()) return result;
|
| FixedArray* result_elms = FixedArray::cast(result);
|
|
|
| AssertNoAllocation no_gc;
|
| @@ -648,9 +672,11 @@
|
|
|
|
|
| BUILTIN(ArraySplice) {
|
| + Object* elms_obj;
|
| + { TryAllocation t = EnsureJSArrayWithWritableFastElements(receiver);
|
| + if (!t->ToObject(&elms_obj)) return t;
|
| + }
|
| Object* receiver = *args.receiver();
|
| - Object* elms_obj = EnsureJSArrayWithWritableFastElements(receiver);
|
| - if (elms_obj->IsFailure()) return elms_obj;
|
| if (elms_obj == NULL ||
|
| !IsJSArrayFastElementMovingAllowed(JSArray::cast(receiver))) {
|
| return CallJsBuiltin("ArraySplice", args);
|
| @@ -694,18 +720,24 @@
|
| int actual_delete_count = Min(Max(delete_count, 0), len - actual_start);
|
|
|
| JSArray* result_array = NULL;
|
| + Object* result;
|
| + { TryAllocation t = AllocateEmptyJSArray();
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| if (actual_delete_count == 0) {
|
| - Object* result = AllocateEmptyJSArray();
|
| - if (result->IsFailure()) return result;
|
| result_array = JSArray::cast(result);
|
| } else {
|
| + Object* result;
|
| + { TryAllocation t = AllocateJSArray();
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| // Allocate result array.
|
| - Object* result = AllocateJSArray();
|
| - if (result->IsFailure()) return result;
|
| result_array = JSArray::cast(result);
|
| + { TryAllocation t =
|
| + Heap::AllocateUninitializedFixedArray(actual_delete_count);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
|
|
| - result = Heap::AllocateUninitializedFixedArray(actual_delete_count);
|
| - if (result->IsFailure()) return result;
|
| FixedArray* result_elms = FixedArray::cast(result);
|
|
|
| AssertNoAllocation no_gc;
|
| @@ -757,9 +789,11 @@
|
| // Check if array need to grow.
|
| if (new_length > elms->length()) {
|
| // New backing storage is needed.
|
| + Object* obj;
|
| + { TryAllocation t = Heap::AllocateUninitializedFixedArray(capacity);
|
| + if (!t->ToObject(&obj)) return t;
|
| + }
|
| int capacity = new_length + (new_length >> 1) + 16;
|
| - Object* obj = Heap::AllocateUninitializedFixedArray(capacity);
|
| - if (obj->IsFailure()) return obj;
|
| FixedArray* new_elms = FixedArray::cast(obj);
|
|
|
| AssertNoAllocation no_gc;
|
| @@ -837,13 +871,16 @@
|
| return AllocateEmptyJSArray();
|
| }
|
|
|
| + Object* result;
|
| + { TryAllocation t = AllocateJSArray();
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
| // Allocate result.
|
| - Object* result = AllocateJSArray();
|
| - if (result->IsFailure()) return result;
|
| JSArray* result_array = JSArray::cast(result);
|
| + { TryAllocation t = Heap::AllocateUninitializedFixedArray(result_len);
|
| + if (!t->ToObject(&result)) return t;
|
| + }
|
|
|
| - result = Heap::AllocateUninitializedFixedArray(result_len);
|
| - if (result->IsFailure()) return result;
|
| FixedArray* result_elms = FixedArray::cast(result);
|
|
|
| // Copy data.
|
|
|