diff --git a/js/src/jit/CodeGenerator.cpp b/js/src/jit/CodeGenerator.cpp index 74754635d546..658b6eba5ebe 100644 --- a/js/src/jit/CodeGenerator.cpp +++ b/js/src/jit/CodeGenerator.cpp @@ -2114,12 +2114,11 @@ static bool PrepareAndExecuteRegExp(JSContext* cx, MacroAssembler& masm, } // Don't handle RegExps with excessive parens. - masm.load32(Address(temp1, RegExpShared::offsetOfParenCount()), temp2); - masm.branch32(Assembler::AboveOrEqual, temp2, + masm.load32(Address(temp1, RegExpShared::offsetOfPairCount()), temp2); + masm.branch32(Assembler::Above, temp2, Imm32(RegExpObject::MaxPairCount), failure); // Fill in the paren count in the MatchPairs on the stack. - masm.add32(Imm32(1), temp2); masm.store32(temp2, pairCountAddress); // Load the code pointer for the type of input string we have, and compute diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp index 43323e273882..534c6d158c2c 100644 --- a/js/src/vm/RegExpObject.cpp +++ b/js/src/vm/RegExpObject.cpp @@ -946,7 +946,7 @@ bool js::StringHasRegExpMetaChars(JSLinearString* str) { /* RegExpShared */ RegExpShared::RegExpShared(JSAtom* source, RegExpFlags flags) - : headerAndSource(source), parenCount(0), flags(flags) {} + : headerAndSource(source), pairCount_(0), flags(flags) {} void RegExpShared::traceChildren(JSTracer* trc) { // Discard code to avoid holding onto ExecutablePools. @@ -1057,7 +1057,7 @@ void RegExpShared::useAtomMatch(HandleAtom pattern) { MOZ_ASSERT(kind() == RegExpShared::Kind::Unparsed); kind_ = RegExpShared::Kind::Atom; patternAtom_ = pattern; - parenCount = 0; + pairCount_ = 1; } #else // !ENABLE_NEW_REGEXP @@ -1082,7 +1082,8 @@ bool RegExpShared::compile(JSContext* cx, MutableHandleRegExpShared re, return false; } - re->parenCount = data.capture_count; + // Add one to account for the whole-match capture. + re->pairCount_ = data.capture_count + 1; JitCodeTables tables; irregexp::RegExpCode code = irregexp::CompilePattern( diff --git a/js/src/vm/RegExpShared.h b/js/src/vm/RegExpShared.h index 3f711d5340fd..f49153bf5f7c 100644 --- a/js/src/vm/RegExpShared.h +++ b/js/src/vm/RegExpShared.h @@ -102,7 +102,7 @@ class RegExpShared : public gc::TenuredCell { RegExpCompilation compilationArray[2]; - uint32_t parenCount; + uint32_t pairCount_; JS::RegExpFlags flags; #ifdef ENABLE_NEW_REGEXP @@ -156,13 +156,13 @@ class RegExpShared : public gc::TenuredCell { /* Accessors */ - size_t getParenCount() const { + size_t pairCount() const { #ifdef ENABLE_NEW_REGEXP MOZ_ASSERT(kind() != Kind::Unparsed); #else MOZ_ASSERT(isCompiled()); #endif - return parenCount; + return pairCount_; } #ifdef ENABLE_NEW_REGEXP @@ -172,8 +172,6 @@ class RegExpShared : public gc::TenuredCell { void useAtomMatch(HandleAtom pattern); #endif - /* Accounts for the "0" (whole match) pair. */ - size_t pairCount() const { return getParenCount() + 1; } JSAtom* getSource() const { return headerAndSource.ptr(); } @@ -209,8 +207,8 @@ class RegExpShared : public gc::TenuredCell { static size_t offsetOfFlags() { return offsetof(RegExpShared, flags); } - static size_t offsetOfParenCount() { - return offsetof(RegExpShared, parenCount); + static size_t offsetOfPairCount() { + return offsetof(RegExpShared, pairCount_); } static size_t offsetOfJitCode(bool latin1) {