aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-08-07 22:27:23 +0200
committerLars Knoll <lars.knoll@qt.io>2018-08-10 14:16:12 +0000
commit886d463061ba34802bf844133396e3706d6912a4 (patch)
tree066b86b99f71388acb07ef1a4e8fc4bb4331ceb2 /src/qml/jsruntime
parent18d2f78437d28987297148b63b99ceed6313a78a (diff)
Enable unicode regular expressions
Add support for the 'u' flag for regular expressions. Change-Id: I409054eaa9c50183619752d14f2638f5a38c0ea7 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/qv4engine.cpp5
-rw-r--r--src/qml/jsruntime/qv4regexp.cpp9
-rw-r--r--src/qml/jsruntime/qv4regexp_p.h5
-rw-r--r--src/qml/jsruntime/qv4regexpobject.cpp3
-rw-r--r--src/qml/jsruntime/qv4regexpobject_p.h4
5 files changed, 19 insertions, 7 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 69b23484a8..6d5a43dd1f 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -377,6 +377,8 @@ ExecutionEngine::ExecutionEngine(QJSEngine *jsEngine)
Q_ASSERT(index == RegExpObject::Index_IgnoreCase);
ic = ic->addMember((str = newIdentifier(QStringLiteral("multiline")))->propertyKey(), Attr_ReadOnly, &index);
Q_ASSERT(index == RegExpObject::Index_Multiline);
+ ic = ic->addMember((str = newIdentifier(QStringLiteral("unicode")))->propertyKey(), Attr_ReadOnly, &index);
+ Q_ASSERT(index == RegExpObject::Index_Unicode);
jsObjects[RegExpProto] = memoryManager->allocObject<RegExpPrototype>(ic->d());
classes[Class_RegExpObject] = ic->changePrototype(regExpPrototype()->d());
@@ -787,9 +789,10 @@ Heap::RegExpObject *ExecutionEngine::newRegExpObject(const QString &pattern, int
bool global = (flags & QV4::CompiledData::RegExp::RegExp_Global);
bool ignoreCase = (flags & QV4::CompiledData::RegExp::RegExp_IgnoreCase);
bool multiline = (flags & QV4::CompiledData::RegExp::RegExp_Multiline);
+ bool unicode = (flags & QV4::CompiledData::RegExp::RegExp_Unicode);
Scope scope(this);
- Scoped<RegExp> re(scope, RegExp::create(this, pattern, ignoreCase, multiline, global));
+ Scoped<RegExp> re(scope, RegExp::create(this, pattern, ignoreCase, multiline, global, unicode));
return newRegExpObject(re);
}
diff --git a/src/qml/jsruntime/qv4regexp.cpp b/src/qml/jsruntime/qv4regexp.cpp
index 89fd9fc233..e562482395 100644
--- a/src/qml/jsruntime/qv4regexp.cpp
+++ b/src/qml/jsruntime/qv4regexp.cpp
@@ -70,7 +70,7 @@ uint RegExp::match(const QString &string, int start, uint *matchOffsets)
return JSC::Yarr::interpret(byteCode(), s.characters16(), string.length(), start, matchOffsets);
}
-Heap::RegExp *RegExp::create(ExecutionEngine* engine, const QString& pattern, bool ignoreCase, bool multiline, bool global)
+Heap::RegExp *RegExp::create(ExecutionEngine* engine, const QString& pattern, bool ignoreCase, bool multiline, bool global, bool unicode)
{
RegExpCacheKey key(pattern, ignoreCase, multiline, global);
@@ -83,7 +83,7 @@ Heap::RegExp *RegExp::create(ExecutionEngine* engine, const QString& pattern, bo
return result->d();
Scope scope(engine);
- Scoped<RegExp> result(scope, engine->memoryManager->alloc<RegExp>(engine, pattern, ignoreCase, multiline, global));
+ Scoped<RegExp> result(scope, engine->memoryManager->alloc<RegExp>(engine, pattern, ignoreCase, multiline, global, unicode));
result->d()->cache = cache;
cachedValue.set(engine, result);
@@ -91,12 +91,13 @@ Heap::RegExp *RegExp::create(ExecutionEngine* engine, const QString& pattern, bo
return result->d();
}
-void Heap::RegExp::init(ExecutionEngine *engine, const QString &pattern, bool ignoreCase, bool multiline, bool global)
+void Heap::RegExp::init(ExecutionEngine *engine, const QString &pattern, bool ignoreCase, bool multiline, bool global, bool unicode)
{
Base::init();
this->pattern = new QString(pattern);
this->ignoreCase = ignoreCase;
this->multiLine = multiline;
+ this->unicode = unicode;
this->global = global;
valid = false;
@@ -109,6 +110,8 @@ void Heap::RegExp::init(ExecutionEngine *engine, const QString &pattern, bool ig
flags = static_cast<JSC::RegExpFlags>(flags | JSC::FlagMultiline);
if (global)
flags = static_cast<JSC::RegExpFlags>(flags | JSC::FlagGlobal);
+ if (unicode)
+ flags = static_cast<JSC::RegExpFlags>(flags | JSC::FlagUnicode);
JSC::Yarr::YarrPattern yarrPattern(WTF::String(pattern), flags, error);
if (error != JSC::Yarr::ErrorCode::NoError)
diff --git a/src/qml/jsruntime/qv4regexp_p.h b/src/qml/jsruntime/qv4regexp_p.h
index 597e42538a..9090aaa7d5 100644
--- a/src/qml/jsruntime/qv4regexp_p.h
+++ b/src/qml/jsruntime/qv4regexp_p.h
@@ -76,7 +76,7 @@ struct RegExpCacheKey;
namespace Heap {
struct RegExp : Base {
- void init(ExecutionEngine *engine, const QString& pattern, bool ignoreCase, bool multiline, bool global);
+ void init(ExecutionEngine *engine, const QString& pattern, bool ignoreCase, bool multiline, bool global, bool unicode);
void destroy();
QString *pattern;
@@ -96,6 +96,7 @@ struct RegExp : Base {
bool ignoreCase;
bool multiLine;
bool global;
+ bool unicode;
bool valid;
int captureCount() const { return subPatternCount + 1; }
@@ -122,7 +123,7 @@ struct RegExp : public Managed
bool multiLine() const { return d()->multiLine; }
bool global() const { return d()->global; }
- static Heap::RegExp *create(ExecutionEngine* engine, const QString& pattern, bool ignoreCase = false, bool multiline = false, bool global = false);
+ static Heap::RegExp *create(ExecutionEngine* engine, const QString& pattern, bool ignoreCase = false, bool multiline = false, bool global = false, bool unicode = false);
bool isValid() const { return d()->valid; }
diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp
index 8429b96baa..f8caf404e9 100644
--- a/src/qml/jsruntime/qv4regexpobject.cpp
+++ b/src/qml/jsruntime/qv4regexpobject.cpp
@@ -151,6 +151,7 @@ void RegExpObject::initProperties()
setProperty(Index_Global, Primitive::fromBoolean(global()));
setProperty(Index_IgnoreCase, Primitive::fromBoolean(value()->ignoreCase));
setProperty(Index_Multiline, Primitive::fromBoolean(value()->multiLine));
+ setProperty(Index_Unicode, Primitive::fromBoolean(value()->unicode));
}
// Converts a JS RegExp to a QRegExp.
@@ -191,6 +192,8 @@ uint RegExpObject::flags() const
f |= QV4::RegExpObject::RegExp_IgnoreCase;
if (value()->multiLine)
f |= QV4::RegExpObject::RegExp_Multiline;
+ if (value()->unicode)
+ f |= QV4::RegExpObject::RegExp_Unicode;
return f;
}
diff --git a/src/qml/jsruntime/qv4regexpobject_p.h b/src/qml/jsruntime/qv4regexpobject_p.h
index 0d4fe760eb..e52220c257 100644
--- a/src/qml/jsruntime/qv4regexpobject_p.h
+++ b/src/qml/jsruntime/qv4regexpobject_p.h
@@ -108,7 +108,8 @@ struct RegExpObject: Object {
enum Flags {
RegExp_Global = 0x01,
RegExp_IgnoreCase = 0x02,
- RegExp_Multiline = 0x04
+ RegExp_Multiline = 0x04,
+ RegExp_Unicode = 0x08
};
enum {
@@ -117,6 +118,7 @@ struct RegExpObject: Object {
Index_Global = 2,
Index_IgnoreCase = 3,
Index_Multiline = 4,
+ Index_Unicode = 5,
Index_ArrayIndex = Heap::ArrayObject::LengthPropertyIndex + 1,
Index_ArrayInput = Index_ArrayIndex + 1
};