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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 // Remember to check the prototype chain. | 306 // Remember to check the prototype chain. |
307 JSFunction* array_function = | 307 JSFunction* array_function = |
308 Top::context()->global_context()->array_function(); | 308 Top::context()->global_context()->array_function(); |
309 JSObject* prototype = JSObject::cast(array_function->prototype()); | 309 JSObject* prototype = JSObject::cast(array_function->prototype()); |
310 top = prototype->GetElement(len - 1); | 310 top = prototype->GetElement(len - 1); |
311 | 311 |
312 return top; | 312 return top; |
313 } | 313 } |
314 | 314 |
315 | 315 |
| 316 BUILTIN(ArrayShift) { |
| 317 JSArray* array = JSArray::cast(*args.receiver()); |
| 318 ASSERT(array->HasFastElements()); |
| 319 |
| 320 int len = Smi::cast(array->length())->value(); |
| 321 if (len == 0) return Heap::undefined_value(); |
| 322 |
| 323 // Fetch the prototype. |
| 324 JSFunction* array_function = |
| 325 Top::context()->global_context()->array_function(); |
| 326 JSObject* prototype = JSObject::cast(array_function->prototype()); |
| 327 |
| 328 // Get first element |
| 329 FixedArray* elms = FixedArray::cast(array->elements()); |
| 330 Object* first = elms->get(0); |
| 331 |
| 332 if (first->IsTheHole()) { |
| 333 first = prototype->GetElement(0); |
| 334 } |
| 335 |
| 336 // Shift the elements. |
| 337 for (int i = 0; i < len - 1; i++) { |
| 338 Object* e = elms->get(i + 1); |
| 339 if (e->IsTheHole() && prototype->HasElement(i + 1)) { |
| 340 e = prototype->GetElement(i + 1); |
| 341 } |
| 342 elms->set(i, e); |
| 343 } |
| 344 elms->set(len - 1, Heap::the_hole_value()); |
| 345 |
| 346 // Set the length. |
| 347 array->set_length(Smi::FromInt(len - 1)); |
| 348 |
| 349 return first; |
| 350 } |
| 351 |
| 352 |
316 // ----------------------------------------------------------------------------- | 353 // ----------------------------------------------------------------------------- |
317 // | 354 // |
318 | 355 |
319 | 356 |
320 // Returns the holder JSObject if the function can legally be called | 357 // Returns the holder JSObject if the function can legally be called |
321 // with this receiver. Returns Heap::null_value() if the call is | 358 // with this receiver. Returns Heap::null_value() if the call is |
322 // illegal. Any arguments that don't fit the expected type is | 359 // illegal. Any arguments that don't fit the expected type is |
323 // overwritten with undefined. Arguments that do fit the expected | 360 // overwritten with undefined. Arguments that do fit the expected |
324 // type is overwritten with the object in the prototype chain that | 361 // type is overwritten with the object in the prototype chain that |
325 // actually has that type. | 362 // actually has that type. |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 if (entry->contains(pc)) { | 989 if (entry->contains(pc)) { |
953 return names_[i]; | 990 return names_[i]; |
954 } | 991 } |
955 } | 992 } |
956 } | 993 } |
957 return NULL; | 994 return NULL; |
958 } | 995 } |
959 | 996 |
960 | 997 |
961 } } // namespace v8::internal | 998 } } // namespace v8::internal |
OLD | NEW |