aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/jsruntime/qv4arraybuffer.cpp10
-rw-r--r--src/qml/jsruntime/qv4arraybuffer_p.h1
-rw-r--r--tests/auto/qml/qjsvalue/tst_qjsvalue.cpp6
3 files changed, 17 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4arraybuffer.cpp b/src/qml/jsruntime/qv4arraybuffer.cpp
index e006773c9e..34c7746684 100644
--- a/src/qml/jsruntime/qv4arraybuffer.cpp
+++ b/src/qml/jsruntime/qv4arraybuffer.cpp
@@ -154,6 +154,7 @@ void ArrayBufferPrototype::init(ExecutionEngine *engine, Object *ctor)
defineDefaultProperty(engine->id_constructor(), (o = ctor));
defineAccessorProperty(QStringLiteral("byteLength"), method_get_byteLength, 0);
defineDefaultProperty(QStringLiteral("slice"), method_slice, 2);
+ defineDefaultProperty(QStringLiteral("toString"), method_toString, 0);
}
ReturnedValue ArrayBufferPrototype::method_get_byteLength(CallContext *ctx)
@@ -198,3 +199,12 @@ ReturnedValue ArrayBufferPrototype::method_slice(CallContext *ctx)
return newBuffer.asReturnedValue();
}
+
+ReturnedValue ArrayBufferPrototype::method_toString(CallContext *ctx)
+{
+ Scope scope(ctx);
+ Scoped<ArrayBuffer> a(scope, ctx->thisObject());
+ if (!a)
+ return Encode::undefined();
+ return Encode(ctx->engine()->newString(QString::fromUtf8(a->asByteArray())));
+}
diff --git a/src/qml/jsruntime/qv4arraybuffer_p.h b/src/qml/jsruntime/qv4arraybuffer_p.h
index d079aeb9f7..b552cef9f1 100644
--- a/src/qml/jsruntime/qv4arraybuffer_p.h
+++ b/src/qml/jsruntime/qv4arraybuffer_p.h
@@ -106,6 +106,7 @@ struct ArrayBufferPrototype: Object
static ReturnedValue method_get_byteLength(CallContext *ctx);
static ReturnedValue method_slice(CallContext *ctx);
+ static ReturnedValue method_toString(CallContext *ctx);
};
diff --git a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp
index 28b9adea38..d28bbc1ffa 100644
--- a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp
+++ b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp
@@ -431,6 +431,12 @@ void tst_QJSValue::toString()
QVERIFY(!o.engine());
QCOMPARE(o.toString(), QStringLiteral("1,2,3"));
}
+
+ {
+ QByteArray hello = QByteArrayLiteral("Hello World");
+ QJSValue jsValue = eng.toScriptValue(hello);
+ QCOMPARE(jsValue.toString(), QString::fromUtf8(hello));
+ }
}
void tst_QJSValue::toNumber()