1// Copyright 2019 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#include 'src/builtins/builtins-regexp-gen.h'
6
7namespace regexp {
8
9// ES#sec-regexp.prototype.test
10// RegExp.prototype.test ( S )
11transitioning javascript builtin RegExpPrototypeTest(
12    js-implicit context: NativeContext, receiver: JSAny)(string: JSAny): JSAny {
13  const methodName: constexpr string = 'RegExp.prototype.test';
14  const receiver = Cast<JSReceiver>(receiver)
15      otherwise ThrowTypeError(
16      MessageTemplate::kIncompatibleMethodReceiver, methodName);
17  const str: String = ToString_Inline(string);
18  if (IsFastRegExpPermissive(receiver)) {
19    RegExpPrototypeExecBodyWithoutResultFast(
20        UnsafeCast<JSRegExp>(receiver), str)
21        otherwise return False;
22    return True;
23  }
24  const matchIndices = RegExpExec(receiver, str);
25  return SelectBooleanConstant(matchIndices != Null);
26}
27
28transitioning builtin RegExpPrototypeTestFast(implicit context: Context)(
29    receiver: JSRegExp, string: String): Object {
30  RegExpPrototypeExecBodyWithoutResultFast(receiver, string)
31      otherwise return False;
32  return True;
33}
34}
35