Daniel Bertalan
12dc2c2079
LibJS: Fix wraparound UB in Value::to_u{8,16}
...
If we call these two functions on a negative value, undefined behavior
occurs due to casting a negative double to an unsigned integer. These
functions are defined to perform modular arithmetic, so negative values
can be fixed up by adding 2^8/2^16.
The reason why this step is not mentioned in ECMA-262 is that it defines
modular arithmetic so that `x mod m` had the same sign as `m`, while
LibM's `fmod(x, m)` copies `x`'s sign.
This issue was found by UBSAN with the Clang toolchain.
2021-08-08 10:55:36 +02:00
Daniel Bertalan
0a05f04d1b
LibJS: Fix UB in Number.IsSafeInteger
...
Casting a floating point number to an integer and comparing that against
the original value is not a good way to test if it is a whole number. It
may cause unnecessary narrowing conversion issues and UB. This was the
case, which was caught be Clang's `-fsanitize=float-cast-overflow`.
This commit changes the code to use `is_integral_number`, as suggested
in ECMA-262.
2021-08-08 10:55:36 +02:00
Daniel Bertalan
fd76e71934
LibJS: Fix UB in Math.clz32
...
If the argument to this function is greater then or equal to 2^32, the
`double` => `u32` cast produces undefined behavior, which Clang catches.
To fix this, we now use `ToUint32` for getting the integer argument, as
specified by ECMA-262.
2021-08-08 10:55:36 +02:00
Linus Groh
6852ba4d34
LibJS: Implement Temporal.Instant.prototype.subtract()
2021-08-07 13:10:35 +01:00
Linus Groh
b38f1fb071
LibJS: Implement Temporal.Instant.prototype.add()
2021-08-07 13:10:35 +01:00
Linus Groh
8ffad70504
LibJS: Add missing spec link to Temporal.Instant.prototype.round()
2021-08-07 13:10:35 +01:00
Linus Groh
6762378f89
LibJS/Tests: Add length test for Temporal.Instant.prototype.round()
2021-08-07 12:10:34 +01:00
Linus Groh
cdb0c879d3
LibJS/Tests: Add length test for Temporal.Instant.prototype.equals()
2021-08-07 12:10:34 +01:00
Linus Groh
a8ba2f4b21
LibJS/Tests: Fix bad copy and paste that crept into a lot of tests
...
The top-level function should have been `describe()``, but instead it's
been nested `test()`s.
2021-08-07 12:10:34 +01:00
sin-ack
ab39a94fdf
LibJS: Cast length to signed integer before subtraction
...
length is size_t as returned, and so subtracting from it may cause
underflow. We handle this case by just casting it to a signed value, and
the for loop predicate takes care of the rest.
2021-08-07 11:32:16 +02:00
Linus Groh
f12152f77e
LibJS: Reflect an editorial change in the Temporal spec
...
See: fb9b550
2021-08-07 01:21:39 +01:00
Linus Groh
5d536c7fbc
LibJS: Reflect infallibility editorial changes in the Temporal spec
...
See: de918c9
2021-08-07 01:15:45 +01:00
davidot
5cd2e0f3a2
LibJS: Improve the TypedArray.prototype.find{,Index} tests
...
Before this we did not check that it actually gave the first result.
2021-08-06 16:17:25 +01:00
davidot
871a29884d
LibJS: Implement proposed TypedArray.prototype.findLast{,Index}
...
Proposal: https://tc39.es/proposal-array-find-from-last/
2021-08-06 16:17:25 +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
Linus Groh
b7b23d05d5
LibJS: Implement Temporal.ZonedDateTime.prototype.getISOFields()
2021-08-05 23:15:27 +01:00
Linus Groh
82ab5da4db
LibJS: Implement Temporal.ZonedDateTime.prototype.toPlainDateTime()
2021-08-05 23:15:27 +01:00
Linus Groh
6ce631b023
LibJS: Implement Temporal.ZonedDateTime.prototype.toPlainTime()
2021-08-05 23:15:27 +01:00
Linus Groh
b4ea4e86a7
LibJS: Implement Temporal.ZonedDateTime.prototype.toPlainDate()
2021-08-05 23:15:27 +01:00
Linus Groh
96a0c201d5
LibJS: Implement Temporal.ZonedDateTime.prototype.toInstant()
2021-08-05 23:15:27 +01:00
Linus Groh
20300bd7c4
LibJS: Implement Temporal.ZonedDateTime.prototype.valueOf()
2021-08-05 23:15:27 +01:00
Linus Groh
6c345c8107
LibJS: Implement Temporal.ZonedDateTime.prototype.offset
2021-08-05 19:19:40 +02:00
Linus Groh
f937e9b966
LibJS: Implement Temporal.ZonedDateTime.prototype.offsetNanoseconds
2021-08-05 19:19:40 +02:00
Linus Groh
dd36593c72
LibJS: Implement Temporal.ZonedDateTime.prototype.inLeapYear
2021-08-05 19:19:40 +02:00
Linus Groh
5a7db1b5f4
LibJS: Implement Temporal.ZonedDateTime.prototype.monthsInYear
2021-08-05 19:19:40 +02:00
Linus Groh
204ba01416
LibJS: Implement Temporal.ZonedDateTime.prototype.daysInYear
2021-08-05 19:19:40 +02:00
Linus Groh
6007fc4804
LibJS: Implement Temporal.ZonedDateTime.prototype.daysInMonth
2021-08-05 19:19:40 +02:00
Linus Groh
d89d55a7a3
LibJS: Implement Temporal.ZonedDateTime.prototype.daysInWeek
2021-08-05 19:19:40 +02:00
Linus Groh
540fdbcf5b
LibJS: Implement Temporal.ZonedDateTime.prototype.weekOfYear
2021-08-05 19:19:40 +02:00
Linus Groh
d20a4fe43e
LibJS: Implement Temporal.ZonedDateTime.prototype.dayOfYear
2021-08-05 19:19:40 +02:00
Linus Groh
39e67a5823
LibJS: Implement Temporal.ZonedDateTime.prototype.dayOfWeek
2021-08-05 19:19:40 +02:00
Linus Groh
f86bbb7a71
LibJS: Implement Temporal.ZonedDateTime.prototype.epochNanoseconds
2021-08-05 19:19:40 +02:00
Linus Groh
62294d62c5
LibJS: Implement Temporal.ZonedDateTime.prototype.epochMicroseconds
2021-08-05 19:19:40 +02:00
Linus Groh
a9162b7e98
LibJS: Implement Temporal.ZonedDateTime.prototype.epochMilliseconds
2021-08-05 19:19:40 +02:00
Linus Groh
47135af987
LibJS: Implement Temporal.ZonedDateTime.prototype.epochSeconds
2021-08-05 19:19:40 +02:00
Linus Groh
a1082412ef
LibJS: Implement Temporal.ZonedDateTime.prototype.nanosecond
2021-08-05 19:19:40 +02:00
Linus Groh
4b22d0f2ce
LibJS: Implement Temporal.ZonedDateTime.prototype.microsecond
2021-08-05 19:19:40 +02:00
Linus Groh
752b3eb0c0
LibJS: Implement Temporal.ZonedDateTime.prototype.millisecond
2021-08-05 19:19:40 +02:00
Linus Groh
9d9ab492df
LibJS: Implement Temporal.ZonedDateTime.prototype.second
2021-08-05 19:19:40 +02:00
Linus Groh
a6775517ad
LibJS: Implement Temporal.ZonedDateTime.prototype.minute
2021-08-05 19:19:40 +02:00
Linus Groh
32f1e17e71
LibJS: Implement Temporal.ZonedDateTime.prototype.hour
2021-08-05 19:19:40 +02:00
Linus Groh
0580f102e4
LibJS: Implement Temporal.ZonedDateTime.prototype.day
2021-08-05 19:19:40 +02:00
Linus Groh
30e27f6483
LibJS: Implement Temporal.ZonedDateTime.prototype.monthCode
2021-08-05 19:19:40 +02:00
Linus Groh
fd18dc782f
LibJS: Implement Temporal.ZonedDateTime.prototype.month
2021-08-05 19:19:40 +02:00
Linus Groh
b8ac31500c
LibJS: Implement Temporal.ZonedDateTime.prototype.year
2021-08-05 19:19:40 +02:00
Linus Groh
e036f4a786
LibJS: Make regulate_iso_date() and iso_date_from_fields() use ISODate
...
No need for TemporalDate, we don't use the calendar field here anyway.
2021-08-05 19:19:40 +02:00
Timothy Flynn
70080feab2
AK+LibJS: Implement String.from{CharCode,CodePoint} using UTF-16 strings
...
Most of String.prototype and RegExp.prototype is implemented with UTF-16
so this is to prevent extra copying of the string data.
2021-08-04 11:18:24 +02:00
Timothy Flynn
b6ff7f4fcc
LibJS: Allow PrimitiveString to be created with a UTF-16 string
...
PrimitiveString may currently only be created with a UTF-8 string, and
it transcodes on the fly when a UTF-16 string is needed. Allow creating
a PrimitiveString from a UTF-16 string to avoid unnecessary transcoding
when the caller only wants UTF-16.
2021-08-04 11:18:24 +02:00
Timothy Flynn
4c2cc419f9
LibJS: Decode UTF-16 surrogate pairs during string literal construction
...
Rather than deferring this decoding to PrimitiveString, we can decode
surrogate pairs when parsing the string. This prevents a string copy
when constructing the PrimitiveString.
2021-08-04 11:18:24 +02:00
Lenny Maiorani
97bd13264a
Everywhere: Make use of container version of all_of
...
Problem:
- New `all_of` implementation takes the entire container so the user
does not need to pass explicit begin/end iterators. This is unused
except is in tests.
Solution:
- Make use of the new and more user-friendly version where possible.
2021-08-03 10:46:43 +02:00