Linus Groh
7f8dc395c1
LibJS: Implement Temporal.ZonedDateTime.prototype.with()
2021-11-13 00:25:40 +00:00
Linus Groh
0d9defdad8
LibJS: Rename MatchBehavior members back to their old names
...
I changed this in 6ef1a27
to "match the spec", but the spec calls it
`match exactly` and `match minutes` - so what we had before was correct
and the change made no sense whatsoever.
2021-11-13 00:25:40 +00:00
Linus Groh
a53542e0a3
LibJS: Clear exception after running each queued Promise job
...
It's not what the spec tells us to do. In fact, the spec tells us the
exact opposite:
9.5 Jobs and Host Operations to Enqueue Jobs
https://tc39.es/ecma262/#sec-jobs
A Job is an Abstract Closure with no parameters that initiates an
ECMAScript computation when no other ECMAScript computation is
currently in progress.
...
Their implementations must conform to the following requirements:
- ...
- The Abstract Closure must return a normal completion, implementing
its own handling of errors.
However, this turned out to not be true in all cases. More specifically,
the NewPromiseReactionJob AO returns the completion result of calling a
user-provided function (PromiseCapability's [[Resolve]] / [[Reject]]),
which may be an abrupt completion:
27.2.2.1 NewPromiseReactionJob ( reaction, argument )
https://tc39.es/ecma262/#sec-newpromisereactionjob
1. Let job be a new Job Abstract Closure with no parameters that
captures reaction and argument and performs the following steps
when called:
...
h. If handlerResult is an abrupt completion, then
i. Let status be Call(promiseCapability.[[Reject]],
undefined, « handlerResult.[[Value]] »).
i. Else,
i. Let status be Call(promiseCapability.[[Resolve]],
undefined, « handlerResult.[[Value]] »).
j. Return Completion(status).
Interestingly, this case is explicitly handled in the HTML spec's
implementation of jobs as microtasks:
8.1.5.3.3 HostEnqueuePromiseJob(job, realm)
https://html.spec.whatwg.org/webappapis.html#hostenqueuepromisejob
2. Queue a microtask on the surrounding agent's event loop to
perform the following steps:
...
5. If result is an abrupt completion, then report the exception
given by result.[[Value]].
This is precisely what all the major engines do - but not only in
browsers; the provided code snippet in the test added in this commit
works just fine in Node.js, for example.
SpiderMonkey:
https://searchfox.org/mozilla-central/rev/25997ce8267ec9e3ea4b727e0973bd9ef02bba79/js/src/builtin/Promise.cpp#6292
https://searchfox.org/mozilla-central/rev/25997ce8267ec9e3ea4b727e0973bd9ef02bba79/js/src/builtin/Promise.cpp#1277
https://searchfox.org/mozilla-central/rev/25997ce8267ec9e3ea4b727e0973bd9ef02bba79/js/src/vm/JSContext.cpp#845
JavaScriptCore:
https://trac.webkit.org/browser/webkit/trunk/Source/JavaScriptCore/builtins/PromiseOperations.js?rev=273718#L562
https://trac.webkit.org/browser/webkit/trunk/Source/JavaScriptCore/runtime/JSMicrotask.cpp?rev=273718#L94
V8:
https://source.chromium.org/chromium/chromium/src/+/main:v8/src/builtins/promise-abstract-operations.tq;l=481;drc=a760f03a6e99bf4863d8d21c5f7896a74a0a39ea
https://source.chromium.org/chromium/chromium/src/+/main:v8/src/builtins/builtins-microtask-queue-gen.cc;l=331;drc=65c9257f1777731d6d0669598f6fe6fe65fa61d3
This should probably be fixed in the ECMAScript spec to relax the rule
that Jobs may not return an abrupt completion, just like in the HTML
spec. The important bit is that those are not surfaced to user code in
any way.
2021-11-12 15:35:03 +02:00
Ali Mohammad Pur
070d2eaa51
LibJS+LibTest+js: Convert BC::Interpreter::run to ThrowCompletionOr<>
...
Note that this is just a shallow API change.
2021-11-12 13:01:59 +00:00
Ali Mohammad Pur
3b0bf05fa5
LibJS: Implement async functions as generator functions in BC mode
...
This applies a simple transformation, and adds a simple wrapper that
translates the generator interface to the async function interface.
2021-11-12 13:01:59 +00:00
Ali Mohammad Pur
c604e95993
LibJS: Run the queued promise reaction jobs on bytecode interpreter exit
...
This is the same as what the AST interpreter does.
2021-11-12 13:01:59 +00:00
Ali Mohammad Pur
e4a7f1a696
LibJS: Make Bytecode::Interpreter return the popped frame
...
And use it to _correctly_ implement state saving for generators.
Prior to this, we were capturing the caller frame, which is completely
irrelevant to the generator frame.
2021-11-12 13:01:59 +00:00
Ali Mohammad Pur
b96118b5d1
LibJS: Fix codegen for nodes after try statements without 'finally'
...
Previously we were just dropping them on the ground :P
2021-11-12 13:01:59 +00:00
Ali Mohammad Pur
5a38f86f1b
LibJS: Use a 'Return' completion for generator object body evaluation
...
The comment a few lines above explains the issue, this one was forgotten
and caused generator functions to return `undefined` when called.
2021-11-12 13:01:59 +00:00
Ali Mohammad Pur
3ec0183b51
LibJS: Use the correct prototype for generator functions
2021-11-12 13:01:59 +00:00
Luke Wilde
f65d25682c
LibJS: Implement Temporal.ZonedDateTime.prototype.subtract
2021-11-12 09:24:36 +00:00
Luke Wilde
9b8524b463
LibJS: Implement Temporal.ZonedDateTime.prototype.add
2021-11-12 09:24:36 +00:00
Timothy Flynn
89523f70cf
LibJS: Begin implementing Intl.NumberFormat.prototype.format
...
There is quite a lot to be done here so this is just a first pass at
number formatting. Decimal and percent formatting are mostly working,
but only for standard and compact notation (engineering and scientific
notation are not implemented here). Currency formatting is parsed, but
there is more work to be done to handle e.g. using symbols instead of
currency codes ("$" instead of "USD"), and putting spaces around the
currency symbol ("USD 2.00" instead of "USD2.00").
2021-11-12 09:17:08 +00:00
Timothy Flynn
0469006263
LibJS: Change Intl's PatternPartition record to hold a String value
...
It was previously holding a StringView, which was either a view into a
LibUnicode-generated string or a string passed from the user.
Intl.NumberFormat will need this record to hold internally-created
strings, so a StringView will not suffice (the way the steps are laid
out, that view will ultimately end up dangling).
This shouldn't be too wasteful since the StringView it was holding was
converted to a String eventually anyways.
2021-11-12 09:17:08 +00:00
Luke Wilde
5e3fe52fc4
LibJS: Implement Temporal.Duration.compare
2021-11-11 21:06:54 +00:00
Luke Wilde
29072f4b09
LibJS: Implement the required AOs for Temporal.Duration.compare
2021-11-11 21:06:54 +00:00
Ali Mohammad Pur
bf59d9e824
Userland: Include Vector.h in a few places to make HeaderCheck happy
...
This header was being transitively pulled in, but that no longer happens
after 5f7d008791
.
2021-11-11 20:36:36 +01:00
Andreas Kling
8b1108e485
Everywhere: Pass AK::StringView by value
2021-11-11 01:27:46 +01:00
Linus Groh
4eaa95769d
LibJS: Add missing (void) to handle [[nodiscard]] TRY() result
2021-11-11 00:03:07 +00:00
Linus Groh
fdffdc43fa
LibJS: Implement the rest of to_temporal_month_day()
...
Always throws at the moment, because parse_temporal_month_day_string()
is basically a stub, and parse_iso_date_time() isn't functional either.
The spec issue has been resolved though, so I figured we might as well
get one small step further :^)
2021-11-10 22:28:27 +00:00
Linus Groh
6ef1a2793f
LibJS: Rename ZonedDateTime's MatchBehavior enum members to match spec
2021-11-10 21:27:25 +00:00
Andreas Kling
cd49f30bea
AK+LibJS: Simplify MUST() and move it from LibJS to AK/Try.h
...
This is generally useful so let's move it to AK. Also it seems that we
don't need the temporary variable hack anymore, so let's lose that.
2021-11-10 21:58:58 +01:00
Andreas Kling
5f7d008791
AK+Everywhere: Stop including Vector.h from StringView.h
...
Preparation for using Error.h from Vector.h. This required moving some
things out of line.
2021-11-10 21:58:58 +01:00
Idan Horowitz
a445deb205
LibJS: Remove left-over debug assertion from the Await AO
2021-11-10 18:11:26 +00:00
Idan Horowitz
d5f637fa21
LibJS: Do not parse async methods with a new line after the "async"
...
This was already checked in normal function expressions, but was
missing for Object Expressions.
2021-11-10 18:11:26 +00:00
Luke Wilde
5594a492f0
LibJS: Implement Temporal.ZonedDateTime.prototype.toJSON
2021-11-10 12:56:56 +00:00
Luke Wilde
6856b6168a
LibJS: Implement Temporal.ZonedDateTime.prototype.toLocaleString
2021-11-10 12:56:56 +00:00
Luke Wilde
a9ad993e78
LibJS: Implement Temporal.ZonedDateTime.prototype.toString
2021-11-10 12:56:56 +00:00
Luke Wilde
dc72d416b2
LibJS: Implement the required AOs for ZonedDateTime stringifiers
2021-11-10 12:56:56 +00:00
Idan Horowitz
04253c3254
LibJS: Add tests for async functions and await expressions
2021-11-10 08:48:27 +00:00
Idan Horowitz
46dabf02ec
LibJS: Add support for await expressions
2021-11-10 08:48:27 +00:00
Idan Horowitz
681787de76
LibJS: Add support for async functions
...
This commit adds support for the most bare bones version of async
functions, support for async generator functions, async arrow functions
and await expressions are TODO.
2021-11-10 08:48:27 +00:00
Luke Wilde
05c3320da3
LibJS: Mark RoundTemporalInstant as infallible
...
This is an editorial change in the Temporal spec.
See: 0b4141c
This also allows us to get rid of two old exception checks.
2021-11-09 23:42:34 +02:00
Linus Groh
e9f66d1c2a
LibJS: Mark DaysUntil as infallible
...
This is an editorial change in the Temporal spec.
See: 30a8939
2021-11-09 20:37:17 +00:00
Idan Horowitz
91881be4b0
LibJS: Convert GeneratorObject to ThrowCompletionOr
2021-11-09 20:32:51 +02:00
Idan Horowitz
11a90700df
LibJS: Convert the IntegerIndexedElementSet AO to ThrowCompletionOr
2021-11-09 20:32:51 +02:00
Idan Horowitz
ba55d77665
LibJS: Remove leftover exception check in OrdinaryHasProperty
2021-11-09 20:32:51 +02:00
Linus Groh
1e3e0477cb
LibJS: Implement Temporal.PlainMonthDay.prototype.with()
2021-11-08 22:19:45 +00:00
Linus Groh
fa1d5feec0
LibJS: Implement Temporal.PlainYearMonth.prototype.with()
2021-11-08 22:19:45 +00:00
Linus Groh
aca2ef9e1c
LibJS: Implement Temporal.PlainDateTime.prototype.with()
2021-11-08 22:19:45 +00:00
Linus Groh
c3c9ac93d0
LibJS: Implement Temporal.PlainDate.prototype.with()
...
With one caveat: in the PreparePartialTemporalFields AO I made a change
to fix a spec issue that would require the input object to always have a
month or monthCode property.
This is tracked in https://github.com/tc39/proposal-temporal/issues/1910
and may get accepted as-is, in which case we simply need to remove the
NOTE comment.
2021-11-08 22:19:45 +00:00
Linus Groh
310016aee4
LibJS/Tests: Fix Temporal.PlainDate.prototype.equals() tests
...
Just calling "expect()" doesn't do anything!
2021-11-08 19:12:54 +00:00
Linus Groh
46d7c34028
LibJS: Use StringView literals in prepare_temporal_fields()
2021-11-08 19:12:47 +00:00
Timothy Flynn
2530b6adf0
LibJS: Create the RegExpExec result's "input" field last
...
We move the input string into this field to avoid a string copy, so we
must do this step last to avoid using any views into it (note that
match.view here is a view into this string).
2021-11-08 01:36:29 +01:00
Linus Groh
a3b8303f3c
LibJS: Fix modulo() template argument deduction on i686
...
Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp:283:24:
note: deduced conflicting types for parameter 'T' ('long long int'
and 'long int')
283 | nanosecond = modulo(nanosecond, 1000l);
| ~~~~~~^~~~~~~~~~~~~~~~~~~
Worked fine on x86_84 :yakshrug:
2021-11-07 21:33:56 +00:00
Linus Groh
b3ea7332b2
LibJS: Fix use of "modulo" for negative values in balance_time()
2021-11-07 21:11:31 +00:00
Linus Groh
3d84fb64c3
LibJS: Add a modulo() function to represent the "x modulo y" notation
...
This *not* being the same as C++ "%" in all cases is a massive footgun,
and hopefully one I came across for the last time.
2021-11-07 21:11:31 +00:00
Linus Groh
e93ce1ff69
LibJS: Fix nanoseconds formatting in format_time_zone_offset_string()
...
Two issues:
- The format string said "{:9}", which left-pads with spaces and not
zeros as required
- Even when correcting that, we were not accounting for step 11 b:
"Set fraction to the longest possible substring of fraction starting
at position 0 and not ending with the code unit 0x0030 (DIGIT ZERO)."
We can safely use trim() for that as the formatted string is known to
not contain only zeros (which would leave the left-most in place).
Also adds tests for "UTC" and various numeric offsets.
2021-11-07 20:06:28 +00:00
Linus Groh
68d80d239b
LibJS: Fix fraction substring in parse_time_zone_offset_string()
...
We're supposed to get the substring from `fraction`, which is guaranteed
to have the required length. `fraction_part` is the user-supplied value
and trying to get a substring view from 0-9 might crash.
2021-11-07 20:01:31 +00:00
Linus Groh
df2ccb3d38
LibJS: Implement Temporal.Duration.prototype.toLocaleString()
2021-11-07 15:31:28 +01:00