Andreas Kling
d84de532f1
LibJS: Add Math.max()
2020-04-05 00:57:00 +02:00
Andreas Kling
16bd99aa52
LibJS: Add Math.round()
2020-04-05 00:29:01 +02:00
Andreas Kling
afff228308
LibJS: Add Math.floor()
2020-04-05 00:26:56 +02:00
Andreas Kling
3c99c27db4
LibJS: Clean up the anonymous wrapper block in "for" using ScopeGuard
...
This ensures that we don't forget to pop the wrapper off of the scope
stack when returning early due to an exception or some such. :^)
2020-04-05 00:24:32 +02:00
Andreas Kling
9ebd066ac8
LibJS: Add support for "continue" inside "for" statements :^)
2020-04-05 00:22:42 +02:00
Andreas Kling
e3b92caa6d
LibJS: Make "break" actually work inside "switch"
2020-04-05 00:09:48 +02:00
Andreas Kling
2db8716a6f
LibJS: Don't return the "last computed value" from Interpreter::run()
...
Only return whatever a "return" statment told us to return.
The last computed value is now available in Interpreter::last_value()
instead, where the REPL can pick it up.
2020-04-04 23:45:13 +02:00
Andreas Kling
97cd1173fa
LibJS: Add String.prototype.indexOf()
2020-04-04 23:44:29 +02:00
Andreas Kling
9e05672f87
LibJS: Math.sqrt.length should be 1
2020-04-04 23:28:38 +02:00
Andreas Kling
a860a3f793
LibJS: Hack the lexer to allow numbers with decimals
...
This is very hackish and should definitely be improved. :^)
2020-04-04 23:13:48 +02:00
Andreas Kling
3a026a1ede
LibJS: Add NumberObject and make to_object() on number values create it
2020-04-04 23:13:13 +02:00
Andreas Kling
d4dfe7e525
LibJS: Add Math.sqrt()
2020-04-04 22:44:48 +02:00
Andreas Kling
d155491122
LibJS: Add basic Array constructor
...
We only support Array() with 0 or 1 parameters so far.
2020-04-04 22:28:21 +02:00
Andreas Kling
eabdbe0ee9
LibJS: Log when we throw a JavaScript Error
...
This makes debugging a lot easier since we actually learn that an Error
got thrown.
2020-04-04 22:14:38 +02:00
Andreas Kling
5e40aa182b
LibJS: Support VariableDeclaration with multiple declarators
...
This patch adds support in the parser and interpreter for this:
var a = 1, b = 2, c = a + b;
VariableDeclaration is now a sequence of VariableDeclarators. :^)
2020-04-04 21:47:12 +02:00
Andreas Kling
9691286cf0
LibJS: Add Declaration class to the AST
...
This is just here to make the AST class hierarchy more spec-like.
2020-04-04 21:32:10 +02:00
Andreas Kling
f8393b80e3
LibJS: Add support for do..while statements
2020-04-04 21:29:23 +02:00
Andreas Kling
da0715aba9
LibJS: Rename WhileStatement::predicate() => body()
...
This name matches other parsers.
2020-04-04 21:22:03 +02:00
Andreas Kling
644ff1bbfd
LibJS: Add basic support for modulo (%) in binary expressions
2020-04-04 21:17:34 +02:00
Andreas Kling
9c8363bb5f
LibJS: Allow "for" statement without curly braces around body
2020-04-04 21:09:06 +02:00
Linus Groh
2944039d6b
LibJS: Add Function() and Function.prototype
2020-04-04 15:58:49 +02:00
Linus Groh
4d931b524d
LibJS: Add length property to ScriptFunction
2020-04-04 15:58:49 +02:00
Linus Groh
cd3e2690eb
LibJS: Set length property in Object::put_native_function()
2020-04-04 15:58:49 +02:00
Andreas Kling
faac43597a
LibJS: Add js_string(Interpreter&, String)
2020-04-04 12:58:05 +02:00
Andreas Kling
a502ba73dc
LibJS: Correctly forward declare "Argument" as a struct
2020-04-04 10:46:00 +02:00
Stephan Unverwerth
520311eb8b
LibJS: Add short circuit logical evaluation
...
When evaluating logical binop expressions, the rhs must not be
evaluated if the lhs leads to the whole expression not being
truthy.
2020-04-03 19:17:52 +02:00
Linus Groh
6e5f9e20eb
LibJS: Fix logical expressions
...
The current implementation of logical AND (&&) and logical OR (||)
always returns a boolean - this is not correct.
2020-04-03 16:32:36 +02:00
Linus Groh
a58640ce6b
LibJS: Parse binary bitwise operators
...
The Lexer and AST already have all the functionality required in place,
so this is just updating Parser::match_secondary_expression() and
Parser::parse_expression() to handle TokenType::{Ampersand,Pipe,Caret},
as well as adding some tests.
2020-04-03 14:10:09 +02:00
Andreas Kling
0622181d1f
LibJS: Implement ConditionalExpression (ternary "?:" operator)
2020-04-03 12:15:14 +02:00
Linus Groh
94afcb54de
LibJS: Implement Error.prototype.toString()
2020-04-03 09:07:05 +02:00
Linus Groh
2636cac6e4
LibJS: Remove UndefinedLiteral, add undefined to global object
...
There is no such thing as a "undefined literal" in JS - undefined is
just a property on the global object with a value of undefined.
This is pretty similar to NaN.
var undefined = "foo"; is a perfectly fine AssignmentExpression :^)
2020-04-03 00:10:52 +02:00
Linus Groh
543c6e00db
LibJS: Implement Infinity
2020-04-02 21:52:15 +02:00
Andreas Kling
99aab4470a
LibJS: Object::put() shouldn't create own properties on prototype chain
...
Unless there is a setter present on the prototype chain, put() should
only set own properties on the object itself.
Fixes #1588 .
2020-04-02 21:36:14 +02:00
Linus Groh
a62230770b
LibJS: Implement unary plus / minus
2020-04-02 19:55:45 +02:00
Andreas Kling
5e6e1fd482
LibJS: Start implementing object shapes
...
This patch adds JS::Shape, which implements a transition tree for our
Object class. Object property keys, prototypes and attributes are now
stored in a Shape, and each Object has a Shape.
When adding a property to an Object, we make a transition from the old
Shape to a new Shape. If we've made the same exact transition in the
past (with another Object), we reuse the same transition and both
objects may now share a Shape.
This will become the foundation of inline caching and other engine
optimizations in the future. :^)
2020-04-02 19:32:21 +02:00
Andreas Kling
fbb16073d1
LibJS: Make JS::Cell non-copyable and non-movable
...
Also make the JS::Cell default constructor protected to provove a
compilation error if you tried to allocate a plain cell.
2020-04-02 15:24:50 +02:00
Andreas Kling
c683665ca9
LibJS: Fix bad cast in Interpreter::run()
...
We were casting to BlockStatement when we should cast to ScopeNode.
2020-04-02 09:56:13 +02:00
Jack Karamanian
bb15b37228
LibJS: Evaluate CallExpression arguments before pushing a CallFrame
2020-04-02 08:50:28 +02:00
Andreas Kling
cd1d369cdd
LibJS: Add argument(i) and argument_count() to Interpreter
...
Add some convenience accessors for retrieving arguments from the
current call frame.
2020-04-01 22:38:59 +02:00
Andreas Kling
1549c5c48b
LibJS: Make Value::as_object() return Object&
...
Let's move towards using references over pointers in LibJS as well.
I had originally steered away from it because that's how I've seen
things done in other engines. But this is not the other engines. :^)
2020-04-01 22:18:47 +02:00
Linus Groh
a0da97cb5a
LibJS: Add NaN to global object
2020-04-01 22:09:37 +02:00
Andreas Kling
9d5d0261e1
LibJS: Add Interpreter::create<GlobalObjectType>()
...
Force Interpreter construction to go via a create() helper that takes
the global object type as a template parameter.
2020-04-01 21:05:35 +02:00
Andreas Kling
aee4c1f583
LibJS: Add GlobalObject to the forwarding header
2020-04-01 21:05:35 +02:00
Linus Groh
ee6472fef2
LibJS: Implement Error function/constructor
2020-04-01 20:47:37 +02:00
Linus Groh
849e2c77e4
LibJS: Implement constructor/non-constructor function calls
...
This adds Function::construct() for constructor function calls via `new`
keyword. NativeFunction doesn't have constructor behaviour by default,
ScriptFunction simply calls call() in construct()
2020-04-01 20:18:36 +02:00
Andreas Kling
d062d7baa7
LibWeb+LibJS: Move DOM Window object to dedicated classes
...
LibWeb now creates a WindowObject which inherits from GlobalObject.
Allocation of the global object is moved out of the Interpreter ctor
to allow for specialized construction.
The existing Window interfaces are moved to WindowObject with their
implementation code in the new Window class.
2020-04-01 18:57:00 +02:00
Andreas Kling
cd9379dca9
LibJS: Reorganize computing of |this| for CallExpressions
...
This avoids executing the LHS of the object expression twice when doing
a call on the result of an object expression.
2020-04-01 18:57:00 +02:00
Linus Groh
632231cc0c
js: Implement print function for Date objects
2020-03-31 21:19:21 +02:00
Andreas Kling
a8dc6501de
LibJS: Use "%d" to stringify numeric values that are whole integers
...
This unbreaks a bunch of the JS tests since they were now printing all
the numbers as "1.000000" instead of "1".
2020-03-31 19:06:10 +02:00
Linus Groh
3fcea71538
LibJS: Implement Date.prototype.to{Date,Time}String()
2020-03-30 21:43:35 +02:00