summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
AgeCommit message (Collapse)Author
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
2022-03-14LibJS/Bytecode: Setup lexical environment boundary for with statementsLuke Wilde
This allows us to properly unwind the object environment for `with` on a block terminating instruction, e.g. an unconditional throw.
2022-03-14LibJS/Bytecode: Unwind to closest unwind boundary on ThrowLuke Wilde
This will leave any lexical/variable environments on the way to the closest unwind context boundary. This will not leave the closest unwind context, as we still need the unwind context to perform the Throw instruction correctly.
2022-03-14LibJS/Bytecode: Unwind environments before block terminating instructionLuke Wilde
When we reach a block terminating instruction (e.g. Break, Throw), we cannot generate anymore instructions after it. This would not allow us to leave any lexical/variable environments. This uses the mechanism introduced in ba9c49 to unwind environments when we encounter these instructions.
2022-03-14LibJS: Leave unwind context if it has no finalizer when using handlerLuke Wilde
For example, a try/catch block with no finally. The try block and catch block do not need to unwind to a finally block, so the unwind context is no longer needed when we jump to the catch block. If we threw an exception in a catch block of a try/catch, there will be no handler or finalizer and the unit would continue on as if nothing happened. This would subsequently crash with the `m_saved_exception.is_null()` assertion failure when we next call a non-native function.
2022-03-14LibJS/Bytecode: Unconditionally end break/continuable scopesLuke Wilde
Previously we would only end these scopes if the block was not terminated. If the block was generated, we would not end the scope and would generate other bytecode with these scopes still open. These functions do not generate any code, so they can be used even if the current block is terminated. The enter and end scope functions are only used to track where to unwind to when break/continue are used.
2022-03-14LibJS: Add a fast path for creating per-iteration DeclarativeEnvironmentTimothy Flynn
The steps for creating a DeclarativeEnvironment for each iteration of a for-loop can be done equivalently to the spec without following the spec directly. For each binding creating in the loop's init expression, we: 1. Create a new binding in the new environment. 2. Grab the current value of the binding in the old environment. 3. Set the value in the new environment to the old value. This can be replaced by initializing the bindings vector in the new environment directly with the bindings in the old environment (but only copying the bindings of the init statement).
2022-03-14LibJS: Preallocate the list returned from CreateListFromArrayLikeTimothy Flynn
This list has up to 10,000 elements in some test262 tests, so let's avoid frequent allocation bumps.
2022-03-14LibWeb: Use inline script tag source line as javascript line offsetIdan Horowitz
This makes JS exception line numbers meaningful for inline script tags.
2022-03-13LibJS: Implement bytecode generation for WithStatementAli Mohammad Pur
2022-03-13LibJS: Initialize 'var' bindings to undefined on declarationAli Mohammad Pur
This is what CreateGlobalVarBinding does, so do the same thing in BC.
2022-03-13LibJS: Leave the unwind context on break/continue/return in bytecodeAli Mohammad Pur
Otherwise we'd keep the old unwind context, and end up never invoking the other handlers up the stack.
2022-03-13LibJS: Propagate abrupt completions in Bytecode::Op::CallAli Mohammad Pur
This was not handling the nullary call case correctly, remove the whole nullary check as there's nothing particularly expensive in the catch-all case anyway.
2022-03-13LibJS: Add some tests for TypedArray.prototype.setmjz19910
2022-03-11LibJS: Apply source's byte offset in TA#set when both TAs have same typeLuke Wilde
On the code path where we are setting a TypedArray from another TypedArray of the same type, we forgo the spec text and simply do a memmove between the two ArrayBuffers. However, we forgot to apply source's byte offset on this code path. This meant if we tried setting a TypedArray from a TypedArray we got from .subarray(), we would still copy from the start of the subarray's ArrayBuffer. This is because .subarray() returns a new TypedArray with the same ArrayBuffer but the new TypedArray has a smaller length and a byte offset that the rest of the codebase is responsible for applying. This affected pako when it was decompressing a zlib stream that has multiple zlib chunks in it. To read from the second chunk, it would set the zlib window TypedArray from the .subarray() of the chunk offset in the stream's TypedArray. This effectively made the decompressed data from the second chunk a mis-mash of old data that looked completely scrambled. It would also cause all future decompression using the same pako Inflate instance to also appear scrambled. As a pako comment aptly puts it: > Call updatewindow() to create and/or update the window state. > Note: a memory error from inflate() is non-recoverable. This allows us to properly decompress the large compressed payloads that Discord Gateway sends down to the Discord client. For example, for an account that's only in the Serenity Discord, one of the payloads is a 20 KB zlib compressed blob that has two chunks in it. Surprisingly, this is not covered by test262! I imagine this would have been caught earlier if there was such a test :^)
2022-03-10LibJS: Use CreateTemporalCalendar in GetBuiltinCalendarLinus Groh
This is an editorial change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/f6b3a10
2022-03-10LibJS: Replace dead code in ParseTimeZoneOffsetString with an assertionLinus Groh
This is an editorial change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/a29c40b
2022-03-10LibJS: Add missing check in ParseTemporalInstantLinus Groh
This is an editorial change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/baead4d
2022-03-10LibJS: Assert CreateTemporalDuration does not throw given correct inputLinus Groh
This is an editorial change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/881dd22