mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
LibJS: Add and use the CreateNonEnumerableDataPropertyOrThrow AO
This commit is contained in:
parent
6da7f43580
commit
6787e86a3a
5 changed files with 67 additions and 59 deletions
|
@ -46,13 +46,11 @@ Value AggregateErrorConstructor::construct(FunctionObject& new_target)
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
|
||||||
|
|
||||||
if (!vm.argument(1).is_undefined()) {
|
if (!vm.argument(1).is_undefined()) {
|
||||||
auto message = vm.argument(1).to_string(global_object);
|
auto message = vm.argument(1).to_string(global_object);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
aggregate_error->define_property(vm.names.message, js_string(vm, message), attr);
|
aggregate_error->create_non_enumerable_data_property_or_throw(vm.names.message, js_string(vm, message));
|
||||||
}
|
}
|
||||||
|
|
||||||
aggregate_error->install_error_cause(vm.argument(2));
|
aggregate_error->install_error_cause(vm.argument(2));
|
||||||
|
@ -63,7 +61,7 @@ Value AggregateErrorConstructor::construct(FunctionObject& new_target)
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
aggregate_error->define_property(vm.names.errors, Array::create_from(global_object, errors_list), attr);
|
aggregate_error->define_property_or_throw(vm.names.errors, { .value = Array::create_from(global_object, errors_list), .writable = true, .enumerable = false, .configurable = true });
|
||||||
|
|
||||||
return aggregate_error;
|
return aggregate_error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ void Error::install_error_cause(Value options)
|
||||||
auto cause = options_object.get(vm.names.cause);
|
auto cause = options_object.get(vm.names.cause);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return;
|
return;
|
||||||
define_property(vm.names.cause, cause, Attribute::Writable | Attribute::Configurable);
|
create_non_enumerable_data_property_or_throw(vm.names.cause, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
||||||
|
|
|
@ -43,13 +43,11 @@ Value ErrorConstructor::construct(FunctionObject& new_target)
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
|
||||||
|
|
||||||
if (!vm.argument(0).is_undefined()) {
|
if (!vm.argument(0).is_undefined()) {
|
||||||
auto message = vm.argument(0).to_string(global_object);
|
auto message = vm.argument(0).to_string(global_object);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
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));
|
error->install_error_cause(vm.argument(1));
|
||||||
|
@ -59,57 +57,55 @@ Value ErrorConstructor::construct(FunctionObject& new_target)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
||||||
ConstructorName::ConstructorName(GlobalObject& global_object) \
|
ConstructorName::ConstructorName(GlobalObject& global_object) \
|
||||||
: NativeFunction(*static_cast<Object*>(global_object.error_constructor())) \
|
: NativeFunction(*static_cast<Object*>(global_object.error_constructor())) \
|
||||||
{ \
|
{ \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
void ConstructorName::initialize(GlobalObject& global_object) \
|
void ConstructorName::initialize(GlobalObject& global_object) \
|
||||||
{ \
|
{ \
|
||||||
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_property(vm.names.prototype, global_object.snake_name##_prototype(), 0); \
|
define_property(vm.names.prototype, global_object.snake_name##_prototype(), 0); \
|
||||||
\
|
\
|
||||||
define_property(vm.names.length, Value(1), Attribute::Configurable); \
|
define_property(vm.names.length, Value(1), Attribute::Configurable); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
ConstructorName::~ConstructorName() { } \
|
ConstructorName::~ConstructorName() { } \
|
||||||
\
|
\
|
||||||
/* 20.5.6.1.1 NativeError ( message ), https://tc39.es/ecma262/#sec-nativeerror */ \
|
/* 20.5.6.1.1 NativeError ( message ), https://tc39.es/ecma262/#sec-nativeerror */ \
|
||||||
Value ConstructorName::call() \
|
Value ConstructorName::call() \
|
||||||
{ \
|
{ \
|
||||||
return construct(*this); \
|
return construct(*this); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
/* 20.5.6.1.1 NativeError ( message ), https://tc39.es/ecma262/#sec-nativeerror */ \
|
/* 20.5.6.1.1 NativeError ( message ), https://tc39.es/ecma262/#sec-nativeerror */ \
|
||||||
Value ConstructorName::construct(FunctionObject& new_target) \
|
Value 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 = ordinary_create_from_constructor<ClassName>( \
|
auto* error = ordinary_create_from_constructor<ClassName>( \
|
||||||
global_object, new_target, &GlobalObject::snake_name##_prototype); \
|
global_object, new_target, &GlobalObject::snake_name##_prototype); \
|
||||||
if (vm.exception()) \
|
if (vm.exception()) \
|
||||||
return {}; \
|
return {}; \
|
||||||
\
|
\
|
||||||
u8 attr = Attribute::Writable | Attribute::Configurable; \
|
if (!vm.argument(0).is_undefined()) { \
|
||||||
\
|
auto message = vm.argument(0).to_string(global_object); \
|
||||||
if (!vm.argument(0).is_undefined()) { \
|
if (vm.exception()) \
|
||||||
auto message = vm.argument(0).to_string(global_object); \
|
return {}; \
|
||||||
if (vm.exception()) \
|
error->create_non_enumerable_data_property_or_throw(vm.names.message, js_string(vm, message)); \
|
||||||
return {}; \
|
} \
|
||||||
error->define_property(vm.names.message, js_string(vm, message), attr); \
|
\
|
||||||
} \
|
error->install_error_cause(vm.argument(1)); \
|
||||||
\
|
if (vm.exception()) \
|
||||||
error->install_error_cause(vm.argument(1)); \
|
return {}; \
|
||||||
if (vm.exception()) \
|
\
|
||||||
return {}; \
|
return error; \
|
||||||
\
|
|
||||||
return error; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_ENUMERATE_NATIVE_ERRORS
|
JS_ENUMERATE_NATIVE_ERRORS
|
||||||
|
|
|
@ -190,6 +190,19 @@ bool Object::create_data_property_or_throw(PropertyName const& property_name, Va
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 7.3.6 CreateNonEnumerableDataPropertyOrThrow ( O, P, V ), https://tc39.es/proposal-error-cause/#sec-createnonenumerabledatapropertyorthrow
|
||||||
|
bool Object::create_non_enumerable_data_property_or_throw(PropertyName const& property_name, Value value)
|
||||||
|
{
|
||||||
|
VERIFY(!value.is_empty());
|
||||||
|
VERIFY(property_name.is_valid());
|
||||||
|
|
||||||
|
// 1. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }.
|
||||||
|
auto new_description = PropertyDescriptor { .value = value, .writable = true, .enumerable = false, .configurable = true };
|
||||||
|
|
||||||
|
// 2. Return ? DefinePropertyOrThrow(O, P, newDesc).
|
||||||
|
return define_property_or_throw(property_name, new_description);
|
||||||
|
}
|
||||||
|
|
||||||
// 7.3.8 DefinePropertyOrThrow ( O, P, desc ), https://tc39.es/ecma262/#sec-definepropertyorthrow
|
// 7.3.8 DefinePropertyOrThrow ( O, P, desc ), https://tc39.es/ecma262/#sec-definepropertyorthrow
|
||||||
bool Object::define_property_or_throw(PropertyName const& property_name, PropertyDescriptor const& property_descriptor)
|
bool Object::define_property_or_throw(PropertyName const& property_name, PropertyDescriptor const& property_descriptor)
|
||||||
{
|
{
|
||||||
|
|
|
@ -78,6 +78,7 @@ public:
|
||||||
bool create_data_property(PropertyName const&, Value);
|
bool create_data_property(PropertyName const&, Value);
|
||||||
bool create_method_property(PropertyName const&, Value);
|
bool create_method_property(PropertyName const&, Value);
|
||||||
bool create_data_property_or_throw(PropertyName const&, Value);
|
bool create_data_property_or_throw(PropertyName const&, Value);
|
||||||
|
bool create_non_enumerable_data_property_or_throw(PropertyName const&, Value);
|
||||||
bool define_property_or_throw(PropertyName const&, PropertyDescriptor const&);
|
bool define_property_or_throw(PropertyName const&, PropertyDescriptor const&);
|
||||||
bool delete_property_or_throw(PropertyName const&);
|
bool delete_property_or_throw(PropertyName const&);
|
||||||
bool has_property(PropertyName const&) const;
|
bool has_property(PropertyName const&) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue