LibJS: Prefer Value::to_string() over to_byte_string() in more places

We should always prefer working with String, and Value::to_string() may
even return a cached String if the Value refers to a primitive string,
but no caching occurs for ByteString.
This commit is contained in:
Andreas Kling 2025-03-16 17:44:29 -05:00 committed by Andreas Kling
parent 8155377b5f
commit e83a2c2369
Notes: github-actions[bot] 2025-03-24 22:28:59 +00:00
6 changed files with 15 additions and 17 deletions

View file

@ -167,13 +167,11 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::raw)
// 7. Let nextIndex be 0.
// 8. Repeat,
for (size_t i = 0; i < literal_count; ++i) {
auto next_key = ByteString::number(i);
// a. Let nextLiteralVal be ? Get(literals, ! ToString(𝔽(nextIndex))).
auto next_literal_value = TRY(literals->get(next_key));
auto next_literal_value = TRY(literals->get(PropertyKey(i)));
// b. Let nextLiteral be ? ToString(nextLiteralVal).
auto next_literal = TRY(next_literal_value.to_byte_string(vm));
auto next_literal = TRY(next_literal_value.to_string(vm));
// c. Set R to the string-concatenation of R and nextLiteral.
builder.append(next_literal);
@ -188,7 +186,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::raw)
auto next_substitution_value = vm.argument(i + 1);
// ii. Let nextSub be ? ToString(nextSubVal).
auto next_substitution = TRY(next_substitution_value.to_byte_string(vm));
auto next_substitution = TRY(next_substitution_value.to_string(vm));
// iii. Set R to the string-concatenation of R and nextSub.
builder.append(next_substitution);