summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartok <martok@martoks-place.de>2023-04-25 11:10:46 +0200
committerMartok <martok@martoks-place.de>2023-04-30 13:26:26 +0200
commit311482507bfa6d0354ac8106ad091fb912cf1244 (patch)
tree8d7e2ab886c46bffb000ded6ce9e8f2397572982
parent9f246c4c74972af93715845cdc36bd9596163512 (diff)
downloaduxp-311482507bfa6d0354ac8106ad091fb912cf1244.tar.gz
Issue #1285 - Follow-up: Correctly handle follow-up compilations of RegExp with named capturing groups
-rw-r--r--js/src/vm/RegExpObject.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp
index f46f4b4510..1d88754084 100644
--- a/js/src/vm/RegExpObject.cpp
+++ b/js/src/vm/RegExpObject.cpp
@@ -994,11 +994,33 @@ RegExpShared::initializeNamedCaptures(JSContext* cx, HandleRegExpShared re,
irregexp::CharacterVectorVector* names,
irregexp::IntegerVector* indices)
{
- MOZ_ASSERT(!re->groupsTemplate_);
MOZ_ASSERT(names);
MOZ_ASSERT(indices);
MOZ_ASSERT(names->length() == indices->length());
+ if (re->getGroupsTemplate()) {
+ // If initializeNamedCaptures was previously called for a different CompilationMode/Latin1Chars combination,
+ // the template object is already created and correct.
+#ifdef DEBUG
+ // In debug builds, verify that.
+ MOZ_ASSERT(re->getGroupsTemplate()->propertyCount() == names->length());
+ RootedId id(cx);
+ RootedNativeObject groupsTemplate(cx, re->getGroupsTemplate());
+ Rooted<PropertyDescriptor> desc(cx);
+ for (uint32_t i = 0; i < names->length(); i++) {
+ irregexp::CharacterVector* cv = (*names)[i];
+ JSAtom* atom = AtomizeChars(cx, cv->begin(), cv->length());
+ MOZ_ASSERT(atom);
+ id = NameToId(atom->asPropertyName());
+ MOZ_ASSERT(NativeGetOwnPropertyDescriptor(cx, groupsTemplate, id, &desc));
+ int32_t idx;
+ MOZ_ASSERT(ToInt32(cx, desc.value(), &idx));
+ MOZ_ASSERT(idx == (*indices)[i]);
+ }
+#endif
+ return true;
+ }
+
// The irregexp parser returns named capture information in the form
// of two arrays. We create a template object with a property for each
// capture name, and store the capture index as Integer in the corresponding value.
@@ -1025,7 +1047,7 @@ RegExpShared::initializeNamedCaptures(JSContext* cx, HandleRegExpShared re,
// Need to explicitly create an Atom (not a String) or it won't get added to the atom table
JSAtom* atom = AtomizeChars(cx, cv->begin(), cv->length());
if (!atom) {
- return false;
+ return false;
}
id = NameToId(atom->asPropertyName());
RootedValue idx(cx, Int32Value((*indices)[i]));