mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:37:46 +00:00
LibJS: Make removed elements in Array.prototype.splice spec compliant
It wasn't using has_property, was directly appending to indexed properties and wasn't setting the length.
This commit is contained in:
parent
bc540de0af
commit
00a83a2957
1 changed files with 15 additions and 2 deletions
|
@ -905,13 +905,26 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::splice)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
for (size_t i = 0; i < actual_delete_count; ++i) {
|
for (size_t i = 0; i < actual_delete_count; ++i) {
|
||||||
auto value = this_object->get(actual_start + i);
|
auto from = actual_start + i;
|
||||||
|
bool from_present = this_object->has_property(from);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
removed_elements->indexed_properties().append(value);
|
if (from_present) {
|
||||||
|
auto from_value = this_object->get(actual_start + i);
|
||||||
|
if (vm.exception())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
removed_elements->define_property(i, from_value);
|
||||||
|
if (vm.exception())
|
||||||
|
return {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removed_elements->put(vm.names.length, Value(actual_delete_count));
|
||||||
|
if (vm.exception())
|
||||||
|
return {};
|
||||||
|
|
||||||
if (insert_count < actual_delete_count) {
|
if (insert_count < actual_delete_count) {
|
||||||
for (size_t i = actual_start; i < initial_length - actual_delete_count; ++i) {
|
for (size_t i = actual_start; i < initial_length - actual_delete_count; ++i) {
|
||||||
auto from = this_object->get(i + actual_delete_count);
|
auto from = this_object->get(i + actual_delete_count);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue