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

LibJS: Bring the super keyword in line with the spec

This patch implements spec-compliant runtime semantics for the following
constructs:

- super.property
- super[property]

The MakeSuperPropertyReference AO is added to support this. :^)
This commit is contained in:
Andreas Kling 2021-07-03 00:20:52 +02:00
parent 52f9aaa823
commit 1270df257b
3 changed files with 58 additions and 0 deletions

View file

@ -25,6 +25,7 @@
#include <LibJS/Runtime/ObjectEnvironment.h>
#include <LibJS/Runtime/PropertyName.h>
#include <LibJS/Runtime/ProxyObject.h>
#include <LibJS/Runtime/Reference.h>
namespace JS {
@ -180,6 +181,25 @@ Object* get_super_constructor(VM& vm)
return super_constructor;
}
// 13.3.7.3 MakeSuperPropertyReference ( actualThis, propertyKey, strict )
Reference make_super_property_reference(GlobalObject& global_object, Value actual_this, StringOrSymbol const& property_key, bool strict)
{
auto& vm = global_object.vm();
// 1. Let env be GetThisEnvironment().
auto& env = verify_cast<FunctionEnvironment>(get_this_environment(vm));
// 2. Assert: env.HasSuperBinding() is true.
VERIFY(env.has_super_binding());
// 3. Let baseValue be ? env.GetSuperBase().
auto base_value = env.get_super_base();
// 4. Let bv be ? RequireObjectCoercible(baseValue).
auto bv = require_object_coercible(global_object, base_value);
if (vm.exception())
return {};
// 5. Return the Reference Record { [[Base]]: bv, [[ReferencedName]]: propertyKey, [[Strict]]: strict, [[ThisValue]]: actualThis }.
// 6. NOTE: This returns a Super Reference Record.
return Reference { bv, property_key, actual_this, strict };
}
// 19.2.1.1 PerformEval ( x, callerRealm, strictCaller, direct ), https://tc39.es/ecma262/#sec-performeval
Value perform_eval(Value x, GlobalObject& caller_realm, CallerMode strict_caller, EvalMode direct)
{