summaryrefslogtreecommitdiff
path: root/deps/v8/src/builtins/regexp-match.tq
blob: dbee8a616ad564d1d57a177596e278d893cd0d90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2019 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.

#include 'src/builtins/builtins-regexp-gen.h'

namespace regexp {

  extern transitioning macro RegExpBuiltinsAssembler::RegExpPrototypeMatchBody(
      implicit context: Context)(Object, String, constexpr bool): JSAny;

  transitioning macro FastRegExpPrototypeMatchBody(implicit context: Context)(
      receiver: FastJSRegExp, string: String): JSAny {
    return RegExpPrototypeMatchBody(receiver, string, true);
  }

  transitioning macro SlowRegExpPrototypeMatchBody(implicit context: Context)(
      receiver: Object, string: String): JSAny {
    return RegExpPrototypeMatchBody(receiver, string, false);
  }

  // Helper that skips a few initial checks. and assumes...
  // 1) receiver is a "fast" RegExp
  // 2) pattern is a string
  transitioning builtin RegExpMatchFast(implicit context: Context)(
      receiver: FastJSRegExp, string: String): JSAny {
    return FastRegExpPrototypeMatchBody(receiver, string);
  }

  // ES#sec-regexp.prototype-@@match
  // RegExp.prototype [ @@match ] ( string )
  transitioning javascript builtin RegExpPrototypeMatch(
      js-implicit context: Context, receiver: JSAny)(string: JSAny): JSAny {
    ThrowIfNotJSReceiver(
        receiver, kIncompatibleMethodReceiver, 'RegExp.prototype.@@match');
    const receiver = UnsafeCast<JSReceiver>(receiver);
    const string: String = ToString_Inline(context, string);

    // Strict: Reads global and unicode properties.
    // TODO(jgruber): Handle slow flag accesses on the fast path and make this
    // permissive.
    const fastRegExp = Cast<FastJSRegExp>(receiver)
        otherwise return SlowRegExpPrototypeMatchBody(receiver, string);

    // TODO(pwong): Could be optimized to remove the overhead of calling the
    //              builtin (at the cost of a larger builtin).
    return RegExpMatchFast(fastRegExp, string);
  }
}