aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4regexp_p.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-08-08 12:39:54 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-09-08 17:45:06 +0000
commitc1fed764a2495373a9e4563bc3ac0d578b2f9409 (patch)
treee263aa10cd111d4d8f0d4e1cfeb49460f2a0eb2b /src/qml/jsruntime/qv4regexp_p.h
parent5f17840a14e22da0cfa973b36b9f6ce3bc8d4067 (diff)
Fix reuse of regexp objects by regexp literals
Accoding to the standard the regexp objects created by literals should be separate objects as if calling new. We were violating that by caching the same object for every instance of a literal. This also fixes a problem with leaking values of lastIndex between separate instances of the same global regexp literal. Task-number: QTBUG-62175 Change-Id: Ib22e9ee68de1d1209fbd4212e72f576bc059d245 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4regexp_p.h')
-rw-r--r--src/qml/jsruntime/qv4regexp_p.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/qml/jsruntime/qv4regexp_p.h b/src/qml/jsruntime/qv4regexp_p.h
index 04cdb468bf..d9b536406c 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);
+ void init(ExecutionEngine* engine, const QString& pattern, bool ignoreCase, bool multiline, bool global);
void destroy();
QString *pattern;
@@ -88,6 +88,7 @@ struct RegExp : Base {
int subPatternCount;
bool ignoreCase;
bool multiLine;
+ bool global;
int captureCount() const { return subPatternCount + 1; }
};
@@ -111,8 +112,9 @@ struct RegExp : public Managed
int subPatternCount() const { return d()->subPatternCount; }
bool ignoreCase() const { return d()->ignoreCase; }
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);
+ static Heap::RegExp *create(ExecutionEngine* engine, const QString& pattern, bool ignoreCase = false, bool multiline = false, bool global = false);
bool isValid() const { return d()->byteCode; }
@@ -127,27 +129,30 @@ struct RegExp : public Managed
struct RegExpCacheKey
{
- RegExpCacheKey(const QString &pattern, bool ignoreCase, bool multiLine)
+ RegExpCacheKey(const QString &pattern, bool ignoreCase, bool multiLine, bool global)
: pattern(pattern)
, ignoreCase(ignoreCase)
, multiLine(multiLine)
+ , global(global)
{ }
explicit inline RegExpCacheKey(const RegExp::Data *re);
bool operator==(const RegExpCacheKey &other) const
- { return pattern == other.pattern && ignoreCase == other.ignoreCase && multiLine == other.multiLine; }
+ { return pattern == other.pattern && ignoreCase == other.ignoreCase && multiLine == other.multiLine && global == other.global; }
bool operator!=(const RegExpCacheKey &other) const
{ return !operator==(other); }
QString pattern;
uint ignoreCase : 1;
uint multiLine : 1;
+ uint global : 1;
};
inline RegExpCacheKey::RegExpCacheKey(const RegExp::Data *re)
: pattern(*re->pattern)
, ignoreCase(re->ignoreCase)
, multiLine(re->multiLine)
+ , global(re->global)
{}
inline uint qHash(const RegExpCacheKey& key, uint seed = 0) Q_DECL_NOTHROW