Andreas Kling
e3b92caa6d
LibJS: Make "break" actually work inside "switch"
2020-04-05 00:09:48 +02:00
Andreas Kling
97cd1173fa
LibJS: Add String.prototype.indexOf()
2020-04-04 23:44:29 +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
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
f8393b80e3
LibJS: Add support for do..while statements
2020-04-04 21:29:23 +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
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
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
Jack Karamanian
bb15b37228
LibJS: Evaluate CallExpression arguments before pushing a CallFrame
2020-04-02 08:50:28 +02:00
Linus Groh
a0da97cb5a
LibJS: Add NaN to global object
2020-04-01 22:09:37 +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
Jack Karamanian
098f1cd0ca
LibJS: Add support for arrow functions
2020-03-30 15:41:36 +02:00
Linus Groh
fb0401871c
LibJS: Throw TypeError when calling non-function object
...
We now have "undefined is not a function" :^)
2020-03-30 14:43:58 +02:00
Linus Groh
d4e3688f4f
LibJS: Start implementing Date :^)
...
This adds:
- A global Date object (with `length` property and `now` function)
- The Date constructor (no arguments yet)
- The Date prototype (with `get*` functions)
2020-03-30 14:11:54 +02:00
Linus Groh
0a94661c14
LibJS: Implement String.prototype.startsWith()
2020-03-29 19:37:16 +02:00
Linus Groh
402fd5a3a3
LibJS: Add tests for Math constants
2020-03-29 17:35:08 +02:00
Linus Groh
c698cc899d
LibJS: Add tests for value to number conversion
2020-03-29 16:45:11 +02:00
Andreas Kling
2d3634d5f5
LibJS: Implement Math.abs()
2020-03-29 15:03:58 +02:00
Andreas Kling
2285f84596
LibJS: Implement basic execution of "switch" statements
...
The "break" keyword now unwinds to the nearest ScopeType::Breakable.
There's no support for break labels yet, but we'll get there too.
2020-03-29 15:03:58 +02:00
Andreas Kling
f95a119627
LibJS: Implement Object.getOwnPropertyNames()
2020-03-29 01:26:57 +01:00
Linus Groh
c209ea1985
LibJS: Implement Array.prototype.{shift,pop}
2020-03-28 22:18:11 +01:00
Andreas Kling
82ca7ae1f8
LibJS: Oops, "instanceof" was backwards!
...
Fix the "instanceof" operator to check if the constructor's prototype
property occurs anywhere in the prototype chain of the instance object.
This patch also adds Object.setPrototypeOf() to make it possible to
create a test for this bug.
Thanks to DexesTTP for pointing this out! :^)
2020-03-28 19:48:12 +01:00
Andreas Kling
14047ca432
LibJS: Add a global "Object" constructor
...
This patch adds an "Object" constructor to the global object. The only
function it implements so far is Object.getPrototypeOf().
2020-03-28 17:23:54 +01:00
Andreas Kling
a3d92b1210
LibJS: Implement the "instanceof" operator
...
This operator walks the prototype chain of the RHS value and looks for
a "prototype" property with the same value as the prototype of the LHS.
This is pretty cool. :^)
2020-03-28 16:56:54 +01:00
Andreas Kling
0593ce406b
LibJS: Implement basic support for the "new" keyword
...
NewExpression mostly piggybacks on the existing CallExpression. The big
difference is that "new" creates a new Object and passes it as |this|
to the callee.
2020-03-28 16:33:52 +01:00
Andreas Kling
14de45296e
LibJS: Fix broken parsing of !o.a
...
Unary expressions parsing now respects precedence and associativity of
operators. This patch also makes `typeof` left-associative which was
an oversight.
Thanks to Conrad for helping me work this out. :^)
2020-03-28 11:51:44 +01:00
Andreas Kling
0cbbf6f5eb
LibJS: Add a tiny little test for the ReferenceError exception
2020-03-28 10:27:48 +01:00
Andreas Kling
6a5cd32205
LibJS: The global isNaN() should coerce to number before testing NaN
...
For stricter NaN checking, we'll have to implement Number.isNaN().
2020-03-27 12:59:41 +01:00
Andreas Kling
c60dc84a33
LibJS: Allow function calls with missing arguments
...
We were interpreting "undefined" as a variable lookup failure in some
cases and throwing a ReferenceError exception instead of treating it
as the valid value "undefined".
This patch wraps the result of variable lookup in Optional<>, which
allows us to only throw ReferenceError when lookup actually fails.
2020-03-27 12:56:05 +01:00
Andreas Kling
04ced9e24a
LibJS: Add global isNaN() function
2020-03-27 12:45:36 +01:00
Andreas Kling
9a78b4af2c
LibJS: Basic NaN support
...
This patch adds js_nan() for constructing a NaN value. You can check
if a Value is NaN with Value::is_nan().
2020-03-27 12:40:22 +01:00
Andreas Kling
6c9d2cfa5e
LibJS: Handle "for" statements with empty initializer and updater
2020-03-25 16:14:51 +01:00
Andreas Kling
30d24af54a
LibJS: Add a basic test for the "throw" keyword
2020-03-25 16:09:23 +01:00
Andreas Kling
9e8d3d6287
LibJS: Rename some tests
...
"feature-basic" is a bit more logical than having a ton of
"basic-feature" (when it comes to the visual overview of it all.)
2020-03-25 15:57:18 +01:00
Andreas Kling
78923d986e
LibJS: Tweak run-tests output a bit
2020-03-25 15:52:17 +01:00
Andreas Kling
45488401b1
LibJS: Add a very basic test runner (shell script) + some tests
2020-03-25 15:32:17 +01:00