mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:37:34 +00:00
LibJS: Store ECMAScriptFunctionObject bytecode in an OwnPtr
Using an Optional was extremely wasteful for function objects that don't even have a bytecode executable. This allows ECMAScriptFunctionObject to fit in a smaller size class.
This commit is contained in:
parent
8d3f92c844
commit
7a742b17da
8 changed files with 33 additions and 28 deletions
|
@ -23,7 +23,7 @@ Generator::~Generator()
|
|||
{
|
||||
}
|
||||
|
||||
Executable Generator::generate(ASTNode const& node, FunctionKind enclosing_function_kind)
|
||||
NonnullOwnPtr<Executable> Generator::generate(ASTNode const& node, FunctionKind enclosing_function_kind)
|
||||
{
|
||||
Generator generator;
|
||||
generator.switch_to_basic_block(generator.make_block());
|
||||
|
@ -45,7 +45,12 @@ Executable Generator::generate(ASTNode const& node, FunctionKind enclosing_funct
|
|||
generator.emit<Bytecode::Op::Yield>(nullptr);
|
||||
}
|
||||
}
|
||||
return { {}, move(generator.m_root_basic_blocks), move(generator.m_string_table), move(generator.m_identifier_table), generator.m_next_register };
|
||||
return adopt_own(*new Executable {
|
||||
.name = {},
|
||||
.basic_blocks = move(generator.m_root_basic_blocks),
|
||||
.string_table = move(generator.m_string_table),
|
||||
.identifier_table = move(generator.m_identifier_table),
|
||||
.number_of_registers = generator.m_next_register });
|
||||
}
|
||||
|
||||
void Generator::grow(size_t additional_size)
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace JS::Bytecode {
|
|||
|
||||
class Generator {
|
||||
public:
|
||||
static Executable generate(ASTNode const&, FunctionKind = FunctionKind::Normal);
|
||||
static NonnullOwnPtr<Executable> generate(ASTNode const&, FunctionKind = FunctionKind::Normal);
|
||||
|
||||
Register allocate_register();
|
||||
|
||||
|
|
|
@ -580,10 +580,10 @@ ThrowCompletionOr<Value> perform_eval(Value x, GlobalObject& caller_realm, Calle
|
|||
|
||||
if (auto* bytecode_interpreter = Bytecode::Interpreter::current()) {
|
||||
auto executable = JS::Bytecode::Generator::generate(program);
|
||||
executable.name = "eval"sv;
|
||||
executable->name = "eval"sv;
|
||||
if (JS::Bytecode::g_dump_bytecode)
|
||||
executable.dump();
|
||||
eval_result = TRY(bytecode_interpreter->run(executable));
|
||||
executable->dump();
|
||||
eval_result = TRY(bytecode_interpreter->run(*executable));
|
||||
// Turn potentially empty JS::Value from the bytecode interpreter into an empty Optional
|
||||
if (eval_result.has_value() && eval_result->is_empty())
|
||||
eval_result = {};
|
||||
|
|
|
@ -775,7 +775,7 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
|
|||
if (bytecode_interpreter) {
|
||||
// FIXME: pass something to evaluate default arguments with
|
||||
TRY(function_declaration_instantiation(nullptr));
|
||||
if (!m_bytecode_executable.has_value()) {
|
||||
if (!m_bytecode_executable) {
|
||||
m_bytecode_executable = Bytecode::Generator::generate(m_ecmascript_code, m_kind);
|
||||
m_bytecode_executable->name = m_name;
|
||||
auto& passes = JS::Bytecode::Interpreter::optimization_pipeline();
|
||||
|
|
|
@ -103,7 +103,7 @@ private:
|
|||
ThrowCompletionOr<void> function_declaration_instantiation(Interpreter*);
|
||||
|
||||
FlyString m_name;
|
||||
Optional<Bytecode::Executable> m_bytecode_executable;
|
||||
OwnPtr<Bytecode::Executable> m_bytecode_executable;
|
||||
i32 m_function_length { 0 };
|
||||
|
||||
// Internal Slots of ECMAScript Function Objects, https://tc39.es/ecma262/#table-internal-slots-of-ecmascript-function-objects
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue