• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2011 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 // A simple interpreter for the Irregexp byte code.
6 
7 #ifndef V8_REGEXP_REGEXP_INTERPRETER_H_
8 #define V8_REGEXP_REGEXP_INTERPRETER_H_
9 
10 #include "src/regexp/regexp.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 class V8_EXPORT_PRIVATE IrregexpInterpreter : public AllStatic {
16  public:
17   enum Result {
18     FAILURE = RegExp::kInternalRegExpFailure,
19     SUCCESS = RegExp::kInternalRegExpSuccess,
20     EXCEPTION = RegExp::kInternalRegExpException,
21     RETRY = RegExp::kInternalRegExpRetry,
22     FALLBACK_TO_EXPERIMENTAL = RegExp::kInternalRegExpFallbackToExperimental,
23   };
24 
25   // In case a StackOverflow occurs, a StackOverflowException is created and
26   // EXCEPTION is returned.
27   static Result MatchForCallFromRuntime(
28       Isolate* isolate, Handle<JSRegExp> regexp, Handle<String> subject_string,
29       int* output_registers, int output_register_count, int start_position);
30 
31   // In case a StackOverflow occurs, EXCEPTION is returned. The caller is
32   // responsible for creating the exception.
33   //
34   // RETRY is returned if a retry through the runtime is needed (e.g. when
35   // interrupts have been scheduled or the regexp is marked for tier-up).
36   //
37   // Arguments input_start, input_end and backtrack_stack are
38   // unused. They are only passed to match the signature of the native irregex
39   // code.
40   //
41   // Arguments output_registers and output_register_count describe the results
42   // array, which will contain register values of all captures if SUCCESS is
43   // returned. For all other return codes, the results array remains unmodified.
44   static Result MatchForCallFromJs(Address subject, int32_t start_position,
45                                    Address input_start, Address input_end,
46                                    int* output_registers,
47                                    int32_t output_register_count,
48                                    Address backtrack_stack,
49                                    RegExp::CallOrigin call_origin,
50                                    Isolate* isolate, Address regexp);
51 
52   static Result MatchInternal(Isolate* isolate, ByteArray code_array,
53                               String subject_string, int* output_registers,
54                               int output_register_count,
55                               int total_register_count, int start_position,
56                               RegExp::CallOrigin call_origin,
57                               uint32_t backtrack_limit);
58 
59  private:
60   static Result Match(Isolate* isolate, JSRegExp regexp, String subject_string,
61                       int* output_registers, int output_register_count,
62                       int start_position, RegExp::CallOrigin call_origin);
63 };
64 
65 }  // namespace internal
66 }  // namespace v8
67 
68 #endif  // V8_REGEXP_REGEXP_INTERPRETER_H_
69