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

LibJS: Implement Object.isFrozen() and Object.isSealed()

This commit is contained in:
Linus Groh 2021-04-06 22:45:12 +02:00 committed by Andreas Kling
parent 9af07c7803
commit f3264b0dbd
7 changed files with 105 additions and 0 deletions

View file

@ -55,6 +55,8 @@ void ObjectConstructor::initialize(GlobalObject& global_object)
define_native_function(vm.names.getPrototypeOf, get_prototype_of, 1, attr);
define_native_function(vm.names.setPrototypeOf, set_prototype_of, 2, attr);
define_native_function(vm.names.isExtensible, is_extensible, 1, attr);
define_native_function(vm.names.isFrozen, is_frozen, 1, attr);
define_native_function(vm.names.isSealed, is_sealed, 1, attr);
define_native_function(vm.names.preventExtensions, prevent_extensions, 1, attr);
define_native_function(vm.names.freeze, freeze, 1, attr);
define_native_function(vm.names.seal, seal, 1, attr);
@ -144,6 +146,24 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is_extensible)
return Value(argument.as_object().is_extensible());
}
// 20.1.2.15 Object.isFrozen, https://tc39.es/ecma262/#sec-object.isfrozen
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is_frozen)
{
auto argument = vm.argument(0);
if (!argument.is_object())
return Value(true);
return Value(argument.as_object().test_integrity_level(Object::IntegrityLevel::Frozen));
}
// 20.1.2.16 Object.isSealed, https://tc39.es/ecma262/#sec-object.issealed
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is_sealed)
{
auto argument = vm.argument(0);
if (!argument.is_object())
return Value(true);
return Value(argument.as_object().test_integrity_level(Object::IntegrityLevel::Sealed));
}
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::prevent_extensions)
{
auto argument = vm.argument(0);