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

LibJS: Implement the CanBeHeldWeakly abstract operation

This AO is required for implementing the rest of the stage 3 'Symbol as
WeakMap Keys Proposal'.
This commit is contained in:
Idan Horowitz 2022-06-22 22:15:59 +03:00
parent 8e26edc8de
commit 22a78e8a2c
2 changed files with 20 additions and 0 deletions

View file

@ -456,6 +456,25 @@ Environment& get_this_environment(VM& vm)
VERIFY_NOT_REACHED();
}
// 9.14 CanBeHeldWeakly ( v ), https://tc39.es/proposal-symbols-as-weakmap-keys/#sec-canbeheldweakly-abstract-operation
bool can_be_held_weakly(Value value)
{
// 1. If Type(v) is Object, return true.
if (value.is_object())
return true;
// 2. If Type(v) is Symbol, then
if (value.is_symbol()) {
// a. For each element e of the GlobalSymbolRegistry List (see 19.4.2.2), do
// i. If SameValue(e.[[Symbol]], v) is true, return false.
// b. Return true.
return !value.as_symbol().is_global();
}
// 3. Return false.
return false;
}
// 13.3.7.2 GetSuperConstructor ( ), https://tc39.es/ecma262/#sec-getsuperconstructor
Object* get_super_constructor(VM& vm)
{