| 
									
										
										
										
											2020-04-29 23:25:21 -07:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-04-22 16:53:07 -07:00
										 |  |  |  * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org> | 
					
						
							| 
									
										
										
										
											2023-02-11 15:51:44 +00:00
										 |  |  |  * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org> | 
					
						
							| 
									
										
										
										
											2020-04-29 23:25:21 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-04-29 23:25:21 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <LibJS/Heap/Heap.h>
 | 
					
						
							|  |  |  | #include <LibJS/Runtime/Symbol.h>
 | 
					
						
							| 
									
										
										
										
											2020-09-27 20:18:30 +02:00
										 |  |  | #include <LibJS/Runtime/VM.h>
 | 
					
						
							| 
									
										
										
										
											2020-04-29 23:25:21 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace JS { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  | Symbol::Symbol(Optional<DeprecatedString> description, bool is_global) | 
					
						
							| 
									
										
										
										
											2020-04-29 23:25:21 -07:00
										 |  |  |     : m_description(move(description)) | 
					
						
							|  |  |  |     , m_is_global(is_global) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-06 22:25:43 +00:00
										 |  |  | NonnullGCPtr<Symbol> Symbol::create(VM& vm, Optional<DeprecatedString> description, bool is_global) | 
					
						
							| 
									
										
										
										
											2020-04-29 23:25:21 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-12-14 17:40:33 +00:00
										 |  |  |     return vm.heap().allocate_without_realm<Symbol>(move(description), is_global); | 
					
						
							| 
									
										
										
										
											2020-09-22 16:18:51 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-11 15:51:44 +00:00
										 |  |  | // 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); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-29 23:25:21 -07:00
										 |  |  | } |