From a0fecb437176786e9c809a45e64351516b05a201 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 5 Aug 2009 18:02:47 +0200 Subject: RegExp.prototype.toString() when pattern is empty Like ECMA-262 says, // starts a single-line comment; /(?:)/ represents an empty regular expression. --- src/3rdparty/webkit/JavaScriptCore/runtime/RegExpPrototype.cpp | 4 ++++ tests/auto/qscriptengine/tst_qscriptengine.cpp | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/3rdparty/webkit/JavaScriptCore/runtime/RegExpPrototype.cpp b/src/3rdparty/webkit/JavaScriptCore/runtime/RegExpPrototype.cpp index b1ab889..e507016 100644 --- a/src/3rdparty/webkit/JavaScriptCore/runtime/RegExpPrototype.cpp +++ b/src/3rdparty/webkit/JavaScriptCore/runtime/RegExpPrototype.cpp @@ -106,6 +106,10 @@ JSValue JSC_HOST_CALL regExpProtoFuncToString(ExecState* exec, JSObject*, JSValu } UString result = "/" + asRegExpObject(thisValue)->get(exec, exec->propertyNames().source).toString(exec); +#ifdef QT_BUILD_SCRIPT_LIB + if (result.size() == 1) + result.append("(?:)"); +#endif result.append('/'); if (asRegExpObject(thisValue)->get(exec, exec->propertyNames().global).toBoolean(exec)) result.append('g'); diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index ec84406..7f22316 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -508,12 +508,10 @@ void tst_QScriptEngine::newRegExp() QScriptValue r9 = rxCtor.construct(); QVERIFY(r9.isRegExp()); - QEXPECT_FAIL("", "JSC: String representation of regexp with empty pattern is wrong", Continue); QCOMPARE(r9.toString(), QString::fromLatin1("/(?:)/")); QScriptValue r10 = rxCtor.construct(QScriptValueList() << "" << "gim"); QVERIFY(r10.isRegExp()); - QEXPECT_FAIL("", "JSC: String representation of regexp with empty pattern is wrong", Continue); QCOMPARE(r10.toString(), QString::fromLatin1("/(?:)/gim")); QScriptValue r11 = rxCtor.construct(QScriptValueList() << "{1.*}" << "g"); -- cgit v0.12