LibJS: Add a bunch more missing ECMA-262 section/title/URL comments

This commit is contained in:
Linus Groh 2021-06-19 00:38:41 +01:00
parent 7f97e33778
commit 7f8245439b
Notes: sideshowbarker 2024-07-18 12:02:59 +09:00
9 changed files with 56 additions and 1 deletions

View File

@ -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());

View File

@ -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(); \

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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<TypeError>(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(); \

View File

@ -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<TypeError>(global_object(), ErrorType::ClassIsAbstract, "TypedArray");

View File

@ -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();

View File

@ -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();