Commit graph

59 commits

Author SHA1 Message Date
Luke Wilde
3ceedbd16a LibJS: Allow assignment expression in spreading property definition
See: https://tc39.es/ecma262/#sec-runtime-semantics-propertydefinitionevaluation
PropertyDefinition : ... AssignmentExpression
Also add a test for this in array spreading, which already had this in
place.
2023-08-29 18:46:01 -04:00
Shannon Booth
9b884a9605 LibJS: Avoid double construction in Array.fromAsync
This is a normative change in the array from async proposal, see:

https://github.com/tc39/proposal-array-from-async/commit/49cfde2

It fixes a double construction when Array.fromAsync is given an array
like object.
2023-08-28 20:45:11 -04:00
Florian Stellbrink
d4d7550588 LibJS/Tests: Test splice at non zero index 2023-07-16 17:13:44 +01:00
Shannon Booth
ba758e9f4d LibJS/Tests: Add some basic tests for Array.fromAsync 2023-07-16 14:56:10 +01:00
Linus Groh
419e710c1c LibJS: Re-implement the Array Grouping proposal as static methods
Closes #19495.
2023-07-12 00:03:54 +02:00
Shannon Booth
be280ff3e4 LibJS/Tests: Enable some now passing Array length tests
Now that serenity is 64 bit only these tests no longer need to be
skipped :^)
2023-06-28 10:48:15 +02:00
Linus Groh
28a3c064c5 LibJS/Tests: Disable one Array.prototype.toSpliced test for now
It keeps failing on i686, and will until we've updated a bunch of size_t
APIs in the codebase to u64.
2022-07-04 18:50:35 +02:00
Linus Groh
4b70ddf5a0 LibJS: Let Array.prototype.toSpliced throw RangeError for len <= 2^53-1
This aligns it with the spec again, it was clarified that the additional
range check before ArrayCreate is intentional:
https://github.com/tc39/proposal-change-array-by-copy/issues/94

Also cast the final variable to an u64 instead of size_t after we have
determined that it is safe to do so, as that's what Array::create()
takes now.
2022-07-04 10:10:11 +02:00
Linus Groh
698062b831 LibJS: Implement Array.prototype.with() 2022-06-13 20:26:54 +01:00
Linus Groh
ae81793f20 LibJS: Implement Array.prototype.toSpliced() 2022-06-13 20:26:54 +01:00
Linus Groh
ce17c868c0 LibJS: Implement Array.prototype.toSorted() 2022-06-13 20:26:54 +01:00
Linus Groh
e4370b7d82 LibJS: Implement Array.prototype.toReversed() 2022-06-13 20:26:54 +01:00
Linus Groh
013e2df858 LibJS: Rename Array.prototype.groupBy{,ToMap} => group{,ToMap}
This is a normative change in the Array Grouping spec.

See: https://github.com/tc39/proposal-array-grouping/commit/0cf4077
2022-06-13 20:05:24 +01:00
Linus Groh
00b8ce4a6d LibJS: Pass this value to fallback func in Array.prototype.toString()
The existing code looks innocently correct, implementing the following
step:

    3. If IsCallable(func) is false, set func to the intrinsic function
       %Object.prototype.toString%.

as

    return ObjectPrototype::to_string(vm, global_object);

However, this misses the fact that the next step calls the function with
the previously ToObject()'d this value (`array`):

    4. Return ? Call(func, array).

This doesn't happen in the current implementation, which will use the
unaltered this value from the Array.prototype.toString() call, and make
another, unequal object in %Object.prototype.toString%. Since both that
and Array.prototype.toString() do a Get() call on said object, this
behavior is observable (see newly added test).

Fix this by actually doing what the spec says and calling the fallback
function the regular way.
2022-04-12 00:23:27 +01:00
Luke Wilde
3e0c19d6ea LibJS: Add tests for all the unscopable Array prototype properties
When I was writing for tests for groupBy and groupByToMap, I noticed
there were no tests for these.
2022-01-05 20:31:25 +01:00
Luke Wilde
0b9ea712be LibJS: Implement Array.prototype.groupByToMap 2022-01-05 11:21:38 +01:00
Luke Wilde
48cc1c97d5 LibJS: Implement Array.prototype.groupBy 2022-01-05 11:21:38 +01:00
Idan Horowitz
957f54d96f LibJS: Throw InternalErrors instead of Errors on CallStackSizeExceeded
These seem more appropriate.
2021-11-27 01:58:05 +02:00
Linus Groh
f1784c9c87 LibJS/Tests: Fix failing Array.prototype.toLocaleString() test 2021-11-17 10:00:20 +00:00
Timothy Flynn
39ab1a8999 LibJS: Implement ECMA-402 Array.prototype.toLocaleString
Turns out the only difference between our existing implementation and
the ECMA-402 implementation is we weren't passing the locales and
options list to each element.toLocaleString invocation.

This also adds spec comments to the definition.
2021-11-17 09:01:32 +00:00
Robert Stefanic
e26cfd313e LibJS: Prevent stack overflow in flatten_into_array()
The check for stack space in VM from push_execution_context has been
moved to a method on VM called did_reach_stack_space_limit. This
allows us to check the stack size in other places besides
push_execution_context.

We can now verify that we have enough space on the stack before calling
flatten_into_array to ensure that we don't cause a stack overflow error
when calling the function with a large depth.
2021-08-15 11:24:30 +01:00
davidot
b6523906b3 LibJS: Implement proposed Array.prototype.findLast{,Index}
Proposal: https://tc39.es/proposal-array-find-from-last/
2021-08-06 16:17:25 +01:00
davidot
a49b47bfe6 LibJS: Fix tests that expected wrong this values 2021-07-20 23:45:28 +02:00
davidot
7310713d11 LibJS: Remove fast array paths in ArrayPrototype::{pop, push}
Unfortunately this fast path leads to problems if Array.prototype is
changed. We probably need to find out some way to optimize these methods
by detecting changes to the prototype or other mechanisms.
2021-07-07 21:24:26 +01:00
Idan Horowitz
a6b8291a9b LibJS: Add define_direct_property and remove the define_property helper
This removes all usages of the non-standard define_property helper
method and replaces all it's usages with the specification required
alternative or with define_direct_property where appropriate.
2021-07-06 14:20:30 +01:00
Hendi
793e1bf28a LibJS: Fix variable scoping issues in two tests 2021-07-06 00:15:37 +01:00
Linus Groh
70c6090fef LibJS/Tests: Enable Array tests that now just work :^) 2021-07-04 22:07:36 +01:00
Linus Groh
4e5362b7cb LibJS/Tests: Remove 'requires at least one argument' Array tests
These will be removed in favour of just taking the argument and
'risking' a ToObject on null or undefined - this is how the spec does
it.
While that will make the message slightly less specific, it'll bring
the code closer to the spec and reduce complexity, which are both
preferable at the moment.

Doing this is a previous, separate commit is simply an attempt to make
the object rewrite commit smaller.
2021-07-04 22:07:36 +01:00
davidot
a63cc2c6b9 LibJS: Skip tests which broke with reversion of f102b563
These tests are correct as other engines pass them but are now broken
2021-06-26 18:16:53 +01:00
davidot
b1441a47b1 LibJS: Allow setting the length of an object with prototype Array
Before this it would always go through the native setter thus
 modifying the array but now you can set length to anything
2021-06-26 18:16:53 +01:00
davidot
b38fb418f8 LibJS: Don't remove non-configurable items in Array when setting length 2021-06-26 18:16:53 +01:00
davidot
f7e2994f35 LibJS: Make string to integer parsing for properties more strict
This does break two TypedArray test262 test but those really were not
  correct because hasProperty was not implemented
2021-06-22 20:49:28 +01:00
davidot
9d1fd403af LibJS: Fix small issues in Array.prototype.concat 2021-06-22 20:49:28 +01:00
davidot
15edad8202 LibJS: Make define_property always throw if specified
Now put uses is_strict_mode to determine define_property should throw
2021-06-22 20:49:28 +01:00
sin-ack
c5073cb287 LibJS: Do not trim whitespace from property names when they're numbers
Fixes #7803.
2021-06-18 19:18:15 +01:00
davidot
ae8b55a80a LibJS: Add additional generic Array.prototype.slice tests 2021-06-14 09:57:06 +01:00
davidot
6c13cc67c6 LibJS: Implement Array.prototype.copyWithin generically 2021-06-14 09:57:06 +01:00
davidot
417f752306 LibJS: Implement Array.prototype.entries 2021-06-14 09:57:06 +01:00
davidot
910b803d8d LibJS: Implement Array.prototype.flatMap
Also made recursive_array_flat more compliant with the spec
So renamed it to flatten_into_array
2021-06-14 09:57:06 +01:00
davidot
4152409ac5 LibJS: Make Array.prototype.concat generic 2021-06-14 09:57:06 +01:00
davidot
2ef9df989f LibJS: Make Array.prototype.reverse generic 2021-06-14 09:57:06 +01:00
davidot
516f6240e8 LibJS: Add additional Array.prototype.reverse tests 2021-06-14 09:57:06 +01:00
davidot
d723c01af7 LibJS: Make Array.prototype.unshift generic 2021-06-14 09:57:06 +01:00
davidot
7c1e2adf8a LibJS: Make Array.prototype.shift generic 2021-06-14 09:57:06 +01:00
Luke
d72aeb2e1a LibJS: Rewrite Array.prototype.slice to be spec compliant
This makes it generic in the process (which is required by jQuery)
This fixes 19 test262 test cases :^)
2021-06-13 16:21:34 +01:00
davidot
e044a3e428 LibJS: Add Array.prototype.keys() 2021-06-12 14:40:34 +01:00
Luke
bc540de0af LibJS: Pass in actual_delete_count to removed array creation in splice
More specifically, Array.prototype.splice. Additionally adds a missing
exception check to the array creation and a link to the spec.

Fixes create-non-array-invalid-len.js in the splice tests in test262.
This test timed out instead of throwing an "Invalid array length"
exception.
2021-06-10 10:04:06 +01:00
Linus Groh
83be39c91a LibJS: Handle Proxy with Array target in IsArray() abstract operation
This was missing from Value::is_array(), which is equivalent to the
spec's IsArray() abstract operation - it treats a Proxy value with an
Array target object as being an Array.
It can throw, so needs both the global object and an exception check
now.
2021-06-08 23:53:13 +02:00
Linus Groh
346560d7c8 LibJS/Tests: Use hasOwnProperty() for duplicate test check
The current way of doing this would also traverse the prototype chain,
and therefore yield false positive results for keys like "toString".
2021-05-05 15:58:53 +01:00
Andreas Kling
3d4afe7614 Everywhere: "indexes" => "indices"
I've wasted a silly amount of time in the past fretting over which
of these words to use. Let's just choose one and use it everywhere. :^)
2021-04-29 22:23:52 +02:00