Idan Horowitz
f65cb63aab
LibJS: Check dates are below the time_clip
threshold
2021-06-06 19:14:11 +01:00
Idan Horowitz
c4530e95f4
LibJS: Add Date.prototype.toJSON()
2021-06-06 19:14:11 +01:00
Idan Horowitz
ed7eb403fe
LibJS: Add Date.prototype[@@toPrimitive]()
2021-06-06 19:14:11 +01:00
Idan Horowitz
60e70e5ee4
LibJS: Add Date.setUTC{Date, Month, Hours, ...}() aliases
...
These are a bit hacky, since they are supposed to be separate methods,
but since serenity only supports UTC currently, they are equivalent.
2021-06-06 19:14:11 +01:00
Idan Horowitz
46214f0657
LibJS: Store Date milliseconds as signed to support negative offsets
...
We need to support the range of -999 to 999.
2021-06-06 19:14:11 +01:00
Idan Horowitz
17afe015a5
LibJS: Add Date.prototype.setTime()
2021-06-06 19:14:11 +01:00
Idan Horowitz
a93b1c7ea0
LibJS: Add Date.prototype.setMonth()
2021-06-06 19:14:11 +01:00
Idan Horowitz
59034554a4
LibJS: Account for differences in month representations (0-11 vs 1-12)
...
Since DateTime stores months as 1 to 12, while JS accepts months as
0 to 11, we have to account for the difference (by subtracting or
adding 1) where appropriate.
2021-06-06 19:14:11 +01:00
Idan Horowitz
b893963651
LibJS: Add Date.prototype.setDate()
2021-06-06 19:14:11 +01:00
Idan Horowitz
3eb05d9413
LibJS: Stub out Date.prototype.getTimezoneOffset()
...
We only support UTC currently, so this always returns 0 as long as the
date is not invalid.
2021-06-06 19:14:11 +01:00
Idan Horowitz
44926b3f80
LibJS: Ignore arguments in Date's constructor when called as a function
...
Since theres no way to drop the arguments before the call to the
constructor (or to signal to the constructor that it was not called
directly), we simply reuse the code for the no arguments provided
special case. (And to prevent code duplication, the code was extracted
into the separate static function Date::now(GlobalObject&).
2021-06-06 19:14:11 +01:00
Linus Groh
ba9d3bc38c
LibJS: Create 1970-01-01 00:00:00 local time Date for invalid ctor call
...
When using Core::DateTime::from_timestamp(0) the resulting Date is
1970-01-01 00:00:00 in UTC, which might be something different in local
time - this is incorrect and relevant as invalid Dates can be made valid
later on.
2021-06-06 19:34:43 +02:00
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
0bf597e99d
LibJS: Uncomment and add parseInt tests
...
Added another test that checks radices > 16, as well as uncommented
several "FIXME" tests that are now working.
2021-06-06 01:34:22 +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
Max Wipfli
106ad6ba09
LibJS: Fix off-by-one error in SyntaxHighlighter
...
This changes the JS syntax highlighter to conform to the now-fixed
rendering of syntax highlighting spans in GUI::TextEditor.
2021-06-05 00:32:28 +04:30
Ryan Chandler
c66b281856
LibJS: Fix functions binding this to global object in strict mode
...
This fixes an issue where this would be bound to the global object
by default when operating in strict mode.
According to the specification, the expected value for |this| when
no binding is provided is undefined.
2021-06-04 13:00:37 +01:00
Ali Mohammad Pur
09cf1040ef
LibJS/Tests: Catch exceptions in describe() itself
...
Otherwise exceptions thrown in that state would simply terminate the
test.
2021-06-04 16:07:42 +04:30
Andreas Kling
bf8fd4c193
Everywhere: Remove accidental '\n' from various outln() invocations
...
Also convert outln(stderr, ...) to warnln(...)
2021-06-03 22:50:21 +02: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