summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-01-24 19:10:46 +0000
committerLinus Groh <mail@linusgroh.de>2022-01-24 20:17:07 +0000
commit886d6c62f9b5f08b15628b291b886f967e6974c8 (patch)
treeacadf36623a043cb18cac941fafdd8d341e57ba5 /Userland
parent5b04c49762a56fed0aafa37883f0c15f3fc41209 (diff)
downloadserenity-886d6c62f9b5f08b15628b291b886f967e6974c8.zip
LibJS: Implement the SetFunctionLength AO
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Runtime/FunctionObject.cpp16
-rw-r--r--Userland/Libraries/LibJS/Runtime/FunctionObject.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/FunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/FunctionObject.cpp
index a6773a6146..1dd175d2e2 100644
--- a/Userland/Libraries/LibJS/Runtime/FunctionObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/FunctionObject.cpp
@@ -76,6 +76,22 @@ void FunctionObject::set_function_name(Variant<PropertyKey, PrivateName> const&
MUST(define_property_or_throw(vm.names.name, PropertyDescriptor { .value = js_string(vm, move(name)), .writable = false, .enumerable = false, .configurable = true }));
}
+// 10.2.10 SetFunctionLength ( F, length ), https://tc39.es/ecma262/#sec-setfunctionlength
+void FunctionObject::set_function_length(double length)
+{
+ auto& vm = this->vm();
+
+ // "length (a non-negative integer or +∞)"
+ VERIFY(trunc(length) == length || __builtin_isinf_sign(length) == 1);
+
+ // 1. Assert: F is an extensible object that does not have a "length" own property.
+ VERIFY(m_is_extensible);
+ VERIFY(!storage_has(vm.names.length));
+
+ // 2. Return ! DefinePropertyOrThrow(F, "length", PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }).
+ MUST(define_property_or_throw(vm.names.length, PropertyDescriptor { .value = Value { length }, .writable = false, .enumerable = false, .configurable = true }));
+}
+
ThrowCompletionOr<BoundFunction*> FunctionObject::bind(Value bound_this_value, Vector<Value> arguments)
{
auto& vm = this->vm();
diff --git a/Userland/Libraries/LibJS/Runtime/FunctionObject.h b/Userland/Libraries/LibJS/Runtime/FunctionObject.h
index 12692c2d3e..0f6a510463 100644
--- a/Userland/Libraries/LibJS/Runtime/FunctionObject.h
+++ b/Userland/Libraries/LibJS/Runtime/FunctionObject.h
@@ -30,6 +30,7 @@ public:
virtual const FlyString& name() const = 0;
void set_function_name(Variant<PropertyKey, PrivateName> const& name_arg, Optional<StringView> const& prefix = {});
+ void set_function_length(double length);
ThrowCompletionOr<BoundFunction*> bind(Value bound_this_value, Vector<Value> arguments);
virtual bool is_strict_mode() const { return false; }