diff --git a/Libraries/LibJS/Runtime/Array.cpp b/Libraries/LibJS/Runtime/Array.cpp index b9ff8b60932..9fced8923ce 100644 --- a/Libraries/LibJS/Runtime/Array.cpp +++ b/Libraries/LibJS/Runtime/Array.cpp @@ -243,10 +243,10 @@ ThrowCompletionOr compare_array_elements(VM& vm, Value x, Value y, Funct } // 5. Let xString be ? ToString(x). - auto x_string = PrimitiveString::create(vm, TRY(x.to_byte_string(vm))); + auto x_string = PrimitiveString::create(vm, TRY(x.to_string(vm))); // 6. Let yString be ? ToString(y). - auto y_string = PrimitiveString::create(vm, TRY(y.to_byte_string(vm))); + auto y_string = PrimitiveString::create(vm, TRY(y.to_string(vm))); // 7. Let xSmaller be ! IsLessThan(xString, yString, true). auto x_smaller = MUST(is_less_than(vm, x_string, y_string, true)); diff --git a/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Libraries/LibJS/Runtime/ArrayPrototype.cpp index c1071888bde..8af530c507d 100644 --- a/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -838,9 +838,9 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join) }; auto length = TRY(length_of_array_like(vm, this_object)); - ByteString separator = ","; + String separator = ","_string; if (!vm.argument(0).is_undefined()) - separator = TRY(vm.argument(0).to_byte_string(vm)); + separator = TRY(vm.argument(0).to_string(vm)); StringBuilder builder; for (size_t i = 0; i < length; ++i) { if (i > 0) @@ -848,11 +848,11 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join) auto value = TRY(this_object->get(i)); if (value.is_nullish()) continue; - auto string = TRY(value.to_byte_string(vm)); + auto string = TRY(value.to_string(vm)); builder.append(string); } - return PrimitiveString::create(vm, builder.to_byte_string()); + return PrimitiveString::create(vm, builder.to_string_without_validation()); } // 23.1.3.19 Array.prototype.keys ( ), https://tc39.es/ecma262/#sec-array.prototype.keys @@ -1650,7 +1650,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string) auto locale_string_result = TRY(value.invoke(vm, vm.names.toLocaleString, locales, options)); // ii. Set R to the string-concatenation of R and S. - auto string = TRY(locale_string_result.to_byte_string(vm)); + auto string = TRY(locale_string_result.to_string(vm)); builder.append(string); } @@ -1658,7 +1658,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string) } // 7. Return R. - return PrimitiveString::create(vm, builder.to_byte_string()); + return PrimitiveString::create(vm, builder.to_string_without_validation()); } // 23.1.3.33 Array.prototype.toReversed ( ), https://tc39.es/ecma262/#sec-array.prototype.toreversed diff --git a/Libraries/LibJS/Runtime/StringConstructor.cpp b/Libraries/LibJS/Runtime/StringConstructor.cpp index 1cc4a8f9006..1da468c6371 100644 --- a/Libraries/LibJS/Runtime/StringConstructor.cpp +++ b/Libraries/LibJS/Runtime/StringConstructor.cpp @@ -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); diff --git a/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp b/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp index 1c150ec9e4f..f121a15bccd 100644 --- a/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp +++ b/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp @@ -1987,7 +1987,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::to_locale_string) if (!next_element.is_nullish()) { // i. Let S be ? ToString(? Invoke(nextElement, "toLocaleString", « locales, options »)). auto locale_string_value = TRY(next_element.invoke(vm, vm.names.toLocaleString, locales, options)); - auto locale_string = TRY(locale_string_value.to_byte_string(vm)); + auto locale_string = TRY(locale_string_value.to_string(vm)); // ii. Set R to the string-concatenation of R and S. builder.append(locale_string); @@ -1997,7 +1997,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::to_locale_string) } // 7. Return R. - return PrimitiveString::create(vm, builder.to_byte_string()); + return PrimitiveString::create(vm, builder.to_string_without_validation()); } // 23.2.3.32 %TypedArray%.prototype.toReversed ( ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.toreversed diff --git a/Tests/LibJS/test-js.cpp b/Tests/LibJS/test-js.cpp index 98174b4e1c4..ee263d40dd9 100644 --- a/Tests/LibJS/test-js.cpp +++ b/Tests/LibJS/test-js.cpp @@ -26,7 +26,7 @@ TESTJS_GLOBAL_FUNCTION(is_strict_mode, isStrictMode, 0) TESTJS_GLOBAL_FUNCTION(can_parse_source, canParseSource) { - auto source = TRY(vm.argument(0).to_byte_string(vm)); + auto source = TRY(vm.argument(0).to_string(vm)); auto parser = JS::Parser(JS::Lexer(source)); (void)parser.parse_program(); return JS::Value(!parser.has_errors()); diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp index 4f8ddc2e229..fe2bfcd36e8 100644 --- a/Tests/LibWasm/test-wasm.cpp +++ b/Tests/LibWasm/test-wasm.cpp @@ -21,7 +21,7 @@ TESTJS_GLOBAL_FUNCTION(read_binary_wasm_file, readBinaryWasmFile) return StringView { error_string, strlen(error_string) }; }; - auto filename = TRY(vm.argument(0).to_byte_string(vm)); + auto filename = TRY(vm.argument(0).to_string(vm)); auto file = Core::File::open(filename, Core::File::OpenMode::Read); if (file.is_error()) return vm.throw_completion(error_code_to_string(file.error().code()));