mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-27 21:21:50 +03:00
LibJS: Rename FunctionKind::{Regular => Normal}
This is what CreateDynamicFunction calls it.
This commit is contained in:
parent
0d65af5e0f
commit
0c73fbbba5
Notes:
sideshowbarker
2024-07-17 20:48:53 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/0c73fbbba51 Pull-request: https://github.com/SerenityOS/serenity/pull/11929 Reviewed-by: https://github.com/IdanHo Reviewed-by: https://github.com/davidot ✅
@ -1633,7 +1633,7 @@ ThrowCompletionOr<ClassElement::ClassValue> ClassField::class_element_evaluation
|
||||
|
||||
// FIXME: A potential optimization is not creating the functions here since these are never directly accessible.
|
||||
auto function_code = create_ast_node<ClassFieldInitializerStatement>(m_initializer->source_range(), copy_initializer.release_nonnull(), name);
|
||||
initializer = ECMAScriptFunctionObject::create(interpreter.global_object(), String::empty(), *function_code, {}, 0, interpreter.lexical_environment(), interpreter.vm().running_execution_context().private_environment, FunctionKind::Regular, true, false, m_contains_direct_call_to_eval, false);
|
||||
initializer = ECMAScriptFunctionObject::create(interpreter.global_object(), String::empty(), *function_code, {}, 0, interpreter.lexical_environment(), interpreter.vm().running_execution_context().private_environment, FunctionKind::Normal, true, false, m_contains_direct_call_to_eval, false);
|
||||
initializer->make_method(target);
|
||||
}
|
||||
|
||||
@ -1675,7 +1675,7 @@ ThrowCompletionOr<ClassElement::ClassValue> StaticInitializer::class_element_eva
|
||||
// 4. Let formalParameters be an instance of the production FormalParameters : [empty] .
|
||||
// 5. Let bodyFunction be OrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParameters, ClassStaticBlockBody, non-lexical-this, lex, privateScope).
|
||||
// Note: The function bodyFunction is never directly accessible to ECMAScript code.
|
||||
auto* body_function = ECMAScriptFunctionObject::create(global_object, "", *m_function_body, {}, 0, lexical_environment, private_scope, FunctionKind::Regular, true, false, m_contains_direct_call_to_eval, false);
|
||||
auto* body_function = ECMAScriptFunctionObject::create(global_object, "", *m_function_body, {}, 0, lexical_environment, private_scope, FunctionKind::Normal, true, false, m_contains_direct_call_to_eval, false);
|
||||
|
||||
// 6. Perform MakeMethod(bodyFunction, homeObject).
|
||||
body_function->make_method(home_object);
|
||||
|
@ -23,7 +23,7 @@ namespace JS::Bytecode {
|
||||
|
||||
class Generator {
|
||||
public:
|
||||
static Executable generate(ASTNode const&, FunctionKind = FunctionKind::Regular);
|
||||
static Executable generate(ASTNode const&, FunctionKind = FunctionKind::Normal);
|
||||
|
||||
Register allocate_register();
|
||||
|
||||
@ -130,7 +130,7 @@ private:
|
||||
|
||||
u32 m_next_register { 2 };
|
||||
u32 m_next_block { 1 };
|
||||
FunctionKind m_enclosing_function_kind { FunctionKind::Regular };
|
||||
FunctionKind m_enclosing_function_kind { FunctionKind::Normal };
|
||||
Vector<Label> m_continuable_scopes;
|
||||
Vector<Label> m_breakable_scopes;
|
||||
};
|
||||
|
@ -155,7 +155,7 @@ public:
|
||||
if (m_var_names.contains(function_name) || m_lexical_names.contains(function_name))
|
||||
throw_identifier_declared(function_name, declaration);
|
||||
|
||||
if (function_declaration.kind() != FunctionKind::Regular || m_parser.m_state.strict_mode) {
|
||||
if (function_declaration.kind() != FunctionKind::Normal || m_parser.m_state.strict_mode) {
|
||||
if (m_function_names.contains(function_name))
|
||||
throw_identifier_declared(function_name, declaration);
|
||||
|
||||
@ -708,7 +708,7 @@ RefPtr<FunctionExpression> Parser::try_parse_arrow_function_expression(bool expe
|
||||
load_state();
|
||||
};
|
||||
|
||||
auto function_kind = FunctionKind::Regular;
|
||||
auto function_kind = FunctionKind::Normal;
|
||||
|
||||
if (is_async) {
|
||||
consume(TokenType::Async);
|
||||
@ -1293,12 +1293,12 @@ NonnullRefPtr<ClassExpression> Parser::parse_class_expression(bool expect_class_
|
||||
|
||||
constructor = create_ast_node<FunctionExpression>(
|
||||
{ m_state.current_token.filename(), rule_start.position(), position() }, class_name, move(constructor_body),
|
||||
Vector { FunctionNode::Parameter { FlyString { "args" }, nullptr, true } }, 0, FunctionKind::Regular,
|
||||
Vector { FunctionNode::Parameter { FlyString { "args" }, nullptr, true } }, 0, FunctionKind::Normal,
|
||||
/* is_strict_mode */ true, /* might_need_arguments_object */ false, /* contains_direct_call_to_eval */ false);
|
||||
} else {
|
||||
constructor = create_ast_node<FunctionExpression>(
|
||||
{ m_state.current_token.filename(), rule_start.position(), position() }, class_name, move(constructor_body),
|
||||
Vector<FunctionNode::Parameter> {}, 0, FunctionKind::Regular,
|
||||
Vector<FunctionNode::Parameter> {}, 0, FunctionKind::Normal,
|
||||
/* is_strict_mode */ true, /* might_need_arguments_object */ false, /* contains_direct_call_to_eval */ false);
|
||||
}
|
||||
}
|
||||
@ -1624,7 +1624,7 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression()
|
||||
property_type = ObjectProperty::Type::KeyValue;
|
||||
RefPtr<Expression> property_name;
|
||||
RefPtr<Expression> property_value;
|
||||
FunctionKind function_kind { FunctionKind::Regular };
|
||||
FunctionKind function_kind { FunctionKind::Normal };
|
||||
|
||||
if (match(TokenType::TripleDot)) {
|
||||
consume();
|
||||
@ -1653,8 +1653,8 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression()
|
||||
consume();
|
||||
property_type = ObjectProperty::Type::KeyValue;
|
||||
property_name = parse_property_key();
|
||||
VERIFY(function_kind == FunctionKind::Regular || function_kind == FunctionKind::Async);
|
||||
function_kind = function_kind == FunctionKind::Regular ? FunctionKind::Generator : FunctionKind::AsyncGenerator;
|
||||
VERIFY(function_kind == FunctionKind::Normal || function_kind == FunctionKind::Async);
|
||||
function_kind = function_kind == FunctionKind::Normal ? FunctionKind::Generator : FunctionKind::AsyncGenerator;
|
||||
} else if (match_identifier()) {
|
||||
auto identifier = consume();
|
||||
if (identifier.original_value() == "get"sv && match_property_key()) {
|
||||
@ -2381,7 +2381,7 @@ NonnullRefPtr<FunctionBody> Parser::parse_function_body(Vector<FunctionDeclarati
|
||||
parse_statement_list(function_body);
|
||||
|
||||
// If the function contains 'use strict' we need to check the parameters (again).
|
||||
if (function_body->in_strict_mode() || function_kind != FunctionKind::Regular) {
|
||||
if (function_body->in_strict_mode() || function_kind != FunctionKind::Normal) {
|
||||
Vector<StringView> parameter_names;
|
||||
for (auto& parameter : parameters) {
|
||||
parameter.binding.visit(
|
||||
@ -2461,17 +2461,17 @@ NonnullRefPtr<FunctionNodeType> Parser::parse_function_node(u8 parse_options)
|
||||
else if ((parse_options & FunctionNodeParseOptions::IsAsyncFunction) != 0)
|
||||
function_kind = FunctionKind::Async;
|
||||
else
|
||||
function_kind = FunctionKind::Regular;
|
||||
function_kind = FunctionKind::Normal;
|
||||
String name;
|
||||
if (parse_options & FunctionNodeParseOptions::CheckForFunctionAndName) {
|
||||
if (function_kind == FunctionKind::Regular && match(TokenType::Async) && !next_token().trivia_contains_line_terminator()) {
|
||||
if (function_kind == FunctionKind::Normal && match(TokenType::Async) && !next_token().trivia_contains_line_terminator()) {
|
||||
function_kind = FunctionKind::Async;
|
||||
consume(TokenType::Async);
|
||||
parse_options = parse_options | FunctionNodeParseOptions::IsAsyncFunction;
|
||||
}
|
||||
consume(TokenType::Function);
|
||||
if (match(TokenType::Asterisk)) {
|
||||
function_kind = function_kind == FunctionKind::Regular ? FunctionKind::Generator : FunctionKind::AsyncGenerator;
|
||||
function_kind = function_kind == FunctionKind::Normal ? FunctionKind::Generator : FunctionKind::AsyncGenerator;
|
||||
consume(TokenType::Asterisk);
|
||||
parse_options = parse_options | FunctionNodeParseOptions::IsGeneratorFunction;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ ECMAScriptFunctionObject* ECMAScriptFunctionObject::create(GlobalObject& global_
|
||||
{
|
||||
Object* prototype = nullptr;
|
||||
switch (kind) {
|
||||
case FunctionKind::Regular:
|
||||
case FunctionKind::Normal:
|
||||
prototype = global_object.function_prototype();
|
||||
break;
|
||||
case FunctionKind::Generator:
|
||||
@ -99,7 +99,7 @@ void ECMAScriptFunctionObject::initialize(GlobalObject& global_object)
|
||||
if (!m_is_arrow_function) {
|
||||
Object* prototype = nullptr;
|
||||
switch (m_kind) {
|
||||
case FunctionKind::Regular:
|
||||
case FunctionKind::Normal:
|
||||
prototype = vm.heap().allocate<Object>(global_object, *global_object.new_ordinary_function_prototype_object_shape());
|
||||
MUST(prototype->define_property_or_throw(vm.names.constructor, { .value = this, .writable = true, .enumerable = false, .configurable = true }));
|
||||
break;
|
||||
@ -787,7 +787,7 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
|
||||
|
||||
// NOTE: Running the bytecode should eventually return a completion.
|
||||
// Until it does, we assume "return" and include the undefined fallback from the call site.
|
||||
if (m_kind == FunctionKind::Regular)
|
||||
if (m_kind == FunctionKind::Normal)
|
||||
return { Completion::Type::Return, result.value_or(js_undefined()), {} };
|
||||
|
||||
auto generator_object = TRY(GeneratorObject::create(global_object(), result, this, vm.running_execution_context().copy(), move(*result_and_frame.frame)));
|
||||
@ -813,7 +813,7 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
|
||||
VM::InterpreterExecutionScope scope(*ast_interpreter);
|
||||
|
||||
// FunctionBody : FunctionStatementList
|
||||
if (m_kind == FunctionKind::Regular) {
|
||||
if (m_kind == FunctionKind::Normal) {
|
||||
// 1. Perform ? FunctionDeclarationInstantiation(functionObject, argumentsList).
|
||||
TRY(function_declaration_instantiation(ast_interpreter));
|
||||
|
||||
|
@ -75,7 +75,7 @@ public:
|
||||
bool has_simple_parameter_list() const { return m_has_simple_parameter_list; }
|
||||
|
||||
// Equivalent to absence of [[Construct]]
|
||||
virtual bool has_constructor() const override { return m_kind == FunctionKind::Regular && !m_is_arrow_function; }
|
||||
virtual bool has_constructor() const override { return m_kind == FunctionKind::Normal && !m_is_arrow_function; }
|
||||
|
||||
FunctionKind kind() const { return m_kind; }
|
||||
|
||||
@ -113,7 +113,7 @@ private:
|
||||
FlyString m_name;
|
||||
Optional<Bytecode::Executable> m_bytecode_executable;
|
||||
i32 m_function_length { 0 };
|
||||
FunctionKind m_kind { FunctionKind::Regular };
|
||||
FunctionKind m_kind { FunctionKind::Normal };
|
||||
bool m_might_need_arguments_object { true };
|
||||
bool m_contains_direct_call_to_eval { true };
|
||||
bool m_is_arrow_function { false };
|
||||
|
@ -76,7 +76,7 @@ ThrowCompletionOr<Value> FunctionConstructor::call()
|
||||
ThrowCompletionOr<Object*> FunctionConstructor::construct(FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto function = TRY(create_dynamic_function_node(global_object(), new_target, FunctionKind::Regular));
|
||||
auto function = TRY(create_dynamic_function_node(global_object(), new_target, FunctionKind::Normal));
|
||||
|
||||
OwnPtr<Interpreter> local_interpreter;
|
||||
Interpreter* interpreter = vm.interpreter_if_exists();
|
||||
|
@ -9,8 +9,8 @@
|
||||
namespace JS {
|
||||
|
||||
enum class FunctionKind {
|
||||
Normal,
|
||||
Generator,
|
||||
Regular,
|
||||
Async,
|
||||
AsyncGenerator
|
||||
};
|
||||
|
@ -134,7 +134,7 @@ void EventTarget::set_event_handler_attribute(FlyString const& name, HTML::Event
|
||||
dbgln("Failed to parse script in event handler attribute '{}'", name);
|
||||
return;
|
||||
}
|
||||
auto* function = JS::ECMAScriptFunctionObject::create(target->script_execution_context()->realm().global_object(), name, program->body(), program->parameters(), program->function_length(), nullptr, nullptr, JS::FunctionKind::Regular, false, false);
|
||||
auto* function = JS::ECMAScriptFunctionObject::create(target->script_execution_context()->realm().global_object(), name, program->body(), program->parameters(), program->function_length(), nullptr, nullptr, JS::FunctionKind::Normal, false, false);
|
||||
VERIFY(function);
|
||||
listener = adopt_ref(*new DOM::EventListener(JS::make_handle(static_cast<JS::FunctionObject*>(function)), true));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user