qmljs: add console.warn,...

Task-number: QTCREATORBUG-7033
Change-Id: I100cd6759534e5e94246f999481f5217f9e51b31
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
Fawzi Mohamed
2013-07-08 14:06:45 +02:00
parent e52383dbef
commit 372fc608df
2 changed files with 33 additions and 5 deletions

View File

@@ -67,7 +67,12 @@ private:
class QmlJS::SharedValueOwner : public ValueOwner class QmlJS::SharedValueOwner : public ValueOwner
{ {
public: public:
SharedValueOwner(); enum SharedValueOwnerKind{
Qt4Kind = 1,
Qt5Kind = 2
};
SharedValueOwner(SharedValueOwnerKind kind = Qt5Kind);
ObjectValue *_objectPrototype; ObjectValue *_objectPrototype;
ObjectValue *_functionPrototype; ObjectValue *_functionPrototype;
@@ -109,9 +114,18 @@ public:
ColorValue _colorValue; ColorValue _colorValue;
AnchorLineValue _anchorLineValue; AnchorLineValue _anchorLineValue;
}; };
Q_GLOBAL_STATIC(SharedValueOwner, sharedValueOwner)
SharedValueOwner::SharedValueOwner() SharedValueOwner *ValueOwner::sharedValueOwner(QString kind)
{
static SharedValueOwner qt5owner(SharedValueOwner::Qt5Kind);
static SharedValueOwner qt4owner(SharedValueOwner::Qt4Kind);
if (kind == QLatin1String("Qt4Kind"))
return &qt4owner;
else
return &qt5owner;
}
SharedValueOwner::SharedValueOwner(SharedValueOwnerKind kind)
: ValueOwner(this) // need to avoid recursing in ValueOwner ctor : ValueOwner(this) // need to avoid recursing in ValueOwner ctor
{ {
_objectPrototype = newObject(/*prototype = */ 0); _objectPrototype = newObject(/*prototype = */ 0);
@@ -526,8 +540,21 @@ SharedValueOwner::SharedValueOwner()
// firebug/webkit compat // firebug/webkit compat
ObjectValue *consoleObject = newObject(/*prototype */ 0); ObjectValue *consoleObject = newObject(/*prototype */ 0);
addFunction(consoleObject, QLatin1String("log"), 1); addFunction(consoleObject, QLatin1String("log"), 1, 0, true);
addFunction(consoleObject, QLatin1String("debug"), 1); addFunction(consoleObject, QLatin1String("debug"), 1, 0, true);
if (kind == Qt5Kind) {
addFunction(consoleObject, QLatin1String("info"), 1, 0, true);
addFunction(consoleObject, QLatin1String("warn"), 1, 0, true);
addFunction(consoleObject, QLatin1String("error"), 1, 0, true);
addFunction(consoleObject, QLatin1String("assert"), 1, 0, true);
addFunction(consoleObject, QLatin1String("count"), 0, 1);
addFunction(consoleObject, QLatin1String("profile"), 0);
addFunction(consoleObject, QLatin1String("profileEnd"), 0);
addFunction(consoleObject, QLatin1String("time"), 1);
addFunction(consoleObject, QLatin1String("timeEnd"), 1);
addFunction(consoleObject, QLatin1String("trace"), 0);
addFunction(consoleObject, QLatin1String("exception"), 1, 0, true);
}
_globalObject->setMember(QLatin1String("console"), consoleObject); _globalObject->setMember(QLatin1String("console"), consoleObject);
// translation functions // translation functions

View File

@@ -66,6 +66,7 @@ class QMLJS_EXPORT ValueOwner
Q_DISABLE_COPY(ValueOwner) Q_DISABLE_COPY(ValueOwner)
public: public:
static SharedValueOwner *sharedValueOwner(QString kind = QString());
ValueOwner(const SharedValueOwner *shared = 0); ValueOwner(const SharedValueOwner *shared = 0);
~ValueOwner(); ~ValueOwner();