mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 20:05:07 +00:00
LibJS/JIT: Compile the GetCalleeAndThisFromEnvironment instruction
This commit is contained in:
parent
dabaaabfc0
commit
935d67cfcf
6 changed files with 94 additions and 38 deletions
|
@ -327,4 +327,52 @@ ThrowCompletionOr<Value> get_variable(Bytecode::Interpreter& interpreter, Deprec
|
|||
return TRY(reference.get_value(vm));
|
||||
}
|
||||
|
||||
ThrowCompletionOr<CalleeAndThis> get_callee_and_this_from_environment(Bytecode::Interpreter& interpreter, DeprecatedFlyString const& name, u32 cache_index)
|
||||
{
|
||||
auto& vm = interpreter.vm();
|
||||
|
||||
Value callee = js_undefined();
|
||||
Value this_value = js_undefined();
|
||||
|
||||
auto& cached_environment_coordinate = interpreter.current_executable().environment_variable_caches[cache_index];
|
||||
if (cached_environment_coordinate.has_value()) {
|
||||
auto environment = vm.running_execution_context().lexical_environment;
|
||||
for (size_t i = 0; i < cached_environment_coordinate->hops; ++i)
|
||||
environment = environment->outer_environment();
|
||||
VERIFY(environment);
|
||||
VERIFY(environment->is_declarative_environment());
|
||||
if (!environment->is_permanently_screwed_by_eval()) {
|
||||
callee = TRY(verify_cast<DeclarativeEnvironment>(*environment).get_binding_value_direct(vm, cached_environment_coordinate.value().index, vm.in_strict_mode()));
|
||||
this_value = js_undefined();
|
||||
if (auto base_object = environment->with_base_object())
|
||||
this_value = base_object;
|
||||
return CalleeAndThis {
|
||||
.callee = callee,
|
||||
.this_value = this_value,
|
||||
};
|
||||
}
|
||||
cached_environment_coordinate = {};
|
||||
}
|
||||
|
||||
auto reference = TRY(vm.resolve_binding(name));
|
||||
if (reference.environment_coordinate().has_value())
|
||||
cached_environment_coordinate = reference.environment_coordinate();
|
||||
|
||||
callee = TRY(reference.get_value(vm));
|
||||
|
||||
if (reference.is_property_reference()) {
|
||||
this_value = reference.get_this_value();
|
||||
} else {
|
||||
if (reference.is_environment_reference()) {
|
||||
if (auto base_object = reference.base_environment().with_base_object(); base_object != nullptr)
|
||||
this_value = base_object;
|
||||
}
|
||||
}
|
||||
|
||||
return CalleeAndThis {
|
||||
.callee = callee,
|
||||
.this_value = this_value,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue