/* * Copyright (c) 2020, Matthew Olsson * Copyright (c) 2022-2023, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include namespace JS { Symbol::Symbol(Optional description, bool is_global) : m_description(move(description)) , m_is_global(is_global) { } NonnullGCPtr Symbol::create(VM& vm, Optional description, bool is_global) { return vm.heap().allocate_without_realm(move(description), is_global); } // 20.4.3.3.1 SymbolDescriptiveString ( sym ), https://tc39.es/ecma262/#sec-symboldescriptivestring ErrorOr 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(String {}); // 4. Return the string-concatenation of "Symbol(", desc, and ")". return String::formatted("Symbol({})", description); } }