aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAurindam Jana <aurindam.jana@nokia.com>2012-06-05 13:34:40 +0200
committerQt by Nokia <qt-info@nokia.com>2012-08-28 14:05:28 +0200
commitcc878137fcf984eb1d6ecec74d4b807e49874d8b (patch)
tree25b51c0056cb7b41ed95898effa2892beccda6fa /src
parentb94b5531b0684965a205d6b0ec744c3482de3940 (diff)
Console API: Print JS object
Calling console.log(), console.debug(), print() etc would only print out "Object" if a JS Object was passed as an argument. This patch calls the toString() on the object. Change-Id: Iadf8b4d1fe81c3e2c7bd65e3c153a930fd994bef Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/qml/v8/qqmlbuiltinfunctions.cpp35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
index c8508e7ecd..3f0702e824 100644
--- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
+++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
@@ -114,24 +114,35 @@ v8::Handle<v8::Value> console(ConsoleLogTypes logType, const v8::Arguments &args
v8::HandleScope handleScope;
QString result;
+ QV8Engine *engine = V8ENGINE();
for (int i = 0; i < args.Length(); ++i) {
if (i != 0)
result.append(QLatin1Char(' '));
v8::Local<v8::Value> value = args[i];
- //Check for Object Type
- if (value->IsObject() && !value->IsFunction()
- && !value->IsArray() && !value->IsDate()
- && !value->IsRegExp()) {
- result.append(QLatin1String("Object"));
- } else {
- v8::Local<v8::String> jsstr = value->ToString();
- QString tmp = V8ENGINE()->toString(jsstr);
- if (value->IsArray())
- result.append(QString::fromLatin1("[%1]").arg(tmp));
- else
- result.append(tmp);
+
+ v8::TryCatch tryCatch;
+ v8::Local<v8::String> toString = value->ToString();
+ if (tryCatch.HasCaught()) {
+ // toString() threw Exception
+ // Is it possible for value to be anything other than Object?
+ QString str;
+ if (value->IsObject()) {
+ str = QStringLiteral("[object Object]");
+ } else {
+ toString = tryCatch.Exception()->ToString();
+ str = QStringLiteral("toString() threw exception: %1")
+ .arg(engine->toString(toString));
+ }
+ result.append(str);
+ continue;
}
+
+ QString tmp = engine->toString(toString);
+ if (value->IsArray())
+ result.append(QStringLiteral("[%1]").arg(tmp));
+ else
+ result.append(tmp);
}
if (printStack) {