OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1852 // Fast case: The new length fits into a Smi. | 1852 // Fast case: The new length fits into a Smi. |
1853 MaybeObject* maybe_smi_length = length->ToSmi(); | 1853 MaybeObject* maybe_smi_length = length->ToSmi(); |
1854 Object* smi_length = Smi::FromInt(0); | 1854 Object* smi_length = Smi::FromInt(0); |
1855 if (maybe_smi_length->ToObject(&smi_length) && smi_length->IsSmi()) { | 1855 if (maybe_smi_length->ToObject(&smi_length) && smi_length->IsSmi()) { |
1856 const int value = Smi::cast(smi_length)->value(); | 1856 const int value = Smi::cast(smi_length)->value(); |
1857 if (value >= 0) { | 1857 if (value >= 0) { |
1858 Object* new_length; | 1858 Object* new_length; |
1859 MaybeObject* result = ElementsAccessorSubclass:: | 1859 MaybeObject* result = ElementsAccessorSubclass:: |
1860 SetLengthWithoutNormalize(backing_store, array, smi_length, value); | 1860 SetLengthWithoutNormalize(backing_store, array, smi_length, value); |
1861 if (!result->ToObject(&new_length)) return result; | 1861 if (!result->ToObject(&new_length)) return result; |
1862 ASSERT(new_length->IsSmi() || new_length->IsUndefined()); | 1862 // even though the proposed length was a smi, new_length could |
| 1863 // still be a heap number because SetLengthWithoutNormalize doesn't |
| 1864 // allow the array length property to drop below the index of |
| 1865 // non-deletable elements. |
| 1866 ASSERT(new_length->IsSmi() || new_length->IsHeapNumber() || |
| 1867 new_length->IsUndefined()); |
1863 if (new_length->IsSmi()) { | 1868 if (new_length->IsSmi()) { |
1864 array->set_length(Smi::cast(new_length)); | 1869 array->set_length(Smi::cast(new_length)); |
1865 return array; | 1870 return array; |
| 1871 } else if (new_length->IsHeapNumber()) { |
| 1872 array->set_length(new_length); |
| 1873 return array; |
1866 } | 1874 } |
1867 } else { | 1875 } else { |
1868 return ThrowArrayLengthRangeError(array->GetHeap()); | 1876 return ThrowArrayLengthRangeError(array->GetHeap()); |
1869 } | 1877 } |
1870 } | 1878 } |
1871 | 1879 |
1872 // Slow case: The new length does not fit into a Smi or conversion | 1880 // Slow case: The new length does not fit into a Smi or conversion |
1873 // to slow elements is needed for other reasons. | 1881 // to slow elements is needed for other reasons. |
1874 if (length->IsNumber()) { | 1882 if (length->IsNumber()) { |
1875 uint32_t value; | 1883 uint32_t value; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1992 UNREACHABLE(); | 2000 UNREACHABLE(); |
1993 break; | 2001 break; |
1994 } | 2002 } |
1995 | 2003 |
1996 array->set_elements(elms); | 2004 array->set_elements(elms); |
1997 array->set_length(Smi::FromInt(number_of_elements)); | 2005 array->set_length(Smi::FromInt(number_of_elements)); |
1998 return array; | 2006 return array; |
1999 } | 2007 } |
2000 | 2008 |
2001 } } // namespace v8::internal | 2009 } } // namespace v8::internal |
OLD | NEW |