Index: src/builtins.cc |
=================================================================== |
--- src/builtins.cc (revision 4073) |
+++ src/builtins.cc (working copy) |
@@ -319,24 +319,6 @@ |
} |
-static bool IsJSArrayWithFastElements(Object* receiver, |
- FixedArray** elements) { |
- if (!receiver->IsJSArray()) { |
- return false; |
- } |
- |
- JSArray* array = JSArray::cast(receiver); |
- |
- HeapObject* elms = HeapObject::cast(array->elements()); |
- if (elms->map() != Heap::fixed_array_map()) { |
- return false; |
- } |
- |
- *elements = FixedArray::cast(elms); |
- return true; |
-} |
- |
- |
static Object* CallJsBuiltin(const char* name, |
BuiltinArguments<NO_EXTRA_ARGUMENTS> args) { |
HandleScope handleScope; |
@@ -364,12 +346,8 @@ |
BUILTIN(ArrayPush) { |
- Object* receiver = *args.receiver(); |
- FixedArray* elms = NULL; |
- if (!IsJSArrayWithFastElements(receiver, &elms)) { |
- return CallJsBuiltin("ArrayPush", args); |
- } |
- JSArray* array = JSArray::cast(receiver); |
+ JSArray* array = JSArray::cast(*args.receiver()); |
+ ASSERT(array->HasFastElements()); |
int len = Smi::cast(array->length())->value(); |
int to_add = args.length() - 1; |
@@ -381,6 +359,7 @@ |
ASSERT(to_add <= (Smi::kMaxValue - len)); |
int new_length = len + to_add; |
+ FixedArray* elms = FixedArray::cast(array->elements()); |
if (new_length > elms->length()) { |
// New backing storage is needed. |
@@ -411,17 +390,14 @@ |
BUILTIN(ArrayPop) { |
- Object* receiver = *args.receiver(); |
- FixedArray* elms = NULL; |
- if (!IsJSArrayWithFastElements(receiver, &elms)) { |
- return CallJsBuiltin("ArrayPop", args); |
- } |
- JSArray* array = JSArray::cast(receiver); |
+ JSArray* array = JSArray::cast(*args.receiver()); |
+ ASSERT(array->HasFastElements()); |
int len = Smi::cast(array->length())->value(); |
if (len == 0) return Heap::undefined_value(); |
// Get top element |
+ FixedArray* elms = FixedArray::cast(array->elements()); |
Object* top = elms->get(len - 1); |
// Set the length. |
@@ -444,18 +420,18 @@ |
BUILTIN(ArrayShift) { |
- Object* receiver = *args.receiver(); |
- FixedArray* elms = NULL; |
- if (!IsJSArrayWithFastElements(receiver, &elms) |
- || !ArrayPrototypeHasNoElements()) { |
+ if (!ArrayPrototypeHasNoElements()) { |
return CallJsBuiltin("ArrayShift", args); |
} |
- JSArray* array = JSArray::cast(receiver); |
+ |
+ JSArray* array = JSArray::cast(*args.receiver()); |
ASSERT(array->HasFastElements()); |
int len = Smi::cast(array->length())->value(); |
if (len == 0) return Heap::undefined_value(); |
+ FixedArray* elms = FixedArray::cast(array->elements()); |
+ |
// Get first element |
Object* first = elms->get(0); |
if (first->IsTheHole()) { |
@@ -475,13 +451,11 @@ |
BUILTIN(ArrayUnshift) { |
- Object* receiver = *args.receiver(); |
- FixedArray* elms = NULL; |
- if (!IsJSArrayWithFastElements(receiver, &elms) |
- || !ArrayPrototypeHasNoElements()) { |
+ if (!ArrayPrototypeHasNoElements()) { |
return CallJsBuiltin("ArrayUnshift", args); |
} |
- JSArray* array = JSArray::cast(receiver); |
+ |
+ JSArray* array = JSArray::cast(*args.receiver()); |
ASSERT(array->HasFastElements()); |
int len = Smi::cast(array->length())->value(); |
@@ -495,6 +469,8 @@ |
// we should never hit this case. |
ASSERT(to_add <= (Smi::kMaxValue - len)); |
+ FixedArray* elms = FixedArray::cast(array->elements()); |
+ |
if (new_length > elms->length()) { |
// New backing storage is needed. |
int capacity = new_length + (new_length >> 1) + 16; |
@@ -527,13 +503,11 @@ |
BUILTIN(ArraySlice) { |
- Object* receiver = *args.receiver(); |
- FixedArray* elms = NULL; |
- if (!IsJSArrayWithFastElements(receiver, &elms) |
- || !ArrayPrototypeHasNoElements()) { |
+ if (!ArrayPrototypeHasNoElements()) { |
return CallJsBuiltin("ArraySlice", args); |
} |
- JSArray* array = JSArray::cast(receiver); |
+ |
+ JSArray* array = JSArray::cast(*args.receiver()); |
ASSERT(array->HasFastElements()); |
int len = Smi::cast(array->length())->value(); |
@@ -584,6 +558,8 @@ |
if (result->IsFailure()) return result; |
FixedArray* result_elms = FixedArray::cast(result); |
+ FixedArray* elms = FixedArray::cast(array->elements()); |
+ |
AssertNoAllocation no_gc; |
CopyElements(&no_gc, result_elms, 0, elms, k, result_len); |
@@ -597,13 +573,11 @@ |
BUILTIN(ArraySplice) { |
- Object* receiver = *args.receiver(); |
- FixedArray* elms = NULL; |
- if (!IsJSArrayWithFastElements(receiver, &elms) |
- || !ArrayPrototypeHasNoElements()) { |
+ if (!ArrayPrototypeHasNoElements()) { |
return CallJsBuiltin("ArraySplice", args); |
} |
- JSArray* array = JSArray::cast(receiver); |
+ |
+ JSArray* array = JSArray::cast(*args.receiver()); |
ASSERT(array->HasFastElements()); |
int len = Smi::cast(array->length())->value(); |
@@ -644,6 +618,8 @@ |
} |
int actual_delete_count = Min(Max(delete_count, 0), len - actual_start); |
+ FixedArray* elms = FixedArray::cast(array->elements()); |
+ |
JSArray* result_array = NULL; |
if (actual_delete_count == 0) { |
Object* result = AllocateEmptyJSArray(); |