mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 16:47:42 +00:00
LibJS: Use CreateUnmappedArgumentsObject for non-simple parameter lists
This patch implements the IsSimpleParameterList static semantics for ordinary function objects. We now also create an unmapped arguments object for callee contexts with non-simple parameter lists, instead of only doing it in strict mode. Covered by test262.
This commit is contained in:
parent
e2e695bc9f
commit
d1ffeaf66d
3 changed files with 18 additions and 1 deletions
|
@ -57,12 +57,17 @@ public:
|
||||||
ThisMode this_mode() const { return m_this_mode; }
|
ThisMode this_mode() const { return m_this_mode; }
|
||||||
void set_this_mode(ThisMode this_mode) { m_this_mode = this_mode; }
|
void set_this_mode(ThisMode this_mode) { m_this_mode = this_mode; }
|
||||||
|
|
||||||
|
// This is for IsSimpleParameterList (static semantics)
|
||||||
|
bool has_simple_parameter_list() const { return m_has_simple_parameter_list; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void visit_edges(Visitor&) override;
|
virtual void visit_edges(Visitor&) override;
|
||||||
|
|
||||||
explicit FunctionObject(Object& prototype);
|
explicit FunctionObject(Object& prototype);
|
||||||
FunctionObject(Value bound_this, Vector<Value> bound_arguments, Object& prototype);
|
FunctionObject(Value bound_this, Vector<Value> bound_arguments, Object& prototype);
|
||||||
|
|
||||||
|
void set_has_simple_parameter_list(bool b) { m_has_simple_parameter_list = b; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool is_function() const override { return true; }
|
virtual bool is_function() const override { return true; }
|
||||||
Value m_bound_this;
|
Value m_bound_this;
|
||||||
|
@ -70,6 +75,7 @@ private:
|
||||||
Value m_home_object;
|
Value m_home_object;
|
||||||
ConstructorKind m_constructor_kind = ConstructorKind::Base;
|
ConstructorKind m_constructor_kind = ConstructorKind::Base;
|
||||||
ThisMode m_this_mode { ThisMode::Global };
|
ThisMode m_this_mode { ThisMode::Global };
|
||||||
|
bool m_has_simple_parameter_list { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,17 @@ OrdinaryFunctionObject::OrdinaryFunctionObject(GlobalObject& global_object, cons
|
||||||
set_this_mode(ThisMode::Strict);
|
set_this_mode(ThisMode::Strict);
|
||||||
else
|
else
|
||||||
set_this_mode(ThisMode::Global);
|
set_this_mode(ThisMode::Global);
|
||||||
|
|
||||||
|
// 15.1.3 Static Semantics: IsSimpleParameterList, https://tc39.es/ecma262/#sec-static-semantics-issimpleparameterlist
|
||||||
|
set_has_simple_parameter_list(all_of(m_parameters.begin(), m_parameters.end(), [&](auto& parameter) {
|
||||||
|
if (parameter.is_rest)
|
||||||
|
return false;
|
||||||
|
if (parameter.default_value)
|
||||||
|
return false;
|
||||||
|
if (!parameter.binding.template has<FlyString>())
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OrdinaryFunctionObject::initialize(GlobalObject& global_object)
|
void OrdinaryFunctionObject::initialize(GlobalObject& global_object)
|
||||||
|
|
|
@ -369,7 +369,7 @@ Value VM::get_variable(const FlyString& name, GlobalObject& global_object)
|
||||||
if (possible_match.has_value())
|
if (possible_match.has_value())
|
||||||
return possible_match.value().value;
|
return possible_match.value().value;
|
||||||
if (!context.arguments_object) {
|
if (!context.arguments_object) {
|
||||||
if (context.function->is_strict_mode()) {
|
if (context.function->is_strict_mode() || !context.function->has_simple_parameter_list()) {
|
||||||
context.arguments_object = create_unmapped_arguments_object(global_object, context.arguments);
|
context.arguments_object = create_unmapped_arguments_object(global_object, context.arguments);
|
||||||
} else {
|
} else {
|
||||||
// FIXME: This code path is completely ad-hoc.
|
// FIXME: This code path is completely ad-hoc.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue