LibJS: Convert define_property_or_throw() to ThrowCompletionOr

This commit is contained in:
Linus Groh 2021-10-03 01:35:36 +01:00
parent ebf57df431
commit fe86b04b42
Notes: sideshowbarker 2024-07-18 03:07:18 +09:00
12 changed files with 31 additions and 58 deletions

View file

@ -78,7 +78,7 @@ void ECMAScriptFunctionObject::initialize(GlobalObject& global_object)
auto* prototype = vm.heap().allocate<Object>(global_object, *global_object.new_ordinary_function_prototype_object_shape());
switch (m_kind) {
case FunctionKind::Regular:
prototype->define_property_or_throw(vm.names.constructor, { .value = this, .writable = true, .enumerable = false, .configurable = true });
MUST(prototype->define_property_or_throw(vm.names.constructor, { .value = this, .writable = true, .enumerable = false, .configurable = true }));
break;
case FunctionKind::Generator:
// prototype is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png)
@ -87,8 +87,8 @@ void ECMAScriptFunctionObject::initialize(GlobalObject& global_object)
}
define_direct_property(vm.names.prototype, prototype, Attribute::Writable);
}
define_property_or_throw(vm.names.length, { .value = Value(m_function_length), .writable = false, .enumerable = false, .configurable = true });
define_property_or_throw(vm.names.name, { .value = js_string(vm, m_name.is_null() ? "" : m_name), .writable = false, .enumerable = false, .configurable = true });
MUST(define_property_or_throw(vm.names.length, { .value = Value(m_function_length), .writable = false, .enumerable = false, .configurable = true }));
MUST(define_property_or_throw(vm.names.name, { .value = js_string(vm, m_name.is_null() ? "" : m_name), .writable = false, .enumerable = false, .configurable = true }));
}
ECMAScriptFunctionObject::~ECMAScriptFunctionObject()
@ -428,7 +428,7 @@ void ECMAScriptFunctionObject::set_name(const FlyString& name)
VERIFY(!name.is_null());
auto& vm = this->vm();
m_name = name;
auto success = define_property_or_throw(vm.names.name, { .value = js_string(vm, m_name), .writable = false, .enumerable = false, .configurable = true });
auto success = MUST(define_property_or_throw(vm.names.name, { .value = js_string(vm, m_name), .writable = false, .enumerable = false, .configurable = true }));
VERIFY(success);
}