1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 19:27:45 +00:00

LibJS: Add spec comments to the NativeError constructor

This commit is contained in:
Linus Groh 2022-02-07 14:44:06 +00:00
parent 6a9eeb2c5c
commit acb91d7869

View file

@ -73,8 +73,7 @@ ThrowCompletionOr<Object*> ErrorConstructor::construct(FunctionObject& new_targe
auto& vm = this->vm(); \ auto& vm = this->vm(); \
NativeFunction::initialize(global_object); \ NativeFunction::initialize(global_object); \
\ \
/* 20.5.6.2.1 NativeError.prototype, \ /* 20.5.6.2.1 NativeError.prototype, https://tc39.es/ecma262/#sec-nativeerror.prototype */ \
https://tc39.es/ecma262/#sec-nativeerror.prototype */ \
define_direct_property(vm.names.prototype, global_object.snake_name##_prototype(), 0); \ define_direct_property(vm.names.prototype, global_object.snake_name##_prototype(), 0); \
\ \
define_direct_property(vm.names.length, Value(1), Attribute::Configurable); \ define_direct_property(vm.names.length, Value(1), Attribute::Configurable); \
@ -82,28 +81,38 @@ ThrowCompletionOr<Object*> ErrorConstructor::construct(FunctionObject& new_targe
\ \
ConstructorName::~ConstructorName() { } \ ConstructorName::~ConstructorName() { } \
\ \
/* 20.5.6.1.1 NativeError ( message ), https://tc39.es/ecma262/#sec-nativeerror */ \ /* 20.5.6.1.1 NativeError ( message [ , options ] ), https://tc39.es/ecma262/#sec-nativeerror */ \
ThrowCompletionOr<Value> ConstructorName::call() \ ThrowCompletionOr<Value> ConstructorName::call() \
{ \ { \
/* 1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget. */ \
return TRY(construct(*this)); \ return TRY(construct(*this)); \
} \ } \
\ \
/* 20.5.6.1.1 NativeError ( message ), https://tc39.es/ecma262/#sec-nativeerror */ \ /* 20.5.6.1.1 NativeError ( message [ , options ] ), https://tc39.es/ecma262/#sec-nativeerror */ \
ThrowCompletionOr<Object*> ConstructorName::construct(FunctionObject& new_target) \ ThrowCompletionOr<Object*> ConstructorName::construct(FunctionObject& new_target) \
{ \ { \
auto& vm = this->vm(); \ auto& vm = this->vm(); \
auto& global_object = this->global_object(); \ auto& global_object = this->global_object(); \
\ \
auto* error = TRY(ordinary_create_from_constructor<ClassName>( \ auto message = vm.argument(0); \
global_object, new_target, &GlobalObject::snake_name##_prototype)); \ auto options = vm.argument(1); \
\ \
if (!vm.argument(0).is_undefined()) { \ /* 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%NativeError.prototype%", « [[ErrorData]] »). */ \
auto message = TRY(vm.argument(0).to_string(global_object)); \ auto* error = TRY(ordinary_create_from_constructor<ClassName>(global_object, new_target, &GlobalObject::snake_name##_prototype)); \
MUST(error->create_non_enumerable_data_property_or_throw(vm.names.message, js_string(vm, message))); \ \
/* 3. If message is not undefined, then */ \
if (!message.is_undefined()) { \
/* a. Let msg be ? ToString(message). */ \
auto msg = TRY(message.to_string(global_object)); \
\
/* b. Perform ! CreateNonEnumerableDataPropertyOrThrow(O, "message", msg). */ \
MUST(error->create_non_enumerable_data_property_or_throw(vm.names.message, js_string(vm, move(msg)))); \
} \ } \
\ \
TRY(error->install_error_cause(vm.argument(1))); \ /* 4. Perform ? InstallErrorCause(O, options). */ \
TRY(error->install_error_cause(options)); \
\ \
/* 5. Return O. */ \
return error; \ return error; \
} }