aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2016-11-24 15:49:39 +0100
committerLars Knoll <lars.knoll@qt.io>2016-11-29 20:00:03 +0000
commita36d19546891a808cf71dbb084d6d63870d2b8ec (patch)
tree37d3ed91068950aeecfeb5d4ad79c030bbe4be87 /src/qml/jsruntime
parent6b641549536d199a0314049a34e61363bd4df7e0 (diff)
Clean up some duplicated methods
Change-Id: Iad64dd2c330ca85a28f8f5c776b0ede623203558 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/qv4dateobject.cpp7
-rw-r--r--src/qml/jsruntime/qv4jsonobject.cpp2
-rw-r--r--src/qml/jsruntime/qv4numberobject.cpp2
-rw-r--r--src/qml/jsruntime/qv4object_p.h2
-rw-r--r--src/qml/jsruntime/qv4objectproto.cpp16
-rw-r--r--src/qml/jsruntime/qv4regexpobject.cpp4
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp23
-rw-r--r--src/qml/jsruntime/qv4runtime_p.h3
-rw-r--r--src/qml/jsruntime/qv4stringobject.cpp2
9 files changed, 18 insertions, 43 deletions
diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp
index 4f3138a452..5af26f8f36 100644
--- a/src/qml/jsruntime/qv4dateobject.cpp
+++ b/src/qml/jsruntime/qv4dateobject.cpp
@@ -1319,14 +1319,17 @@ ReturnedValue DatePrototype::method_toISOString(CallContext *ctx)
ReturnedValue DatePrototype::method_toJSON(CallContext *ctx)
{
Scope scope(ctx);
- ScopedValue O(scope, RuntimeHelpers::toObject(scope.engine, ctx->thisObject()));
+ ScopedObject O(scope, ctx->thisObject().toObject(scope.engine));
+ if (scope.hasException())
+ return Encode::undefined();
+
ScopedValue tv(scope, RuntimeHelpers::toPrimitive(O, NUMBER_HINT));
if (tv->isNumber() && !std::isfinite(tv->toNumber()))
return Encode::null();
ScopedString s(scope, ctx->d()->engine->newString(QStringLiteral("toISOString")));
- ScopedValue v(scope, O->objectValue()->get(s));
+ ScopedValue v(scope, O->get(s));
FunctionObject *toIso = v->as<FunctionObject>();
if (!toIso)
diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp
index 94a6e4daa1..6a01f207c4 100644
--- a/src/qml/jsruntime/qv4jsonobject.cpp
+++ b/src/qml/jsruntime/qv4jsonobject.cpp
@@ -917,7 +917,7 @@ ReturnedValue JsonObject::method_stringify(CallContext *ctx)
Value *v = stringify.propertyList + i;
*v = o->getIndexed(i);
if (v->as<NumberObject>() || v->as<StringObject>() || v->isNumber())
- *v = RuntimeHelpers::toString(scope.engine, *v);
+ *v = v->toString(scope.engine);
if (!v->isString()) {
v->setM(0);
} else {
diff --git a/src/qml/jsruntime/qv4numberobject.cpp b/src/qml/jsruntime/qv4numberobject.cpp
index 1733df34ae..5b5aa29d55 100644
--- a/src/qml/jsruntime/qv4numberobject.cpp
+++ b/src/qml/jsruntime/qv4numberobject.cpp
@@ -283,7 +283,7 @@ ReturnedValue NumberPrototype::method_toPrecision(CallContext *ctx)
return Encode::undefined();
if (!ctx->argc() || ctx->args()[0].isUndefined())
- return RuntimeHelpers::toString(scope.engine, v);
+ return Encode(v->toString(scope.engine));
int precision = ctx->args()[0].toInt32();
if (precision < 1 || precision > 21) {
diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h
index 00a004ef5f..91d9f03ad1 100644
--- a/src/qml/jsruntime/qv4object_p.h
+++ b/src/qml/jsruntime/qv4object_p.h
@@ -500,7 +500,7 @@ inline void Object::arraySet(uint index, const Value &value)
template<>
inline const ArrayObject *Value::as() const {
- return isManaged() && m() && m()->vtable()->type == Managed::Type_ArrayObject ? static_cast<const ArrayObject *>(this) : 0;
+ return isManaged() && m()->vtable()->type == Managed::Type_ArrayObject ? static_cast<const ArrayObject *>(this) : 0;
}
#ifndef V4_BOOTSTRAP
diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp
index 6020c48250..8191083544 100644
--- a/src/qml/jsruntime/qv4objectproto.cpp
+++ b/src/qml/jsruntime/qv4objectproto.cpp
@@ -62,26 +62,24 @@ void Heap::ObjectCtor::init(QV4::ExecutionContext *scope)
void ObjectCtor::construct(const Managed *that, Scope &scope, CallData *callData)
{
const ObjectCtor *ctor = static_cast<const ObjectCtor *>(that);
- ExecutionEngine *v4 = ctor->engine();
if (!callData->argc || callData->args[0].isUndefined() || callData->args[0].isNull()) {
- ScopedObject obj(scope, v4->newObject());
- ScopedObject proto(scope, ctor->get(v4->id_prototype()));
+ ScopedObject obj(scope, scope.engine->newObject());
+ ScopedObject proto(scope, ctor->get(scope.engine->id_prototype()));
if (!!proto)
obj->setPrototype(proto);
scope.result = obj.asReturnedValue();
} else {
- scope.result = RuntimeHelpers::toObject(scope.engine, callData->args[0]);
+ scope.result = callData->args[0].toObject(scope.engine);
}
}
-void ObjectCtor::call(const Managed *m, Scope &scope, CallData *callData)
+void ObjectCtor::call(const Managed *, Scope &scope, CallData *callData)
{
- const ObjectCtor *ctor = static_cast<const ObjectCtor *>(m);
- ExecutionEngine *v4 = ctor->engine();
+ ExecutionEngine *v4 = scope.engine;
if (!callData->argc || callData->args[0].isUndefined() || callData->args[0].isNull()) {
scope.result = v4->newObject()->asReturnedValue();
} else {
- scope.result = RuntimeHelpers::toObject(v4, callData->args[0]);
+ scope.result = callData->args[0].toObject(v4);
}
}
@@ -398,7 +396,7 @@ ReturnedValue ObjectPrototype::method_toString(CallContext *ctx)
} else if (ctx->thisObject().isNull()) {
return ctx->d()->engine->newString(QStringLiteral("[object Null]"))->asReturnedValue();
} else {
- ScopedObject obj(scope, RuntimeHelpers::toObject(scope.engine, ctx->thisObject()));
+ ScopedObject obj(scope, ctx->thisObject().toObject(scope.engine));
QString className = obj->className();
return ctx->d()->engine->newString(QStringLiteral("[object %1]").arg(className))->asReturnedValue();
}
diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp
index 4022d98c3f..c35286bd3a 100644
--- a/src/qml/jsruntime/qv4regexpobject.cpp
+++ b/src/qml/jsruntime/qv4regexpobject.cpp
@@ -262,7 +262,7 @@ void RegExpCtor::construct(const Managed *, Scope &scope, CallData *callData)
bool ignoreCase = false;
bool multiLine = false;
if (!f->isUndefined()) {
- f = RuntimeHelpers::toString(scope.engine, f);
+ f = f->toString(scope.engine);
if (scope.hasException()) {
scope.result = Encode::undefined();
return;
@@ -356,7 +356,7 @@ ReturnedValue RegExpPrototype::method_exec(CallContext *ctx)
return ctx->engine()->throwTypeError();
ScopedValue arg(scope, ctx->argument(0));
- arg = RuntimeHelpers::toString(scope.engine, arg);
+ arg = arg->toString(scope.engine);
if (scope.hasException())
return Encode::undefined();
QString s = arg->stringValue()->toQString();
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 2026ecdfde..11ab4c85a0 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -1367,29 +1367,6 @@ QV4::ReturnedValue Runtime::method_decrement(const Value &value)
}
}
-#ifndef V4_BOOTSTRAP
-
-QV4::ReturnedValue RuntimeHelpers::toString(ExecutionEngine *engine, const Value &value)
-{
- if (value.isString())
- return value.asReturnedValue();
- return RuntimeHelpers::convertToString(engine, value)->asReturnedValue();
-}
-
-QV4::ReturnedValue RuntimeHelpers::toObject(ExecutionEngine *engine, const Value &value)
-{
- if (value.isObject())
- return value.asReturnedValue();
-
- Heap::Object *o = RuntimeHelpers::convertToObject(engine, value);
- if (!o) // type error
- return Encode::undefined();
-
- return Encode(o);
-}
-
-#endif // V4_BOOTSTRAP
-
ReturnedValue Runtime::method_toDouble(const Value &value)
{
TRACE1(value);
diff --git a/src/qml/jsruntime/qv4runtime_p.h b/src/qml/jsruntime/qv4runtime_p.h
index a32b3f1663..0d787714cf 100644
--- a/src/qml/jsruntime/qv4runtime_p.h
+++ b/src/qml/jsruntime/qv4runtime_p.h
@@ -106,10 +106,7 @@ struct Q_QML_PRIVATE_EXPORT RuntimeHelpers {
static double toNumber(const Value &value);
static void numberToString(QString *result, double num, int radix = 10);
- static ReturnedValue toString(ExecutionEngine *engine, const Value &value);
static Heap::String *convertToString(ExecutionEngine *engine, const Value &value);
-
- static ReturnedValue toObject(ExecutionEngine *engine, const Value &value);
static Heap::Object *convertToObject(ExecutionEngine *engine, const Value &value);
static Bool equalHelper(const Value &x, const Value &y);
diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp
index 829ada0c1a..68b693c5a0 100644
--- a/src/qml/jsruntime/qv4stringobject.cpp
+++ b/src/qml/jsruntime/qv4stringobject.cpp
@@ -284,7 +284,7 @@ ReturnedValue StringPrototype::method_concat(CallContext *context)
ScopedValue v(scope);
for (int i = 0; i < context->argc(); ++i) {
- v = RuntimeHelpers::toString(scope.engine, context->args()[i]);
+ v = context->args()[i].toString(scope.engine);
if (scope.hasException())
return Encode::undefined();
Q_ASSERT(v->isString());