[regexp] Expose RegExp::NewWithBacktrackLimit through the API

Bug: v8:9695
Change-Id: I401a18c84a9ec1af7e14f44004a0788cbfd4a34b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1864657
Reviewed-by: Yang Guo <yangguo@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64501}
This commit is contained in:
Jakob Gruber 2019-10-21 16:16:38 +02:00 committed by Commit Bot
parent b71af5c38a
commit b0fadf7f70
2 changed files with 24 additions and 0 deletions

View File

@ -5739,6 +5739,15 @@ class V8_EXPORT RegExp : public Object {
Local<String> pattern,
Flags flags);
/**
* Like New, but additionally specifies a backtrack limit. If the number of
* backtracks done in one Exec call hits the limit, a match failure is
* immediately returned.
*/
static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> NewWithBacktrackLimit(
Local<Context> context, Local<String> pattern, Flags flags,
uint32_t backtrack_limit);
/**
* Returns the value of the source property: a string representing
* the regular expression.

View File

@ -6617,6 +6617,21 @@ MaybeLocal<v8::RegExp> v8::RegExp::New(Local<Context> context,
RETURN_ESCAPED(result);
}
MaybeLocal<v8::RegExp> v8::RegExp::NewWithBacktrackLimit(
Local<Context> context, Local<String> pattern, Flags flags,
uint32_t backtrack_limit) {
CHECK(i::Smi::IsValid(backtrack_limit));
CHECK_NE(backtrack_limit, i::JSRegExp::kNoBacktrackLimit);
PREPARE_FOR_EXECUTION(context, RegExp, New, RegExp);
Local<v8::RegExp> result;
has_pending_exception = !ToLocal<RegExp>(
i::JSRegExp::New(isolate, Utils::OpenHandle(*pattern),
static_cast<i::JSRegExp::Flags>(flags), backtrack_limit),
&result);
RETURN_ON_FAILED_EXECUTION(RegExp);
RETURN_ESCAPED(result);
}
Local<v8::String> v8::RegExp::GetSource() const {
i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this);
return Utils::ToLocal(