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

LibJS: Explicitly return and accept a Function* in species_constructor

The second argument (the default constructor) and the return value have
to be constructors (as a result functions), so we can require that
explicitly by using appropriate types.
This commit is contained in:
Idan Horowitz 2021-06-10 23:50:48 +03:00 committed by Linus Groh
parent 4531f689ff
commit b041108a1e
3 changed files with 5 additions and 5 deletions

View file

@ -89,7 +89,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
} else { } else {
// 27.2.5.3.1 Then Finally Functions, https://tc39.es/ecma262/#sec-thenfinallyfunctions // 27.2.5.3.1 Then Finally Functions, https://tc39.es/ecma262/#sec-thenfinallyfunctions
auto* then_finally_function = NativeFunction::create(global_object, "", [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm, auto& global_object) -> Value { auto* then_finally_function = NativeFunction::create(global_object, "", [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm, auto& global_object) -> Value {
auto& constructor = const_cast<Object&>(*constructor_handle.cell()); auto& constructor = const_cast<Function&>(*constructor_handle.cell());
auto& on_finally = const_cast<Function&>(*on_finally_handle.cell()); auto& on_finally = const_cast<Function&>(*on_finally_handle.cell());
auto value = vm.argument(0); auto value = vm.argument(0);
auto result = vm.call(on_finally, js_undefined()); auto result = vm.call(on_finally, js_undefined());
@ -107,7 +107,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
// 27.2.5.3.2 Catch Finally Functions, https://tc39.es/ecma262/#sec-catchfinallyfunctions // 27.2.5.3.2 Catch Finally Functions, https://tc39.es/ecma262/#sec-catchfinallyfunctions
auto* catch_finally_function = NativeFunction::create(global_object, "", [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm, auto& global_object) -> Value { auto* catch_finally_function = NativeFunction::create(global_object, "", [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm, auto& global_object) -> Value {
auto& constructor = const_cast<Object&>(*constructor_handle.cell()); auto& constructor = const_cast<Function&>(*constructor_handle.cell());
auto& on_finally = const_cast<Function&>(*on_finally_handle.cell()); auto& on_finally = const_cast<Function&>(*on_finally_handle.cell());
auto reason = vm.argument(0); auto reason = vm.argument(0);
auto result = vm.call(on_finally, js_undefined()); auto result = vm.call(on_finally, js_undefined());

View file

@ -1387,7 +1387,7 @@ size_t length_of_array_like(GlobalObject& global_object, const Object& object)
} }
// 7.3.22 SpeciesConstructor, https://tc39.es/ecma262/#sec-speciesconstructor // 7.3.22 SpeciesConstructor, https://tc39.es/ecma262/#sec-speciesconstructor
Object* species_constructor(GlobalObject& global_object, const Object& object, Object& default_constructor) Function* species_constructor(GlobalObject& global_object, const Object& object, Function& default_constructor)
{ {
auto& vm = global_object.vm(); auto& vm = global_object.vm();
auto constructor = object.get(vm.names.constructor).value_or(js_undefined()); auto constructor = object.get(vm.names.constructor).value_or(js_undefined());
@ -1403,7 +1403,7 @@ Object* species_constructor(GlobalObject& global_object, const Object& object, O
if (species.is_nullish()) if (species.is_nullish())
return &default_constructor; return &default_constructor;
if (species.is_constructor()) if (species.is_constructor())
return &species.as_object(); return &species.as_function();
vm.throw_exception<TypeError>(global_object, ErrorType::NotAConstructor, species.to_string_without_side_effects()); vm.throw_exception<TypeError>(global_object, ErrorType::NotAConstructor, species.to_string_without_side_effects());
return nullptr; return nullptr;
} }

View file

@ -372,7 +372,7 @@ bool same_value_non_numeric(Value lhs, Value rhs);
TriState abstract_relation(GlobalObject&, bool left_first, Value lhs, Value rhs); TriState abstract_relation(GlobalObject&, bool left_first, Value lhs, Value rhs);
Function* get_method(GlobalObject& global_object, Value, const PropertyName&); Function* get_method(GlobalObject& global_object, Value, const PropertyName&);
size_t length_of_array_like(GlobalObject&, const Object&); size_t length_of_array_like(GlobalObject&, const Object&);
Object* species_constructor(GlobalObject&, const Object&, Object& default_constructor); Function* species_constructor(GlobalObject&, const Object&, Function& default_constructor);
Value require_object_coercible(GlobalObject&, Value); Value require_object_coercible(GlobalObject&, Value);
MarkedValueList create_list_from_array_like(GlobalObject&, Value, AK::Function<Result<void, ErrorType>(Value)> = {}); MarkedValueList create_list_from_array_like(GlobalObject&, Value, AK::Function<Result<void, ErrorType>(Value)> = {});