From 7f8245439b0c5063377e5af9304e39b9226d6a18 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 19 Jun 2021 00:38:41 +0100 Subject: [PATCH] LibJS: Add a bunch more missing ECMA-262 section/title/URL comments --- .../Libraries/LibJS/Runtime/BooleanConstructor.cpp | 7 ++++++- .../Libraries/LibJS/Runtime/ErrorConstructor.cpp | 11 +++++++++++ .../Libraries/LibJS/Runtime/FunctionConstructor.cpp | 3 +++ .../Libraries/LibJS/Runtime/RegExpConstructor.cpp | 6 ++++++ Userland/Libraries/LibJS/Runtime/SetConstructor.cpp | 3 +++ Userland/Libraries/LibJS/Runtime/TypedArray.cpp | 13 +++++++++++++ .../LibJS/Runtime/TypedArrayConstructor.cpp | 5 +++++ .../Libraries/LibJS/Runtime/WeakMapConstructor.cpp | 4 ++++ .../Libraries/LibJS/Runtime/WeakSetConstructor.cpp | 5 +++++ 9 files changed, 56 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp b/Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp index 41842078fa..eb89763c3c 100644 --- a/Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp @@ -21,7 +21,10 @@ void BooleanConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); - define_property(vm.names.prototype, Value(global_object.boolean_prototype()), 0); + + // 20.3.2.1 Boolean.prototype, https://tc39.es/ecma262/#sec-boolean.prototype + define_property(vm.names.prototype, global_object.boolean_prototype(), 0); + define_property(vm.names.length, Value(1), Attribute::Configurable); } @@ -29,11 +32,13 @@ BooleanConstructor::~BooleanConstructor() { } +// 20.3.1.1 Boolean ( value ), https://tc39.es/ecma262/#sec-boolean-constructor-boolean-value Value BooleanConstructor::call() { return Value(vm().argument(0).to_boolean()); } +// 20.3.1.1 Boolean ( value ), https://tc39.es/ecma262/#sec-boolean-constructor-boolean-value Value BooleanConstructor::construct(Function&) { return BooleanObject::create(global_object(), vm().argument(0).to_boolean()); diff --git a/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp index bae4f731e7..156e0b09f4 100644 --- a/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp @@ -19,15 +19,20 @@ void ErrorConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); + + // 20.5.2.1 Error.prototype, https://tc39.es/ecma262/#sec-error.prototype define_property(vm.names.prototype, global_object.error_prototype(), 0); + define_property(vm.names.length, Value(1), Attribute::Configurable); } +// 20.5.1.1 Error ( message ), https://tc39.es/ecma262/#sec-error-message Value ErrorConstructor::call() { return construct(*this); } +// 20.5.1.1 Error ( message ), https://tc39.es/ecma262/#sec-error-message Value ErrorConstructor::construct(Function&) { auto& vm = this->vm(); @@ -60,17 +65,23 @@ Value ErrorConstructor::construct(Function&) { \ auto& vm = this->vm(); \ NativeFunction::initialize(global_object); \ + \ + /* 20.5.6.2.1 NativeError.prototype, \ + https://tc39.es/ecma262/#sec-nativeerror.prototype */ \ define_property(vm.names.prototype, global_object.snake_name##_prototype(), 0); \ + \ define_property(vm.names.length, Value(1), Attribute::Configurable); \ } \ \ ConstructorName::~ConstructorName() { } \ \ + /* 20.5.6.1.1 NativeError ( message ), https://tc39.es/ecma262/#sec-nativeerror */ \ Value ConstructorName::call() \ { \ return construct(*this); \ } \ \ + /* 20.5.6.1.1 NativeError ( message ), https://tc39.es/ecma262/#sec-nativeerror */ \ Value ConstructorName::construct(Function&) \ { \ auto& vm = this->vm(); \ diff --git a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp index 44f10fdaea..988f829bc9 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp @@ -24,7 +24,10 @@ void FunctionConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); + + // 20.2.2.2 Function.prototype, https://tc39.es/ecma262/#sec-function.prototype define_property(vm.names.prototype, global_object.function_prototype(), 0); + define_property(vm.names.length, Value(1), Attribute::Configurable); } diff --git a/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp b/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp index 496efe0913..1740d5d62b 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp @@ -20,7 +20,10 @@ void RegExpConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); + + // 22.2.4.1 RegExp.prototype, https://tc39.es/ecma262/#sec-regexp.prototype define_property(vm.names.prototype, global_object.regexp_prototype(), 0); + define_property(vm.names.length, Value(2), Attribute::Configurable); define_native_accessor(vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable); @@ -30,11 +33,13 @@ RegExpConstructor::~RegExpConstructor() { } +// 22.2.3.1 RegExp ( pattern, flags ), https://tc39.es/ecma262/#sec-regexp-pattern-flags Value RegExpConstructor::call() { return construct(*this); } +// 22.2.3.1 RegExp ( pattern, flags ), https://tc39.es/ecma262/#sec-regexp-pattern-flags Value RegExpConstructor::construct(Function&) { auto& vm = this->vm(); @@ -53,6 +58,7 @@ Value RegExpConstructor::construct(Function&) return RegExpObject::create(global_object(), pattern, flags); } +// 22.2.4.2 get RegExp [ @@species ], https://tc39.es/ecma262/#sec-get-regexp-@@species JS_DEFINE_NATIVE_GETTER(RegExpConstructor::symbol_species_getter) { return vm.this_value(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp b/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp index 209ca57c05..f4ec3c6f27 100644 --- a/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp @@ -34,6 +34,7 @@ SetConstructor::~SetConstructor() { } +// 24.2.1.1 Set ( [ iterable ] ), https://tc39.es/ecma262/#sec-set-iterable Value SetConstructor::call() { auto& vm = this->vm(); @@ -41,6 +42,7 @@ Value SetConstructor::call() return {}; } +// 24.2.1.1 Set ( [ iterable ] ), https://tc39.es/ecma262/#sec-set-iterable Value SetConstructor::construct(Function&) { auto& vm = this->vm(); @@ -66,6 +68,7 @@ Value SetConstructor::construct(Function&) return set; } +// 24.2.2.2 get Set [ @@species ], https://tc39.es/ecma262/#sec-get-set-@@species JS_DEFINE_NATIVE_GETTER(SetConstructor::symbol_species_getter) { return vm.this_value(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index 5ecadf71e6..76df4fdd2a 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -198,6 +198,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor) : TypedArray(length, prototype) \ { \ } \ + \ ClassName::~ClassName() { } \ \ String ClassName::element_name() const \ @@ -211,27 +212,39 @@ void TypedArrayBase::visit_edges(Visitor& visitor) auto& vm = this->vm(); \ define_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0); \ } \ + \ PrototypeName::~PrototypeName() { } \ \ ConstructorName::ConstructorName(GlobalObject& global_object) \ : TypedArrayConstructor(vm().names.ClassName.as_string(), *global_object.typed_array_constructor()) \ { \ } \ + \ ConstructorName::~ConstructorName() { } \ + \ void ConstructorName::initialize(GlobalObject& global_object) \ { \ auto& vm = this->vm(); \ NativeFunction::initialize(global_object); \ + \ + /* 23.2.6.2 TypedArray.prototype, https://tc39.es/ecma262/#sec-typedarray.prototype */ \ define_property(vm.names.prototype, global_object.snake_name##_prototype(), 0); \ + \ define_property(vm.names.length, Value(3), Attribute::Configurable); \ + \ + /* 23.2.6.1 TypedArray.BYTES_PER_ELEMENT, https://tc39.es/ecma262/#sec-typedarray.bytes_per_element */ \ define_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0); \ } \ + \ + /* 23.2.5.1 TypedArray ( ...args ), https://tc39.es/ecma262/#sec-typedarray */ \ Value ConstructorName::call() \ { \ auto& vm = this->vm(); \ vm.throw_exception(global_object(), ErrorType::ConstructorWithoutNew, vm.names.ClassName); \ return {}; \ } \ + \ + /* 23.2.5.1 TypedArray ( ...args ), https://tc39.es/ecma262/#sec-typedarray */ \ Value ConstructorName::construct(Function&) \ { \ auto& vm = this->vm(); \ diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp index b26274b6d2..fa045b9c59 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp @@ -24,7 +24,10 @@ void TypedArrayConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); + + // 23.2.2.3 %TypedArray%.prototype, https://tc39.es/ecma262/#sec-%typedarray%.prototype define_property(vm.names.prototype, global_object.typed_array_prototype(), 0); + define_property(vm.names.length, Value(0), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; @@ -37,11 +40,13 @@ TypedArrayConstructor::~TypedArrayConstructor() { } +// 23.2.1.1 %TypedArray% ( ), https://tc39.es/ecma262/#sec-%typedarray% Value TypedArrayConstructor::call() { return construct(*this); } +// 23.2.1.1 %TypedArray% ( ), https://tc39.es/ecma262/#sec-%typedarray% Value TypedArrayConstructor::construct(Function&) { vm().throw_exception(global_object(), ErrorType::ClassIsAbstract, "TypedArray"); diff --git a/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp b/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp index a3fe694d8c..40c272c962 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp @@ -21,7 +21,10 @@ void WeakMapConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); + + // 24.3.2.1 WeakMap.prototype, https://tc39.es/ecma262/#sec-weakmap.prototype define_property(vm.names.prototype, global_object.weak_map_prototype(), 0); + define_property(vm.names.length, Value(0), Attribute::Configurable); } @@ -29,6 +32,7 @@ WeakMapConstructor::~WeakMapConstructor() { } +// 24.3.1.1 WeakMap ( [ iterable ] ), https://tc39.es/ecma262/#sec-weakmap-iterable Value WeakMapConstructor::call() { auto& vm = this->vm(); diff --git a/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp b/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp index e42bee40ab..d07b514440 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp @@ -21,7 +21,10 @@ void WeakSetConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); + + // 24.4.2.1 WeakSet.prototype, https://tc39.es/ecma262/#sec-weakset.prototype define_property(vm.names.prototype, global_object.weak_set_prototype(), 0); + define_property(vm.names.length, Value(0), Attribute::Configurable); } @@ -29,6 +32,7 @@ WeakSetConstructor::~WeakSetConstructor() { } +// 24.4.1.1 WeakSet ( [ iterable ] ), https://tc39.es/ecma262/#sec-weakset-iterable Value WeakSetConstructor::call() { auto& vm = this->vm(); @@ -36,6 +40,7 @@ Value WeakSetConstructor::call() return {}; } +// 24.4.1.1 WeakSet ( [ iterable ] ), https://tc39.es/ecma262/#sec-weakset-iterable Value WeakSetConstructor::construct(Function&) { auto& vm = this->vm();