Commit graph

201 commits

Author SHA1 Message Date
Linus Groh
07f9ae908c LibJS: Add spec comments to bitwise_or() 2022-12-10 11:23:23 +00:00
Linus Groh
9d3d4a760f LibJS: Add spec comments to bitwise_and() 2022-12-10 11:23:23 +00:00
Linus Groh
3a8c704d19 LibJS: Add spec comments to less_than_equals() 2022-12-10 11:23:23 +00:00
Linus Groh
e53c8ae593 LibJS: Add spec comments to less_than() 2022-12-10 11:23:23 +00:00
Linus Groh
27ed1f6d5e LibJS: Add spec comments to greater_than_equals() 2022-12-10 11:23:23 +00:00
Linus Groh
444ba191af LibJS: Add spec comments to greater_than() 2022-12-10 11:23:23 +00:00
Linus Groh
058a247c61 LibJS: Add spec comments to Value::to_integer_or_infinity() 2022-12-10 11:23:23 +00:00
Linus Groh
72ee346f64 LibJS: Add spec comments to Value::to_index() 2022-12-10 11:23:23 +00:00
Linus Groh
d1b2ac41fd LibJS: Add spec comments to Value::to_length() 2022-12-10 11:23:23 +00:00
Linus Groh
34e372cbff LibJS: Add spec comments to Value::to_u8_clamp() 2022-12-10 11:23:23 +00:00
Linus Groh
fff5fe44c1 LibJS: Add spec comments to Value::to_u8() 2022-12-10 11:23:23 +00:00
Linus Groh
2a3f150ab8 LibJS: Add spec comments to Value::to_i8() 2022-12-10 11:23:23 +00:00
Linus Groh
42eac3b7d3 LibJS: Add spec comments to Value::to_u16() 2022-12-10 11:23:23 +00:00
Linus Groh
b8ae9ca206 LibJS: Add spec comments to Value::to_i16() 2022-12-10 11:23:23 +00:00
Linus Groh
1ef2b43e4c LibJS: Add spec comments to Value::to_u32() 2022-12-10 11:23:23 +00:00
Linus Groh
f958b19b19 LibJS: Add spec comments to Value::to_i32{,_slow_case}() 2022-12-10 11:23:23 +00:00
Linus Groh
c2d33ec48a LibJS: Add spec comments to Value::to_property_key() 2022-12-10 11:23:23 +00:00
Linus Groh
7abd9efe33 LibJS: Add spec comments to Value::to_bigint_uint64() 2022-12-10 11:23:23 +00:00
Linus Groh
fb5256b225 LibJS: Add spec comments to Value::to_bigint_int64() 2022-12-10 11:23:23 +00:00
Linus Groh
0d4b798932 LibJS: Add spec comments to Value::to_bigint() 2022-12-10 11:23:23 +00:00
Linus Groh
b97cdfc36c LibJS: Add spec comments to Value::to_number() 2022-12-10 11:23:23 +00:00
Linus Groh
9a406ccba6 LibJS: Add spec comments to Value::to_numeric() 2022-12-10 11:23:23 +00:00
Linus Groh
63f6099cc3 LibJS: Add spec comments to Value::to_object() 2022-12-10 11:23:23 +00:00
Linus Groh
9c10624278 LibJS: Add spec comments to Value::to_primitive() 2022-12-10 11:23:23 +00:00
Linus Groh
e3c8e1362f LibJS: Add spec comments to Value::to_boolean() 2022-12-10 11:23:23 +00:00
Linus Groh
596b30df5f LibJS: Add spec comments to Value::to_string() 2022-12-10 11:23:23 +00:00
Linus Groh
9a961af0b0 LibJS: Add spec comments to Value::typeof() 2022-12-10 11:23:23 +00:00
Linus Groh
1fe7984160 LibJS: Add spec comments to Value::is_regexp() 2022-12-10 11:23:23 +00:00
Linus Groh
b11135cbc2 LibJS: Add spec comments to Value::is_function() 2022-12-10 11:23:23 +00:00
Linus Groh
aaa4fe8c34 LibJS: Add spec comments to Value::is_array() 2022-12-10 11:23:23 +00:00
Linus Groh
4cdfe684b8 LibJS: Remove redundant starts_with()s from is_less_than() string branch
This is not in the spec and does pointless work:
- If either of them is true, we would determine the same result with the
  manual code point iteration and comparison
- If neither of them is true, we iterate from the start again and repeat
  the work that was just done

Instead, only have the manual loop from the spec and do a length
comparison at the end.

Removing it brings the following microbenchmark from ~5.5s down to ~3.5s
on my machine:

```js
const a = "x".repeat(100_000_000) + "a";
const b = "x".repeat(100_000_000) + "b";
a < b
```
2022-12-10 00:40:52 +00:00
Linus Groh
525f22d018 LibJS: Replace standalone js_string() with PrimitiveString::create()
Note that js_rope_string() has been folded into this, the old name was
misleading - it would not always create a rope string, only if both
sides are not empty strings. Use a three-argument create() overload
instead.
2022-12-07 16:43:06 +00:00
Linus Groh
5db38d7ba1 LibJS: Replace standalone js_bigint() with BigInt::create()
Three standalone Cell creation functions remain in the JS namespace:

- js_bigint()
- js_string()
- js_symbol()

All of them are leftovers from early iterations when LibJS still took
inspiration from JSC, which itself has jsString(). Nowadays, we pretty
much exclusively use static create() functions to construct types
allocated on the JS heap, and there's no reason to not do the same for
these.
Also change the return type from BigInt* to NonnullGCPtr<BigInt> while
we're here.

This is patch 1/3, replacement of js_string() and js_symbol() follow.
2022-12-07 16:43:06 +00:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Timothy Flynn
9620a092de LibJS: Publicly expose double_to_string and rename it number_to_string
Rename it to match the name used by the spec.

Add an override mode to skip formatting numbers with an exponential sign
(e.g. 1e23). This mode is needed by Number and Intl.NumberFormat, who
don't call out a specific number-to-string method to use (they just say
to make "the String consisting of the digits of n").
2022-11-04 21:12:10 +00:00
Dan Klishch
56aa21a7dc LibJS: Implement precise double_to_string 2022-11-03 20:17:09 -06:00
Moustafa Raafat
54b8a2b094 LibCrypto: Add a way to compare UnsignedBigInteger with double
This patch also make SignedBigInteger::compare_to_double make use
of the new function.
2022-11-02 22:04:34 -06:00
davidot
783b1a479d LibJS: Make string_to_double use the new double parser 2022-10-23 15:48:45 +02:00
Timothy Flynn
e952dca026 LibJS: Expose the StringToNumber AO for public use
This will be needed outside of Value.cpp.
2022-10-15 18:05:02 +02:00
Linus Groh
69415f0608 LibJS: Make string_to_bigint() a standalone function
This now matches the newly added string_to_number().
2022-08-30 10:30:54 +01:00
Linus Groh
15e3a99250 LibJS: Trim non-ASCII whitespace as well in StringToBigInt
This was never caught since the original implementation AFAICT, and
isn't being covered by test262 either:
https://github.com/tc39/test262/issues/1354
2022-08-30 10:30:43 +01:00
Linus Groh
c88c33dc22 LibJS: Trim non-ASCII whitespace as well in StringToNumber
This regressed in f4b3bb5.
2022-08-30 10:20:45 +01:00
Slappy826
f4b3bb519f LibJS: Handle non-decimal integer literals in Value::to_number
Implements support for parsing binary and octal literals, and fixes
instances where a hex literal is parsed in ways the spec doesn't
allow.
2022-08-30 01:00:48 +01:00
Linus Groh
50428ea8d2 LibJS: Move intrinsics to the realm
Intrinsics, i.e. mostly constructor and prototype objects, but also
things like empty and new object shape now live on a new heap-allocated
JS::Intrinsics object, thus completing the long journey of taking all
the magic away from the global object.
This represents the Realm's [[Intrinsics]] slot in the spec and matches
its existing [[GlobalObject]] / [[GlobalEnv]] slots in terms of
architecture.

In the majority of cases it should now be possibly to fully allocate a
regular object without the global object existing, and in fact that's
what we do now - the realm is allocated before the global object, and
the intrinsics between both :^)
2022-08-27 11:29:10 +01:00
davidot
e663504df1 LibJS: Fix that leftshift for BigInts did not round down
For negative number this previously rounded towards zero instead of the
intended always rounding down.
2022-08-24 23:27:17 +01:00
davidot
cb49c07fb7 LibJS: Use the new BigInt compare_to_double algorithm :^)
Although this is much more complicated it does not seem to impact
performance that much even when looking only at values in which the
previous casting to i32 was correct.
2022-08-24 23:27:17 +01:00
davidot
a9d2d806b6 LibJS: Use __builtin_isnan in static_assert instead of isnan
For the fuzzer build isnan was not usable in a constexpr context however
__builtin_isnan seems to always be.

Also while we're here add my name to the copyright since I forgot after
the Value rewrite.
2022-08-23 22:30:15 +01:00
Linus Groh
25849f8a6d LibJS: Replace GlobalObject with VM in common AOs [Part 18/19] 2022-08-23 13:58:30 +01:00
Linus Groh
a022e548b8 LibJS: Replace GlobalObject with VM in Value AOs [Part 4/19]
This is where the fun begins. :^)
2022-08-23 13:58:30 +01:00