From e79f5b6e857d8f6b79eec5aad3d524237ea0a23b Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 13 Apr 2023 14:34:00 +0200 Subject: [PATCH] LibJS: Port Value::to_primitive_string() to NonnullGCPtr --- Userland/Libraries/LibJS/Runtime/StringPrototype.cpp | 6 +++--- Userland/Libraries/LibJS/Runtime/Value.cpp | 8 ++++---- Userland/Libraries/LibJS/Runtime/Value.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp index 0d452174cc2..2dbfa9de30e 100644 --- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -301,15 +301,15 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::concat) auto object = TRY(require_object_coercible(vm, vm.this_value())); // 2. Let S be ? ToString(O). - auto* string = TRY(object.to_primitive_string(vm)); + auto string = TRY(object.to_primitive_string(vm)); // 3. Let R be S. - auto* result = string; + auto result = string; // 4. For each element next of args, do for (size_t i = 0; i < vm.argument_count(); ++i) { // a. Let nextString be ? ToString(next). - auto* next_string = TRY(vm.argument(i).to_primitive_string(vm)); + auto next_string = TRY(vm.argument(i).to_primitive_string(vm)); // b. Set R to the string-concatenation of R and nextString. result = PrimitiveString::create(vm, *result, *next_string); diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index 100327c78fb..0c8de4df192 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -397,12 +397,12 @@ ErrorOr Value::to_string_without_side_effects() const } } -ThrowCompletionOr Value::to_primitive_string(VM& vm) +ThrowCompletionOr> Value::to_primitive_string(VM& vm) { if (is_string()) - return &as_string(); + return as_string(); auto string = TRY(to_string(vm)); - return PrimitiveString::create(vm, move(string)).ptr(); + return PrimitiveString::create(vm, move(string)); } // 7.1.17 ToString ( argument ), https://tc39.es/ecma262/#sec-tostring @@ -1728,7 +1728,7 @@ ThrowCompletionOr add(VM& vm, Value lhs, Value rhs) auto rhs_string = TRY(rhs_primitive.to_primitive_string(vm)); // iii. Return the string-concatenation of lstr and rstr. - return PrimitiveString::create(vm, *lhs_string, *rhs_string); + return PrimitiveString::create(vm, lhs_string, rhs_string); } // d. Set lval to lprim. diff --git a/Userland/Libraries/LibJS/Runtime/Value.h b/Userland/Libraries/LibJS/Runtime/Value.h index 81ac4c57ec5..351b8505563 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.h +++ b/Userland/Libraries/LibJS/Runtime/Value.h @@ -369,7 +369,7 @@ public: ThrowCompletionOr to_string(VM&) const; ThrowCompletionOr to_deprecated_string(VM&) const; ThrowCompletionOr to_utf16_string(VM&) const; - ThrowCompletionOr to_primitive_string(VM&); + ThrowCompletionOr> to_primitive_string(VM&); ThrowCompletionOr to_primitive(VM&, PreferredType preferred_type = PreferredType::Default) const; ThrowCompletionOr to_object(VM&) const; ThrowCompletionOr to_numeric(VM&) const;