1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:47:34 +00:00

LibJS: Add and use the CreateNonEnumerableDataPropertyOrThrow AO

This commit is contained in:
Idan Horowitz 2021-07-06 00:13:19 +03:00 committed by Linus Groh
parent 6da7f43580
commit 6787e86a3a
5 changed files with 67 additions and 59 deletions

View file

@ -43,13 +43,11 @@ Value ErrorConstructor::construct(FunctionObject& new_target)
if (vm.exception())
return {};
u8 attr = Attribute::Writable | Attribute::Configurable;
if (!vm.argument(0).is_undefined()) {
auto message = vm.argument(0).to_string(global_object);
if (vm.exception())
return {};
error->define_property(vm.names.message, js_string(vm, message), attr);
error->create_non_enumerable_data_property_or_throw(vm.names.message, js_string(vm, message));
}
error->install_error_cause(vm.argument(1));
@ -59,57 +57,55 @@ Value ErrorConstructor::construct(FunctionObject& new_target)
return error;
}
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
ConstructorName::ConstructorName(GlobalObject& global_object) \
: NativeFunction(*static_cast<Object*>(global_object.error_constructor())) \
{ \
} \
\
void ConstructorName::initialize(GlobalObject& global_object) \
{ \
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(FunctionObject& new_target) \
{ \
auto& vm = this->vm(); \
auto& global_object = this->global_object(); \
\
auto* error = ordinary_create_from_constructor<ClassName>( \
global_object, new_target, &GlobalObject::snake_name##_prototype); \
if (vm.exception()) \
return {}; \
\
u8 attr = Attribute::Writable | Attribute::Configurable; \
\
if (!vm.argument(0).is_undefined()) { \
auto message = vm.argument(0).to_string(global_object); \
if (vm.exception()) \
return {}; \
error->define_property(vm.names.message, js_string(vm, message), attr); \
} \
\
error->install_error_cause(vm.argument(1)); \
if (vm.exception()) \
return {}; \
\
return error; \
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
ConstructorName::ConstructorName(GlobalObject& global_object) \
: NativeFunction(*static_cast<Object*>(global_object.error_constructor())) \
{ \
} \
\
void ConstructorName::initialize(GlobalObject& global_object) \
{ \
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(FunctionObject& new_target) \
{ \
auto& vm = this->vm(); \
auto& global_object = this->global_object(); \
\
auto* error = ordinary_create_from_constructor<ClassName>( \
global_object, new_target, &GlobalObject::snake_name##_prototype); \
if (vm.exception()) \
return {}; \
\
if (!vm.argument(0).is_undefined()) { \
auto message = vm.argument(0).to_string(global_object); \
if (vm.exception()) \
return {}; \
error->create_non_enumerable_data_property_or_throw(vm.names.message, js_string(vm, message)); \
} \
\
error->install_error_cause(vm.argument(1)); \
if (vm.exception()) \
return {}; \
\
return error; \
}
JS_ENUMERATE_NATIVE_ERRORS