diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 064aaabb6ea0..6a13b1832ee3 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -6390,14 +6390,26 @@ nsContentUtils::FindInternalContentViewer(const nsACString& aType, static void ReportPatternCompileFailure(nsAString& aPattern, const Document* aDocument, - JS::MutableHandle error, JSContext* cx) { + MOZ_ASSERT(JS_IsExceptionPending(cx)); + + JS::RootedValue exn(cx); + if (!JS_GetPendingException(cx, &exn)) { + return; + } + if (!exn.isObject()) { + // If pending exception is not an object, it should be OOM. + return; + } + JS::AutoSaveExceptionState savedExc(cx); - JS::RootedObject exnObj(cx, &error.toObject()); + JS::RootedObject exnObj(cx, &exn.toObject()); JS::RootedValue messageVal(cx); if (!JS_GetProperty(cx, exnObj, "message", &messageVal)) { return; } + MOZ_ASSERT(messageVal.isString()); + JS::RootedString messageStr(cx, messageVal.toString()); MOZ_ASSERT(messageStr); @@ -6434,16 +6446,15 @@ Maybe nsContentUtils::IsPatternMatching(nsAString& aValue, // Check if the pattern by itself is valid first, and not that it only becomes // valid once we add ^(?: and )$. - JS::RootedValue error(cx); - if (!JS::CheckRegExpSyntax( - cx, static_cast(aPattern.BeginWriting()), - aPattern.Length(), JS::RegExpFlag::Unicode, &error)) { - return Nothing(); - } - - if (!error.isUndefined()) { - ReportPatternCompileFailure(aPattern, aDocument, &error, cx); - return Some(true); + { + JS::Rooted testRe( + cx, JS::NewUCRegExpObject( + cx, static_cast(aPattern.BeginWriting()), + aPattern.Length(), JS::RegExpFlag::Unicode)); + if (!testRe) { + ReportPatternCompileFailure(aPattern, aDocument, cx); + return Some(true); + } } // The pattern has to match the entire value. @@ -6454,9 +6465,8 @@ Maybe nsContentUtils::IsPatternMatching(nsAString& aValue, cx, JS::NewUCRegExpObject(cx, static_cast(aPattern.BeginWriting()), aPattern.Length(), JS::RegExpFlag::Unicode)); - if (!re) { - return Nothing(); - } + // We checked that the pattern is valid above. + MOZ_ASSERT(re, "Adding ^(?: and )$ shouldn't make a valid regexp invalid"); JS::Rooted rval(cx, JS::NullValue()); size_t idx = 0; diff --git a/js/public/RegExp.h b/js/public/RegExp.h index 8e2e8d30a1ff..5ee5ce88c2e5 100644 --- a/js/public/RegExp.h +++ b/js/public/RegExp.h @@ -79,16 +79,6 @@ extern JS_PUBLIC_API RegExpFlags GetRegExpFlags(JSContext* cx, */ extern JS_PUBLIC_API JSString* GetRegExpSource(JSContext* cx, Handle obj); -/** - * Check whether the given source is a valid regexp. If the regexp parses - * successfully, returns true and sets |error| to undefined. If the regexp - * has a syntax error, returns true, sets |error| to that error object, and - * clears the exception. Returns false on OOM or over-recursion. - */ -extern JS_PUBLIC_API bool CheckRegExpSyntax(JSContext* cx, - const char16_t* chars, - size_t length, RegExpFlags flags, - MutableHandle error); } // namespace JS diff --git a/js/src/jit-test/tests/binast/lazy/regexp/huge-01.binjs b/js/src/jit-test/tests/binast/lazy/regexp/huge-01.binjs index e69de29bb2d1..268e799b3bba 100644 Binary files a/js/src/jit-test/tests/binast/lazy/regexp/huge-01.binjs and b/js/src/jit-test/tests/binast/lazy/regexp/huge-01.binjs differ diff --git a/js/src/jit-test/tests/binast/nonlazy/regexp/huge-01.binjs b/js/src/jit-test/tests/binast/nonlazy/regexp/huge-01.binjs index e69de29bb2d1..84da54409541 100644 Binary files a/js/src/jit-test/tests/binast/nonlazy/regexp/huge-01.binjs and b/js/src/jit-test/tests/binast/nonlazy/regexp/huge-01.binjs differ diff --git a/js/src/jit-test/tests/regexp/huge-01.js b/js/src/jit-test/tests/regexp/huge-01.js index bc1529f0c66c..ddd1953b23b3 100644 --- a/js/src/jit-test/tests/regexp/huge-01.js +++ b/js/src/jit-test/tests/regexp/huge-01.js @@ -10,9 +10,7 @@ function g(N, p) { // 1. Regexp too big is raised by the lack of the 64k virtual registers // reserved for the regexp evaluation. // 2. The stack overflow can occur during the analysis of the regexp - assertEq(e.message.includes("regexp too big") || - e.message.includes("Stack overflow") || - e.message.includes("too much recursion"), true); + assertEq(e.message.includes("regexp too big") || e.message.includes("Stack overflow"), true); } } diff --git a/js/src/new-regexp/RegExpAPI.cpp b/js/src/new-regexp/RegExpAPI.cpp index 11782e237156..4118dd8505ed 100644 --- a/js/src/new-regexp/RegExpAPI.cpp +++ b/js/src/new-regexp/RegExpAPI.cpp @@ -153,11 +153,6 @@ static void ReportSyntaxError(TokenStreamAnyChars& ts, gc::AutoSuppressGC suppressGC(ts.context()); uint32_t errorNumber = ErrorNumber(result.error); - if (errorNumber == JSMSG_OVER_RECURSED) { - ReportOverRecursed(ts.context()); - return; - } - uint32_t offset = std::max(result.error_pos, 0); MOZ_ASSERT(offset <= length); @@ -432,7 +427,7 @@ bool CompilePattern(JSContext* cx, MutableHandleRegExpShared re, data.error = AnalyzeRegExp(cx->isolate, isLatin1, data.node); if (data.error != RegExpError::kNone) { MOZ_ASSERT(data.error == RegExpError::kAnalysisStackOverflow); - ReportOverRecursed(cx); + JS_ReportErrorASCII(cx, "Stack overflow"); return false; } diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp index 152de6cfd89c..91a1b9590acb 100644 --- a/js/src/vm/RegExpObject.cpp +++ b/js/src/vm/RegExpObject.cpp @@ -1758,36 +1758,3 @@ JS_PUBLIC_API JSString* JS::GetRegExpSource(JSContext* cx, HandleObject obj) { } return shared->getSource(); } - -JS_PUBLIC_API bool JS::CheckRegExpSyntax(JSContext* cx, const char16_t* chars, - size_t length, RegExpFlags flags, - MutableHandleValue error) { - AssertHeapIsIdle(); - CHECK_THREAD(cx); - - CompileOptions dummyOptions(cx); - frontend::DummyTokenStream dummyTokenStream(cx, dummyOptions); - - LifoAllocScope allocScope(&cx->tempLifoAlloc()); - - mozilla::Range source(chars, length); -#ifdef ENABLE_NEW_REGEXP - bool success = - irregexp::CheckPatternSyntax(cx, dummyTokenStream, source, flags); -#else - bool success = irregexp::ParsePatternSyntax( - dummyTokenStream, allocScope.alloc(), source, flags.unicode()); -#endif - error.set(UndefinedValue()); - if (!success) { - // We can fail because of OOM or over-recursion even if the syntax is valid. - if (cx->isThrowingOutOfMemory() || cx->isThrowingOverRecursed()) { - return false; - } - if (!cx->getPendingException(error)) { - return false; - } - cx->clearPendingException(); - } - return true; -} diff --git a/testing/web-platform/tests/html/semantics/forms/constraints/input-pattern-dynamic-value.html b/testing/web-platform/tests/html/semantics/forms/constraints/input-pattern-dynamic-value.html deleted file mode 100644 index 58e566c7386e..000000000000 --- a/testing/web-platform/tests/html/semantics/forms/constraints/input-pattern-dynamic-value.html +++ /dev/null @@ -1,17 +0,0 @@ - - -Pattern dynamic value attribute change - - - - -