mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:47:46 +00:00
LibJS: Strict mode is now handled by Functions and Programs, not Blocks
Since blocks can't be strict by themselves, it makes no sense for them to store whether or not they are strict. Strict-ness is now stored in the Program and FunctionNode ASTNodes. Fixes issue #3641
This commit is contained in:
parent
1b3f9c170c
commit
6eb6752c4c
10 changed files with 92 additions and 37 deletions
|
@ -47,18 +47,19 @@ static ScriptFunction* typed_this(VM& vm, GlobalObject& global_object)
|
|||
return static_cast<ScriptFunction*>(this_object);
|
||||
}
|
||||
|
||||
ScriptFunction* ScriptFunction::create(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, bool is_arrow_function)
|
||||
ScriptFunction* ScriptFunction::create(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, bool is_strict, bool is_arrow_function)
|
||||
{
|
||||
return global_object.heap().allocate<ScriptFunction>(global_object, global_object, name, body, move(parameters), m_function_length, parent_environment, *global_object.function_prototype(), is_arrow_function);
|
||||
return global_object.heap().allocate<ScriptFunction>(global_object, global_object, name, body, move(parameters), m_function_length, parent_environment, *global_object.function_prototype(), is_strict, is_arrow_function);
|
||||
}
|
||||
|
||||
ScriptFunction::ScriptFunction(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, Object& prototype, bool is_arrow_function)
|
||||
ScriptFunction::ScriptFunction(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, Object& prototype, bool is_strict, bool is_arrow_function)
|
||||
: Function(prototype, is_arrow_function ? vm().this_value(global_object) : Value(), {})
|
||||
, m_name(name)
|
||||
, m_body(body)
|
||||
, m_parameters(move(parameters))
|
||||
, m_parent_environment(parent_environment)
|
||||
, m_function_length(m_function_length)
|
||||
, m_is_strict(is_strict)
|
||||
, m_is_arrow_function(is_arrow_function)
|
||||
{
|
||||
}
|
||||
|
@ -140,7 +141,7 @@ Value ScriptFunction::call()
|
|||
arguments.append({ parameter.name, value });
|
||||
vm().current_environment()->set(global_object(), parameter.name, { value, DeclarationKind::Var });
|
||||
}
|
||||
return interpreter->execute_statement(global_object(), m_body, arguments, ScopeType::Function);
|
||||
return interpreter->execute_statement(global_object(), m_body, arguments, ScopeType::Function, m_is_strict);
|
||||
}
|
||||
|
||||
Value ScriptFunction::construct(Function&)
|
||||
|
|
|
@ -35,9 +35,9 @@ class ScriptFunction final : public Function {
|
|||
JS_OBJECT(ScriptFunction, Function);
|
||||
|
||||
public:
|
||||
static ScriptFunction* create(GlobalObject&, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, bool is_arrow_function = false);
|
||||
static ScriptFunction* create(GlobalObject&, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, bool is_strict, bool is_arrow_function = false);
|
||||
|
||||
ScriptFunction(GlobalObject&, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, Object& prototype, bool is_arrow_function = false);
|
||||
ScriptFunction(GlobalObject&, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, Object& prototype, bool is_strict, bool is_arrow_function = false);
|
||||
virtual void initialize(GlobalObject&) override;
|
||||
virtual ~ScriptFunction();
|
||||
|
||||
|
@ -63,6 +63,7 @@ private:
|
|||
const Vector<FunctionNode::Parameter> m_parameters;
|
||||
LexicalEnvironment* m_parent_environment { nullptr };
|
||||
i32 m_function_length;
|
||||
bool m_is_strict;
|
||||
bool m_is_arrow_function;
|
||||
};
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ struct ScopeFrame {
|
|||
ScopeType type;
|
||||
NonnullRefPtr<ScopeNode> scope_node;
|
||||
bool pushed_environment { false };
|
||||
bool is_strict_mode { false };
|
||||
};
|
||||
|
||||
struct CallFrame {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue