1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:57:34 +00:00

LibJS: Rename Symbol::to_deprecated_string() to descriptive_string()

This implements the spec's SymbolDescriptiveString AO and should be
named accordingly.
This commit is contained in:
Linus Groh 2023-02-11 15:51:44 +00:00
parent ac440e6c0e
commit 89700a2101
7 changed files with 22 additions and 9 deletions

View file

@ -216,7 +216,7 @@ DeprecatedString Reference::to_deprecated_string() const
if (!m_name.is_valid())
builder.append("<invalid>"sv);
else if (m_name.is_symbol())
builder.appendff("{}", m_name.as_symbol()->to_deprecated_string());
builder.appendff("{}", m_name.as_symbol()->descriptive_string());
else
builder.appendff("{}", m_name.to_string());
builder.appendff(", Strict={}", m_strict);

View file

@ -47,7 +47,7 @@ ThrowCompletionOr<Value> StringConstructor::call()
if (!vm.argument_count())
return PrimitiveString::create(vm, String {});
if (vm.argument(0).is_symbol())
return PrimitiveString::create(vm, vm.argument(0).as_symbol().to_deprecated_string());
return PrimitiveString::create(vm, vm.argument(0).as_symbol().descriptive_string());
return TRY(vm.argument(0).to_primitive_string(vm));
}

View file

@ -79,7 +79,7 @@ public:
if (is_string())
return as_string();
if (is_symbol())
return as_symbol()->to_deprecated_string();
return as_symbol()->descriptive_string();
VERIFY_NOT_REACHED();
}

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -22,4 +22,16 @@ NonnullGCPtr<Symbol> Symbol::create(VM& vm, Optional<DeprecatedString> descripti
return vm.heap().allocate_without_realm<Symbol>(move(description), is_global);
}
// 20.4.3.3.1 SymbolDescriptiveString ( sym ), https://tc39.es/ecma262/#sec-symboldescriptivestring
DeprecatedString Symbol::descriptive_string() const
{
// 1. Let desc be sym's [[Description]] value.
// 2. If desc is undefined, set desc to the empty String.
// 3. Assert: desc is a String.
auto description = m_description.value_or("");
// 4. Return the string-concatenation of "Symbol(", desc, and ")".
return DeprecatedString::formatted("Symbol({})", description);
}
}

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -24,7 +24,8 @@ public:
DeprecatedString description() const { return m_description.value_or(""); }
Optional<DeprecatedString> const& raw_description() const { return m_description; }
bool is_global() const { return m_is_global; }
DeprecatedString to_deprecated_string() const { return DeprecatedString::formatted("Symbol({})", description()); }
DeprecatedString descriptive_string() const;
private:
Symbol(Optional<DeprecatedString>, bool);

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -63,7 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::description_getter)
JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::to_string)
{
auto* symbol = TRY(this_symbol_value(vm, vm.this_value()));
return PrimitiveString::create(vm, symbol->to_deprecated_string());
return PrimitiveString::create(vm, symbol->descriptive_string());
}
// 20.4.3.4 Symbol.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-symbol.prototype.valueof

View file

@ -372,7 +372,7 @@ DeprecatedString Value::to_string_without_side_effects() const
case STRING_TAG:
return MUST(as_string().deprecated_string());
case SYMBOL_TAG:
return as_symbol().to_deprecated_string();
return as_symbol().descriptive_string();
case BIGINT_TAG:
return as_bigint().to_deprecated_string();
case OBJECT_TAG: