1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 20:28:11 +00:00

LibJS: Implement the GetFunctionRealm() abstract operation

This commit is contained in:
Linus Groh 2021-06-19 22:15:00 +01:00 committed by Andreas Kling
parent 55db9539a5
commit 6312627218
2 changed files with 29 additions and 0 deletions

View file

@ -13,6 +13,7 @@
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/PropertyName.h>
#include <LibJS/Runtime/ProxyObject.h>
namespace JS {
@ -112,4 +113,31 @@ Function* species_constructor(GlobalObject& global_object, Object const& object,
return nullptr;
}
// 7.3.24 GetFunctionRealm ( obj ), https://tc39.es/ecma262/#sec-getfunctionrealm
GlobalObject* get_function_realm(GlobalObject& global_object, Function const& function)
{
auto& vm = global_object.vm();
// FIXME: not sure how to do this currently.
// 2. If obj has a [[Realm]] internal slot, then
// a. Return obj.[[Realm]].
if (is<BoundFunction>(function)) {
auto& bound_function = static_cast<BoundFunction const&>(function);
auto& target = bound_function.target_function();
return get_function_realm(global_object, target);
}
if (is<ProxyObject>(function)) {
auto& proxy = static_cast<ProxyObject const&>(function);
if (proxy.is_revoked()) {
vm.throw_exception<TypeError>(global_object, ErrorType::ProxyRevoked);
return nullptr;
}
auto& proxy_target = proxy.target();
VERIFY(proxy_target.is_function());
return get_function_realm(global_object, static_cast<Function const&>(proxy_target));
}
// 5. Return the current Realm Record.
return &global_object;
}
}