diff --git a/include/v8.h b/include/v8.h index e8fbb18a00..02a7103be9 100644 --- a/include/v8.h +++ b/include/v8.h @@ -5739,6 +5739,15 @@ class V8_EXPORT RegExp : public Object { Local 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 NewWithBacktrackLimit( + Local context, Local pattern, Flags flags, + uint32_t backtrack_limit); + /** * Returns the value of the source property: a string representing * the regular expression. diff --git a/src/api/api.cc b/src/api/api.cc index 28ae18ad9e..9554bcf887 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -6617,6 +6617,21 @@ MaybeLocal v8::RegExp::New(Local context, RETURN_ESCAPED(result); } +MaybeLocal v8::RegExp::NewWithBacktrackLimit( + Local context, Local 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 result; + has_pending_exception = !ToLocal( + i::JSRegExp::New(isolate, Utils::OpenHandle(*pattern), + static_cast(flags), backtrack_limit), + &result); + RETURN_ON_FAILED_EXECUTION(RegExp); + RETURN_ESCAPED(result); +} + Local v8::RegExp::GetSource() const { i::Handle obj = Utils::OpenHandle(this); return Utils::ToLocal(