| 
									
										
										
										
											2020-04-06 11:09:01 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Redistribution and use in source and binary forms, with or without | 
					
						
							|  |  |  |  * modification, are permitted provided that the following conditions are met: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 1. Redistributions of source code must retain the above copyright notice, this | 
					
						
							|  |  |  |  *    list of conditions and the following disclaimer. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 2. Redistributions in binary form must reproduce the above copyright notice, | 
					
						
							|  |  |  |  *    this list of conditions and the following disclaimer in the documentation | 
					
						
							|  |  |  |  *    and/or other materials provided with the distribution. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
					
						
							|  |  |  |  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
					
						
							|  |  |  |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
					
						
							|  |  |  |  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | 
					
						
							|  |  |  |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
					
						
							|  |  |  |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 
					
						
							|  |  |  |  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 
					
						
							|  |  |  |  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
					
						
							|  |  |  |  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
					
						
							|  |  |  |  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 20:11:35 +01:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-16 14:20:30 +01:00
										 |  |  | #include <LibJS/Runtime/Object.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-12 20:11:35 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace JS { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  | class GlobalObject : public Object { | 
					
						
							| 
									
										
										
										
											2020-03-12 20:11:35 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-13 11:06:32 +01:00
										 |  |  |     explicit GlobalObject(); | 
					
						
							| 
									
										
										
										
											2020-04-18 13:18:06 +02:00
										 |  |  |     virtual void initialize(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 20:11:35 +01:00
										 |  |  |     virtual ~GlobalObject() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-18 13:18:06 +02:00
										 |  |  | #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName)            \
 | 
					
						
							|  |  |  |     ConstructorName* snake_name##_constructor() { return m_##snake_name##_constructor; } \ | 
					
						
							|  |  |  |     Object* snake_name##_prototype() { return m_##snake_name##_prototype; } | 
					
						
							| 
									
										
										
										
											2020-04-10 14:06:52 +02:00
										 |  |  |     JS_ENUMERATE_BUILTIN_TYPES | 
					
						
							|  |  |  | #undef __JS_ENUMERATE
 | 
					
						
							| 
									
										
										
										
											2020-04-08 11:05:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-08 21:11:51 +02:00
										 |  |  | protected: | 
					
						
							|  |  |  |     virtual void visit_children(Visitor&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 20:11:35 +01:00
										 |  |  | private: | 
					
						
							|  |  |  |     virtual const char* class_name() const override { return "GlobalObject"; } | 
					
						
							| 
									
										
										
										
											2020-03-28 23:10:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     static Value gc(Interpreter&); | 
					
						
							|  |  |  |     static Value is_nan(Interpreter&); | 
					
						
							| 
									
										
										
										
											2020-04-08 11:05:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     template<typename ConstructorType> | 
					
						
							|  |  |  |     void add_constructor(const FlyString& property_name, ConstructorType*&, Object& prototype); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-10 14:06:52 +02:00
										 |  |  | #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
 | 
					
						
							| 
									
										
										
										
											2020-04-18 13:18:06 +02:00
										 |  |  |     ConstructorName* m_##snake_name##_constructor { nullptr };                \ | 
					
						
							|  |  |  |     Object* m_##snake_name##_prototype { nullptr }; | 
					
						
							| 
									
										
										
										
											2020-04-10 14:06:52 +02:00
										 |  |  |     JS_ENUMERATE_BUILTIN_TYPES | 
					
						
							|  |  |  | #undef __JS_ENUMERATE
 | 
					
						
							| 
									
										
										
										
											2020-03-12 20:11:35 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |