1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 21:48:11 +00:00
serenity/Userland/Libraries/LibJS/Runtime/Symbol.cpp
Linus Groh 89700a2101 LibJS: Rename Symbol::to_deprecated_string() to descriptive_string()
This implements the spec's SymbolDescriptiveString AO and should be
named accordingly.
2023-02-11 21:47:57 +00:00

37 lines
1.1 KiB
C++

/*
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Heap/Heap.h>
#include <LibJS/Runtime/Symbol.h>
#include <LibJS/Runtime/VM.h>
namespace JS {
Symbol::Symbol(Optional<DeprecatedString> description, bool is_global)
: m_description(move(description))
, m_is_global(is_global)
{
}
NonnullGCPtr<Symbol> Symbol::create(VM& vm, Optional<DeprecatedString> description, bool is_global)
{
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);
}
}