Commit graph

2972 commits

Author SHA1 Message Date
Linus Groh
e815d3f9ce LibJS: De-duplicate ClassFieldDefinition Records
This was defined twice, despite being the very same thing:
- ClassElement::ClassFieldDefinition
- ECMAScriptFunctionObject::InstanceField

Move the former to a new header and use it everywhere. Also update the
define_field() AO to take a single field instead of separate name and
initializer arguments.
2022-04-20 00:08:32 +02:00
Ali Mohammad Pur
e1cd36559d LibJS: Make the BC generator.next(value) work
This used to put the value in the previous frame's accumulator register,
which is only correct for the first invocation of the generator.
2022-04-18 23:59:30 +04:30
Ali Mohammad Pur
d5791c85b4 LibJS: Avoid copying the frame into the interpreter in BC generators 2022-04-18 23:59:30 +04:30
Linus Groh
472ff7a6d4 LibJS: Don't coerce this value in %IteratorPrototype%[@@iterator]
Another day, another mistake that's been there for a long time but
would've been immediately obvious when adding spec comments. :^)
2022-04-18 00:24:02 +02:00
Linus Groh
ee1379520a LibJS: Add missing whitespace around namespace curly braces 2022-04-17 23:00:35 +02:00
Timothy Flynn
6654efcd82 LibJS: Remove cloneConstructor parameter from CloneArrayBuffer
This is a normative change in the ECMA-262 spec. See:
https://github.com/tc39/ecma262/commit/e7979fd

Note that this implements a FIXME in InitializeTypedArrayFromTypedArray,
now that shared array buffers are no longer a concern there. We already
have test coverage for the now-handled case.
2022-04-16 16:49:52 +01:00
Timothy Flynn
39b308ba52 LibJS: Factor out TypedArrayElement{Size,Type} abstract operations
This is an editorial change in the ECMA-262 spec. See:
https://github.com/tc39/ecma262/commit/a90670d5

This also adds missing spec comments to the following prototypes which
were affected by this change:
    Atomics.load
    Atomics.store
    %TypedArray%.prototype.slice
    %TypedArray%.prototype.subarray
2022-04-16 16:49:52 +01:00
Timothy Flynn
0174993bea LibJS: Add explicit ErrorType values for TypedArray prototype exceptions 2022-04-16 16:49:52 +01:00
Timothy Flynn
c20e8cea19 LibJS: Define AllocateTypedArrayBuffer AO out of line
Not only is it easier to compare to the spec when defined out of line,
but this AO was implemented inside other AOs twice.
2022-04-16 16:49:52 +01:00
Timothy Flynn
c076b363ce LibJS: Define SetTypedArrayFrom{TypedArray,ArrayLike} AOs out of line
%TypedArray%.prototype.set was a bit hard to read / compare to the spec
with these AOs defined inside it.
2022-04-16 16:49:52 +01:00
Andreas Kling
343d699627 LibJS: Add missing Vector::in_reverse() in ensure_property_table()
Regressed with 35fcb028e9.
2022-04-13 21:02:37 +02:00
Andreas Kling
35fcb028e9 LibJS: Tidy up Shape::ensure_property_table() a little bit
- Use a vector or references for the transition chain since null shapes
  are not allowed in the chain.

- Use Vector::in_reverse() for iterating the chain backwards.
2022-04-13 19:52:25 +02:00
Timothy Flynn
4d0315099f LibJS: Allow TypeArray to become detached in TypedArray.prototype.set
This is a normative change in the ECMA-262 spec. See:
https://github.com/tc39/ecma262/commit/4d570c4
2022-04-13 16:02:01 +02:00
Linus Groh
5397278bfc LibJS: Update spec comments to use ToZeroPaddedDecimalString AO
This is an editorial change in the ECMA-262 and Temporal specs.

See:
- https://github.com/tc39/ecma262/commit/843d8b8
- https://github.com/tc39/proposal-temporal/commit/f9211d9

Note that we don't actually need to implement the AO as we already have
String::formatted() for this, and use unified format strings instead of
zero-padding in individual steps in many cases anyway.
2022-04-12 23:43:29 +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
c32dcf7f75 LibJS: Update ZonedDateTime AO spec comments for structured headers
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/01714a5
2022-04-11 23:47:02 +01:00
Linus Groh
7e18d1c078 LibJS: Remove unused include from AbstractOperations.cpp 2022-04-11 21:34:57 +01:00
Linus Groh
24d772af7c LibJS: Move additional notes to spec comments onto their own line
Having all spec comments verbatim on their own line with no additions
made by us will make it easier to automate comparing said comments to
their current spec counterparts.
2022-04-11 21:32:37 +01:00
Luke Wilde
90f14de1e9 LibJS: Call HostEnsureCanCompileStrings in CreateDynamicFunction
I noticed we were missing this when I added to PerformEval :^)
2022-04-11 21:23:36 +01:00
Luke Wilde
7798821f5b LibJS: Add tests for the new steps added to PerformEval 2022-04-11 21:23:36 +01:00
Luke Wilde
34f902fb52 LibJS: Add missing steps and spec comments to PerformEval
While adding spec comments to PerformEval, I noticed we were missing
multiple steps.

Namely, these were:
- Checking if the host will allow us to compile the string
  (allowing LibWeb to perform CSP for eval)
- The parser's initial state depending on the environment around us
  on direct eval:
   - Allowing new.target via eval in functions
   - Allowing super calls and super properties via eval in classes
   - Disallowing the use of the arguments object in class field
     initializers at eval's parse time
- Setting ScriptOrModule of eval's execution context

The spec allows us to apply the additional parsing steps in any order.
The method I have gone with is passing in a struct to the parser's
constructor, which overrides the parser's initial state to (dis)allow
the things stated above from the get-go.
2022-04-11 21:23:36 +01:00
Linus Groh
b4c6fd51be LibJS: Use single page spec link for BoundFunctionCreate 2022-04-11 19:44:56 +01:00
Linus Groh
231acda7f8 LibJS: Fix two bogus spec links 2022-04-11 19:44:33 +01:00
Timothy Flynn
84a81dd466 LibJS: Do not throw a TypeError when sorting a detached TypedArray
This is a normative change in the ECMA-262 spec. See:
https://github.com/tc39/ecma262/commit/e0c74e1
2022-04-08 11:15:16 +01:00
Timothy Flynn
13d05403ff LibJS: Move DetachArrayBuffer implementation to the ArrayBuffer object
The spec notes that this AO is unused by ECMA-262, but is provided for
ECMAScript hosts. Move the definition to a common location to allow
test-js to also use it.
2022-04-08 11:15:16 +01:00
Linus Groh
e109b967a1 LibJS: Make options object const in more Temporal AOs 2022-04-08 00:43:17 +01:00
Linus Groh
2844a2c448 LibJS: Handle undefined options in MergeLargestUnitOption
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/5e161a2
2022-04-08 00:43:17 +01:00
Linus Groh
151eb8606d LibJS: Consistently call observable Temporal AOs with undefined options
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/6fa5b9d
2022-04-07 12:58:39 +01:00
Timothy Flynn
29b6c22384 LibJS: Reorder and reduce steps of InitializeDateTimeFormat
These are editorial changes in the Intl spec. See:
https://github.com/tc39/ecma402/commit/7d0326c
https://github.com/tc39/ecma402/commit/05a299b
https://github.com/tc39/ecma402/commit/8c24ea7
https://github.com/tc39/ecma402/commit/fd8dea9
2022-04-06 20:58:12 -04:00
Timothy Flynn
f3f3e3cdc3 LibJS: Remove outdated FIXME from String.prototype.localeCompare
This FIXME was addressed in 0975eba724.
2022-04-06 20:58:12 -04:00
Ali Mohammad Pur
4b5a9bab34 LibJS: Actually generate a lexical env for SwitchStatement in BC
We had code for this in ScopeNode, but that function was never called
for a SwitchStatement.
This fixes a bunch of scoping tests for switch.
2022-04-05 11:46:48 +02:00
Ali Mohammad Pur
0e1943937c LibJS: Use InitializeOrSet to initialize function declarations in BC
A function may be redefined, in which case the existing binding is
expected to be reused.
2022-04-05 11:46:48 +02:00
Ali Mohammad Pur
5407fe8fcf LibJS: Make Handle<Value>::is_null() also consider the contained value
Previously this would've said `make_handle(Value(1234))` is null, as it
did not contain a cell (but rather a plain Value), which made throwing
primitives spin forever in BC mode.
2022-04-05 11:46:48 +02:00
Linus Groh
421d9a6361 LibJS: Fix typo in a variable name in get_substitution() 2022-04-04 20:35:57 +01:00
Linus Groh
0057d489bd LibJS: Fix some clang-tidy warnings in Temporal
- Remove unused declarations of removed functions
- Remove unused includes
- Declare pointer values as `auto*`
2022-04-04 19:22:58 +01:00
Linus Groh
f0523aa098 LibJS: Use MUST() instead of TRY() for two infallible Temporal AOs
These were incorrectly used during the conversion from exception checks
to completions.
2022-04-04 19:04:07 +01:00
Linus Groh
5b48912d35 LibJS: Remove a bunch of gratuitous JS namespace qualifiers 2022-04-03 15:19:33 +01:00
Linus Groh
83e8dfae38 LibJS: Use AK::Time in system_utc_epoch_nanoseconds()
This also uses <time.h> APIs internally, but wraps them in a much nicer
interface.
2022-04-03 01:10:31 +01:00
Idan Horowitz
59080f441e LibJS: Normalize NaN values in Sets and Maps
This ensures that different NaN types (e.g. 0/0, 0 * Infinity, etc) are
mapped to the same Set/Map entry.
2022-04-02 14:15:43 +01:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Andreas Kling
7047a5ca59 LibJS: Allow JS::make_handle(T*) to be called with nullptr
Instead of asserting, just return an empty Handle.
2022-03-31 18:25:06 +02:00
Ali Mohammad Pur
7ea095feb0 LibJS: Don't assume that for-in/of target is a variable on LHS::Assign
e.g. `for ([foo.bar] in ...)` is actually a binding pattern.
2022-03-31 18:11:08 +02:00
Ali Mohammad Pur
56c0fdc1c4 LibJS: Implement codegen for MemberExpression binding patterns 2022-03-31 18:11:08 +02:00
Ali Mohammad Pur
007ffcd763 LibJS: Implement bytecode generation for all ObjectExpression properties 2022-03-31 18:11:08 +02:00
Linus Groh
8e175b4959 LibJS: Adjust ISO8601 representation for years between 1 BCE and 999 CE
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/39eeecd
2022-03-31 17:09:10 +01:00
Linus Groh
cfb04765fa LibJS: Correct PlainYearMonth arithmetic for non-ISO calendars
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/61e8dd0
2022-03-31 17:09:10 +01:00
Linus Groh
b020b8eea2 LibJS: Handle Etc/GMT timezones properly in TimeZone{IANA,Bracketed}Name
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/8c73780
2022-03-31 17:09:10 +01:00
Linus Groh
b5392f9e39 LibJS: Emit reference information for { calendarName: "always" } option
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/4f7519a
2022-03-31 17:09:10 +01:00
Linus Groh
29aa938fa5 LibJS: Fix Duration.compare() for dates with unusual number of hours
This is a normative change in the Temporal spec.

See:
- https://github.com/tc39/proposal-temporal/commit/08bcd53
- https://github.com/tc39/proposal-temporal/commit/e962797
2022-03-31 17:09:10 +01:00
Hendiadyoin1
c79e4961f6 LibJS: Add explicit default copy+move constructors to ThrowCompletionOr
This stops clangd from complaining about not being able to determine the
copy-constructibility of ThrowCompletionOr and Completion.
2022-03-31 09:25:17 -04:00