11cb0ef41Sopenharmony_ci// Copyright 2016 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_REGEXP_REGEXP_UTILS_H_
61cb0ef41Sopenharmony_ci#define V8_REGEXP_REGEXP_UTILS_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/common/globals.h"
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cinamespace v8 {
111cb0ef41Sopenharmony_cinamespace internal {
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciclass JSReceiver;
141cb0ef41Sopenharmony_ciclass Object;
151cb0ef41Sopenharmony_ciclass RegExpMatchInfo;
161cb0ef41Sopenharmony_ciclass String;
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci// Helper methods for C++ regexp builtins.
191cb0ef41Sopenharmony_ciclass RegExpUtils : public AllStatic {
201cb0ef41Sopenharmony_ci public:
211cb0ef41Sopenharmony_ci  // Last match info accessors.
221cb0ef41Sopenharmony_ci  static Handle<String> GenericCaptureGetter(Isolate* isolate,
231cb0ef41Sopenharmony_ci                                             Handle<RegExpMatchInfo> match_info,
241cb0ef41Sopenharmony_ci                                             int capture, bool* ok = nullptr);
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  // Last index (RegExp.lastIndex) accessors.
271cb0ef41Sopenharmony_ci  static V8_WARN_UNUSED_RESULT MaybeHandle<Object> SetLastIndex(
281cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSReceiver> regexp, uint64_t value);
291cb0ef41Sopenharmony_ci  static V8_WARN_UNUSED_RESULT MaybeHandle<Object> GetLastIndex(
301cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSReceiver> recv);
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci  // ES#sec-regexpexec Runtime Semantics: RegExpExec ( R, S )
331cb0ef41Sopenharmony_ci  static V8_WARN_UNUSED_RESULT MaybeHandle<Object> RegExpExec(
341cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSReceiver> regexp, Handle<String> string,
351cb0ef41Sopenharmony_ci      Handle<Object> exec);
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci  // Checks whether the given object is an unmodified JSRegExp instance.
381cb0ef41Sopenharmony_ci  // Neither the object's map, nor its prototype's map, nor any relevant
391cb0ef41Sopenharmony_ci  // method on the prototype may be modified.
401cb0ef41Sopenharmony_ci  //
411cb0ef41Sopenharmony_ci  // Note: This check is limited may only be used in situations where the only
421cb0ef41Sopenharmony_ci  // relevant property is 'exec'.
431cb0ef41Sopenharmony_ci  static bool IsUnmodifiedRegExp(Isolate* isolate, Handle<Object> obj);
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci  // ES#sec-advancestringindex
461cb0ef41Sopenharmony_ci  // AdvanceStringIndex ( S, index, unicode )
471cb0ef41Sopenharmony_ci  static uint64_t AdvanceStringIndex(Handle<String> string, uint64_t index,
481cb0ef41Sopenharmony_ci                                     bool unicode);
491cb0ef41Sopenharmony_ci  static V8_WARN_UNUSED_RESULT MaybeHandle<Object> SetAdvancedStringIndex(
501cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSReceiver> regexp, Handle<String> string,
511cb0ef41Sopenharmony_ci      bool unicode);
521cb0ef41Sopenharmony_ci};
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci}  // namespace internal
551cb0ef41Sopenharmony_ci}  // namespace v8
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci#endif  // V8_REGEXP_REGEXP_UTILS_H_
58