Skip to content

Commit

Permalink
LibJS: Fix small issues in Array.prototype.concat
Browse files Browse the repository at this point in the history
  • Loading branch information
davidot authored and linusg committed Jun 22, 2021
1 parent 91de113 commit 9d1fd40
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat)
if (!spreadable.is_undefined())
return spreadable.to_boolean();

return object->is_array();
return val.is_array(global_object);
};

auto append_to_new_array = [&vm, &is_concat_spreadable, &new_array, &global_object, &n](Value arg) {
Expand All @@ -546,7 +546,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat)
if (vm.exception())
return;

if (length + k > MAX_ARRAY_LIKE_INDEX) {
if (n + length > MAX_ARRAY_LIKE_INDEX) {
vm.throw_exception<TypeError>(global_object, ErrorType::ArrayMaxSize);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@ describe("normal behavior", () => {
expect(concatenated[4]).toBe(1);
expect(concatenated[5]).toEqual([2, 3]);
});

test("Proxy is concatenated as array", () => {
var proxy = new Proxy([9, 8], {});
var concatenated = array.concat(proxy);
expect(array).toHaveLength(1);
expect(concatenated).toHaveLength(3);
expect(concatenated[0]).toBe("hello");
expect(concatenated[1]).toBe(9);
expect(concatenated[2]).toBe(8);
});
});

0 comments on commit 9d1fd40

Please sign in to comment.