| 
									
										
										
										
											2020-03-24 22:03:50 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2021-04-24 20:16:31 +02:00
										 |  |  |  * Copyright (c) 2021, Linus Groh <linusg@serenityos.org> | 
					
						
							| 
									
										
										
										
											2020-03-24 22:03:50 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-03-24 22:03:50 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-27 20:18:30 +02:00
										 |  |  | #include <AK/String.h>
 | 
					
						
							| 
									
										
										
										
											2020-12-28 20:45:22 +03:30
										 |  |  | #include <LibJS/AST.h>
 | 
					
						
							| 
									
										
										
										
											2021-03-21 12:18:56 +01:00
										 |  |  | #include <LibJS/Interpreter.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-24 22:03:50 +01:00
										 |  |  | #include <LibJS/Runtime/Exception.h>
 | 
					
						
							| 
									
										
										
										
											2020-09-27 20:18:30 +02:00
										 |  |  | #include <LibJS/Runtime/VM.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-24 22:03:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace JS { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Exception::Exception(Value value) | 
					
						
							|  |  |  |     : m_value(value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-03-21 12:18:56 +01:00
										 |  |  |     auto& vm = this->vm(); | 
					
						
							| 
									
										
										
										
											2021-04-24 18:15:02 +02:00
										 |  |  |     m_traceback.ensure_capacity(vm.call_stack().size()); | 
					
						
							| 
									
										
										
										
											2021-06-03 12:43:38 +02:00
										 |  |  |     for (ssize_t i = vm.call_stack().size() - 1; i >= 0; i--) { | 
					
						
							|  |  |  |         auto* call_frame = vm.call_stack()[i]; | 
					
						
							| 
									
										
										
										
											2021-04-24 18:15:02 +02:00
										 |  |  |         auto function_name = call_frame->function_name; | 
					
						
							| 
									
										
										
										
											2020-06-02 14:11:59 +01:00
										 |  |  |         if (function_name.is_empty()) | 
					
						
							|  |  |  |             function_name = "<anonymous>"; | 
					
						
							| 
									
										
										
										
											2021-06-03 12:43:38 +02:00
										 |  |  |         m_traceback.empend( | 
					
						
							|  |  |  |             move(function_name), | 
					
						
							| 
									
										
										
										
											2021-04-25 21:45:23 +02:00
										 |  |  |             // We might not have an AST node associated with the call frame, e.g. in promise
 | 
					
						
							|  |  |  |             // reaction jobs (which aren't called anywhere from the source code).
 | 
					
						
							|  |  |  |             // They're not going to generate any _unhandled_ exceptions though, so a meaningless
 | 
					
						
							|  |  |  |             // source range is fine.
 | 
					
						
							| 
									
										
										
										
											2021-06-03 12:43:38 +02:00
										 |  |  |             call_frame->current_node ? call_frame->current_node->source_range() : SourceRange {}); | 
					
						
							| 
									
										
										
										
											2020-06-02 14:11:59 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-03-24 22:03:50 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-28 14:33:36 +01:00
										 |  |  | void Exception::visit_edges(Visitor& visitor) | 
					
						
							| 
									
										
										
										
											2020-03-24 22:03:50 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-28 14:33:36 +01:00
										 |  |  |     Cell::visit_edges(visitor); | 
					
						
							| 
									
										
										
										
											2020-03-24 22:03:50 +01:00
										 |  |  |     visitor.visit(m_value); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |