summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/AST.h
AgeCommit message (Collapse)Author
2020-06-29LibJS: Initial class implementation; allow super expressions in objectJack Karamanian
literal methods; add EnvrionmentRecord fields and methods to LexicalEnvironment Adding EnvrionmentRecord's fields and methods lets us throw an exception when |this| is not initialized, which occurs when the super constructor in a derived class has not yet been called, or when |this| has already been initialized (the super constructor was already called).
2020-06-08LibJS: Pass GlobalObject& to AST node execute() functionsAndreas Kling
More work towards supporting multiple global objects.
2020-06-07LibJS: Add BigIntLinus Groh
2020-06-07LibJS: Lex and parse regex literals, add RegExp objectsMatthew Olsson
This adds regex parsing/lexing, as well as a relatively empty RegExpObject. The purpose of this patch is to allow the engine to not get hung up on parsing regexes. This will aid in finding new syntax errors (say, from google or twitter) without having to replace all of their regexes first!
2020-06-06LibJS: Hoist function declarationsMarcin Gasperowicz
This patch adds function declaration hoisting. The mechanism is similar to var hoisting. Hoisted function declarations are to be put before the hoisted var declarations, hence they have to be treated separately.
2020-06-01LibJS: Rewrite Parser.parse_object_expression()Matthew Olsson
This rewrite drastically increases the accuracy of object literals. Additionally, an "assertIsSyntaxError" function has been added to test-common.js to assist in testing syntax errors.
2020-05-30LibJS: Track whether ScriptFunctions and FunctionExpressions are arrowJack Karamanian
functions
2020-05-29LibJS: Parse labels in continue and break statementsMatthew Olsson
2020-05-29LibJS: Parse labelled statementsMatthew Olsson
All statements now have an optional label string that can be null.
2020-05-28LibJS: Add strict modeMatthew Olsson
Adds the ability for a scope (either a function or the entire program) to be in strict mode. Scopes default to non-strict mode. There are two ways to determine the strict-ness of the JS engine: 1. In the parser, this can be accessed with the parser_state variable m_is_strict_mode boolean. If true, the Parser is currently parsing in strict mode. This is done so that the Parser can generate syntax errors at parse time, which is required in some cases. 2. With Interpreter.is_strict_mode(). This allows strict mode checking at runtime as opposed to compile time. Additionally, in order to test this, a global isStrictMode() function has been added to the JS ReplObject under the test-mode flag.
2020-05-26LibJS: Fix style inconsistencies in AST.h (#2403)Emanuele Torre
Our current configuration clang-format allows both of these styles: ------------------ class A : B , C { ----------------- class A : B , C { ------------------ I was not able to find a setting of clang-format to only allow the latter style (or disallow the first style), but let's at least be consistent with the style within a file.
2020-05-25LibJS: Implement basic for..in and for..of loopsLinus Groh
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-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-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-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-05LibJS: Implement modulo assignment operator (%=)Linus Groh
2020-05-05LibJS: Implement exponentiation assignment operator (**=)Linus Groh
2020-05-05LibJS: Implement bitwise assignment operators (&=, |=, ^=)Linus Groh
2020-05-05LibJS: run clang-format on all the filesEmanuele Torre
2020-05-04LibJS: Implement rest parametersLinus Groh
2020-05-04LibJS: Add template literalsmattco98
Adds fully functioning template literals. Because template literals contain expressions, most of the work has to be done in the Lexer rather than the Parser. And because of the complexity of template literals (expressions, nesting, escapes, etc), the Lexer needs to have some template-related state. When entering a new template literal, a TemplateLiteralStart token is emitted. When inside a literal, all text will be parsed up until a '${' or '`' (or EOF, but that's a syntax error) is seen, and then a TemplateLiteralExprStart token is emitted. At this point, the Lexer proceeds as normal, however it keeps track of the number of opening and closing curly braces it has seen in order to determine the close of the expression. Once it finds a matching curly brace for the '${', a TemplateLiteralExprEnd token is emitted and the state is updated accordingly. When the Lexer is inside of a template literal, but not an expression, and sees a '`', this must be the closing grave: a TemplateLiteralEnd token is emitted. The state required to correctly parse template strings consists of a vector (for nesting) of two pieces of information: whether or not we are in a template expression (as opposed to a template string); and the count of the number of unmatched open curly braces we have seen (only applicable if the Lexer is currently in a template expression). TODO: Add support for template literal newlines in the JS REPL (this will cause a syntax error currently): > `foo > bar` 'foo bar'
2020-05-03LibJS: Support empty statementsLinus Groh
We already skipped random semicolons in Parser::parse_program(), but now they are properly matched and parsed as empty statements - and thus recognized as a valid body of an if / else / while / ... statement.
2020-05-03LibJS: Add function default argumentsMatthew Olsson
Adds the ability for function arguments to have default values. This works for standard functions as well as arrow functions. Default values are not printed in a <function>.toString() call, as nodes cannot print their source string representation.
2020-05-01LibJS: Implement (no-op) debugger statementLinus Groh
2020-04-28LibJS: Add spreading in object literalsmattco98
Supports spreading strings, arrays, and other objects within object literals.
2020-04-28LibJS: Make AssignmentExpression assign through a ReferenceAndreas Kling
Reference now has assign(Interpreter&, Value) which is used to write transparently through a Reference into whatever location it refers to.
2020-04-28LibJS: Allow "delete someGlobalVariable"Andreas Kling
This is solved by allowing Identifier nodes to produce a Reference with the global object as base.
2020-04-28LibJS: Add Reference class to represent a base.property referenceAndreas Kling
Expression nodes can now be asked to produce a Reference. We then use this to implement the "delete" operator without downcasting the child node to a MemberExpression manually.
2020-04-27LibJS: Add spreading in array literalsmattco98
Implement the syntax and behavor necessary to support array literals such as [...[1, 2, 3]]. A type error is thrown if the target of the spread operator does not evaluate to an array (though it should eventually just check for an iterable). Note that the spread token's name is TripleDot, since the '...' token is used for two features: spread and rest. Calling it anything involving 'spread' or 'rest' would be a bit confusing.
2020-04-26LibJS: Implement basic support for the "delete" operatorAndreas Kling
It turns out "delete" is actually a unary op :) This patch implements deletion of object properties, it doesn't yet work for casually deleting properties from the global object. When deleting a property from an object, we switch that object to having a unique shape, no longer sharing shapes with others. Once an object has a unique shape, it no longer needs to care about shape transitions.
2020-04-23LibJS: Implement computed properties in object expressionsLinus Groh
2020-04-23LibJS: Implement 'in' operatorLinus Groh
2020-04-23LibJS: Implement bitwise unsigned right shift operator (>>>)Linus Groh
2020-04-23LibJS: Implement bitwise right shift operator (>>)Linus Groh
2020-04-23LibJS: Implement bitwise left shift operator (<<)Linus Groh
2020-04-19LibJS: Improve CallExpression::execute()'s error messagesLinus Groh
2020-04-18LibJS: Implement nullish coalescing operator (??)Linus Groh
2020-04-15LibJS: Support empty values in array expressionLinus Groh
2020-04-15LibJS: Implement void operatorLinus Groh
2020-04-13LibJS: Hoist variable declarations to the nearest relevant scopeAndreas Kling
"var" declarations are hoisted to the nearest function scope, while "let" and "const" are hoisted to the nearest block scope. This is done by the parser, which keeps two scope stacks, one stack for the current var scope and one for the current let/const scope. When the interpreter enters a scope, we walk all of the declarations and insert them into the variable environment. We don't support the temporal dead zone for let/const yet.
2020-04-13LibJS: Parse "this" as ThisExpressionStephan Unverwerth
2020-04-11LibJS: Make Function and CallFrame aware of their function nameLinus Groh
2020-04-08LibJS: rename JS::DeclarationType => JS::DeclarationKindEmanuele Torre
Many other parsers call it with this name. Also Type can be confusing in this context since the DeclarationType is not the type (number, string, etc.) of the variables that are being declared by the VariableDeclaration.
2020-04-07LibJS: Add SequenceExpression AST node (comma operator)Andreas Kling
This patch only adds the AST node, the parser doesn't create them yet.
2020-04-06LibJS: Add a PropertyName class that represents a string or a numberAndreas Kling
Now that we have two separate storages for Object properties depending on what kind of index they have, it's nice to have an abstraction that still allows us to say "here's a property name". We use PropertyName to always choose the optimal storage path directly while interpreting the AST. :^)
2020-04-05LibJS: Implement exponentiation (** operator)Linus Groh
2020-04-05LibJS: Rename BinaryOp::{Plus,Minus,Asterisk,Slash}Linus Groh