diff --git a/Libraries/LibJS/Contrib/Test262/262Object.cpp b/Libraries/LibJS/Contrib/Test262/262Object.cpp index c24e086f45e..c3a8ec80107 100644 --- a/Libraries/LibJS/Contrib/Test262/262Object.cpp +++ b/Libraries/LibJS/Contrib/Test262/262Object.cpp @@ -87,7 +87,7 @@ JS_DEFINE_NATIVE_FUNCTION($262Object::detach_array_buffer) JS_DEFINE_NATIVE_FUNCTION($262Object::eval_script) { - auto source_text = TRY(vm.argument(0).to_byte_string(vm)); + auto source_text = TRY(vm.argument(0).to_string(vm)); // 1. Let hostDefined be any host-defined values for the provided sourceText (obtained in an implementation dependent manner) diff --git a/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp b/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp index 9aee7a63d52..f1a5f1d14a0 100644 --- a/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp +++ b/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp @@ -36,7 +36,7 @@ void GlobalObject::visit_edges(Cell::Visitor& visitor) JS_DEFINE_NATIVE_FUNCTION(GlobalObject::print) { - auto string = TRY(vm.argument(0).to_byte_string(vm)); + auto string = TRY(vm.argument(0).to_string(vm)); outln("{}", string); return js_undefined(); } diff --git a/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp b/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp index bbdcaf308f0..519e511ae02 100644 --- a/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp +++ b/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp @@ -55,7 +55,7 @@ ThrowCompletionOr> AggregateErrorConstructor::construct(Function // 3. If message is not undefined, then if (!message.is_undefined()) { // a. Let msg be ? ToString(message). - auto msg = TRY(message.to_byte_string(vm)); + auto msg = TRY(message.to_string(vm)); // b. Perform CreateNonEnumerableDataPropertyOrThrow(O, "message", msg). aggregate_error->create_non_enumerable_data_property_or_throw(vm.names.message, PrimitiveString::create(vm, msg)); diff --git a/Libraries/LibJS/Runtime/NumberPrototype.cpp b/Libraries/LibJS/Runtime/NumberPrototype.cpp index 059ad0f47cc..ecdb66f3e5a 100644 --- a/Libraries/LibJS/Runtime/NumberPrototype.cpp +++ b/Libraries/LibJS/Runtime/NumberPrototype.cpp @@ -92,7 +92,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_exponential) // 4. If x is not finite, return Number::toString(x). if (!number_value.is_finite_number()) - return PrimitiveString::create(vm, MUST(number_value.to_byte_string(vm))); + return PrimitiveString::create(vm, MUST(number_value.to_string(vm))); // 5. If f < 0 or f > 100, throw a RangeError exception. if (fraction_digits < 0 || fraction_digits > 100) @@ -220,7 +220,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_fixed) // 6. If x is not finite, return Number::toString(x). if (!number_value.is_finite_number()) - return PrimitiveString::create(vm, TRY(number_value.to_byte_string(vm))); + return PrimitiveString::create(vm, TRY(number_value.to_string(vm))); // 7. Set x to ℝ(x). auto number = number_value.as_double(); @@ -236,7 +236,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_fixed) // 10. If x ≥ 10^21, then // a. Let m be ! ToString(𝔽(x)). if (number >= 1e+21) - return PrimitiveString::create(vm, MUST(number_value.to_byte_string(vm))); + return PrimitiveString::create(vm, MUST(number_value.to_string(vm))); // 11. Else, // a. Let n be an integer for which n / (10^f) - x is as close to zero as possible. If there are two such n, pick the larger n. @@ -289,14 +289,14 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_precision) // 2. If precision is undefined, return ! ToString(x). if (precision_value.is_undefined()) - return PrimitiveString::create(vm, MUST(number_value.to_byte_string(vm))); + return PrimitiveString::create(vm, MUST(number_value.to_string(vm))); // 3. Let p be ? ToIntegerOrInfinity(precision). auto precision = TRY(precision_value.to_integer_or_infinity(vm)); // 4. If x is not finite, return Number::toString(x). if (!number_value.is_finite_number()) - return PrimitiveString::create(vm, MUST(number_value.to_byte_string(vm))); + return PrimitiveString::create(vm, MUST(number_value.to_string(vm))); // 5. If p < 1 or p > 100, throw a RangeError exception. if ((precision < 1) || (precision > 100)) @@ -428,7 +428,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string) // 5. If radixMV = 10, return ! ToString(x). if (radix_mv == 10) - return PrimitiveString::create(vm, MUST(number_value.to_byte_string(vm))); + return PrimitiveString::create(vm, MUST(number_value.to_string(vm))); // 6. Return the String representation of this Number value using the radix specified by radixMV. Letters a-z are used for digits with values 10 through 35. The precise algorithm is implementation-defined, however the algorithm should be a generalization of that specified in 6.1.6.1.20. if (number_value.is_positive_infinity()) diff --git a/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Libraries/LibJS/Runtime/RegExpPrototype.cpp index 983b6de5333..491747c7804 100644 --- a/Libraries/LibJS/Runtime/RegExpPrototype.cpp +++ b/Libraries/LibJS/Runtime/RegExpPrototype.cpp @@ -481,7 +481,6 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::exec) // 22.2.6.4 get RegExp.prototype.flags, https://tc39.es/ecma262/#sec-get-regexp.prototype.flags JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::flags) { - // 1. Let R be the this value. // 2. If Type(R) is not Object, throw a TypeError exception. auto regexp_object = TRY(this_object(vm)); @@ -513,7 +512,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::flags) #undef __JS_ENUMERATE // 20. Return result. - return PrimitiveString::create(vm, builder.to_byte_string()); + return PrimitiveString::create(vm, builder.to_string_without_validation()); } // 22.2.6.8 RegExp.prototype [ @@match ] ( string ), https://tc39.es/ecma262/#sec-regexp.prototype-@@match @@ -530,7 +529,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match) // 4. Let flags be ? ToString(? Get(rx, "flags")). auto flags_value = TRY(regexp_object->get(vm.names.flags)); - auto flags = TRY(flags_value.to_byte_string(vm)); + auto flags = TRY(flags_value.to_string(vm)); // 5. If flags does not contain "g", then if (!flags.contains('g')) { @@ -573,7 +572,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match) // 1. Let matchStr be ? ToString(? Get(result, "0")). auto match_value = TRY(result.get(0)); - auto match_str = TRY(match_value.to_byte_string(vm)); + auto match_str = TRY(match_value.to_string(vm)); // 2. Perform ! CreateDataPropertyOrThrow(A, ! ToString(𝔽(n)), matchStr). MUST(array->create_data_property_or_throw(n, PrimitiveString::create(vm, match_str))); @@ -606,7 +605,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match_all) // 5. Let flags be ? ToString(? Get(R, "flags")). auto flags_value = TRY(regexp_object->get(vm.names.flags)); - auto flags = TRY(flags_value.to_byte_string(vm)); + auto flags = TRY(flags_value.to_string(vm)); // Steps 9-12 are performed early so that flags can be moved. @@ -651,13 +650,13 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace) // 6. If functionalReplace is false, then if (!replace_value.is_function()) { // a. Set replaceValue to ? ToString(replaceValue). - auto replace_string = TRY(replace_value.to_byte_string(vm)); + auto replace_string = TRY(replace_value.to_string(vm)); replace_value = PrimitiveString::create(vm, move(replace_string)); } // 7. Let flags be ? ToString(? Get(rx, "flags")). auto flags_value = TRY(regexp_object->get(vm.names.flags)); - auto flags = TRY(flags_value.to_byte_string(vm)); + auto flags = TRY(flags_value.to_string(vm)); // 8. If flags contains "g", let global be true. Otherwise, let global be false. bool global = flags.contains('g'); @@ -694,7 +693,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace) // 1. Let matchStr be ? ToString(? Get(result, "0")). auto match_value = TRY(result.get(vm, 0)); - auto match_str = TRY(match_value.to_byte_string(vm)); + auto match_str = TRY(match_value.to_string(vm)); // 2. If matchStr is the empty String, then if (match_str.is_empty()) { @@ -746,7 +745,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace) // ii. If capN is not undefined, then if (!capture.is_undefined()) { // 1. Set capN to ? ToString(capN). - capture = PrimitiveString::create(vm, TRY(capture.to_byte_string(vm))); + capture = PrimitiveString::create(vm, TRY(capture.to_string(vm))); } // iii. Append capN as the last element of captures. @@ -810,13 +809,13 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace) // 16. If nextSourcePosition ≥ lengthS, return accumulatedResult. if (next_source_position >= string.length_in_code_units()) - return PrimitiveString::create(vm, accumulated_result.to_byte_string()); + return PrimitiveString::create(vm, accumulated_result.to_string_without_validation()); // 17. Return the string-concatenation of accumulatedResult and the substring of S from nextSourcePosition. auto substring = string.substring_view(next_source_position); accumulated_result.append(substring); - return PrimitiveString::create(vm, accumulated_result.to_byte_string()); + return PrimitiveString::create(vm, accumulated_result.to_string_without_validation()); } // 22.2.6.12 RegExp.prototype [ @@search ] ( string ), https://tc39.es/ecma262/#sec-regexp.prototype-@@search @@ -901,7 +900,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split) // 5. Let flags be ? ToString(? Get(rx, "flags")). auto flags_value = TRY(regexp_object->get(vm.names.flags)); - auto flags = TRY(flags_value.to_byte_string(vm)); + auto flags = TRY(flags_value.to_string(vm)); // 6. If flags contains "u" or flags contains "v", let unicodeMatching be true. // 7. Else, let unicodeMatching be false. @@ -909,7 +908,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split) // 8. If flags contains "y", let newFlags be flags. // 9. Else, let newFlags be the string-concatenation of flags and "y". - auto new_flags = flags.find('y').has_value() ? move(flags) : ByteString::formatted("{}y", flags); + auto new_flags = flags.bytes_as_string_view().find('y').has_value() ? move(flags) : MUST(String::formatted("{}y", flags)); // 10. Let splitter be ? Construct(C, « rx, newFlags »). auto splitter = TRY(construct(vm, *constructor, regexp_object, PrimitiveString::create(vm, move(new_flags)))); @@ -1066,11 +1065,11 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::to_string) // 3. Let pattern be ? ToString(? Get(R, "source")). auto source_attr = TRY(regexp_object->get(vm.names.source)); - auto pattern = TRY(source_attr.to_byte_string(vm)); + auto pattern = TRY(source_attr.to_string(vm)); // 4. Let flags be ? ToString(? Get(R, "flags")). auto flags_attr = TRY(regexp_object->get(vm.names.flags)); - auto flags = TRY(flags_attr.to_byte_string(vm)); + auto flags = TRY(flags_attr.to_string(vm)); // 5. Let result be the string-concatenation of "/", pattern, "/", and flags. // 6. Return result. diff --git a/Libraries/LibJS/Runtime/RegExpStringIteratorPrototype.cpp b/Libraries/LibJS/Runtime/RegExpStringIteratorPrototype.cpp index 4fa03378e77..c9955795140 100644 --- a/Libraries/LibJS/Runtime/RegExpStringIteratorPrototype.cpp +++ b/Libraries/LibJS/Runtime/RegExpStringIteratorPrototype.cpp @@ -53,7 +53,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpStringIteratorPrototype::next) auto match_object = TRY(match.to_object(vm)); auto match_string_value = TRY(match_object->get(0)); - auto match_string = TRY(match_string_value.to_byte_string(vm)); + auto match_string = TRY(match_string_value.to_string(vm)); if (match_string.is_empty()) { auto last_index_value = TRY(iterator->regexp_object().get(vm.names.lastIndex)); auto last_index = TRY(last_index_value.to_length(vm)); diff --git a/Services/WebContent/ConsoleGlobalEnvironmentExtensions.cpp b/Services/WebContent/ConsoleGlobalEnvironmentExtensions.cpp index f0c485a6398..7a97a30db3d 100644 --- a/Services/WebContent/ConsoleGlobalEnvironmentExtensions.cpp +++ b/Services/WebContent/ConsoleGlobalEnvironmentExtensions.cpp @@ -71,7 +71,7 @@ JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalEnvironmentExtensions::$_function) auto* console_global_object = TRY(get_console(vm)); auto& window = *console_global_object->m_window_object; - auto selector = TRY(vm.argument(0).to_byte_string(vm)); + auto selector = TRY(vm.argument(0).to_string(vm)); if (vm.argument_count() > 1) { auto element_value = vm.argument(1); @@ -95,7 +95,7 @@ JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalEnvironmentExtensions::$$_function) auto* console_global_object = TRY(get_console(vm)); auto& window = *console_global_object->m_window_object; - auto selector = TRY(vm.argument(0).to_byte_string(vm)); + auto selector = TRY(vm.argument(0).to_string(vm)); Web::DOM::ParentNode* element = &window.associated_document(); diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp index 926614f80bd..abefeab5db5 100644 --- a/Tests/LibWasm/test-wasm.cpp +++ b/Tests/LibWasm/test-wasm.cpp @@ -283,14 +283,14 @@ void WebAssemblyModule::initialize(JS::Realm& realm) JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::get_export) { - auto name = TRY(vm.argument(0).to_byte_string(vm)); + auto name = TRY(vm.argument(0).to_string(vm)); auto this_value = vm.this_value(); auto object = TRY(this_value.to_object(vm)); if (!is(*object)) return vm.throw_completion("Not a WebAssemblyModule"sv); auto& instance = static_cast(*object); for (auto& entry : instance.module_instance().exports()) { - if (entry.name() == name) { + if (entry.name() == name.to_byte_string()) { auto& value = entry.value(); if (auto ptr = value.get_pointer()) return JS::Value(static_cast(ptr->value()));