1 // Copyright 2016 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_REGEXP_REGEXP_UTILS_H_ 6 #define V8_REGEXP_REGEXP_UTILS_H_ 7 8 #include "src/common/globals.h" 9 10 namespace v8 { 11 namespace internal { 12 13 class JSReceiver; 14 class Object; 15 class RegExpMatchInfo; 16 class String; 17 18 // Helper methods for C++ regexp builtins. 19 class RegExpUtils : public AllStatic { 20 public: 21 // Last match info accessors. 22 static Handle<String> GenericCaptureGetter(Isolate* isolate, 23 Handle<RegExpMatchInfo> match_info, 24 int capture, bool* ok = nullptr); 25 26 // Last index (RegExp.lastIndex) accessors. 27 static V8_WARN_UNUSED_RESULT MaybeHandle<Object> SetLastIndex( 28 Isolate* isolate, Handle<JSReceiver> regexp, uint64_t value); 29 static V8_WARN_UNUSED_RESULT MaybeHandle<Object> GetLastIndex( 30 Isolate* isolate, Handle<JSReceiver> recv); 31 32 // ES#sec-regexpexec Runtime Semantics: RegExpExec ( R, S ) 33 static V8_WARN_UNUSED_RESULT MaybeHandle<Object> RegExpExec( 34 Isolate* isolate, Handle<JSReceiver> regexp, Handle<String> string, 35 Handle<Object> exec); 36 37 // Checks whether the given object is an unmodified JSRegExp instance. 38 // Neither the object's map, nor its prototype's map, nor any relevant 39 // method on the prototype may be modified. 40 // 41 // Note: This check is limited may only be used in situations where the only 42 // relevant property is 'exec'. 43 static bool IsUnmodifiedRegExp(Isolate* isolate, Handle<Object> obj); 44 45 // ES#sec-advancestringindex 46 // AdvanceStringIndex ( S, index, unicode ) 47 static uint64_t AdvanceStringIndex(Handle<String> string, uint64_t index, 48 bool unicode); 49 static V8_WARN_UNUSED_RESULT MaybeHandle<Object> SetAdvancedStringIndex( 50 Isolate* isolate, Handle<JSReceiver> regexp, Handle<String> string, 51 bool unicode); 52 }; 53 54 } // namespace internal 55 } // namespace v8 56 57 #endif // V8_REGEXP_REGEXP_UTILS_H_ 58