mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-10-31 21:30:58 +00:00 
			
		
		
		
	 f218a4b548
			
		
	
	
		f218a4b548
		
	
	
	
	
		
			
			20.5.1.1 Error ( message )
    When the Error function is called with argument message, the
    following steps are taken:
    [...]
    3b. Let msgDesc be the PropertyDescriptor {
        [[Value]]: msg,
        [[Writable]]: true,
        [[Enumerable]]: false,
        [[Configurable]]: true
    }.
    3c. Perform ! DefinePropertyOrThrow(O, "message", msgDesc).
		
	
			
		
			
				
	
	
		
			49 lines
		
	
	
	
		
			2.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
	
		
			2.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
 | |
|  * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <LibJS/Runtime/Error.h>
 | |
| #include <LibJS/Runtime/GlobalObject.h>
 | |
| 
 | |
| namespace JS {
 | |
| 
 | |
| Error* Error::create(GlobalObject& global_object, const String& message)
 | |
| {
 | |
|     auto& vm = global_object.vm();
 | |
|     auto* error = global_object.heap().allocate<Error>(global_object, *global_object.error_prototype());
 | |
|     if (!message.is_null()) {
 | |
|         u8 attr = Attribute::Writable | Attribute::Configurable;
 | |
|         error->define_property(vm.names.message, js_string(vm, message), attr);
 | |
|     }
 | |
|     return error;
 | |
| }
 | |
| 
 | |
| Error::Error(Object& prototype)
 | |
|     : Object(prototype)
 | |
| {
 | |
| }
 | |
| 
 | |
| #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType)                                \
 | |
|     ClassName* ClassName::create(GlobalObject& global_object, const String& message)                                    \
 | |
|     {                                                                                                                   \
 | |
|         auto& vm = global_object.vm();                                                                                  \
 | |
|         auto* error = global_object.heap().allocate<ClassName>(global_object, *global_object.snake_name##_prototype()); \
 | |
|         if (!message.is_null()) {                                                                                       \
 | |
|             u8 attr = Attribute::Writable | Attribute::Configurable;                                                    \
 | |
|             error->define_property(vm.names.message, js_string(vm, message), attr);                                     \
 | |
|         }                                                                                                               \
 | |
|         return error;                                                                                                   \
 | |
|     }                                                                                                                   \
 | |
|                                                                                                                         \
 | |
|     ClassName::ClassName(Object& prototype)                                                                             \
 | |
|         : Error(prototype)                                                                                              \
 | |
|     {                                                                                                                   \
 | |
|     }
 | |
| 
 | |
| JS_ENUMERATE_ERROR_SUBCLASSES
 | |
| #undef __JS_ENUMERATE
 | |
| 
 | |
| }
 |