Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 // Remember to check the prototype chain. | 328 // Remember to check the prototype chain. |
| 329 JSFunction* array_function = | 329 JSFunction* array_function = |
| 330 Top::context()->global_context()->array_function(); | 330 Top::context()->global_context()->array_function(); |
| 331 JSObject* prototype = JSObject::cast(array_function->prototype()); | 331 JSObject* prototype = JSObject::cast(array_function->prototype()); |
| 332 top = prototype->GetElement(len - 1); | 332 top = prototype->GetElement(len - 1); |
| 333 | 333 |
| 334 return top; | 334 return top; |
| 335 } | 335 } |
| 336 | 336 |
| 337 | 337 |
| 338 BUILTIN(ArrayShift) { | |
| 339 JSArray* array = JSArray::cast(*args.receiver()); | |
| 340 ASSERT(array->HasFastElements()); | |
| 341 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.
| |
| 342 | |
| 343 int len = Smi::cast(array->length())->value(); | |
| 344 if (len == 0) return undefined; | |
| 345 | |
| 346 // Fetch the prototype. | |
| 347 JSFunction* array_function = | |
| 348 Top::context()->global_context()->array_function(); | |
| 349 JSObject* prototype = JSObject::cast(array_function->prototype()); | |
| 350 | |
| 351 // Get first element | |
| 352 FixedArray* elms = FixedArray::cast(array->elements()); | |
| 353 Object* first = elms->get(0); | |
| 354 | |
| 355 // Set the length. | |
| 356 array->set_length(Smi::FromInt(len - 1)); | |
| 357 | |
| 358 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.
| |
| 359 first = prototype->GetElement(0); | |
| 360 | |
| 361 for (int i = 0; i < len - 1; i++) { | |
| 362 Object* e = elms->get(i + 1); | |
| 363 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.
| |
| 364 e = prototype->GetElement(i + 1); | |
| 365 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.
| |
| 366 } | |
| 367 elms->set(len - 1, Heap::the_hole_value()); | |
| 368 | |
| 369 return first; | |
| 370 } | |
| 371 | |
| 372 | |
| 338 // ----------------------------------------------------------------------------- | 373 // ----------------------------------------------------------------------------- |
| 339 // | 374 // |
| 340 | 375 |
| 341 | 376 |
| 342 // Returns the holder JSObject if the function can legally be called | 377 // Returns the holder JSObject if the function can legally be called |
| 343 // with this receiver. Returns Heap::null_value() if the call is | 378 // with this receiver. Returns Heap::null_value() if the call is |
| 344 // illegal. Any arguments that don't fit the expected type is | 379 // illegal. Any arguments that don't fit the expected type is |
| 345 // overwritten with undefined. Arguments that do fit the expected | 380 // overwritten with undefined. Arguments that do fit the expected |
| 346 // type is overwritten with the object in the prototype chain that | 381 // type is overwritten with the object in the prototype chain that |
| 347 // actually has that type. | 382 // actually has that type. |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 973 if (entry->contains(pc)) { | 1008 if (entry->contains(pc)) { |
| 974 return names_[i]; | 1009 return names_[i]; |
| 975 } | 1010 } |
| 976 } | 1011 } |
| 977 } | 1012 } |
| 978 return NULL; | 1013 return NULL; |
| 979 } | 1014 } |
| 980 | 1015 |
| 981 | 1016 |
| 982 } } // namespace v8::internal | 1017 } } // namespace v8::internal |
| OLD | NEW |