mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
LibJS: New expressions look for expressions with correct precedence
This commit is contained in:
parent
688ca7b196
commit
5cd01ed79e
2 changed files with 52 additions and 2 deletions
|
@ -893,8 +893,7 @@ NonnullRefPtr<NewExpression> Parser::parse_new_expression()
|
||||||
{
|
{
|
||||||
consume(TokenType::New);
|
consume(TokenType::New);
|
||||||
|
|
||||||
// FIXME: Support full expressions as the callee as well.
|
auto callee = parse_expression(g_operator_precedence.get(TokenType::New).value(), Associativity::Right, { TokenType::ParenOpen });
|
||||||
auto callee = create_ast_node<Identifier>(consume(TokenType::Identifier).value());
|
|
||||||
|
|
||||||
Vector<CallExpression::Argument> arguments;
|
Vector<CallExpression::Argument> arguments;
|
||||||
|
|
||||||
|
|
51
Libraries/LibJS/Tests/new-expression.js
Normal file
51
Libraries/LibJS/Tests/new-expression.js
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
load("test-common.js");
|
||||||
|
|
||||||
|
try {
|
||||||
|
function Foo() { this.x = 1; }
|
||||||
|
|
||||||
|
let foo = new Foo();
|
||||||
|
assert(foo.x === 1);
|
||||||
|
|
||||||
|
foo = new Foo
|
||||||
|
assert(foo.x === 1);
|
||||||
|
|
||||||
|
foo = new
|
||||||
|
Foo
|
||||||
|
()
|
||||||
|
assert(foo.x === 1);
|
||||||
|
|
||||||
|
foo = new Foo + 2
|
||||||
|
assert(foo === "[object Object]2");
|
||||||
|
|
||||||
|
let a = {
|
||||||
|
b: function() {
|
||||||
|
this.x = 2;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
foo = new a.b();
|
||||||
|
assert(foo.x === 2);
|
||||||
|
|
||||||
|
foo = new a.b;
|
||||||
|
assert(foo.x === 2);
|
||||||
|
|
||||||
|
foo = new
|
||||||
|
a.b();
|
||||||
|
assert(foo.x === 2);
|
||||||
|
|
||||||
|
function funcGetter() {
|
||||||
|
return function(a, b) {
|
||||||
|
this.x = a + b;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
foo = new funcGetter()(1, 5);
|
||||||
|
assert(foo === undefined);
|
||||||
|
|
||||||
|
foo = new (funcGetter())(1, 5);
|
||||||
|
assert(foo.x === 6);
|
||||||
|
|
||||||
|
console.log("PASS");
|
||||||
|
} catch (e) {
|
||||||
|
console.log("FAIL: " + e);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue