| 
									
										
										
										
											2020-06-03 16:05:49 -07:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-04-22 16:53:07 -07:00
										 |  |  |  * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org> | 
					
						
							| 
									
										
										
										
											2020-06-03 16:05:49 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-06-03 16:05:49 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-20 09:14:27 -04:00
										 |  |  | #include <AK/Optional.h>
 | 
					
						
							| 
									
										
										
										
											2021-07-29 10:34:37 -04:00
										 |  |  | #include <AK/Result.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-03 16:05:49 -07:00
										 |  |  | #include <LibJS/AST.h>
 | 
					
						
							|  |  |  | #include <LibJS/Runtime/Object.h>
 | 
					
						
							| 
									
										
										
										
											2020-11-19 01:50:00 +03:30
										 |  |  | #include <LibRegex/Regex.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-03 16:05:49 -07:00
										 |  |  | namespace JS { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-14 11:03:11 +01:00
										 |  |  | RegExpObject* regexp_create(GlobalObject&, Value pattern, Value flags); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-29 10:34:37 -04:00
										 |  |  | Result<regex::RegexOptions<ECMAScriptFlags>, String> regex_flags_from_string(StringView flags); | 
					
						
							|  |  |  | String parse_regex_pattern(StringView pattern, bool unicode); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-03 16:05:49 -07:00
										 |  |  | class RegExpObject : public Object { | 
					
						
							| 
									
										
										
										
											2020-06-21 15:14:02 +02:00
										 |  |  |     JS_OBJECT(RegExpObject, Object); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-03 16:05:49 -07:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2021-07-29 10:34:37 -04:00
										 |  |  |     // JS regexps are all 'global' by default as per our definition, but the "global" flag enables "stateful".
 | 
					
						
							|  |  |  |     // FIXME: Enable 'BrowserExtended' only if in a browser context.
 | 
					
						
							|  |  |  |     static constexpr regex::RegexOptions<ECMAScriptFlags> default_flags { (regex::ECMAScriptFlags)regex::AllFlags::Global | (regex::ECMAScriptFlags)regex::AllFlags::SkipTrimEmptyMatches | regex::ECMAScriptFlags::BrowserExtended }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-20 09:14:27 -04:00
										 |  |  |     static RegExpObject* create(GlobalObject&); | 
					
						
							| 
									
										
										
										
											2021-07-29 10:34:37 -04:00
										 |  |  |     static RegExpObject* create(GlobalObject&, Regex<ECMA262> regex, String pattern, String flags); | 
					
						
							| 
									
										
										
										
											2020-06-03 16:05:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-20 09:14:27 -04:00
										 |  |  |     RegExpObject(Object& prototype); | 
					
						
							| 
									
										
										
										
											2021-07-29 10:34:37 -04:00
										 |  |  |     RegExpObject(Regex<ECMA262> regex, String pattern, String flags, Object& prototype); | 
					
						
							| 
									
										
										
										
											2021-08-20 09:14:27 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     RegExpObject* regexp_initialize(GlobalObject&, Value pattern, Value flags); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-19 01:50:00 +03:30
										 |  |  |     virtual void initialize(GlobalObject&) override; | 
					
						
							| 
									
										
										
										
											2020-06-03 16:05:49 -07:00
										 |  |  |     virtual ~RegExpObject() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-29 10:34:37 -04:00
										 |  |  |     const String& pattern() const { return m_pattern; } | 
					
						
							| 
									
										
										
										
											2020-06-03 16:05:49 -07:00
										 |  |  |     const String& flags() const { return m_flags; } | 
					
						
							| 
									
										
										
										
											2021-08-20 09:14:27 -04:00
										 |  |  |     const Regex<ECMA262>& regex() { return *m_regex; } | 
					
						
							|  |  |  |     const Regex<ECMA262>& regex() const { return *m_regex; } | 
					
						
							| 
									
										
										
										
											2020-06-03 16:05:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2021-07-29 10:34:37 -04:00
										 |  |  |     String m_pattern; | 
					
						
							| 
									
										
										
										
											2020-06-03 16:05:49 -07:00
										 |  |  |     String m_flags; | 
					
						
							| 
									
										
										
										
											2021-08-20 09:14:27 -04:00
										 |  |  |     Optional<Regex<ECMA262>> m_regex; | 
					
						
							| 
									
										
										
										
											2020-06-03 16:05:49 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |