mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:57:35 +00:00
LibJS: Evaluate CallExpression arguments before pushing a CallFrame
This commit is contained in:
parent
8f08ec5038
commit
bb15b37228
2 changed files with 23 additions and 2 deletions
|
@ -101,16 +101,20 @@ Value CallExpression::execute(Interpreter& interpreter) const
|
||||||
|
|
||||||
auto& function = static_cast<Function&>(callee.as_object());
|
auto& function = static_cast<Function&>(callee.as_object());
|
||||||
|
|
||||||
auto& call_frame = interpreter.push_call_frame();
|
Vector<Value> arguments;
|
||||||
|
arguments.ensure_capacity(m_arguments.size());
|
||||||
for (size_t i = 0; i < m_arguments.size(); ++i) {
|
for (size_t i = 0; i < m_arguments.size(); ++i) {
|
||||||
auto value = m_arguments[i].execute(interpreter);
|
auto value = m_arguments[i].execute(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
call_frame.arguments.append(value);
|
arguments.append(value);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto& call_frame = interpreter.push_call_frame();
|
||||||
|
call_frame.arguments = move(arguments);
|
||||||
|
|
||||||
Object* new_object = nullptr;
|
Object* new_object = nullptr;
|
||||||
Value result;
|
Value result;
|
||||||
if (is_new_expression()) {
|
if (is_new_expression()) {
|
||||||
|
|
17
Libraries/LibJS/Tests/function-this-in-arguments.js
Normal file
17
Libraries/LibJS/Tests/function-this-in-arguments.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
function assert(x) { if (!x) throw 1; }
|
||||||
|
|
||||||
|
try {
|
||||||
|
assert(typeof this === "object");
|
||||||
|
assert(this === global);
|
||||||
|
|
||||||
|
function Foo() {
|
||||||
|
this.x = 5;
|
||||||
|
assert(typeof this === "object");
|
||||||
|
assert(this.x === 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
new Foo();
|
||||||
|
console.log("PASS");
|
||||||
|
} catch (err) {
|
||||||
|
console.log("FAIL: " + err);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue