Chromium Code Reviews| Index: src/builtins.cc |
| diff --git a/src/builtins.cc b/src/builtins.cc |
| index 18afe9119d634fe0001375f6f5dcdb4b9fd05bf3..854337784bb866494cf7aae7febe05fba88fff31 100644 |
| --- a/src/builtins.cc |
| +++ b/src/builtins.cc |
| @@ -335,6 +335,41 @@ BUILTIN(ArrayPop) { |
| } |
| +BUILTIN(ArrayShift) { |
| + JSArray* array = JSArray::cast(*args.receiver()); |
| + ASSERT(array->HasFastElements()); |
| + Object* undefined = Heap::undefined_value(); |
|
Mads Ager (chromium)
2010/02/12 13:27:51
Get rid of the local variable and just put in Heap
antonm
2010/02/12 14:05:55
Done.
|
| + |
| + int len = Smi::cast(array->length())->value(); |
| + if (len == 0) return undefined; |
| + |
| + // Fetch the prototype. |
| + JSFunction* array_function = |
| + Top::context()->global_context()->array_function(); |
| + JSObject* prototype = JSObject::cast(array_function->prototype()); |
| + |
| + // Get first element |
| + FixedArray* elms = FixedArray::cast(array->elements()); |
| + Object* first = elms->get(0); |
| + |
| + // Set the length. |
| + array->set_length(Smi::FromInt(len - 1)); |
| + |
| + if (first->IsTheHole()) |
|
Mads Ager (chromium)
2010/02/12 13:27:51
Please use braces around the body.
antonm
2010/02/12 14:05:55
Done.
|
| + first = prototype->GetElement(0); |
| + |
| + for (int i = 0; i < len - 1; i++) { |
| + Object* e = elms->get(i + 1); |
| + if (e->IsTheHole()) |
|
Mads Ager (chromium)
2010/02/12 13:27:51
Please use braces around the body.
antonm
2010/02/12 14:05:55
Done.
|
| + e = prototype->GetElement(i + 1); |
| + elms->set(i, e); |
|
Mads Ager (chromium)
2010/02/12 13:27:51
Will this preserve array holes? Won't GetElement
antonm
2010/02/12 14:05:55
Nice catch, thanks a lot. Regression test added.
|
| + } |
| + elms->set(len - 1, Heap::the_hole_value()); |
| + |
| + return first; |
| +} |
| + |
| + |
| // ----------------------------------------------------------------------------- |
| // |