summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests
AgeCommit message (Collapse)Author
2021-10-15LibJS: Enable now working tests for duplicated variable declarationsdavidot
2021-10-15LibJS: Implement ShadowRealm.prototype.importValue()Linus Groh
Well... sort of. This adds the function itself and all the scaffolding from the ShadowRealm API (and basically completes its implementation). However, we do not nearly have enough support for modules and imports, so we currently pretend whatever was attempted to be imported failed - once we have HostImportModuleDynamically it should be relatively easy to complete the implementation.
2021-10-15LibJS/Tests: Test ShadowRealm.prototype.evaluate() this value type checkLinus Groh
2021-10-15LibJS: Fix typo in LHS Object and RHS BigInt loosely equals checkLuke Wilde
Step 12 was using `lhs.is_bigint()` instead of `rhs.is_bigint()`, meaning you got: ```js 1n == Object(1n); // true Object(1n) == 1n; // false ``` This also adds spec comments to is_loosely_equal.
2021-10-14LibJS: Implement ShadowRealm.prototype.evaluate()Linus Groh
2021-10-14LibJS: Implement ShadowRealm.prototype[@@toStringTag]Linus Groh
2021-10-14LibJS: Start implementing ShadowRealmLinus Groh
This commit adds the ShadowRealm object itself, its constructor, and prototype (currently empty).
2021-10-11LibJS: Implement Temporal.PlainMonthDay.prototype.toPlainDate()Linus Groh
2021-10-11LibJS: Implement Temporal.PlainYearMonth.prototype.toPlainDate()Linus Groh
2021-10-11LibJS: Implement Temporal.Calendar.prototype.dateUntil()Linus Groh
2021-10-09LibJS: Implement [[Call]] and [[Construct]] internal slots properlyLinus Groh
This patch implements: - Spec compliant [[Call]] and [[Construct]] internal slots, as virtual FunctionObject::internal_{call,construct}(). These effectively replace the old virtual FunctionObject::{call,construct}(), but with several advantages: - Clear and consistent naming, following the object internal methods - Use of completions - internal_construct() returns an Object, and not Value! This has been a source of confusion for a long time, since in the spec there's always an Object returned but the Value return type in LibJS meant that this could not be fully trusted and something could screw you over. - Arguments are passed explicitly in form of a MarkedValueList, allowing manipulation (BoundFunction). We still put them on the execution context as a lot of code depends on it (VM::arguments()), but not from the Call() / Construct() AOs anymore, which now allows for bypassing them and invoking [[Call]] / [[Construct]] directly. Nothing but Call() / Construct() themselves do that at the moment, but future additions to ECMA262 or already existing web specs might. - Spec compliant, standalone Call() and Construct() AOs: currently the closest we have is VM::{call,construct}(), but those try to cater to all the different function object subclasses at once, resulting in a horrible mess and calling AOs with functions they should never be called with; most prominently PrepareForOrdinaryCall and OrdinaryCallBindThis, which are only for ECMAScriptFunctionObject. As a result this also contains an implicit optimization: we no longer need to create a new function environment for NativeFunctions - which, worth mentioning, is what started this whole crusade in the first place :^)
2021-10-07LibJS: Fast non-local variable access :^)Andreas Kling
This patch introduces the "environment coordinate" concept, which encodes the distance from a variable access to the binding it ends up resolving to. EnvironmentCoordinate has two fields: - hops: The number of hops up the lexical environment chain we have to make before getting to the resolved binding. - index: The index of the resolved binding within its declarative environment record. Whenever a variable lookup resolves somewhere inside a declarative environment, we now cache the coordinates and reuse them in subsequent lookups. This is achieved via a coordinate cache in JS::Identifier. Note that non-strict direct eval() breaks this optimization and so it will not be performed if the resolved environment has been permanently screwed by eval(). This makes variable access *significantly* faster. :^)
2021-09-30LibJS: Fix switch skipping case evaluation when hitting the default casedavidot
When no case match we should not just execute the statements of the default case but also of any cases below the default case.
2021-09-30LibJS: Make scoping follow the specdavidot
Before this we used an ad-hoc combination of references and 'variables' stored in a hashmap. This worked in most cases but is not spec like. Additionally hoisting, dynamically naming functions and scope analysis was not done properly. This patch fixes all of that by: - Implement BindingInitialization for destructuring assignment. - Implementing a new ScopePusher which tracks the lexical and var scoped declarations. This hoists functions to the top level if no lexical declaration name overlaps. Furthermore we do checking of redeclarations in the ScopePusher now requiring less checks all over the place. - Add methods for parsing the directives and statement lists instead of having that code duplicated in multiple places. This allows declarations to pushed to the appropriate scope more easily. - Remove the non spec way of storing 'variables' in DeclarativeEnvironment and make Reference follow the spec instead of checking both the bindings and 'variables'. - Remove all scoping related things from the Interpreter. And instead use environments as specified by the spec. This also includes fixing that NativeFunctions did not produce a valid FunctionEnvironment which could cause issues with callbacks and eval. All FunctionObjects now have a valid NewFunctionEnvironment implementation. - Remove execute_statements from Interpreter and instead use ASTNode::execute everywhere this simplifies AST.cpp as you no longer need to worry about which method to call. - Make ScopeNodes setup their own environment. This uses four different methods specified by the spec {Block, Function, Eval, Global}DeclarationInstantiation with the annexB extensions. - Implement and use NamedEvaluation where specified. Additionally there are fixes to things exposed by these changes to eval, {for, for-in, for-of} loops and assignment. Finally it also fixes some tests in test-js which where passing before but not now that we have correct behavior :^).
2021-09-30LibJS: Handle escaped keywords in more cases and handle 'await' labelsdavidot
2021-09-30LibJS: Allow multiple labels on the same statementdavidot
Since there are only a number of statements where labels can actually be used we now also only store labels when necessary. Also now tracks the first continue usage of a label since this might not be valid but that can only be determined after we have parsed the statement. Also ensures the correct error does not get wiped by load_state.
2021-09-26LibJS: Allow statements to have multiple labelsAndreas Kling
This is a curious thing that occurs more often than you'd think in minified JavaScript: a: b: c: for (...) { ... break b; ... }
2021-09-26LibJS: Defer execution of switch default clause until after case clausesLinus Groh
When we encounter a default clause in a switch statement, we should not execute it immediately, instead we need to wait until all case clauses have been executed as a matching case clause can break from the switch/case. The code is nowhere close to the spec, so instead of fixing it properly I just made it slightly worse, but correct. Needs a complete refactor at some point.
2021-09-25LibJS: Rename OrdinaryFunctionObject to ECMAScriptFunctionObjectLinus Groh
The old name is the result of the perhaps somewhat confusingly named abstract operation OrdinaryFunctionCreate(), which creates an "ordinary object" (https://tc39.es/ecma262/#ordinary-object) in contrast to an "exotic object" (https://tc39.es/ecma262/#exotic-object). However, the term "Ordinary Function" is not used anywhere in the spec, instead the created object is referred to as an "ECMAScript Function Object" (https://tc39.es/ecma262/#sec-ecmascript-function-objects), so let's call it that. The "ordinary" vs. "exotic" distinction is important because there are also "Built-in Function Objects", which can be either implemented as ordinary ECMAScript function objects, or as exotic objects (our NativeFunction). More work needs to be done to move a lot of infrastructure to ECMAScriptFunctionObject in order to make FunctionObject nothing more than an interface for objects that implement [[Call]] and optionally [[Construct]].
2021-09-14LibJS: Implement parsing and execution of optional chainsAli Mohammad Pur
2021-09-13LibJS: Evaluate function arguments before checking callee typeLinus Groh
In the spec, this happens in the EvaluateCall abstract operation (https://tc39.es/ecma262/#sec-evaluatecall), and the order is defined as: 3. Let argList be ? ArgumentListEvaluation of arguments. 4. If Type(func) is not Object, throw a TypeError exception. 5. If IsCallable(func) is false, throw a TypeError exception. In LibJS this is handled by CallExpression::execute(), which had the callee function check first and would therefore never evaluate the arguments for a non-function callee.
2021-09-12LibJS: Change wording of ErrorType::NotA to be independent of contextTimothy Flynn
Currently, we have NotA and NotAn, to be used dependent on whether the following word begins with a vowel or not. To avoid this, change the wording on NotA to be independent of this context.
2021-09-11LibJS: Implement Intl.NumberFormat.prototype.resolvedOptionsTimothy Flynn
2021-09-11LibJS: Implement Intl.NumberFormat.supportedLocalesOfTimothy Flynn
2021-09-11LibJS: Implement the Intl.NumberFormat constructorTimothy Flynn
2021-09-11LibJS: Implement a nearly empty Intl.NumberFormat objectTimothy Flynn
This adds plumbing for the Intl.NumberFormat object, constructor, and prototype.
2021-09-10LibJS: Implement Temporal.PlainMonthDay.prototype.equalsLuke Wilde
2021-09-10LibJS: Implement Temporal.PlainMonthDay.fromLuke Wilde
2021-09-09LibJS: Implement Temporal.PlainYearMonth.compareLuke Wilde
2021-09-09LibJS: Implement Temporal.PlainYearMonth.fromLuke Wilde
2021-09-09LibJS: Implement Temporal.PlainYearMonth.prototype.equalsLuke Wilde
2021-09-09LibJS: Implement Temporal.Instant.prototype.toZonedDateTimeISO()Linus Groh
2021-09-09LibJS: Implement Temporal.Instant.prototype.toZonedDateTime()Linus Groh
2021-09-08LibJS: Implement Temporal.PlainTime.prototype.toJSON()Linus Groh
2021-09-08LibJS: Implement Temporal.PlainTime.prototype.toLocaleString()Linus Groh
2021-09-08LibJS: Implement Temporal.PlainTime.prototype.toString()Linus Groh
2021-09-08LibJS: Restore the environment if an exception is thrown in 'with' blockdavidot
2021-09-08LibJS: Implement Temporal.PlainTime.prototype.withLuke Wilde
Ticks off one box in #8982 and fixes one test262 case.
2021-09-08test-js: Add a mark_as_garbage method to force GC to collect that objectdavidot
This should fix the flaky tests of test-js. It also fixes the tests when running with the -g flag since the values will not be garbage collected too soon.
2021-09-08LibJS: Fix Temporal.PlainTime.prototype.equals testLuke Wilde
The two plain times weren't being compared to each other.
2021-09-08LibJS: Add and use the CreateNegatedTemporalDuration AOLinus Groh
This is a normative change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/6178ed3
2021-09-08LibJS: Validate Calendar.prototype.fields() values more strictlyLinus Groh
This is a normative change in the Temporal spec. See: - https://github.com/tc39/proposal-temporal/commit/75b66d8 - https://github.com/tc39/proposal-temporal/commit/9c2262b
2021-09-07Everywhere: Behaviour => BehaviorAndreas Kling
2021-09-06LibJS: Implement Intl.ListFormat.prototype.resolvedOptionsTimothy Flynn
2021-09-06LibJS: Implement Intl.ListFormat.prototype.formatToPartsTimothy Flynn
2021-09-06LibJS: Implement Intl.ListFormat.prototype.formatTimothy Flynn
2021-09-06LibJS: Implement Intl.ListFormat.supportedLocalesOfTimothy Flynn
2021-09-06LibJS: Implement the Intl.ListFormat constructorTimothy Flynn
2021-09-06LibJS: Implement a nearly empty Intl.ListFormat objectTimothy Flynn
This adds plumbing for the Intl.ListFormat object, constructor, and prototype.
2021-09-06LibJS: Implement Temporal.Instant.prototype.sinceIdan Horowitz