Linus Groh
ff5aa3ca70
LibJS: Make it so that Date.prototype.toGMTString === .toUTCString
2021-06-06 19:34:43 +02:00
Linus Groh
60aace8400
LibJS: Remove unused includes from SymbolPrototype.cpp
2021-06-06 19:34:43 +02:00
Linus Groh
b661363dfe
LibJS: Implement String.prototype[@@toPrimitive]()
2021-06-06 19:34:43 +02:00
Linus Groh
e9a0759b16
LibJS: Add String.prototype.valueOf()
...
It should have its own and not inherit from the Object prototype.
2021-06-06 19:34:43 +02:00
Linus Groh
8d7ec28924
LibJS: Remove String.prototype.length
...
A string's length property is supposed to be a regular non-writable,
non-enumerable, non-configurable property on the StringObject instead.
2021-06-06 19:34:43 +02:00
Linus Groh
fc2673d111
LibJS: Replace SymbolPrototype's typed_this() with this_symbol_value()
...
This brings the code close to the spec with no trade-offs, which is
always valuable.
No functionality change.
2021-06-06 19:34:43 +02:00
Linus Groh
6f96f01171
LibJS: Replace StringPrototype's typed_this() with this_string_value()
...
This brings the code close to the spec with no trade-offs, which is
always valuable.
No functionality change.
2021-06-06 19:34:43 +02:00
Linus Groh
68d669443f
LibJS: Replace bigint_object_from() with this_bigint_value()
...
This brings the code close to the spec with no trade-offs, which is
always valuable.
No functionality change.
2021-06-06 19:34:43 +02:00
Linus Groh
d255e6892b
LibJS: Update NumberPrototype's this_number_value() to take a Value
...
This is now about as close to the spec as it gets - instead of querying
the |this| value inside of the function, we now pass it in from the
outside.
Also get rid of the oddly specific error messages, they're nice but
pretty inconsistent with most others. Let's prefer consistency and
simplicity for now.
Other than that, no functionality change.
2021-06-06 19:34:43 +02:00
Linus Groh
3cfd9f51f7
LibJS: Replace some is_nullish() checks with require_object_coercible()
2021-06-06 19:34:43 +02:00
Linus Groh
cd12b2aa57
LibJS: Implement the RequireObjectCoercible abstract operation
...
Throws an exception if the given value is nullish, returns it otherwise.
We can now gradually replace such manual checks with this function where
applicable.
This also has the advantage that the somewhat useless "ToObject on null
or undefined" will be replaced with "null cannot be converted to an
object" or "undefined cannot be converted to an object". :^)
2021-06-06 19:34:43 +02:00
Andreas Kling
f290048662
LibJS: Pass unwinding target labels a bit more efficiently
...
Use const reference or move semantics when passing these labels.
2021-06-06 11:45:52 +02:00
Linus Groh
887852f36d
LibJS: Make Number.prototype.toString() radix coercion spec compliant
...
This should use the ToIntegerOrInfinity() abstract operation.
2021-06-06 07:03:12 +01:00
Linus Groh
adc3de4480
LibJS: Implement Number.prototype.valueOf()
2021-06-06 06:56:08 +01:00
Idan Horowitz
aa5b144f90
LibJS: Correct modulo behaviour in to_i32 to match the specification
2021-06-06 01:34:22 +01:00
Idan Horowitz
bbf75d0bea
LibJS: Trim initial whitespace in parseFloat
2021-06-06 01:34:22 +01:00
Idan Horowitz
bda32e9440
LibJS: Parse digits with parse_ascii_base36_digit in parseInt
...
This was accidentally replaced with parse_ascii_hex_digit in
bc8d16ad28
which caused radices above
16 (hex) to fail.
2021-06-06 01:34:22 +01:00
Idan Horowitz
26a0dbdd9e
LibJS: Set the length property of parseInt to 2
...
The method takes 2 arguments
2021-06-06 01:34:22 +01:00
Idan Horowitz
2a8f4f097c
LibJS: Throw TypeError on write to non-writable property in strict mode
2021-06-05 23:54:08 +01:00
Idan Horowitz
442ef63008
LibJS: Add the global escape() & unescape() methods
2021-06-05 18:55:08 +01:00
Idan Horowitz
e2fb7943f7
LibJS: Correctly handle NaN and negative infinity in Math.atan2
...
The current implementation was missing an early return on a NaN
argument and mixed up a couple of the positive/negative infinity early
returns.
2021-06-05 14:56:58 +01:00
Idan Horowitz
57a52094d1
LibJS: Rewrite Math.hypot to handle exceptions, NaNs, Infinity properly
...
The specification requires that we immediately return Infinity during
the iteration over the arguments if positive or negative infinity is
encountered, and return a NaN if it is encountered and no Infinity was
found. The specification also requires all arguments to be coerced into
numbers before the operation starts, or else a number conversion
exception could be missed due to the Infinity/NaN early return.
2021-06-05 14:56:58 +01:00
Idan Horowitz
03255c1c53
LibJS: Handle NaN/Infinity/Zero edge cases in Math.pow()
...
This commit replaces the current simple call to LibM's pow with the
full implementation of 6.1.6.1.3 Number::exponentiate:
https://tc39.es/ecma262/#sec-numeric-types-number-exponentiate
2021-06-05 14:56:58 +01:00
Idan Horowitz
7507999230
LibJS: Rewrite Math.{max, min} to handle exceptions and NaNs properly
...
The specification requires that we immediately return a NaN during the
iteration over the arguments if one is encountered. It also requires
all arguments to be coerced into numbers before the operation starts,
or else a number conversion exception could be missed due to the NaN
early return.
2021-06-05 14:56:58 +01:00
Idan Horowitz
24ffe91b16
LibJS: Handle negative zero and negative infinity in Math.abs()
...
As required by the specification:
3. If n is -0, return +0.
4. If n is -∞, return +∞.
2021-06-05 14:56:58 +01:00
Idan Horowitz
9d2e90d569
LibJS: Add Math.imul()
2021-06-05 14:56:58 +01:00
Idan Horowitz
de10f0dc6c
LibJS: Support symbol keys in Object.prototype.propertyIsEnumerable
2021-06-05 14:15:28 +01:00
Idan Horowitz
eb0b1c432a
LibJS: Replace StringOrSymbol::from_value with Value::to_property_key
...
This is a more specification compliant implementation of the
abstract operation 7.1.19 ToPropertyKey which should handle boxed
symbols correctly.
2021-06-05 14:15:28 +01:00
Andreas Kling
42fcc2219d
LibJS: Use PropertyName::as_string() in Object::get()
...
After we've already checked is_string(), we can use as_string() to
avoid a temporary String.
2021-06-05 13:00:34 +02:00
Idan Horowitz
0f8ed6183b
LibJS: Add the Number.{MAX, MIN}_VALUE constants
2021-06-05 02:38:37 +01:00
Gunnar Beutner
32ee195d62
LibJS: Avoid allocations in the Exception constructor
2021-06-03 14:47:15 +01:00
Gunnar Beutner
8b449214af
LibJS: Optimize insertion order in the Exception constructor
...
By inserting the stack frames in the correct order we can improve the
runtime for the test-js test suite by about 20%.
2021-06-03 14:47:15 +01:00
Max Wipfli
bc8d16ad28
Everywhere: Replace ctype.h to avoid narrowing conversions
...
This replaces ctype.h with CharacterType.h everywhere I could find
issues with narrowing conversions. While using it will probably make
sense almost everywhere in the future, the most critical places should
have been addressed.
2021-06-03 13:31:46 +02:00
Linus Groh
d1d1f4f251
LibJS: Remove declarations of some TODO()'d BigInt and Promise functions
...
In hindsight declaring these prematurely wasn't the greatest idea - that
just makes any script checking for their existence believe they'll work,
and what follows next is a crash of the js or WebContent process. If we
omit the declarations, a polyfill can be provided instead.
This also affects the test262, which tests these - instead of reporting
a bunch of assertion crash errors, we should simply report test failure
for 'not a function', which in turn makes it easier to spot any actual
bugs causing crashes.
2021-06-02 21:06:21 +01:00
Linus Groh
163d776df6
LibJS: Replace iterator hint string argument with an enum
...
There's no reason at all for this to be a string or to accept arbitrary
values - just because it's displayed as strings in the spec doesn't mean
we have to do the same :^)
2021-06-02 20:52:46 +01:00
Idan Horowitz
de8d081ca4
LibJS: Add the String.prototype.trim{Left, Right} aliases
...
These are the same as trim{Start, End} respectively.
2021-06-02 09:42:25 +02:00
Andreas Kling
12a42edd13
Everywhere: codepoint => code point
2021-06-01 10:01:11 +02:00
Andreas Kling
407d6cd9e4
AK: Rename Utf8CodepointIterator => Utf8CodePointIterator
2021-06-01 09:45:52 +02:00
Idan Horowitz
67a5e9f018
LibJS: Add left shift & right shift operator support for BigIntegers
...
Based on https://tc39.es/ecma262/#sec-numeric-types-bigint-leftShift
(This commit also includes the matching tests)
2021-05-31 19:50:29 +01:00
Idan Horowitz
6bfeb87572
LibJS: Add String.prototype.anchor & friends
...
Adds an implementation of the following StringPrototype methods:
anchor, big, blink, bold, fixed, fontcolor, fontsize, italics, link,
small, strike, sub, sup.
2021-05-30 10:32:05 +01:00
Idan Horowitz
09233b9e41
LibJS: Add Date.prototype.{get, set}Year()
2021-05-29 23:42:08 +01:00
Idan Horowitz
96ee5e36ed
LibJS: Replace the broken and unused Date::year getter
2021-05-29 23:42:08 +01:00
Ali Mohammad Pur
7a00d6d9c8
LibJS: Implement destructuring assignments and function parameters
2021-05-29 23:02:23 +04:30
Stephan Unverwerth
10ceeb092f
Everywhere: Use s.unverwerth@serenityos.org :^)
2021-05-29 12:30:08 +01:00
Ali Mohammad Pur
6af596d9e8
LibJS+LibWeb: Make Uint8ClampedArray use TypedArray
...
Instead of being its own separate unrelated class.
This automatically makes typed array properties available to it,
as well as making it available to the runtime.
2021-05-26 15:34:13 +04:30
Ali Mohammad Pur
4fd43a8f96
LibJS: Allow ArrayBuffer to not own its backing data buffer as well
...
This is implemented as a ByteBuffer* in a variant, so its size should
only be increased by an index.
2021-05-26 15:34:13 +04:30
Andreas Kling
679fc3066c
LibJS: Fix clang-tidy warnings about unnecessary move()s in VM.cpp
2021-05-25 18:52:00 +02:00
Andreas Kling
47a4b2ba9f
LibJS: Make Value::as_cell() return a Cell&
2021-05-25 18:48:11 +02:00
Andreas Kling
0de954e86b
LibJS: Make Cell::Visitor::visit_impl() take a Cell&
...
Passing a null cell pointer is not supported.
2021-05-25 18:39:01 +02:00
Andreas Kling
91656d63c7
LibJS: Inline Cell::Visitor::visit() functions
...
This allows the calls to MarkingVisitor::visit_impl() during GC to be
devirtualized in Heap::mark_live_cells().
2021-05-25 18:18:48 +02:00