Browse Source

LibJS: Port Value::to_primitive_string() to NonnullGCPtr

Linus Groh 2 years ago
parent
commit
e79f5b6e85

+ 3 - 3
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);

+ 4 - 4
Userland/Libraries/LibJS/Runtime/Value.cpp

@@ -397,12 +397,12 @@ ErrorOr<String> Value::to_string_without_side_effects() const
     }
 }
 
-ThrowCompletionOr<PrimitiveString*> Value::to_primitive_string(VM& vm)
+ThrowCompletionOr<NonnullGCPtr<PrimitiveString>> 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<Value> 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.

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Value.h

@@ -369,7 +369,7 @@ public:
     ThrowCompletionOr<String> to_string(VM&) const;
     ThrowCompletionOr<DeprecatedString> to_deprecated_string(VM&) const;
     ThrowCompletionOr<Utf16String> to_utf16_string(VM&) const;
-    ThrowCompletionOr<PrimitiveString*> to_primitive_string(VM&);
+    ThrowCompletionOr<NonnullGCPtr<PrimitiveString>> to_primitive_string(VM&);
     ThrowCompletionOr<Value> to_primitive(VM&, PreferredType preferred_type = PreferredType::Default) const;
     ThrowCompletionOr<Object*> to_object(VM&) const;
     ThrowCompletionOr<Value> to_numeric(VM&) const;