summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests
AgeCommit message (Collapse)Author
2020-05-24LibJS: Make Array.prototype.includes() genericLinus Groh
2020-05-24LibJS: Make Array.prototype.lastIndexOf() genericLinus Groh
2020-05-24LibJS: Make Array.prototype.indexOf() genericLinus Groh
2020-05-24LibJS: add Array.prototype.reduceRight()Marcin Gasperowicz
This patch adds `Array.prototype.reduceRight()` method to LibJS Runtime. The implementation is (to my best knowledge) conformant to https://tc39.es/ecma262/#sec-array.prototype.reduceright. Short test in `LibJS/Tests/Array.prototype-generic-functions.js` demonstrates that the function can be applied to other objects besides `Array`.
2020-05-23LibJS: Add Array.prototype.reduce() (#2334)Marcin Gasperowicz
This patch adds `Array.prototype.reduce()` method to LibJS Runtime. The implementation is (to my best knowledge) comformant to ECMA262. The test `Array.prototype-generic-functions.js` demonstrates that the function can be applied to other objects besides `Array`.
2020-05-23LibJS: Treat NaN in Value::to_i32() as zeroLinus Groh
Let's treat it as zero like the ECMAScript spec does in toInteger(). That way we can use to_i32() and don't have to care about weird input input values where a number is expected, i.e. "foo".charAt() === "f" "foo".charAt("bar") === "f" "foo".charAt(0) === "f"
2020-05-23LibJS: Fix Array.prototype.lastIndexOf() implementationLinus Groh
2020-05-23LibJS: Treat missing arg in Array.prototype.{indexOf,lastIndexOf}() as undefinedLinus Groh
2020-05-22LibJS: Make Array.prototype.{join,toString}() genericLinus Groh
2020-05-22LibJS: Make Array.prototype.pop() genericLinus Groh
2020-05-22LibJS: Make Array.prototype.push() genericLinus Groh
2020-05-22LibJS: Let Array.prototype.join() ignore additional argumentsLinus Groh
I.e. array.join("x", "y", "z") === array.join("x") rather than array.join("x", "y", "z") === array.join()
2020-05-22LibJS: Add object literal getter/setter shorthandMatthew Olsson
Adds support for the following syntax: let foo = { get x() { // ... }, set x(value) { // ... } }
2020-05-22LibJS: Disallow multiple parameters in paren-less arrow functionLinus Groh
Fixes #2323.
2020-05-21LibJS: Add getter/setter supportMatthew Olsson
This patch adds a GetterSetterPair object. Values can now store pointers to objects of this type. These objects are created when using Object.defineProperty and providing an accessor descriptor.
2020-05-21LibJS: Refactor Array.prototype callback functions and make them genericLinus Groh
2020-05-21LibJS: Treat missing arg in Array.prototype.includes() as undefinedLinus Groh
2020-05-21LibJS: Add Array.prototype.everyLuke
2020-05-18LibJS: Handle hex and unicode escape sequences in string literalsMatthew Olsson
Introduces the following syntax: '\x55' '\u26a0' '\u{1f41e}'
2020-05-18LibJS: Add Math.clz32()Linus Groh
2020-05-18LibJS: Add Math.expm1()Linus Groh
2020-05-18LibJS: Add Math.exp()Linus Groh
2020-05-18LibJS: Add Math.sign()Linus Groh
2020-05-18LibJS: Throw TypeError when coercing symbol to numberLinus Groh
2020-05-18LibJS: Pass Interpreter& to Value::to_number() et al.Linus Groh
This patch is unfortunately rather large and might make some things feel bloated, but it is necessary to fix a few flaws in LibJS, primarily blindly coercing values to numbers without exception checks - i.e. interpreter.argument(0).to_i32(); // can fail!!! Some examples where the interpreter would actually crash: var o = { toString: () => { throw Error() } }; +o; o - 1; "foo".charAt(o); "bar".repeat(o); To fix this, we now have the following... to_double(Interpreter&) to_i32() to_i32(Interpreter&) to_size_t() to_size_t(Interpreter&) ...and a whole lot of exception checking. There's intentionally no to_double(), use as_double() directly instead. This way we still can use these convenient utility functions but don't need to check for exceptions if we are sure the value already is a number. Fixes #2267.
2020-05-17LibJS: Add symbol objectsmattco98
This commit adds the following classes: SymbolObject, SymbolConstructor, SymbolPrototype, and Symbol. This commit does not introduce any new functionality to the Object class, so they cannot be used as property keys in objects.
2020-05-17LibJS: Add Number.parseFloat()Linus Groh
2020-05-17LibJS: Add parseFloat()Linus Groh
2020-05-16LibJS: Make Object.prototype.constructor non-enumerableLinus Groh
2020-05-15LibM: Fix floor() and floorf() for negative numbersAndreas Kling
And add a LibJS test to exercise the code. :^)
2020-05-15LibJS: Add side-effect-free version of Value::to_string()Andreas Kling
There are now two API's on Value: - Value::to_string(Interpreter&) -- may throw. - Value::to_string_without_side_effects() -- will never throw. These are some pretty big sweeping changes, so it's possible that I did some part the wrong way. We'll work it out as we go. :^) Fixes #2123.
2020-05-15LibJS: Let parser keep track of errorsLinus Groh
Rather than printing them to stderr directly the parser now keeps a Vector<Error>, which allows the "owner" of the parser to consume them individually after parsing. The Error struct has a message, line number, column number and a to_string() helper function to format this information into a meaningful error message. The Function() constructor will now include an error message when throwing a SyntaxError.
2020-05-14Build: Switch to CMake :^)Sergey Bugaev
Closes https://github.com/SerenityOS/serenity/issues/2080
2020-05-13LibJS: Trim whitespace from string before coercing to numberLinus Groh
2020-05-13LibJS: Make string to number coercion work for doublesLinus Groh
2020-05-13LibJS: Make the Function() constructor throw a SyntaxError, not returnLinus Groh
2020-05-13LibJS: Check AssignmentExpression LHS in parserLinus Groh
There are many cases which shouldn't even parse, like null = ... true = ... false = ... 123 = ... "foo" = ... However this *is* valid syntax: foo() = ... So we still have to keep the current code doing a runtime check if the LHS value is a resolvable reference. I believe this was declared valid syntax to *in theory* allow functions returning references - though in practice that isn't a thing. Fixes #2204.
2020-05-11LibJS: Parse comma operator into SequenceExpressionLinus Groh
2020-05-08LibJS: Add Array.of()Linus Groh
2020-05-08LibJS: Add Array.isArray()Linus Groh
2020-05-08LibJS: Support multiple arguments in Array constructorLinus Groh
2020-05-08LibJS: Spec-compliant equality comparisonsMatthew Olsson
The ECMAScript spec defines multiple equality operations which are used all over the spec; this patch introduces them. Of course, the two primary equality operations are AbtractEquals ('==') and StrictEquals ('==='), which have been renamed to 'abstract_eq' and 'strict_eq' in this patch. In support of the two operations mentioned above, the following have also been added: SameValue, SameValueZero, and SameValueNonNumeric. These are important to have, because they are used elsewhere in the spec aside from the two primary equality comparisons.
2020-05-07LibJS: Limit scope of 'for' loop variablesYonatan Goldschmidt
This required 2 changes: 1. In the parser, create a new variable scope, so the variable is declared in it instead of the scope in which the 'for' is found. 2. On execute, push the variable into the newly created block. Existing code created an empty block (no variables, no arguments) which allows Interpreter::enter_scope() to skip the creation of a new environment, therefore when the variable initializer is executed, it sets the variable to the outer scope. By attaching the variable to the new block, the block gets a new environment. This is only needed for 'let' / 'const' declarations, since 'var' declarations are expected to leak. Fixes: #2103
2020-05-07LibJS: Add String.rawMatthew Olsson
2020-05-07LibJS: Add raw strings to tagged template literalsMatthew Olsson
When calling a function with a tagged template, the first array that is passed in now contains a "raw" property with the raw, escaped strings.
2020-05-07LibJS: Fix shellcheck warnings in Tests/run-testsEmanuele Torre
2020-05-06LibJS: Add function call spreadingMatthew Olsson
Adds support for the following syntax: myFunction(...x, ...[1, 2, 3], ...o.foo, ...'abcd')
2020-05-06LibJS: Function.length respects default and rest parametersMatthew Olsson
"[Function.length is] the number of formal parameters. This number excludes the rest parameter and only includes parameters before the first one with a default value." - MDN
2020-05-06LibJS: Implement tagged template literals (foo`bar`)Linus Groh
To make processing tagged template literals easier, template literals will now add one empty StringLiteral before and after each template expression *if* there's no other string - e.g.: `${foo}` -> "", foo, "" `test${foo}${bar}test` -> "test", foo, "", bar, "test" This also matches the behaviour of many other parsers.
2020-05-06LibJS: Fix syntax error for arrow function non-decl variable assignmentMatthew Olsson
A regression was introduced in dc9b4da where the parser would incorrectly parse the assignment of arrow functions to (non-declaration) variables. For example, consider: a = () => {} Because the parser was aware of default parameters, in try_parse_arrow_function, the equals sign would be interpreted as a default argument, leading to incorrect parsing of the overall expression. Also resulted in some funny behavior (a = () => {} => {} worked just fine!). The simple fix is to only look for default parameters if the arrow function is required to have parenthesis.