From f3264b0dbd9f7f618d142caa7a896b59a33ffd20 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 6 Apr 2021 22:45:12 +0200 Subject: LibJS: Implement Object.isFrozen() and Object.isSealed() --- .../Libraries/LibJS/Runtime/ObjectConstructor.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp') diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 735a5ef4b2..bbbb3c4a33 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -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); -- cgit v1.2.3