From 7beccaf41b4ba27beeb5e78688cc0382efeec213 Mon Sep 17 00:00:00 2001 From: davidot Date: Fri, 15 Oct 2021 15:05:02 +0200 Subject: [PATCH] LibJS: Add comment clarifying the order of function properties --- .../Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index abd92758d4..94c03b44bd 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -76,6 +76,12 @@ void ECMAScriptFunctionObject::initialize(GlobalObject& global_object) { auto& vm = this->vm(); Base::initialize(global_object); + // Note: The ordering of these properties must be: length, name, prototype which is the order + // they are defined in the spec: https://tc39.es/ecma262/#sec-function-instances . + // This is observable through something like: https://tc39.es/ecma262/#sec-ordinaryownpropertykeys + // which must give the properties in chronological order which in this case is the order they + // are defined in the spec. + MUST(define_property_or_throw(vm.names.length, { .value = Value(m_function_length), .writable = false, .enumerable = false, .configurable = true })); MUST(define_property_or_throw(vm.names.name, { .value = js_string(vm, m_name.is_null() ? "" : m_name), .writable = false, .enumerable = false, .configurable = true }));