LibJS: Port Value::to_primitive_string() to NonnullGCPtr

This commit is contained in:
Linus Groh 2023-04-13 14:34:00 +02:00 committed by Andreas Kling
parent 04198a29a8
commit e79f5b6e85
Notes: sideshowbarker 2024-07-17 04:09:56 +09:00
3 changed files with 8 additions and 8 deletions

View file

@ -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);

View file

@ -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.

View file

@ -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;