summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
AgeCommit message (Collapse)Author
2022-03-28LibJS: Add more delete operator testsLuke Wilde
2022-03-28LibJS/Bytecode: Implement the delete unary expressionLuke Wilde
`delete` has to operate directly on Reference Records, so this introduces a new set of operations called DeleteByValue, DeleteVariable and DeleteById. They operate similarly to their Get counterparts, except they end in creating a (temporary) Reference and calling delete_ on it.
2022-03-28LibJS: Only store MemberExpression object when loading a computed propLuke Wilde
When calling emit_load_from_reference with a MemberExpression, it is only necessary to store the result of evaluating MemberExpression's object when performing computed property lookup. This allows us to skip unnecessary stores for identifier lookup. For example, this would generate 3 unnecessary stores: ``` > Temporal.PlainDateTime.prototype.add JS::Bytecode::Executable (REPL) 1: [ 0] GetVariable 0 (Temporal) [ 28] Store $2 [ 30] GetById 1 (PlainDateTime) [ 40] Store $3 [ 48] GetById 2 (prototype) [ 58] Store $4 [ 60] GetById 3 (add) ``` With this, it generates: ``` > Temporal.PlainDateTime.prototype.add JS::Bytecode::Executable (REPL) 1: [ 0] GetVariable 0 (Temporal) [ 28] GetById 1 (PlainDateTime) [ 38] GetById 2 (prototype) [ 48] GetById 3 (add) ```
2022-03-28LibJS: Generate update Jump in for/in/of only if block is not terminatedLuke Wilde
The body of for/in/of can contain an unconditional block terminator (e.g. return, throw), so we have to check for that before generating the Jump to the loop update block.
2022-03-28LibJS/Bytecode: Update NewArray stringifier to print a register rangeLuke Wilde
NewArray now only contains two elements maximum in `m_elements` to indicate the range of registers to create the array from. However, `m_element_count` still contains how many registers are in the range and the stringifier was not updated to account for this. Thus, if the range contained more than 2 registers, it would do a read OOB on `m_elements`. This makes it now just print the first and second entries in `m_elements` in the format of `[<reg>-<reg>]`.
2022-03-25LibJS: Fix number types in GetISOPartsFromEpochLinus Groh
This is an editorial change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/c5b645d This means we now have to pass a global object and construct a BigInt object just for the assertion, but oh well. We might want to have an assertion macro that's optimized away in release builds at a later point, however.
2022-03-25LibJS: Update spec comment in BuiltinTimeZoneGetPlainDateTimeForLinus Groh
This is an editorial change in the Temporal spec from a long time ago. See: https://github.com/tc39/proposal-temporal/commit/e480d40
2022-03-20LibJS: Allow 'expect().fail("some random string")' in test-jsAli Mohammad Pur
Previously fail() wanted the fail object to be a callable, allow it to be a string also.
2022-03-19LibJS/Bytecode: Make construct Call throw if callee isn't a constructorLuke Wilde
2022-03-19LibJS/Bytecode: Add support for new.targetLuke Wilde
2022-03-19LibJS: Change nanoseconds_to_days() argument from a JS to Crypto BigIntLinus Groh
This is an editorial change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/0b1346c
2022-03-19LibJS: Change nanoseconds_to_days() result from a JS to Crypto BigIntLinus Groh
Similar to the preceding commit(s).
2022-03-19LibJS: Change balance_duration() nanoseconds from a JS to Crypto BigIntLinus Groh
Similar to the preceding commit.
2022-03-19LibJS: Change total_duration_nanoseconds() from JS to Crypto BigIntsLinus Groh
This removes a bunch of silly wrapping and unwrapping of Crypto SignedBigInteger values in JS BigInt objects, which isn't even intended by the spec - it just wants us to take an integer value, not a BigInt specifically. Nice opportunity to remove a couple of allocations. :^)
2022-03-19LibJS: Implement bytecode generation for For-In/Of statementsAli Mohammad Pur
This also implements the rather interesting behaviour that #12772 relies on, so this fixes that bug in BC mode (the AST interp remains affected).
2022-03-19DevTools+LibJS+LibWeb: Change class_name to use StringViewLenny Maiorani
This helps make the overall codebase consistent. `class_name()` in `Kernel` is always `StringView`, but not elsewhere. Additionally, this results in the `strlen` (which needs to be done when printing or other operations) always being computed at compile-time.
2022-03-18Everywhere: Deduplicate day/month name constantsLenny Maiorani
Day and month name constants are defined in numerous places. This pulls them together into a single place and eliminates the duplication. It also ensures they are `constexpr`.
2022-03-18Userland: Change static const variables to static constexprLenny Maiorani
`static const` variables can be computed and initialized at run-time during initialization or the first time a function is called. Change them to `static constexpr` to ensure they are computed at compile-time. This allows some removal of `strlen` because the length of the `StringView` can be used which is pre-computed at compile-time.
2022-03-18LibJS: Tweak Interpreter::create() for more spec-likenessLinus Groh
Store a reference to the newly created execution context in an aptly named variable, rename global_this_value to just this_value, and only call set_global_object() in a single place.
2022-03-18LibJS: Use TRY(push_execution_context()) in places where we can recoverLinus Groh
2022-03-18LibJS: Add infallible variant of VM::push_execution_context()Linus Groh
It makes no sense to require passing a global object and doing a stack space check in some cases where running out of stack is highly unlikely, we can't recover from errors, and currently ignore the result anyway. This is most commonly in constructors and when setting things up, rather than regular function calls.
2022-03-17LibJS: Update specification steps for RegExp Match IndicesTimothy Flynn
This proposal was implemented in Stage 3 in commit: 6c67de8186e22d9c39c2fa1eec92de784669336f It is now Stage 4 and has been merged into the main ECMA-262 spec: https://github.com/tc39/ecma262/commit/0209d85
2022-03-16LibJS: Fix fraction substring in ParseTimeZoneOffsetStringLinus Groh
This is a normative change in the Temporal spec. See: - https://github.com/tc39/proposal-temporal/commit/97d553c - https://github.com/tc39/proposal-temporal/commit/d53af7f Note that we already implemented this correctly, so the only change is updating the spec comment.
2022-03-16LibJS: Remove unused code in DifferenceISODateLinus Groh
This is an editorial change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/056f695
2022-03-16LibJS: Remove the ConstrainToRange AOLinus Groh
This is an editorial change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/537b3e6
2022-03-16LibJS: Remove argument type assertion from ParseTemporalDurationStringLinus Groh
This is an editorial change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/8615b41
2022-03-16LibJS: Assume Get() on the result of PrepareTemporalFields can't failLinus Groh
This is an editorial change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/980e168
2022-03-16LibJS: Relax line and column number restrictions in Error stack testsSimon Wanner
2022-03-16Libraries: Use default constructors/destructors in LibJSLenny Maiorani
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler."
2022-03-16LibTest: Provide detailed per-file JSON output with --per-fileAli Mohammad Pur
This makes test-js style runners dump out output in the same format as libjs-test262's per-file output.
2022-03-15LibJS: Handle non-Error this object in Error.prototype.stack getterLinus Groh
This is taken from the abandoned error stacks proposal, which already serves as the source of truth for the setter. It only requires the this value to be an object - if it's not an Error object, the getter returns undefined. I have not compared this behavior to the non-standard implementations of the stack property in other engines, but presumably the spec authors already did that work. This change gets the Sentry browser SDK working to a point where it can actually send uncaught exceptions via the API :^)
2022-03-15LibJS/Tests: Consolidate Error.prototype.stack testsLinus Groh
We don't usually separate tests for the getter and setter of a property, and that error-stack.js (getter) test belongs in builtins/.
2022-03-15LibJS: Set internal function name of NativeError constructorsLinus Groh
By using the same NativeFunction constructor as plain ErrorConstructor and passing the name, TypeError & co. will now include their name in backtraces and such. Eventually we should probably rely on [[InitialName]] for this, but for now that's how it works.
2022-03-15LibJS: Reorganize spec steps for Intl.RelativeTimeFormatTimothy Flynn
This is an editorial change in the Intl spec: https://github.com/tc39/ecma402/commit/a3ae343
2022-03-15LibJS: Reorganize spec steps for Intl.PluralRulesTimothy Flynn
This is an editorial change in the Intl spec: https://github.com/tc39/ecma402/commit/d7c7157
2022-03-15LibJS: Reorganize spec steps for Intl.NumberFormatTimothy Flynn
This is an editorial change in the Intl spec: https://github.com/tc39/ecma402/commit/110cb1f
2022-03-15LibJS: Reorganize spec steps for Intl.LocaleTimothy Flynn
This is an editorial change in the Intl spec: https://github.com/tc39/ecma402/commit/31f6003
2022-03-15LibJS: Reorganize spec steps for Intl.ListFormatTimothy Flynn
This is an editorial change in the Intl spec: https://github.com/tc39/ecma402/commit/61bc370
2022-03-15LibJS: Reorganize spec steps for Intl.DisplayNamesTimothy Flynn
This is an editorial change in the Intl spec: https://github.com/tc39/ecma402/commit/5b51804
2022-03-15LibJS: Reorganize spec steps for Intl.DateTimeFormatTimothy Flynn
This is an editorial change in the Intl spec: https://github.com/tc39/ecma402/commit/97e1ecc
2022-03-15LibJS: Reorganize spec steps for Intl.CollatorTimothy Flynn
This is an editorial change in the Intl spec: https://github.com/tc39/ecma402/commit/7c13db4 This also normalizes the spelling of the "Internal slots" heading in Intl.Collator, which is another editorial change in the Intl spec: https://github.com/tc39/ecma402/commit/ec064bd
2022-03-15LibJS/Bytecode: Fix typo in object binding an entry with no aliasLuke Wilde
In object binding, we would attempt to get NonnullRefPtr<Identifier> from alias on the alias.has<Empty>() code path. In this case, we need to get it from name instead.
2022-03-15LibJS/Bytecode: End for's variable scope after update block generationLuke Wilde
The update block can generate bytecode that refers to the lexical environment, so we have to end the scope after it has been generated. Previously the Jump to the update block would terminate the block, causing us to leave the lexical environment just before jumping to the update block.
2022-03-15LibJS: Stop generating switch case statements on block terminationLuke Wilde
After we terminate a block (e.g. break, continue), we cannot generate anymore bytecode for the block. This caused us to crash with this example code: ``` a = 0; switch (a) { case 0: break; console.log("hello world"); } ``` Anything after a block terminating instruction is considered unreachable code, so we can safely skip any statements after it.
2022-03-14LibJS: Implement default values for function parameters in BCAli Mohammad Pur
2022-03-14LibJS/Bytecode: Replace merged block references before copying themAli Mohammad Pur
2022-03-14LibJS: Use ranges instead of specifying all registers for NewArrayAli Mohammad Pur
Listing all the registers will lead to the inability to allocate enough space in one basic block (as there can be an arbitrary number of registers used), instead switch to specifying the range of registers used and save a lot of space in the process.
2022-03-14LibJS/Bytecode: Make NewArray write directly to indexed propertiesLuke Wilde
This follows how the regular AST interpreter creates arrays, as using Array::create_from uses create_data_property_or_throw, which will crash when it encounters an empty value. We require empty values to represent array holes.
2022-03-14LibJS/Bytecode: Setup declarative environment for lexical for statementsLuke Wilde
2022-03-14LibJS/Bytecode: Setup declarative environment for catch with variableLuke Wilde