Issue #2008 - Implement missing s parameter parsing and align case with spec.

This does 2 things.
First, it adds parsing of the 's' parameter parsing to DOM object construction of regexes
Second, it corrects the DOM property to be `dotAll` instead of `dotall`

For consistency's sake, all function names and calls were renamed with the finalized casing.

This resolves #2008
This commit is contained in:
Moonchild 2022-09-18 11:01:27 +00:00 • committed by roytam1
commit 05389eb41f
6 changed files with 21 additions and 13 deletions

View file

@ -665,7 +665,7 @@ js::regexp_multiline(JSContext* cx, unsigned argc, JS::Value* vp)
// ES 2018 dotAll // ES 2018 dotAll
MOZ_ALWAYS_INLINE bool MOZ_ALWAYS_INLINE bool
regexp_dotall_impl(JSContext* cx, const CallArgs& args) regexp_dotAll_impl(JSContext* cx, const CallArgs& args)
{ {
MOZ_ASSERT(IsRegExpInstanceOrPrototype(args.thisv())); MOZ_ASSERT(IsRegExpInstanceOrPrototype(args.thisv()));
@ -675,15 +675,15 @@ regexp_dotall_impl(JSContext* cx, const CallArgs& args)
} }
Rooted<RegExpObject*> reObj(cx, &args.thisv().toObject().as<RegExpObject>()); Rooted<RegExpObject*> reObj(cx, &args.thisv().toObject().as<RegExpObject>());
args.rval().setBoolean(reObj->dotall()); args.rval().setBoolean(reObj->dotAll());
return true; return true;
} }
bool bool
js::regexp_dotall(JSContext* cx, unsigned argc, JS::Value* vp) js::regexp_dotAll(JSContext* cx, unsigned argc, JS::Value* vp)
{ {
CallArgs args = CallArgsFromVp(argc, vp); CallArgs args = CallArgsFromVp(argc, vp);
return CallNonGenericMethod<IsRegExpInstanceOrPrototype, regexp_dotall_impl>(cx, args); return CallNonGenericMethod<IsRegExpInstanceOrPrototype, regexp_dotAll_impl>(cx, args);
} }
// ES 2017 draft rev32 21.2.5.10. // ES 2017 draft rev32 21.2.5.10.
@ -781,7 +781,7 @@ const JSPropertySpec js::regexp_properties[] = {
JS_PSG("source", regexp_source, 0), JS_PSG("source", regexp_source, 0),
JS_PSG("sticky", regexp_sticky, 0), JS_PSG("sticky", regexp_sticky, 0),
JS_PSG("unicode", regexp_unicode, 0), JS_PSG("unicode", regexp_unicode, 0),
JS_PSG("dotall", regexp_dotall, 0), JS_PSG("dotAll", regexp_dotAll, 0),
JS_PS_END JS_PS_END
}; };
@ -1667,10 +1667,10 @@ js::RegExpPrototypeOptimizableRaw(JSContext* cx, JSObject* proto)
return false; return false;
JSNative dotAllGetter; JSNative dotAllGetter;
if (!GetOwnNativeGetterPure(cx, proto, NameToId(cx->names().dotall), &dotAllGetter)) if (!GetOwnNativeGetterPure(cx, proto, NameToId(cx->names().dotAll), &dotAllGetter))
return false; return false;
if (dotAllGetter != regexp_dotall) if (dotAllGetter != regexp_dotAll)
return false; return false;
// Check if @@match, @@search, and exec are own data properties, // Check if @@match, @@search, and exec are own data properties,

View file

@ -153,7 +153,7 @@ regexp_sticky(JSContext* cx, unsigned argc, JS::Value* vp);
extern MOZ_MUST_USE bool extern MOZ_MUST_USE bool
regexp_unicode(JSContext* cx, unsigned argc, JS::Value* vp); regexp_unicode(JSContext* cx, unsigned argc, JS::Value* vp);
extern MOZ_MUST_USE bool extern MOZ_MUST_USE bool
regexp_dotall(JSContext* cx, unsigned argc, JS::Value* vp); regexp_dotAll(JSContext* cx, unsigned argc, JS::Value* vp);
} /* namespace js */ } /* namespace js */

View file

@ -34,7 +34,7 @@ function RegExpFlagsGetter() {
result += "y"; result += "y";
// ES2018 // ES2018
if (R.dotall) if (R.dotAll)
result += "s"; result += "s";
// Step 19. // Step 19.

View file

@ -99,7 +99,7 @@
macro(displayURL, displayURL, "displayURL") \ macro(displayURL, displayURL, "displayURL") \
macro(do, do_, "do") \ macro(do, do_, "do") \
macro(done, done, "done") \ macro(done, done, "done") \
macro(dotall, dotall, "dotall") \ macro(dotAll, dotAll, "dotAll") \
macro(dotGenerator, dotGenerator, ".generator") \ macro(dotGenerator, dotGenerator, ".generator") \
macro(dotThis, dotThis, ".this") \ macro(dotThis, dotThis, ".this") \
macro(each, each, "each") \ macro(each, each, "each") \

View file

@ -167,6 +167,10 @@ RegExpObject::isOriginalFlagGetter(JSNative native, RegExpFlag* mask)
*mask = UnicodeFlag; *mask = UnicodeFlag;
return true; return true;
} }
if (native == regexp_dotAll) {
*mask = DotAllFlag;
return true;
}
return false; return false;
} }
@ -1016,7 +1020,7 @@ RegExpShared::compile(JSContext* cx, HandleAtom pattern, HandleLinearString inpu
irregexp::RegExpCompileData data; irregexp::RegExpCompileData data;
if (!irregexp::ParsePattern(dummyTokenStream, cx->tempLifoAlloc(), pattern, if (!irregexp::ParsePattern(dummyTokenStream, cx->tempLifoAlloc(), pattern,
multiline(), mode == MatchOnly, unicode(), ignoreCase(), multiline(), mode == MatchOnly, unicode(), ignoreCase(),
global(), sticky(), dotall(), &data)) global(), sticky(), dotAll(), &data))
{ {
return false; return false;
} }
@ -1468,6 +1472,10 @@ ParseRegExpFlags(const CharT* chars, size_t length, RegExpFlag* flagsOut, char16
if (!HandleRegExpFlag(MultilineFlag, flagsOut)) if (!HandleRegExpFlag(MultilineFlag, flagsOut))
return false; return false;
break; break;
case 's':
if (!HandleRegExpFlag(DotAllFlag, flagsOut))
return false;
break;
case 'y': case 'y':
if (!HandleRegExpFlag(StickyFlag, flagsOut)) if (!HandleRegExpFlag(StickyFlag, flagsOut))
return false; return false;

View file

@ -194,7 +194,7 @@ class RegExpShared
bool multiline() const { return flags & MultilineFlag; } bool multiline() const { return flags & MultilineFlag; }
bool sticky() const { return flags & StickyFlag; } bool sticky() const { return flags & StickyFlag; }
bool unicode() const { return flags & UnicodeFlag; } bool unicode() const { return flags & UnicodeFlag; }
bool dotall() const { return flags & DotAllFlag; } bool dotAll() const { return flags & DotAllFlag; }
bool isCompiled(CompilationMode mode, bool latin1, bool isCompiled(CompilationMode mode, bool latin1,
ForceByteCodeEnum force = DontForceByteCode) const { ForceByteCodeEnum force = DontForceByteCode) const {
@ -482,7 +482,7 @@ class RegExpObject : public NativeObject
bool multiline() const { return getFlags() & MultilineFlag; } bool multiline() const { return getFlags() & MultilineFlag; }
bool sticky() const { return getFlags() & StickyFlag; } bool sticky() const { return getFlags() & StickyFlag; }
bool unicode() const { return getFlags() & UnicodeFlag; } bool unicode() const { return getFlags() & UnicodeFlag; }
bool dotall() const { return getFlags() & DotAllFlag; } bool dotAll() const { return getFlags() & DotAllFlag; }
static bool isOriginalFlagGetter(JSNative native, RegExpFlag* mask); static bool isOriginalFlagGetter(JSNative native, RegExpFlag* mask);