summaryrefslogtreecommitdiff
path: root/Libraries/LibJS
AgeCommit message (Collapse)Author
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-21LibJS: Make Interpreter::call() this_value a required argumentLinus Groh
Right now the default is an empty value, which we accidentally exposed in set{Interval,Timeout}() by not providing a custom this value, which should't happen at all. Let's just make it a required argument instead.
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: Return early from parseFloat() if argument is a numberLinus Groh
This saves us both a bit of time and accuracy, as Serenity's strtod() still is a little bit off sometimes - and stringifying the result and parsing it again just increases that offset.
2020-05-18LibJS: Remove is_nan() check in as_size_t() and fix to_size_t()Linus Groh
We need to call as_double() on the freshly converted number, not the value itself.
2020-05-18LibJS: Rename to_{i32,size_t}() to as_{i32,size_t}() for clarityLinus Groh
As these parameter-less overloads don't change the value's type and just assume Type::Number, naming them as_i32() and as_size_t() is more appropriate.
2020-05-18LibJS: Check for exception after converting object to string primitiveLinus 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-18LibJS: Change Value::to_object(Heap& -> Interpreter&)Linus Groh
Passing a Heap& to it only to then call interpreter() on that is weird. Let's just give it the Interpreter& directly, like some of the other to_something() functions.
2020-05-18LibJS: Remove no-op SymbolPrototype::description_setter()Linus Groh
We can just give put_native_property() a nullptr for the setter.
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: Simplify various StringPrototype functionsLinus Groh
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-15LibJS: Remove syntax errors from lexerLinus Groh
Giving the lexer the ability to generate errors adds unnecessary complexity - also it only calls its syntax_error() function in one place anyway ("unterminated string literal"). But since the lexer *also* emits tokens like Eof or UnterminatedStringLiteral, it should be up to the consumer of these tokens to decide what to do. Also remove the option to not print errors to stderr as that's not relevant anymore.
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: Use String::trim_whitespace() for String.prototype.trim*()Linus 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-13LibJS: Handle empty values in operator<<()Linus Groh
Otherwise something like dbg() << Value(); chokes on ASSERT_NOT_REACHED() in Value::to_string()
2020-05-12LibJS: Add missing keywords/tokensLinus Groh
Some of these are required for syntax we have not implemented yet, some are future reserved words in strict mode.
2020-05-11LibJS: Parse comma operator into SequenceExpressionLinus Groh
2020-05-08LibJS: Correct tiny issue with passing a String to String::formatAnotherTest
I'm not sure how this even _builds_
2020-05-08LibJS: Be a bit more explicit about sizeof(buf) / sizeof(FlatPtr)AnotherTest
This (seemingly) no-op cast communicates our intention to clang
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: Add Value::is_integer()Linus 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