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()
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();
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:
}
// 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
}
/// 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);
}
/// 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);
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)
}
/// 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)
}
/// 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)
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)
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));
}
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