From ab62ad883041221ceda6cf8f80bf4720b9e93998 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 5 Apr 2013 21:38:09 +0200 Subject: Convert the remaining builtin methods to use the SimpleCallContext Change-Id: Ib01bd0c15578b93829abd6fcf8df22cac12daf14 Reviewed-by: Simon Hausmann --- src/v4/qv4engine.cpp | 6 -- src/v4/qv4engine.h | 1 - src/v4/qv4functionobject.cpp | 23 ------- src/v4/qv4functionobject.h | 12 ---- src/v4/qv4globalobject.cpp | 40 ++++++------ src/v4/qv4globalobject.h | 8 +-- src/v4/qv4mathobject.cpp | 84 ++++++++++++------------- src/v4/qv4mathobject.h | 36 +++++------ src/v4/qv4object.cpp | 9 --- src/v4/qv4object.h | 1 - src/v4/qv4objectproto.cpp | 10 +-- src/v4/qv4objectproto.h | 2 +- src/v4/qv4stringobject.cpp | 144 +++++++++++++++++++++---------------------- src/v4/qv4stringobject.h | 22 +++---- 14 files changed, 173 insertions(+), 225 deletions(-) diff --git a/src/v4/qv4engine.cpp b/src/v4/qv4engine.cpp index d1226ba2..eb0aab87 100644 --- a/src/v4/qv4engine.cpp +++ b/src/v4/qv4engine.cpp @@ -391,12 +391,6 @@ FunctionObject *ExecutionEngine::newBuiltinFunction(ExecutionContext *scope, Str return f; } -FunctionObject *ExecutionEngine::newBuiltinFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *, Value, Value *, int)) -{ - BuiltinFunction *f = new (memoryManager) BuiltinFunction(scope, name, code); - return f; -} - FunctionObject *ExecutionEngine::newScriptFunction(ExecutionContext *scope, VM::Function *function) { assert(function); diff --git a/src/v4/qv4engine.h b/src/v4/qv4engine.h index 051c51f2..1537027e 100644 --- a/src/v4/qv4engine.h +++ b/src/v4/qv4engine.h @@ -209,7 +209,6 @@ struct Q_V4_EXPORT ExecutionEngine VM::Function *newFunction(const QString &name); FunctionObject *newBuiltinFunction(ExecutionContext *scope, String *name, Value (*code)(SimpleCallContext *)); - FunctionObject *newBuiltinFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *, Value, Value *, int)); FunctionObject *newScriptFunction(ExecutionContext *scope, VM::Function *function); BoundFunction *newBoundFunction(ExecutionContext *scope, FunctionObject *target, Value boundThis, const QVector &boundArgs); diff --git a/src/v4/qv4functionobject.cpp b/src/v4/qv4functionobject.cpp index a1685045..849f3d50 100644 --- a/src/v4/qv4functionobject.cpp +++ b/src/v4/qv4functionobject.cpp @@ -463,29 +463,6 @@ Value BuiltinFunctionOld::call(Managed *that, ExecutionContext *context, const V } -DEFINE_MANAGED_VTABLE(BuiltinFunction); - -BuiltinFunction::BuiltinFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *, Value, Value *, int)) - : FunctionObject(scope) - , code(code) -{ - vtbl = &static_vtbl; - this->name = name; - isBuiltinFunction = true; -} - -Value BuiltinFunction::call(Managed *that, ExecutionContext *context, const Value &thisObject, Value *args, int argc) -{ - BuiltinFunction *f = static_cast(that); - return f->code(context, thisObject, args, argc); -} - -Value BuiltinFunction::construct(Managed *, ExecutionContext *ctx, Value *, int) -{ - ctx->throwTypeError(); - return Value::undefinedValue(); -} - DEFINE_MANAGED_VTABLE(BoundFunction); BoundFunction::BoundFunction(ExecutionContext *scope, FunctionObject *target, Value boundThis, const QVector &boundArgs) diff --git a/src/v4/qv4functionobject.h b/src/v4/qv4functionobject.h index e3533d67..c20eb69e 100644 --- a/src/v4/qv4functionobject.h +++ b/src/v4/qv4functionobject.h @@ -261,18 +261,6 @@ protected: static const ManagedVTable static_vtbl; }; -struct BuiltinFunction: FunctionObject { - Value (*code)(ExecutionContext *parentContext, Value thisObject, Value *args, int argc); - - BuiltinFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *, Value, Value *, int)); - - static Value construct(Managed *, ExecutionContext *context, Value *args, int argc); - static Value call(Managed *that, ExecutionContext *, const Value &, Value *, int); - -protected: - static const ManagedVTable static_vtbl; -}; - struct ScriptFunction: FunctionObject { ScriptFunction(ExecutionContext *scope, VM::Function *function); diff --git a/src/v4/qv4globalobject.cpp b/src/v4/qv4globalobject.cpp index 44b50f9b..be243cca 100644 --- a/src/v4/qv4globalobject.cpp +++ b/src/v4/qv4globalobject.cpp @@ -653,63 +653,63 @@ Value GlobalFunctions::method_isFinite(SimpleCallContext *context) } /// decodeURI [15.1.3.1] -Value GlobalFunctions::method_decodeURI(ExecutionContext *parentCtx, Value, Value *argv, int argc) +Value GlobalFunctions::method_decodeURI(SimpleCallContext *context) { - if (argc == 0) + if (context->argumentCount == 0) return Value::undefinedValue(); - QString uriString = argv[0].toString(parentCtx)->toQString(); + QString uriString = context->arguments[0].toString(context)->toQString(); bool ok; QString out = decode(uriString, DecodeNonReserved, &ok); if (!ok) - parentCtx->throwURIError(Value::fromString(parentCtx, QStringLiteral("malformed URI sequence"))); + context->throwURIError(Value::fromString(context, QStringLiteral("malformed URI sequence"))); - return Value::fromString(parentCtx, out); + return Value::fromString(context, out); } /// decodeURIComponent [15.1.3.2] -Value GlobalFunctions::method_decodeURIComponent(ExecutionContext *parentCtx, Value, Value *argv, int argc) +Value GlobalFunctions::method_decodeURIComponent(SimpleCallContext *context) { - if (argc == 0) + if (context->argumentCount == 0) return Value::undefinedValue(); - QString uriString = argv[0].toString(parentCtx)->toQString(); + QString uriString = context->arguments[0].toString(context)->toQString(); bool ok; QString out = decode(uriString, DecodeAll, &ok); if (!ok) - parentCtx->throwURIError(Value::fromString(parentCtx, QStringLiteral("malformed URI sequence"))); + context->throwURIError(Value::fromString(context, QStringLiteral("malformed URI sequence"))); - return Value::fromString(parentCtx, out); + return Value::fromString(context, out); } /// encodeURI [15.1.3.3] -Value GlobalFunctions::method_encodeURI(ExecutionContext *parentCtx, Value, Value *argv, int argc) +Value GlobalFunctions::method_encodeURI(SimpleCallContext *context) { - if (argc == 0) + if (context->argumentCount == 0) return Value::undefinedValue(); - QString uriString = argv[0].toString(parentCtx)->toQString(); + QString uriString = context->arguments[0].toString(context)->toQString(); bool ok; QString out = encode(uriString, uriUnescapedReserved, &ok); if (!ok) - parentCtx->throwURIError(Value::fromString(parentCtx, QStringLiteral("malformed URI sequence"))); + context->throwURIError(Value::fromString(context, QStringLiteral("malformed URI sequence"))); - return Value::fromString(parentCtx, out); + return Value::fromString(context, out); } /// encodeURIComponent [15.1.3.4] -Value GlobalFunctions::method_encodeURIComponent(ExecutionContext *parentCtx, Value, Value *argv, int argc) +Value GlobalFunctions::method_encodeURIComponent(SimpleCallContext *context) { - if (argc == 0) + if (context->argumentCount == 0) return Value::undefinedValue(); - QString uriString = argv[0].toString(parentCtx)->toQString(); + QString uriString = context->arguments[0].toString(context)->toQString(); bool ok; QString out = encode(uriString, uriUnescaped, &ok); if (!ok) - parentCtx->throwURIError(Value::fromString(parentCtx, QStringLiteral("malformed URI sequence"))); + context->throwURIError(Value::fromString(context, QStringLiteral("malformed URI sequence"))); - return Value::fromString(parentCtx, out); + return Value::fromString(context, out); } Value GlobalFunctions::method_escape(SimpleCallContext *context) diff --git a/src/v4/qv4globalobject.h b/src/v4/qv4globalobject.h index ac96ac78..f9776f95 100644 --- a/src/v4/qv4globalobject.h +++ b/src/v4/qv4globalobject.h @@ -77,10 +77,10 @@ struct GlobalFunctions static Value method_parseFloat(SimpleCallContext *context); static Value method_isNaN(SimpleCallContext *context); static Value method_isFinite(SimpleCallContext *context); - static Value method_decodeURI(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_decodeURIComponent(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_encodeURI(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_encodeURIComponent(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); + static Value method_decodeURI(SimpleCallContext *context); + static Value method_decodeURIComponent(SimpleCallContext *context); + static Value method_encodeURI(SimpleCallContext *context); + static Value method_encodeURIComponent(SimpleCallContext *context); static Value method_escape(SimpleCallContext *context); static Value method_unescape(SimpleCallContext *context); }; diff --git a/src/v4/qv4mathobject.cpp b/src/v4/qv4mathobject.cpp index e7c455ae..ed27f3df 100644 --- a/src/v4/qv4mathobject.cpp +++ b/src/v4/qv4mathobject.cpp @@ -97,54 +97,54 @@ static double copySign(double x, double y) return x; } -Value MathObject::method_abs(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value MathObject::method_abs(SimpleCallContext *context) { - if (!argc) + if (!context->argumentCount) return Value::fromDouble(qSNaN()); - if (argv[0].isInteger()) { - int i = argv[0].integerValue(); + if (context->arguments[0].isInteger()) { + int i = context->arguments[0].integerValue(); return Value::fromInt32(i < 0 ? - i : i); } - double v = argv[0].toNumber(parentCtx); + double v = context->arguments[0].toNumber(context); if (v == 0) // 0 | -0 return Value::fromDouble(0); return Value::fromDouble(v < 0 ? -v : v); } -Value MathObject::method_acos(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value MathObject::method_acos(SimpleCallContext *context) { - double v = argc ? argv[0].toNumber(parentCtx) : 2; + double v = context->argumentCount ? context->arguments[0].toNumber(context) : 2; if (v > 1) return Value::fromDouble(qSNaN()); return Value::fromDouble(::acos(v)); } -Value MathObject::method_asin(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value MathObject::method_asin(SimpleCallContext *context) { - double v = argc ? argv[0].toNumber(parentCtx) : 2; + double v = context->argumentCount ? context->arguments[0].toNumber(context) : 2; if (v > 1) return Value::fromDouble(qSNaN()); else return Value::fromDouble(::asin(v)); } -Value MathObject::method_atan(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value MathObject::method_atan(SimpleCallContext *context) { - double v = argc ? argv[0].toNumber(parentCtx) : qSNaN(); + double v = context->argumentCount ? context->arguments[0].toNumber(context) : qSNaN(); if (v == 0.0) return Value::fromDouble(v); else return Value::fromDouble(::atan(v)); } -Value MathObject::method_atan2(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value MathObject::method_atan2(SimpleCallContext *context) { - double v1 = argc ? argv[0].toNumber(parentCtx) : qSNaN(); - double v2 = argc > 1 ? argv[1].toNumber(parentCtx) : qSNaN(); + double v1 = context->argumentCount ? context->arguments[0].toNumber(context) : qSNaN(); + double v2 = context->argumentCount > 1 ? context->arguments[1].toNumber(context) : qSNaN(); if ((v1 < 0) && qIsFinite(v1) && qIsInf(v2) && (copySign(1.0, v2) == 1.0)) return Value::fromDouble(copySign(0, -1.0)); @@ -159,24 +159,24 @@ Value MathObject::method_atan2(ExecutionContext *parentCtx, Value thisObject, Va return Value::fromDouble(::atan2(v1, v2)); } -Value MathObject::method_ceil(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value MathObject::method_ceil(SimpleCallContext *context) { - double v = argc ? argv[0].toNumber(parentCtx) : qSNaN(); + double v = context->argumentCount ? context->arguments[0].toNumber(context) : qSNaN(); if (v < 0.0 && v > -1.0) return Value::fromDouble(copySign(0, -1.0)); else return Value::fromDouble(::ceil(v)); } -Value MathObject::method_cos(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value MathObject::method_cos(SimpleCallContext *context) { - double v = argc ? argv[0].toNumber(parentCtx) : qSNaN(); + double v = context->argumentCount ? context->arguments[0].toNumber(context) : qSNaN(); return Value::fromDouble(::cos(v)); } -Value MathObject::method_exp(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value MathObject::method_exp(SimpleCallContext *context) { - double v = argc ? argv[0].toNumber(parentCtx) : qSNaN(); + double v = context->argumentCount ? context->arguments[0].toNumber(context) : qSNaN(); if (qIsInf(v)) { if (copySign(1.0, v) == -1.0) return Value::fromDouble(0); @@ -187,37 +187,37 @@ Value MathObject::method_exp(ExecutionContext *parentCtx, Value thisObject, Valu } } -Value MathObject::method_floor(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value MathObject::method_floor(SimpleCallContext *context) { - double v = argc ? argv[0].toNumber(parentCtx) : qSNaN(); + double v = context->argumentCount ? context->arguments[0].toNumber(context) : qSNaN(); return Value::fromDouble(::floor(v)); } -Value MathObject::method_log(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value MathObject::method_log(SimpleCallContext *context) { - double v = argc ? argv[0].toNumber(parentCtx) : qSNaN(); + double v = context->argumentCount ? context->arguments[0].toNumber(context) : qSNaN(); if (v < 0) return Value::fromDouble(qSNaN()); else return Value::fromDouble(::log(v)); } -Value MathObject::method_max(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value MathObject::method_max(SimpleCallContext *context) { double mx = -qInf(); - for (unsigned i = 0; i < argc; ++i) { - double x = argv[i].toNumber(parentCtx); + for (unsigned i = 0; i < context->argumentCount; ++i) { + double x = context->arguments[i].toNumber(context); if (x > mx || isnan(x)) mx = x; } return Value::fromDouble(mx); } -Value MathObject::method_min(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value MathObject::method_min(SimpleCallContext *context) { double mx = qInf(); - for (unsigned i = 0; i < argc; ++i) { - double x = argv[i].toNumber(parentCtx); + for (unsigned i = 0; i < context->argumentCount; ++i) { + double x = context->arguments[i].toNumber(context); if ((x == 0 && mx == x && copySign(1.0, x) == -1.0) || (x < mx) || isnan(x)) { mx = x; @@ -226,10 +226,10 @@ Value MathObject::method_min(ExecutionContext *parentCtx, Value thisObject, Valu return Value::fromDouble(mx); } -Value MathObject::method_pow(ExecutionContext *parentCtx, Value, Value *argv, int argc) +Value MathObject::method_pow(SimpleCallContext *context) { - double x = argc > 0 ? argv[0].toNumber(parentCtx) : qSNaN(); - double y = argc > 1 ? argv[1].toNumber(parentCtx) : qSNaN(); + double x = context->argumentCount > 0 ? context->arguments[0].toNumber(context) : qSNaN(); + double y = context->argumentCount > 1 ? context->arguments[1].toNumber(context) : qSNaN(); if (isnan(y)) return Value::fromDouble(qSNaN()); @@ -276,33 +276,33 @@ Value MathObject::method_pow(ExecutionContext *parentCtx, Value, Value *argv, in return Value::fromDouble(qSNaN()); } -Value MathObject::method_random(ExecutionContext *, Value, Value *, int) +Value MathObject::method_random(SimpleCallContext *) { return Value::fromDouble(qrand() / (double) RAND_MAX); } -Value MathObject::method_round(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value MathObject::method_round(SimpleCallContext *context) { - double v = argc ? argv[0].toNumber(parentCtx) : qSNaN(); + double v = context->argumentCount ? context->arguments[0].toNumber(context) : qSNaN(); v = copySign(::floor(v + 0.5), v); return Value::fromDouble(v); } -Value MathObject::method_sin(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value MathObject::method_sin(SimpleCallContext *context) { - double v = argc ? argv[0].toNumber(parentCtx) : qSNaN(); + double v = context->argumentCount ? context->arguments[0].toNumber(context) : qSNaN(); return Value::fromDouble(::sin(v)); } -Value MathObject::method_sqrt(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value MathObject::method_sqrt(SimpleCallContext *context) { - double v = argc ? argv[0].toNumber(parentCtx) : qSNaN(); + double v = context->argumentCount ? context->arguments[0].toNumber(context) : qSNaN(); return Value::fromDouble(::sqrt(v)); } -Value MathObject::method_tan(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value MathObject::method_tan(SimpleCallContext *context) { - double v = argc ? argv[0].toNumber(parentCtx) : qSNaN(); + double v = context->argumentCount ? context->arguments[0].toNumber(context) : qSNaN(); if (v == 0.0) return Value::fromDouble(v); else diff --git a/src/v4/qv4mathobject.h b/src/v4/qv4mathobject.h index 77db4868..68ca87d3 100644 --- a/src/v4/qv4mathobject.h +++ b/src/v4/qv4mathobject.h @@ -52,24 +52,24 @@ struct MathObject: Object { MathObject(ExecutionContext *ctx); - static Value method_abs(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_acos(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_asin(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_atan(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_atan2(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_ceil(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_cos(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_exp(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_floor(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_log(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_max(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_min(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_pow(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_random(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_round(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_sin(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_sqrt(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_tan(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); + static Value method_abs(SimpleCallContext *context); + static Value method_acos(SimpleCallContext *context); + static Value method_asin(SimpleCallContext *context); + static Value method_atan(SimpleCallContext *context); + static Value method_atan2(SimpleCallContext *context); + static Value method_ceil(SimpleCallContext *context); + static Value method_cos(SimpleCallContext *context); + static Value method_exp(SimpleCallContext *context); + static Value method_floor(SimpleCallContext *context); + static Value method_log(SimpleCallContext *context); + static Value method_max(SimpleCallContext *context); + static Value method_min(SimpleCallContext *context); + static Value method_pow(SimpleCallContext *context); + static Value method_random(SimpleCallContext *context); + static Value method_round(SimpleCallContext *context); + static Value method_sin(SimpleCallContext *context); + static Value method_sqrt(SimpleCallContext *context); + static Value method_tan(SimpleCallContext *context); }; } // namespace VM diff --git a/src/v4/qv4object.cpp b/src/v4/qv4object.cpp index b75b6722..4f5a6579 100644 --- a/src/v4/qv4object.cpp +++ b/src/v4/qv4object.cpp @@ -214,15 +214,6 @@ void Object::defineDefaultProperty(ExecutionContext *context, const QString &nam defineDefaultProperty(s, Value::fromObject(function)); } -void Object::defineDefaultProperty(ExecutionContext *context, const QString &name, Value (*code)(ExecutionContext *, Value, Value *, int), int argumentCount) -{ - Q_UNUSED(argumentCount); - String *s = context->engine->newIdentifier(name); - FunctionObject* function = context->engine->newBuiltinFunction(context, s, code); - function->defineReadonlyProperty(context->engine->id_length, Value::fromInt32(argumentCount)); - defineDefaultProperty(s, Value::fromObject(function)); -} - void Object::defineReadonlyProperty(ExecutionEngine *engine, const QString &name, Value value) { defineReadonlyProperty(engine->newIdentifier(name), value); diff --git a/src/v4/qv4object.h b/src/v4/qv4object.h index b24e270a..caee8b62 100644 --- a/src/v4/qv4object.h +++ b/src/v4/qv4object.h @@ -179,7 +179,6 @@ struct Q_V4_EXPORT Object: Managed { void defineDefaultProperty(String *name, Value value); void defineDefaultProperty(ExecutionContext *context, const QString &name, Value value); void defineDefaultProperty(ExecutionContext *context, const QString &name, Value (*code)(SimpleCallContext *), int count = 0); - void defineDefaultProperty(ExecutionContext *context, const QString &name, Value (*code)(ExecutionContext *, Value, Value *, int), int argumentCount = 0); /* Fixed: Writable: false, Enumerable: false, Configurable: false */ void defineReadonlyProperty(ExecutionEngine *engine, const QString &name, Value value); void defineReadonlyProperty(String *name, Value value); diff --git a/src/v4/qv4objectproto.cpp b/src/v4/qv4objectproto.cpp index 9d63ea05..907b6fe2 100644 --- a/src/v4/qv4objectproto.cpp +++ b/src/v4/qv4objectproto.cpp @@ -149,14 +149,14 @@ Value ObjectPrototype::method_getOwnPropertyDescriptor(SimpleCallContext *ctx) return fromPropertyDescriptor(ctx, desc); } -Value ObjectPrototype::method_getOwnPropertyNames(ExecutionContext *parentCtx, Value, Value *argv, int argc) +Value ObjectPrototype::method_getOwnPropertyNames(SimpleCallContext *context) { - Object *O = argc ? argv[0].asObject() : 0; + Object *O = context->argumentCount ? context->arguments[0].asObject() : 0; if (!O) - parentCtx->throwTypeError(); + context->throwTypeError(); - ArrayObject *array = parentCtx->engine->newArrayObject(parentCtx)->asArrayObject(); - ObjectIterator it(parentCtx, O, ObjectIterator::NoFlags); + ArrayObject *array = context->engine->newArrayObject(context)->asArrayObject(); + ObjectIterator it(context, O, ObjectIterator::NoFlags); while (1) { Value v = it.nextPropertyNameAsString(); if (v.isNull()) diff --git a/src/v4/qv4objectproto.h b/src/v4/qv4objectproto.h index e4ce916b..1abd8d13 100644 --- a/src/v4/qv4objectproto.h +++ b/src/v4/qv4objectproto.h @@ -69,7 +69,7 @@ struct ObjectPrototype: Object static Value method_getPrototypeOf(SimpleCallContext *ctx); static Value method_getOwnPropertyDescriptor(SimpleCallContext *ctx); - static Value method_getOwnPropertyNames(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); + static Value method_getOwnPropertyNames(SimpleCallContext *context); static Value method_create(SimpleCallContext *ctx); static Value method_defineProperty(SimpleCallContext *ctx); static Value method_defineProperties(SimpleCallContext *ctx); diff --git a/src/v4/qv4stringobject.cpp b/src/v4/qv4stringobject.cpp index ba9e6ac5..28537dd2 100644 --- a/src/v4/qv4stringobject.cpp +++ b/src/v4/qv4stringobject.cpp @@ -180,7 +180,7 @@ static QString getThisString(ExecutionContext *ctx) return str->toQString(); } -static QString getThisString(ExecutionContext *parentCtx, Value thisObject) +static QString getThisString(ExecutionContext *context, Value thisObject) { if (thisObject.isString()) return thisObject.stringValue()->toQString(); @@ -189,45 +189,45 @@ static QString getThisString(ExecutionContext *parentCtx, Value thisObject) if (StringObject *thisString = thisObject.asStringObject()) str = thisString->value.stringValue(); else if (thisObject.isUndefined() || thisObject.isNull()) - parentCtx->throwTypeError(); + context->throwTypeError(); else - str = thisObject.toString(parentCtx); + str = thisObject.toString(context); return str->toQString(); } -Value StringPrototype::method_toString(ExecutionContext *parentCtx, Value thisObject, Value *, int) +Value StringPrototype::method_toString(SimpleCallContext *context) { - if (thisObject.isString()) - return thisObject; + if (context->thisObject.isString()) + return context->thisObject; - StringObject *o = thisObject.asStringObject(); + StringObject *o = context->thisObject.asStringObject(); if (!o) - parentCtx->throwTypeError(); + context->throwTypeError(); return o->value; } -Value StringPrototype::method_charAt(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value StringPrototype::method_charAt(SimpleCallContext *context) { - const QString str = getThisString(parentCtx, thisObject); + const QString str = getThisString(context, context->thisObject); int pos = 0; - if (argc > 0) - pos = (int) argv[0].toInteger(parentCtx); + if (context->argumentCount > 0) + pos = (int) context->arguments[0].toInteger(context); QString result; if (pos >= 0 && pos < str.length()) result += str.at(pos); - return Value::fromString(parentCtx, result); + return Value::fromString(context, result); } -Value StringPrototype::method_charCodeAt(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value StringPrototype::method_charCodeAt(SimpleCallContext *context) { - const QString str = getThisString(parentCtx, thisObject); + const QString str = getThisString(context, context->thisObject); int pos = 0; - if (argc > 0) - pos = (int) argv[0].toInteger(parentCtx); + if (context->argumentCount > 0) + pos = (int) context->arguments[0].toInteger(context); if (pos >= 0 && pos < str.length()) @@ -236,30 +236,30 @@ Value StringPrototype::method_charCodeAt(ExecutionContext *parentCtx, Value this return Value::fromDouble(qSNaN()); } -Value StringPrototype::method_concat(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value StringPrototype::method_concat(SimpleCallContext *context) { - QString value = getThisString(parentCtx, thisObject); + QString value = getThisString(context, context->thisObject); - for (int i = 0; i < argc; ++i) { - Value v = __qmljs_to_string(argv[i], parentCtx); + for (int i = 0; i < context->argumentCount; ++i) { + Value v = __qmljs_to_string(context->arguments[i], context); assert(v.isString()); value += v.stringValue()->toQString(); } - return Value::fromString(parentCtx, value); + return Value::fromString(context, value); } -Value StringPrototype::method_indexOf(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value StringPrototype::method_indexOf(SimpleCallContext *context) { - QString value = getThisString(parentCtx, thisObject); + QString value = getThisString(context, context->thisObject); QString searchString; - if (argc) - searchString = argv[0].toString(parentCtx)->toQString(); + if (context->argumentCount) + searchString = context->arguments[0].toString(context)->toQString(); int pos = 0; - if (argc > 1) - pos = (int) argv[1].toInteger(parentCtx); + if (context->argumentCount > 1) + pos = (int) context->arguments[1].toInteger(context); int index = -1; if (! value.isEmpty()) @@ -268,18 +268,18 @@ Value StringPrototype::method_indexOf(ExecutionContext *parentCtx, Value thisObj return Value::fromDouble(index); } -Value StringPrototype::method_lastIndexOf(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value StringPrototype::method_lastIndexOf(SimpleCallContext *context) { - const QString value = getThisString(parentCtx, thisObject); + const QString value = getThisString(context, context->thisObject); QString searchString; - if (argc) { - Value v = __qmljs_to_string(argv[0], parentCtx); + if (context->argumentCount) { + Value v = __qmljs_to_string(context->arguments[0], context); searchString = v.stringValue()->toQString(); } - Value posArg = argc > 1 ? argv[1] : Value::undefinedValue(); - double position = __qmljs_to_number(posArg, parentCtx); + Value posArg = context->argumentCount > 1 ? context->arguments[1] : Value::undefinedValue(); + double position = __qmljs_to_number(posArg, context); if (isnan(position)) position = +qInf(); else @@ -294,57 +294,57 @@ Value StringPrototype::method_lastIndexOf(ExecutionContext *parentCtx, Value thi return Value::fromDouble(index); } -Value StringPrototype::method_localeCompare(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value StringPrototype::method_localeCompare(SimpleCallContext *context) { - const QString value = getThisString(parentCtx, thisObject); - const QString that = (argc ? argv[0] : Value::undefinedValue()).toString(parentCtx)->toQString(); + const QString value = getThisString(context, context->thisObject); + const QString that = (context->argumentCount ? context->arguments[0] : Value::undefinedValue()).toString(context)->toQString(); return Value::fromDouble(QString::localeAwareCompare(value, that)); } -Value StringPrototype::method_match(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value StringPrototype::method_match(SimpleCallContext *context) { - if (thisObject.isUndefined() || thisObject.isNull()) - parentCtx->throwTypeError(); + if (context->thisObject.isUndefined() || context->thisObject.isNull()) + context->throwTypeError(); - String *s = thisObject.toString(parentCtx); + String *s = context->thisObject.toString(context); - Value regexp = argc ? argv[0] : Value::undefinedValue(); + Value regexp = context->argumentCount ? context->arguments[0] : Value::undefinedValue(); RegExpObject *rx = regexp.asRegExpObject(); if (!rx) - rx = parentCtx->engine->regExpCtor.asFunctionObject()->construct(parentCtx, ®exp, 1).asRegExpObject(); + rx = context->engine->regExpCtor.asFunctionObject()->construct(context, ®exp, 1).asRegExpObject(); if (!rx) // ### CHECK - parentCtx->throwTypeError(); + context->throwTypeError(); bool global = rx->global; // ### use the standard builtin function, not the one that might be redefined in the proto - FunctionObject *exec = parentCtx->engine->regExpPrototype->get(parentCtx, parentCtx->engine->newString(QStringLiteral("exec")), 0).asFunctionObject(); + FunctionObject *exec = context->engine->regExpPrototype->get(context, context->engine->newString(QStringLiteral("exec")), 0).asFunctionObject(); Value arg = Value::fromString(s); if (!global) - return exec->call(parentCtx, Value::fromObject(rx), &arg, 1); + return exec->call(context, Value::fromObject(rx), &arg, 1); - String *lastIndex = parentCtx->engine->newString(QStringLiteral("lastIndex")); - rx->put(parentCtx, lastIndex, Value::fromInt32(0)); - ArrayObject *a = parentCtx->engine->newArrayObject(parentCtx); + String *lastIndex = context->engine->newString(QStringLiteral("lastIndex")); + rx->put(context, lastIndex, Value::fromInt32(0)); + ArrayObject *a = context->engine->newArrayObject(context); double previousLastIndex = 0; uint n = 0; while (1) { - Value result = exec->call(parentCtx, Value::fromObject(rx), &arg, 1); + Value result = exec->call(context, Value::fromObject(rx), &arg, 1); if (result.isNull()) break; assert(result.isObject()); - double thisIndex = rx->get(parentCtx, lastIndex, 0).toInteger(parentCtx); + double thisIndex = rx->get(context, lastIndex, 0).toInteger(context); if (previousLastIndex == thisIndex) { previousLastIndex = thisIndex + 1; - rx->put(parentCtx, lastIndex, Value::fromDouble(previousLastIndex)); + rx->put(context, lastIndex, Value::fromDouble(previousLastIndex)); } else { previousLastIndex = thisIndex; } - Value matchStr = result.objectValue()->getIndexed(parentCtx, 0, (bool *)0); + Value matchStr = result.objectValue()->getIndexed(context, 0, (bool *)0); a->arraySet(n, matchStr); ++n; } @@ -615,17 +615,17 @@ Value StringPrototype::method_split(SimpleCallContext *ctx) return result; } -Value StringPrototype::method_substr(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value StringPrototype::method_substr(SimpleCallContext *context) { - const QString value = getThisString(parentCtx, thisObject); + const QString value = getThisString(context, context->thisObject); double start = 0; - if (argc > 0) - start = argv[0].toInteger(parentCtx); + if (context->argumentCount > 0) + start = context->arguments[0].toInteger(context); double length = +qInf(); - if (argc > 1) - length = argv[1].toInteger(parentCtx); + if (context->argumentCount > 1) + length = context->arguments[1].toInteger(context); double count = value.length(); if (start < 0) @@ -635,23 +635,23 @@ Value StringPrototype::method_substr(ExecutionContext *parentCtx, Value thisObje qint32 x = Value::toInt32(start); qint32 y = Value::toInt32(length); - return Value::fromString(parentCtx, value.mid(x, y)); + return Value::fromString(context, value.mid(x, y)); } -Value StringPrototype::method_substring(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc) +Value StringPrototype::method_substring(SimpleCallContext *context) { - QString value = getThisString(parentCtx, thisObject); + QString value = getThisString(context, context->thisObject); int length = value.length(); double start = 0; double end = length; - if (argc > 0) - start = argv[0].toInteger(parentCtx); + if (context->argumentCount > 0) + start = context->arguments[0].toInteger(context); - Value endValue = argc > 1 ? argv[1] : Value::undefinedValue(); + Value endValue = context->argumentCount > 1 ? context->arguments[1] : Value::undefinedValue(); if (!endValue.isUndefined()) - end = endValue.toInteger(parentCtx); + end = endValue.toInteger(context); if (isnan(start) || start < 0) start = 0; @@ -673,7 +673,7 @@ Value StringPrototype::method_substring(ExecutionContext *parentCtx, Value thisO qint32 x = (int)start; qint32 y = (int)(end - start); - return Value::fromString(parentCtx, value.mid(x, y)); + return Value::fromString(context, value.mid(x, y)); } Value StringPrototype::method_toLowerCase(SimpleCallContext *ctx) @@ -698,15 +698,15 @@ Value StringPrototype::method_toLocaleUpperCase(SimpleCallContext *ctx) return method_toUpperCase(ctx); } -Value StringPrototype::method_fromCharCode(ExecutionContext *parentCtx, Value, Value *argv, int argc) +Value StringPrototype::method_fromCharCode(SimpleCallContext *context) { - QString str(argc, Qt::Uninitialized); + QString str(context->argumentCount, Qt::Uninitialized); QChar *ch = str.data(); - for (int i = 0; i < argc; ++i) { - *ch = QChar(argv[i].toUInt16(parentCtx)); + for (int i = 0; i < context->argumentCount; ++i) { + *ch = QChar(context->arguments[i].toUInt16(context)); ++ch; } - return Value::fromString(parentCtx, str); + return Value::fromString(context, str); } Value StringPrototype::method_trim(SimpleCallContext *ctx) diff --git a/src/v4/qv4stringobject.h b/src/v4/qv4stringobject.h index 0bbb3cc3..73dc740d 100644 --- a/src/v4/qv4stringobject.h +++ b/src/v4/qv4stringobject.h @@ -78,25 +78,25 @@ struct StringPrototype: StringObject StringPrototype(ExecutionContext *ctx): StringObject(ctx, Value::fromString(ctx, QString())) {} void init(ExecutionContext *ctx, const Value &ctor); - static Value method_toString(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_charAt(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_charCodeAt(ExecutionContext *, Value thisObject, Value *argv, int argc); - static Value method_concat(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_indexOf(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_lastIndexOf(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_localeCompare(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_match(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); + static Value method_toString(SimpleCallContext *context); + static Value method_charAt(SimpleCallContext *context); + static Value method_charCodeAt(SimpleCallContext *context); + static Value method_concat(SimpleCallContext *context); + static Value method_indexOf(SimpleCallContext *context); + static Value method_lastIndexOf(SimpleCallContext *context); + static Value method_localeCompare(SimpleCallContext *context); + static Value method_match(SimpleCallContext *context); static Value method_replace(SimpleCallContext *ctx); static Value method_search(SimpleCallContext *ctx); static Value method_slice(SimpleCallContext *ctx); static Value method_split(SimpleCallContext *ctx); - static Value method_substr(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); - static Value method_substring(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); + static Value method_substr(SimpleCallContext *context); + static Value method_substring(SimpleCallContext *context); static Value method_toLowerCase(SimpleCallContext *ctx); static Value method_toLocaleLowerCase(SimpleCallContext *ctx); static Value method_toUpperCase(SimpleCallContext *ctx); static Value method_toLocaleUpperCase(SimpleCallContext *ctx); - static Value method_fromCharCode(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc); + static Value method_fromCharCode(SimpleCallContext *context); static Value method_trim(SimpleCallContext *ctx); }; -- cgit v1.2.3