_patternFlags = 0;
while (isIdentLetter(_char)) {
int flag = regExpFlagFromChar(_char);
- if (flag == 0) {
+ if (flag == 0 || _patternFlags & flag) {
_errorMessage = QCoreApplication::translate("QQmlParser", "Invalid regular expression flag '%0'")
.arg(QChar(_char));
return false;
, value(0)
, global(false)
{
+ vtbl = &static_vtbl;
+ type = Type_RegExpObject;
+
// Convert the pattern to a ECMAScript pattern.
QString pattern = qt_regexp_toCanonical(re.pattern(), re.patternSyntax());
if (re.isMinimal()) {
return Value::fromObject(o);
}
- if (r.isUndefined())
- r = Value::fromString(ctx, QString());
- else if (!r.isString())
- r = __qmljs_to_string(r, ctx);
+ QString pattern;
+ if (!r.isUndefined())
+ pattern = r.toString(ctx)->toQString();
+ // See sec 15.10.4.1
+ if (pattern.isEmpty())
+ pattern = QStringLiteral("(?:)");
bool global = false;
bool ignoreCase = false;
}
}
- RegExp* re = RegExp::create(ctx->engine, r.stringValue()->toQString(), ignoreCase, multiLine);
+ RegExp* re = RegExp::create(ctx->engine, pattern, ignoreCase, multiLine);
if (!re->isValid())
ctx->throwSyntaxError(0);