Fix length property of global utility functions
authorSimon Hausmann <simon.hausmann@digia.com>
Tue, 22 Jan 2013 15:12:12 +0000 (16:12 +0100)
committerLars Knoll <lars.knoll@digia.com>
Tue, 22 Jan 2013 16:06:47 +0000 (17:06 +0100)
Functions such as parseInt must have a correct length property
that is read-only.

Change-Id: I91d9a8709c9a2ee23c72388a8737b8761357a285
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
qmljs_engine.cpp
qv4globalobject.cpp
qv4globalobject.h
tests/TestExpectations

index 23697fb..c2fe43c 100644 (file)
@@ -220,16 +220,16 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory)
 
     glo->defineDefaultProperty(rootContext, QStringLiteral("eval"), Value::fromObject(new (memoryManager) EvalFunction(rootContext)));
 
-    glo->defineDefaultProperty(rootContext, QStringLiteral("parseInt"), Value::fromObject(new (memoryManager) ParseIntFunction(rootContext)));
-    glo->defineDefaultProperty(rootContext, QStringLiteral("parseFloat"), Value::fromObject(new (memoryManager) ParseFloatFunction(rootContext)));
-    glo->defineDefaultProperty(rootContext, QStringLiteral("isNaN"), Value::fromObject(new (memoryManager) IsNaNFunction(rootContext)));
-    glo->defineDefaultProperty(rootContext, QStringLiteral("isFinite"), Value::fromObject(new (memoryManager) IsFiniteFunction(rootContext)));
-    glo->defineDefaultProperty(rootContext, QStringLiteral("decodeURI"), Value::fromObject(new (memoryManager) DecodeUriFunction(rootContext)));
-    glo->defineDefaultProperty(rootContext, QStringLiteral("decodeURIComponent"), Value::fromObject(new (memoryManager) DecodeUriComponentFunction(rootContext)));
-    glo->defineDefaultProperty(rootContext, QStringLiteral("encodeURI"), Value::fromObject(new (memoryManager) EncodeUriFunction(rootContext)));
-    glo->defineDefaultProperty(rootContext, QStringLiteral("encodeURIComponent"), Value::fromObject(new (memoryManager) EncodeUriComponentFunction(rootContext)));
-    glo->defineDefaultProperty(rootContext, QStringLiteral("escape"), Value::fromObject(new (memoryManager) EscapeFunction(rootContext)));
-    glo->defineDefaultProperty(rootContext, QStringLiteral("unescape"), Value::fromObject(new (memoryManager) UnescapeFunction(rootContext)));
+    glo->defineDefaultProperty(rootContext, QStringLiteral("parseInt"), GlobalFunctions::method_parseInt, 2);
+    glo->defineDefaultProperty(rootContext, QStringLiteral("parseFloat"), GlobalFunctions::method_parseFloat, 1);
+    glo->defineDefaultProperty(rootContext, QStringLiteral("isNaN"), GlobalFunctions::method_isNaN, 1);
+    glo->defineDefaultProperty(rootContext, QStringLiteral("isFinite"), GlobalFunctions::method_isFinite, 1);
+    glo->defineDefaultProperty(rootContext, QStringLiteral("decodeURI"), GlobalFunctions::method_decodeURI, 1);
+    glo->defineDefaultProperty(rootContext, QStringLiteral("decodeURIComponent"), GlobalFunctions::method_decodeURIComponent, 1);
+    glo->defineDefaultProperty(rootContext, QStringLiteral("encodeURI"), GlobalFunctions::method_encodeURI, 1);
+    glo->defineDefaultProperty(rootContext, QStringLiteral("encodeURIComponent"), GlobalFunctions::method_encodeURIComponent, 1);
+    glo->defineDefaultProperty(rootContext, QStringLiteral("escape"), GlobalFunctions::method_escape, 1);
+    glo->defineDefaultProperty(rootContext, QStringLiteral("unescape"), GlobalFunctions::method_unescape, 1);
 }
 
 ExecutionEngine::~ExecutionEngine()
index a4603ae..5d01d86 100644 (file)
@@ -405,13 +405,6 @@ QQmlJS::VM::Function *EvalFunction::parseSource(QQmlJS::VM::ExecutionContext *ct
     return globalCode;
 }
 
-// parseInt [15.1.2.2]
-ParseIntFunction::ParseIntFunction(ExecutionContext *scope)
-    : FunctionObject(scope)
-{
-    name = scope->engine->newString(QLatin1String("parseInt"));
-}
-
 static inline int toInt(const QChar &qc, int R)
 {
     ushort c = qc.unicode();
@@ -428,12 +421,11 @@ static inline int toInt(const QChar &qc, int R)
         return -1;
 }
 
-Value ParseIntFunction::call(ExecutionContext *context, Value thisObject, Value *args, int argc)
+// parseInt [15.1.2.2]
+Value GlobalFunctions::method_parseInt(ExecutionContext *context)
 {
-    Q_UNUSED(thisObject);
-
-    Value string = (argc > 0) ? args[0] : Value::undefinedValue();
-    Value radix = (argc > 1) ? args[1] : Value::undefinedValue();
+    Value string = context->argument(0);
+    Value radix = context->argument(1);
     int R = radix.isUndefined() ? 0 : radix.toInt32(context);
 
     // [15.1.2.2] step by step:
@@ -509,18 +501,9 @@ Value ParseIntFunction::call(ExecutionContext *context, Value thisObject, Value
 }
 
 // parseFloat [15.1.2.3]
-ParseFloatFunction::ParseFloatFunction(ExecutionContext *scope)
-    : FunctionObject(scope)
-{
-    name = scope->engine->newString(QLatin1String("parseFloat"));
-}
-
-Value ParseFloatFunction::call(ExecutionContext *context, Value thisObject, Value *args, int argc)
+Value GlobalFunctions::method_parseFloat(ExecutionContext *context)
 {
-    Q_UNUSED(context);
-    Q_UNUSED(thisObject);
-
-    Value string = (argc > 0) ? args[0] : Value::undefinedValue();
+    Value string = context->argument(0);
 
     // [15.1.2.3] step by step:
     String *inputString = string.toString(context); // 1
@@ -544,15 +527,9 @@ Value ParseFloatFunction::call(ExecutionContext *context, Value thisObject, Valu
 }
 
 /// isNaN [15.1.2.4]
-IsNaNFunction::IsNaNFunction(ExecutionContext *scope)
-    : FunctionObject(scope)
-{
-    name = scope->engine->newString(QLatin1String("isNaN"));
-}
-
-Value IsNaNFunction::call(ExecutionContext *context, Value /*thisObject*/, Value *args, int argc)
+Value GlobalFunctions::method_isNaN(ExecutionContext *context)
 {
-    const Value &v = (argc > 0) ? args[0] : Value::undefinedValue();
+    const Value &v = context->argument(0);
     if (v.integerCompatible())
         return Value::fromBoolean(false);
 
@@ -561,15 +538,9 @@ Value IsNaNFunction::call(ExecutionContext *context, Value /*thisObject*/, Value
 }
 
 /// isFinite [15.1.2.5]
-IsFiniteFunction::IsFiniteFunction(ExecutionContext *scope)
-    : FunctionObject(scope)
-{
-    name = scope->engine->newString(QLatin1String("isFinite"));
-}
-
-Value IsFiniteFunction::call(ExecutionContext *context, Value /*thisObject*/, Value *args, int argc)
+Value GlobalFunctions::method_isFinite(ExecutionContext *context)
 {
-    const Value &v = (argc > 0) ? args[0] : Value::undefinedValue();
+    const Value &v = context->argument(0);
     if (v.integerCompatible())
         return Value::fromBoolean(true);
 
@@ -577,20 +548,13 @@ Value IsFiniteFunction::call(ExecutionContext *context, Value /*thisObject*/, Va
     return Value::fromBoolean(std::isfinite(d));
 }
 
-
 /// decodeURI [15.1.3.1]
-DecodeUriFunction::DecodeUriFunction(ExecutionContext *scope)
-    : FunctionObject(scope)
-{
-    name = scope->engine->newString(QLatin1String("decodeURI"));
-}
-
-Value DecodeUriFunction::call(ExecutionContext *context, Value /*thisObject*/, Value *args, int argc)
+Value GlobalFunctions::method_decodeURI(ExecutionContext *context)
 {
-    if (argc == 0)
+    if (context->argumentCount == 0)
         return Value::undefinedValue();
 
-    QString uriString = args[0].toString(context)->toQString();
+    QString uriString = context->argument(0).toString(context)->toQString();
     bool ok;
     QString out = decode(uriString, QString::fromUtf8(uriReserved) + QString::fromUtf8("#"), &ok);
     if (!ok)
@@ -600,18 +564,12 @@ Value DecodeUriFunction::call(ExecutionContext *context, Value /*thisObject*/, V
 }
 
 /// decodeURIComponent [15.1.3.2]
-DecodeUriComponentFunction::DecodeUriComponentFunction(ExecutionContext *scope)
-    : FunctionObject(scope)
-{
-    name = scope->engine->newString(QLatin1String("decodeURIComponent"));
-}
-
-Value DecodeUriComponentFunction::call(ExecutionContext *context, Value /*thisObject*/, Value *args, int argc)
+Value GlobalFunctions::method_decodeURIComponent(ExecutionContext *context)
 {
-    if (argc == 0)
+    if (context->argumentCount == 0)
         return Value::undefinedValue();
 
-    QString uriString = args[0].toString(context)->toQString();
+    QString uriString = context->argument(0).toString(context)->toQString();
     bool ok;
     QString out = decode(uriString, QString(), &ok);
     if (!ok)
@@ -621,18 +579,12 @@ Value DecodeUriComponentFunction::call(ExecutionContext *context, Value /*thisOb
 }
 
 /// encodeURI [15.1.3.3]
-EncodeUriFunction::EncodeUriFunction(ExecutionContext *scope)
-    : FunctionObject(scope)
+Value GlobalFunctions::method_encodeURI(ExecutionContext *context)
 {
-    name = scope->engine->newString(QLatin1String("encodeURI"));
-}
-
-Value EncodeUriFunction::call(ExecutionContext *context, Value /*thisObject*/, Value *args, int argc)
-{
-    if (argc == 0)
+    if (context->argumentCount == 0)
         return Value::undefinedValue();
 
-    QString uriString = args[0].toString(context)->toQString();
+    QString uriString = context->argument(0).toString(context)->toQString();
     bool ok;
     QString out = encode(uriString, QLatin1String(uriReserved) + QLatin1String(uriUnescaped) + QString::fromUtf8("#"), &ok);
     if (!ok)
@@ -641,20 +593,13 @@ Value EncodeUriFunction::call(ExecutionContext *context, Value /*thisObject*/, V
     return Value::fromString(context, out);
 }
 
-
 /// encodeURIComponent [15.1.3.4]
-EncodeUriComponentFunction::EncodeUriComponentFunction(ExecutionContext *scope)
-    : FunctionObject(scope)
-{
-    name = scope->engine->newString(QLatin1String("encodeURIComponent"));
-}
-
-Value EncodeUriComponentFunction::call(ExecutionContext *context, Value /*thisObject*/, Value *args, int argc)
+Value GlobalFunctions::method_encodeURIComponent(ExecutionContext *context)
 {
-    if (argc == 0)
+    if (context->argumentCount == 0)
         return Value::undefinedValue();
 
-    QString uriString = args[0].toString(context)->toQString();
+    QString uriString = context->argument(0).toString(context)->toQString();
     bool ok;
     QString out = encode(uriString, QString(), &ok);
     if (!ok)
@@ -663,34 +608,20 @@ Value EncodeUriComponentFunction::call(ExecutionContext *context, Value /*thisOb
     return Value::fromString(context, out);
 }
 
-
-EscapeFunction::EscapeFunction(ExecutionContext *scope)
-    : FunctionObject(scope)
-{
-    name = scope->engine->newString(QLatin1String("escape"));
-}
-
-Value EscapeFunction::call(ExecutionContext *context, Value /*thisObject*/, Value *args, int argc)
+Value GlobalFunctions::method_escape(ExecutionContext *context)
 {
-    if (!argc)
+    if (!context->argumentCount)
         return Value::fromString(context, QStringLiteral("undefined"));
 
-    QString str = args->toString(context)->toQString();
+    QString str = context->argument(0).toString(context)->toQString();
     return Value::fromString(context, escape(str));
 }
 
-
-UnescapeFunction::UnescapeFunction(ExecutionContext *scope)
-    : FunctionObject(scope)
-{
-    name = scope->engine->newString(QLatin1String("unescape"));
-}
-
-Value UnescapeFunction::call(ExecutionContext *context, Value /*thisObject*/, Value *args, int argc)
+Value GlobalFunctions::method_unescape(ExecutionContext *context)
 {
-    if (!argc)
+    if (!context->argumentCount)
         return Value::fromString(context, QStringLiteral("undefined"));
 
-    QString str = args->toString(context)->toQString();
+    QString str = context->argument(0).toString(context)->toQString();
     return Value::fromString(context, unescape(str));
 }
index 152f4d3..3ea7b38 100644 (file)
@@ -59,74 +59,18 @@ struct EvalFunction : FunctionObject
     virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc);
 };
 
-struct ParseIntFunction: FunctionObject
+struct GlobalFunctions
 {
-    ParseIntFunction(ExecutionContext *scope);
-
-    virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc);
-};
-
-struct ParseFloatFunction: FunctionObject
-{
-    ParseFloatFunction(ExecutionContext *scope);
-
-    virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc);
-};
-
-struct IsNaNFunction: FunctionObject
-{
-    IsNaNFunction(ExecutionContext *scope);
-
-    virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc);
-};
-
-struct IsFiniteFunction: FunctionObject
-{
-    IsFiniteFunction(ExecutionContext *scope);
-
-    virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc);
-};
-
-struct DecodeUriFunction: FunctionObject
-{
-    DecodeUriFunction(ExecutionContext *scope);
-
-    virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc);
-};
-
-struct DecodeUriComponentFunction: FunctionObject
-{
-    DecodeUriComponentFunction(ExecutionContext *scope);
-
-    virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc);
-};
-
-struct EncodeUriFunction: FunctionObject
-{
-    EncodeUriFunction(ExecutionContext *scope);
-
-    virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc);
-};
-
-struct EncodeUriComponentFunction: FunctionObject
-{
-    EncodeUriComponentFunction(ExecutionContext *scope);
-
-    virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc);
-};
-
-struct EscapeFunction: FunctionObject
-{
-    EscapeFunction(ExecutionContext *scope);
-
-    virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc);
-};
-
-struct UnescapeFunction: FunctionObject
-{
-    UnescapeFunction(ExecutionContext *scope);
-
-    virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc);
+    static Value method_parseInt(ExecutionContext *context);
+    static Value method_parseFloat(ExecutionContext *context);
+    static Value method_isNaN(ExecutionContext *context);
+    static Value method_isFinite(ExecutionContext *context);
+    static Value method_decodeURI(ExecutionContext *context);
+    static Value method_decodeURIComponent(ExecutionContext *context);
+    static Value method_encodeURI(ExecutionContext *context);
+    static Value method_encodeURIComponent(ExecutionContext *context);
+    static Value method_escape(ExecutionContext *context);
+    static Value method_unescape(ExecutionContext *context);
 };
 
 } // namespace VM
index 029387c..82e49a5 100644 (file)
@@ -269,11 +269,6 @@ S12.7_A7 failing
 S12.8_A4_T1 failing
 S12.8_A4_T2 failing
 S12.8_A4_T3 failing
-S15.1.2.2_A9.1 failing
-S15.1.2.2_A9.2 failing
-S15.1.2.2_A9.3 failing
-S15.1.2.2_A9.4 failing
-S15.1.2.2_A9.7 failing
 15.12.1.1-g6-3 failing
 15.12.1.1-g6-4 failing
 15.12.1.1-g6-5 failing
@@ -288,21 +283,6 @@ S15.12.2_A1 failing
 15.12.3-11-13 failing
 15.12.3-11-14 failing
 15.12.3-11-15 failing
-S15.1.2.3_A7.1 failing
-S15.1.2.3_A7.2 failing
-S15.1.2.3_A7.3 failing
-S15.1.2.3_A7.4 failing
-S15.1.2.3_A7.7 failing
-S15.1.2.4_A2.1 failing
-S15.1.2.4_A2.2 failing
-S15.1.2.4_A2.3 failing
-S15.1.2.4_A2.4 failing
-S15.1.2.4_A2.7 failing
-S15.1.2.5_A2.1 failing
-S15.1.2.5_A2.2 failing
-S15.1.2.5_A2.3 failing
-S15.1.2.5_A2.4 failing
-S15.1.2.5_A2.7 failing
 S15.1.3.1_A1.13_T1 failing
 S15.1.3.1_A1.13_T2 failing
 S15.1.3.1_A1.14_T1 failing
@@ -346,16 +326,9 @@ S15.1.3.1_A1.15_T6 failing
 15.12.3_2-3-a-2 failing
 15.12.3_2-3-a-3 failing
 15.12.3_4-1-2 failing
-S15.1.3.2_A5.4 failing
-S15.1.3.2_A5.7 failing
 S15.1.3.3_A2.4_T1 failing
 S15.1.3.3_A2.4_T2 failing
 S15.1.3.3_A2.5_T1 failing
-S15.1.3.3_A5.1 failing
-S15.1.3.3_A5.2 failing
-S15.1.3.3_A5.3 failing
-S15.1.3.3_A5.4 failing
-S15.1.3.3_A5.7 failing
 S15.1.3.4_A2.4_T1 failing
 S15.1.3.4_A2.4_T2 failing
 S15.1.3.4_A2.5_T1 failing
@@ -366,20 +339,10 @@ S15.1.3.4_A4_T1 failing
 S15.1.3.4_A4_T2 failing
 S15.1.3.4_A4_T3 failing
 S15.1.3.4_A4_T4 failing
-S15.1.3.4_A5.1 failing
-S15.1.3.4_A5.2 failing
-S15.1.3.4_A5.3 failing
-S15.1.3.4_A5.4 failing
-S15.1.3.4_A5.7 failing
 S15.1.3.4_A6_T1 failing
 S15.1.3.1_A2.3_T1 failing
 S15.1.3.1_A2.4_T1 failing
 S15.1.3.1_A4_T2 failing
-S15.1.3.1_A5.1 failing
-S15.1.3.1_A5.2 failing
-S15.1.3.1_A5.3 failing
-S15.1.3.1_A5.4 failing
-S15.1.3.1_A5.7 failing
 S15.1.3.2_A1.13_T1 failing
 S15.1.3.2_A1.13_T2 failing
 S15.1.3.2_A1.14_T1 failing
@@ -395,9 +358,6 @@ S15.1.3.2_A1.15_T6 failing
 S15.1.3.2_A2.3_T1 failing
 S15.1.3.2_A2.4_T1 failing
 S15.1.3.2_A4_T2 failing
-S15.1.3.2_A5.1 failing
-S15.1.3.2_A5.2 failing
-S15.1.3.2_A5.3 failing
 15.2.3.6-2-17-1 failing
 15.2.3.6-4-291-1 failing
 15.2.3.6-4-292-1 failing
@@ -623,4 +583,4 @@ S15.4.4.4_A1_T2 failing
 
 15.4.4.21-8-b-iii-1-6 failing
 15.12.3_4-1-1
-15.12.3_4-1-3
+15.12.3_4-1-3
\ No newline at end of file