regexp-utils.h 2.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_REGEXP_REGEXP_UTILS_H_
#define V8_REGEXP_REGEXP_UTILS_H_

#include "src/objects.h"

namespace v8 {
namespace internal {

13 14
class RegExpMatchInfo;

15 16 17 18 19
// Helper methods for C++ regexp builtins.
class RegExpUtils : public AllStatic {
 public:
  // Last match info accessors.
  static Handle<String> GenericCaptureGetter(Isolate* isolate,
20
                                             Handle<RegExpMatchInfo> match_info,
21 22 23
                                             int capture, bool* ok = nullptr);

  // Last index (RegExp.lastIndex) accessors.
24
  static V8_WARN_UNUSED_RESULT MaybeHandle<Object> SetLastIndex(
25
      Isolate* isolate, Handle<JSReceiver> regexp, uint64_t value);
26
  static V8_WARN_UNUSED_RESULT MaybeHandle<Object> GetLastIndex(
27
      Isolate* isolate, Handle<JSReceiver> recv);
28 29

  // ES#sec-regexpexec Runtime Semantics: RegExpExec ( R, S )
30
  static V8_WARN_UNUSED_RESULT MaybeHandle<Object> RegExpExec(
31 32
      Isolate* isolate, Handle<JSReceiver> regexp, Handle<String> string,
      Handle<Object> exec);
33 34 35 36 37

  // ES#sec-isregexp IsRegExp ( argument )
  // Includes checking of the match property.
  static Maybe<bool> IsRegExp(Isolate* isolate, Handle<Object> object);

38
  // Checks whether the given object is an unmodified JSRegExp instance.
39 40
  // Neither the object's map, nor its prototype's map, nor any relevant
  // method on the prototype may be modified.
41
  static bool IsUnmodifiedRegExp(Isolate* isolate, Handle<Object> obj);
42

43 44
  // ES#sec-advancestringindex
  // AdvanceStringIndex ( S, index, unicode )
45 46
  static uint64_t AdvanceStringIndex(Handle<String> string, uint64_t index,
                                     bool unicode);
47
  static V8_WARN_UNUSED_RESULT MaybeHandle<Object> SetAdvancedStringIndex(
48 49
      Isolate* isolate, Handle<JSReceiver> regexp, Handle<String> string,
      bool unicode);
50 51 52 53 54 55
};

}  // namespace internal
}  // namespace v8

#endif  // V8_REGEXP_REGEXP_UTILS_H_