summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-04-06 22:45:12 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-07 09:05:01 +0200
commitf3264b0dbd9f7f618d142caa7a896b59a33ffd20 (patch)
treeddbaed31707b6ce63a54c439bd2e00812f712f61 /Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp
parent9af07c7803aaf08c55414dca315bbbfb9a23754e (diff)
downloadserenity-f3264b0dbd9f7f618d142caa7a896b59a33ffd20.zip
LibJS: Implement Object.isFrozen() and Object.isSealed()
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp')
-rw-r--r--Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp20
1 files changed, 20 insertions, 0 deletions
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);