1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:47:36 +00:00

LibJS: Convert to_primitive_string() to ThrowCompletionOr

This commit is contained in:
Linus Groh 2021-10-12 18:05:46 +01:00
parent da59c77fe3
commit 96ab116f0d
8 changed files with 18 additions and 30 deletions

View file

@ -49,10 +49,7 @@ Value StringConstructor::call()
return js_string(heap(), "");
if (vm().argument(0).is_symbol())
return js_string(heap(), vm().argument(0).as_symbol().to_string());
auto* string = vm().argument(0).to_primitive_string(global_object());
if (vm().exception())
return {};
return string;
return TRY_OR_DISCARD(vm().argument(0).to_primitive_string(global_object()));
}
// 22.1.1.1 String ( value ), https://tc39.es/ecma262/#sec-string-constructor-string-value
@ -64,9 +61,7 @@ Value StringConstructor::construct(FunctionObject& new_target)
if (!vm.argument_count())
primitive_string = js_string(vm, "");
else
primitive_string = vm.argument(0).to_primitive_string(global_object());
if (!primitive_string)
return {};
primitive_string = TRY_OR_DISCARD(vm.argument(0).to_primitive_string(global_object()));
auto* prototype = TRY_OR_DISCARD(get_prototype_from_constructor(global_object(), new_target, &GlobalObject::string_prototype));
return StringObject::create(global_object(), *primitive_string, *prototype);
}