mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-10 02:08:38 +09:00
Issue #1285 - Follow-up: Correctly handle follow-up compilations of RegExp with named capturing groups
This commit is contained in:
parent
aece6260fb
commit
0a74a57585
1 changed files with 24 additions and 2 deletions
|
|
@ -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]));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue