Commit Graph

2413 Commits

Author SHA1 Message Date
Sam Atkins
d702678d16 LibJS+WebContent+Browser+js: Implement console.group() methods
This implements:
- console.group()
- console.groupCollapsed()
- console.groupEnd()

In the Browser, we use `<details>` for the groups, which is not actually
implemented yet, so groups are always open.

In the REPL, groups are non-interactive, but still indent any output.
This looks weird since the console prompt and return values remain on
the far left, but this matches what Node does so it's probably fine. :^)
I expect `console.group()` is not used much outside of browsers.
2021-12-27 21:44:07 +01:00
Sam Atkins
ff5e07d718 LibJS+WebContent+js: Bring console.trace() to spec
The spec very kindly defines `Printer` as accepting
"Implementation-specific representations of printable things such as a
stack trace or group." for the `args`. We make use of that here by
passing the `Trace` itself to `Printer`, instead of having to produce a
representation of the stack trace in advance and then pass that to
`Printer`. That both avoids the hassle of tracking whether the data has
been html-encoded or not, and means clients don't have to implement the
whole `trace()` algorithm, but only the code needed to output the trace.
2021-12-27 21:44:07 +01:00
Sam Atkins
ce694490f3 LibJS+WebContent+js: Bring console.assert() to spec 2021-12-27 21:44:07 +01:00
Sam Atkins
9b78e287b0 LibJS+WebContent+js: Bring console.clear() to spec
This is identical to before, since we don't have "group stacks" yet, but
clear() now uses ThrowCompletionOr.
2021-12-27 21:44:07 +01:00
Sam Atkins
834ced82d4 LibJS+WebContent+js: Bring console.count[Reset]() to spec
The `CountReset` log level is displayed as a warning, since the message
is always to warn that the counter doesn't exist. This is also in line
with the table at https://console.spec.whatwg.org/#loglevel-severity
2021-12-27 21:44:07 +01:00
Sam Atkins
260836135a LibJS+WebContent+js: Reimplement console.log() and friends to spec
This implements the Logger and Printer abstract operations defined in
the console spec, and stubs out the Formatter AO. These are then used
for the "output a categorized log message" functions.
2021-12-27 21:44:07 +01:00
Linus Groh
5ec39ca363 LibJS: Add spec comments to Number.prototype functions 2021-12-26 21:02:00 +01:00
Luke Wilde
2d26a50d28 LibJS: Fix toFixed throwing on undefined, null and NaN fractionDigits
It was checking the original fractionDigits argument was a finite
number instead of the coerced fraction_digits.
2021-12-26 20:37:44 +01:00
Linus Groh
3ab1c52e2b LibJS: Require 'T' prefix for ambiguous time-only strings
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/514ede3
2021-12-24 00:07:52 +01:00
Timothy Flynn
9ce4ff4265 LibJS: Avoid crashing when the Unicode data generators are disabled
The general idea when ENABLE_UNICODE_DATABASE_DOWNLOAD is OFF has been
that the Intl APIs will provide obviously incorrect results, but should
not crash. This regressed a bit with NumberFormat and DateTimeFormat.
2021-12-22 17:30:43 +01:00
Linus Groh
c56e5139f5 LibJS: Fix modulo in get_iso_parts_from_epoch() for negative epoch ns
This now matches the spec change from reminder() to modulo which was
done here: https://github.com/tc39/proposal-temporal/commit/bdf60f5
2021-12-22 11:27:31 +01:00
Linus Groh
61410e05eb LibJS: Add modulo(x, y) overload for Crypto::{Unsigned,Signed}BigInteger
Just like with integral and floating numbers, doing it manually is
error-prone: when we get a negative remainder, y has to be added to the
result to match the spec's modulo.
Solve this by just adding another (templated) overload to also permit
using the function for LibCrypto BigInts.
2021-12-22 11:27:31 +01:00
Linus Groh
9c209b8079 LibJS: Support modulo(x, y) with different types
It's a bit annoying having to add '.0' to y given that it's an integral
number in most cases.
This turns the single template parameter T into T and U to permit that.
2021-12-22 11:27:31 +01:00
Nick Johnson
08e4a1a4dc AK+Everywhere: Replace __builtin bit functions
In order to reduce our reliance on __builtin_{ffs, clz, ctz, popcount},
this commit removes all calls to these functions and replaces them with
the equivalent functions in AK/BuiltinWrappers.h.
2021-12-21 22:13:51 +01:00
Luke Wilde
6d5531112f LibJS: Add TypedArray.prototype.@@iterator 2021-12-21 15:40:41 +01:00
Timothy Flynn
4fe47ed86e LibJS: Update spec link for InstallErrorCause AO 2021-12-21 14:56:28 +01:00
Timothy Flynn
d69f5ca128 LibJS: Update spec numbers for Operations on Objects AOs
The error cause proposal was merged, so some spec numbers were bumped.
2021-12-21 14:56:28 +01:00
Timothy Flynn
968f6e2432 LibJS: Define RegExp.prototype methods in spec order 2021-12-21 14:56:00 +01:00
Timothy Flynn
7ea85ed10b LibJS: Add spec comments to RegExp.prototype AOs
This also replaces an instance of TRY with MUST as the spec indicates
that step 35b of RegExpBuiltinExec cannot throw. Further, this moves
some lines of code around to align with the spec as best as we can,
though the end effect is the same.
2021-12-21 14:56:00 +01:00
Timothy Flynn
179ca9d058 LibJS: Add spec comments to RegExp.prototype.[flags, source, exec, test] 2021-12-21 14:56:00 +01:00
Timothy Flynn
4a915fc9fa LibJS: Add spec comments to RegExp.prototype.compile 2021-12-21 14:56:00 +01:00
Timothy Flynn
c6e2b03073 LibJS: Add spec comments to RegExp.prototype [ @@split ]
In doing so, this caught another erroneous ToObject invocation.
2021-12-21 14:56:00 +01:00
Timothy Flynn
cb901f70af LibJS: Add spec comments to RegExp.prototype [ @@search ] 2021-12-21 14:56:00 +01:00
Timothy Flynn
25b6e79238 LibJS: Add spec comments to RegExp.prototype [ @@replace ]
In doing so, this caught an erroneous ToObject invocation. In the one
spot that requires the value to be an object (the invocation to
LengthOfArrayLike), we know by then the value is an object because all
other possibilities have been handled.
2021-12-21 14:56:00 +01:00
Timothy Flynn
9f7c3e6cad LibJS: Add spec comments to RegExp.prototype [ @@matchAll ] 2021-12-21 14:56:00 +01:00
Timothy Flynn
5eb4d2e96e LibJS: Add spec comments to RegExp.prototype [ @@match ]
In doing so, this fixes a few minor issues:

1. We were accessing the "unicode" and "lastIndex" properties out of
   order. This is somewhat frequently tested by test262, but not in
   this case.

2. We were doing a Value::to_object() followed by Object::get(), rather
   than just Value::get() as the spec dictates.

3. We were TRYing a step (CreateDataPropertyOrThrow) that should never
   fail, and should have been a MUST.
2021-12-21 14:56:00 +01:00
Timothy Flynn
26294a2d27 LibJS: Convert a RegExp throw_exception to throw_completion
RegExpExec already returns a ThrowCompletionOr so this potentional error
should be a completion. RegExp.prototype [ @@replace ] is tripped up by
this mistake when implemented closer to the spec.
2021-12-21 14:56:00 +01:00
davidot
be3b806487 LibJS: Parse assert clauses of in- and export statements
Based on proposal: https://tc39.es/proposal-import-assertions
Since imports are not supported yet this is not functional.
2021-12-21 14:04:23 +01:00
davidot
81312986fe LibJS: Disallow async generator functions called 'await' or 'yield' 2021-12-21 14:04:23 +01:00
davidot
c8e80690a7 LibJS: Don't treat yield after void as identifier in generator functions 2021-12-21 14:04:23 +01:00
davidot
a1308bfc60 LibJS: Make new lines in block comments reset line has token
Before this a closing html comment would not be treated as a comment if
directly following a block comment which was not the first token of its
first line.
2021-12-21 14:04:23 +01:00
davidot
45578f58dc LibJS: Allow super property lookup and new.target in static init blocks 2021-12-21 14:04:23 +01:00
Linus Groh
9271005357 LibJS: Fix typo in spec comment 2021-12-19 09:35:02 +00:00
Linus Groh
f7fe7f8c77 LibJS: Capture TimeFraction parse result instead of Fraction
Not much of a difference as TimeFraction just parses Fraction, but let's
do it correctly. Small mistake I did in 4b7f716.

Thanks to YouTube user gla3dr for noticing this :^)
2021-12-19 09:29:46 +00:00
Luke Wilde
cf5f08b317 LibJS: Only allow TimeZone this value in TimeZone#getPlainDateTimeFor
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/2644fc6
2021-12-19 00:13:01 +00:00
Luke Wilde
7729598b5b LibJS: Only allow TimeZone this value in Temporal.TimeZone#toJSON
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/2644fc6
2021-12-19 00:13:01 +00:00
Luke Wilde
6c8c34ed6c LibJS: Only allow TimeZone this value in Temporal.TimeZone#id
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/2644fc6
2021-12-19 00:13:01 +00:00
Luke Wilde
803e96f0c5 LibJS: Only allow Calendar this value in Temporal.Calendar#toJSON
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/2644fc6
2021-12-19 00:13:01 +00:00
Linus Groh
5277646f46 LibJS: Fix 'precision != "auto"' check in temporal_duration_to_string()
If the Variant does *not* have a StringView, it *also* is not "auto".

Thanks to YouTube user JWeis for noticing this :^)
2021-12-18 23:20:00 +00:00
Linus Groh
01eefc344a LibJS: Disallow date-only strings for PlainTime
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/b16a296
2021-12-18 22:32:39 +00:00
Linus Groh
6da6da73cc LibJS: Allow 'T' prefix in time-only strings
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/f5e8edf
2021-12-18 22:32:39 +00:00
Linus Groh
acce65b52c LibJS: Fix fractionalSecondDigits behavior in Duration.proto.toString()
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/3ee771e
2021-12-18 22:32:39 +00:00
Linus Groh
6d5e95d621 LibJS: Add optional calendar to Plain{Time,YearMonth,MonthDay} prod
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/7e58ba3
2021-12-18 22:32:39 +00:00
Linus Groh
b70a55bd5a LibJS: Update spec comment in get_iso_parts_from_epoch()
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/bdf60f5
2021-12-18 22:32:39 +00:00
Linus Groh
4b7f716f21 LibJS: Fix ambiguity in FractionalPart grammar
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/0f11bd6
2021-12-18 22:32:39 +00:00
Linus Groh
bbfbd02c1b LibJS: Make PlainDate difference methods units handling consistent
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/8b7ba00
2021-12-18 22:32:39 +00:00
Linus Groh
006bea5d31 LibJS: Remove outdated comment in prepare_partial_temporal_fields()
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/bf066ea
2021-12-18 22:32:39 +00:00
Linus Groh
69b8079b11 LibJS: Fix "smallestUnit" property name typo in a couple of places
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/900e4bc
2021-12-18 22:32:39 +00:00
Linus Groh
70e6eae27b LibJS: Fix off-by-one in balance_iso_date() for leap year inputs
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/5ab1822
2021-12-18 22:32:39 +00:00
Linus Groh
7270bbb255 LibJS: Remove outdated comment from parse_temporal_duration_string()
This is a normative change in the Temporal spec.

See:

- https://github.com/tc39/proposal-temporal/commit/e7182d3
- https://github.com/tc39/proposal-temporal/commit/6dae066
2021-12-18 22:32:39 +00:00