diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/declarative.pro | 4 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 14 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine_p.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/qmlxmlhttprequest.cpp | 164 |
4 files changed, 57 insertions, 126 deletions
diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro index e4901bf..62ae289 100644 --- a/src/declarative/declarative.pro +++ b/src/declarative/declarative.pro @@ -9,8 +9,8 @@ solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2 unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui QtXml -# QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage -# LIBS += -lgcov +QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage -fno-elide-constructors +LIBS += -lgcov INCLUDEPATH += ../../include/QtDeclarative diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 6e3cf69..b6f3bde 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -88,6 +88,7 @@ #include <private/qmllistscriptclass_p.h> #include <qmlscriptstring.h> #include <private/qmlglobal_p.h> +#include <QtCore/qcryptographichash.h> #ifdef Q_OS_WIN // for %APPDATA% #include "qt_windows.h" @@ -150,6 +151,7 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) qtObject.setProperty(QLatin1String("closestAngle"), scriptEngine.newFunction(QmlEnginePrivate::closestAngle, 2)); qtObject.setProperty(QLatin1String("playSound"), scriptEngine.newFunction(QmlEnginePrivate::playSound, 1)); qtObject.setProperty(QLatin1String("openUrlExternally"),scriptEngine.newFunction(desktopOpenUrl, 1)); + qtObject.setProperty(QLatin1String("md5"),scriptEngine.newFunction(md5, 1)); scriptEngine.globalObject().setProperty(QLatin1String("createQmlObject"), scriptEngine.newFunction(QmlEnginePrivate::createQmlObject, 1)); @@ -816,6 +818,18 @@ QScriptValue QmlEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QScriptEngin return e->newVariant(QVariant(ret)); } +QScriptValue QmlEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine *e) +{ + QByteArray data; + + if (ctxt->argumentCount() >= 1) + data = ctxt->argument(0).toString().toUtf8(); + + QByteArray result = QCryptographicHash::hash(data, QCryptographicHash::Md5); + + return QScriptValue(QLatin1String(result.toHex())); +} + QScriptValue QmlEnginePrivate::closestAngle(QScriptContext *ctxt, QScriptEngine *e) { if(ctxt->argumentCount() < 2) diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index a3e2d52..2e880bb 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -272,6 +272,7 @@ public: static QScriptValue closestAngle(QScriptContext*, QScriptEngine*); static QScriptValue playSound(QScriptContext*, QScriptEngine*); static QScriptValue desktopOpenUrl(QScriptContext*, QScriptEngine*); + static QScriptValue md5(QScriptContext*, QScriptEngine*); static QScriptEngine *getScriptEngine(QmlEngine *e) { return &e->d_func()->scriptEngine; } static QmlEngine *getEngine(QScriptEngine *e) { return static_cast<QmlScriptEngine*>(e)->p->q_func(); } diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp index e5ee2f5..848533c 100644 --- a/src/declarative/qml/qmlxmlhttprequest.cpp +++ b/src/declarative/qml/qmlxmlhttprequest.cpp @@ -131,10 +131,10 @@ public: QList<NodeImpl *> attributes; }; -class DocumentImpl : public QmlRefCount +class DocumentImpl : public NodeImpl { public: - DocumentImpl() : root(0) { } + DocumentImpl() : root(0) { type = Document; } virtual ~DocumentImpl() { if (root) D(root); } @@ -158,12 +158,13 @@ public: NamedNodeMap(); NamedNodeMap(const NamedNodeMap &); - NamedNodeMap &operator=(const NamedNodeMap &); ~NamedNodeMap(); bool isNull(); NodeImpl *d; QList<NodeImpl *> *list; +private: + NamedNodeMap &operator=(const NamedNodeMap &); }; class NamedNodeMapClass : public QScriptClass @@ -180,7 +181,6 @@ class NodeList public: // JS API static QScriptValue length(QScriptContext *context, QScriptEngine *engine); - static QScriptValue item(QScriptContext *context, QScriptEngine *engine); // C++ API static QScriptValue prototype(QScriptEngine *); @@ -188,11 +188,12 @@ public: NodeList(); NodeList(const NodeList &); - NodeList &operator=(const NodeList &); ~NodeList(); bool isNull(); NodeImpl *d; +private: + NodeList &operator=(const NodeList &); }; class NodeListClass : public QScriptClass @@ -232,11 +233,13 @@ public: Node(); Node(const Node &o); - Node &operator=(const Node &); ~Node(); bool isNull() const; NodeImpl *d; + +private: + Node &operator=(const Node &); }; class Element : public Node @@ -301,31 +304,29 @@ public: // C++ API static QScriptValue prototype(QScriptEngine *); static QScriptValue load(QScriptEngine *engine, const QString &data); - - Document(); - Document(const Document &); - Document &operator=(const Document &); - ~Document(); - bool isNull() const; - - DocumentImpl *d; -private: - Document(DocumentImpl *); }; -}; +}; // namespace Q_DECLARE_METATYPE(Node); Q_DECLARE_METATYPE(NodeList); Q_DECLARE_METATYPE(NamedNodeMap); -Q_DECLARE_METATYPE(Document); QScriptValue Node::nodeName(QScriptContext *context, QScriptEngine *engine) { Node node = qscriptvalue_cast<Node>(context->thisObject()); if (node.isNull()) return engine->undefinedValue(); - return QScriptValue(node.d->name); + switch (node.d->type) { + case NodeImpl::Document: + return QScriptValue(QLatin1String("#document")); + case NodeImpl::CDATA: + return QScriptValue(QLatin1String("#cdata-section")); + case NodeImpl::Text: + return QScriptValue(QLatin1String("#text")); + default: + return QScriptValue(node.d->name); + } } QScriptValue Node::nodeValue(QScriptContext *context, QScriptEngine *engine) @@ -465,12 +466,11 @@ QScriptValue Node::create(QScriptEngine *engine, NodeImpl *data) case NodeImpl::Entity: case NodeImpl::EntityReference: case NodeImpl::Notation: + case NodeImpl::ProcessingInstruction: + return QScriptValue(); case NodeImpl::CDATA: instance.setPrototype(CDATA::prototype(engine)); break; - case NodeImpl::ProcessingInstruction: - instance.setPrototype(Node::prototype(engine)); - break; case NodeImpl::Text: instance.setPrototype(Text::prototype(engine)); break; @@ -556,8 +556,7 @@ QScriptValue Text::isElementContentWhitespace(QScriptContext *context, QScriptEn Node node = qscriptvalue_cast<Node>(context->thisObject()); if (node.isNull()) return engine->undefinedValue(); - // ### implement - return QScriptValue(false); + return node.d->data.trimmed().isEmpty(); } QScriptValue Text::wholeText(QScriptContext *context, QScriptEngine *engine) @@ -565,8 +564,7 @@ QScriptValue Text::wholeText(QScriptContext *context, QScriptEngine *engine) Node node = qscriptvalue_cast<Node>(context->thisObject()); if (node.isNull()) return engine->undefinedValue(); - // ### implement - return QScriptValue(QString()); + return node.d->data; } QScriptValue Text::prototype(QScriptEngine *engine) @@ -646,6 +644,7 @@ QScriptValue Document::load(QScriptEngine *engine, const QString &data) attr->name = a.name().toString(); attr->data = a.value().toString(); attr->parent = node; + A(attr->parent); node->attributes.append(attr); } } @@ -681,7 +680,9 @@ QScriptValue Document::load(QScriptEngine *engine, const QString &data) QScriptValue instance = engine->newObject(); instance.setPrototype(Document::prototype(engine)); - return engine->newVariant(instance, qVariantFromValue(Document(document))); + Node documentNode; + documentNode.d = document; + return engine->newVariant(instance, qVariantFromValue(documentNode)); } Node::Node() @@ -695,14 +696,6 @@ Node::Node(const Node &o) if (d) A(d); } -Node &Node::operator=(const Node &o) -{ - if (o.d) A(o.d); - if (d) D(d); - d = o.d; - return *this; -} - Node::~Node() { if (d) D(d); @@ -761,15 +754,6 @@ NamedNodeMap::NamedNodeMap(const NamedNodeMap &o) if (d) A(d); } -NamedNodeMap &NamedNodeMap::operator=(const NamedNodeMap &o) -{ - if (o.d) A(o.d); - if (d) D(d); - d = o.d; - list = o.list; - return *this; -} - NamedNodeMap::~NamedNodeMap() { if (d) D(d); @@ -780,20 +764,6 @@ bool NamedNodeMap::isNull() return d == 0; } -QScriptValue NodeList::item(QScriptContext *context, QScriptEngine *engine) -{ - NodeList list = qscriptvalue_cast<NodeList>(context->thisObject().data()); - if (list.isNull() || context->argumentCount() != 1) - return engine->undefinedValue(); - - qint32 index = context->argument(0).toInt32(); - - if (index >= list.d->children.count()) - return engine->undefinedValue(); // ### Exception - else - return Node::create(engine, list.d->children.at(index)); -} - QScriptValue NodeList::length(QScriptContext *context, QScriptEngine *engine) { NodeList list = qscriptvalue_cast<NodeList>(context->thisObject().data()); @@ -807,7 +777,6 @@ QScriptValue NodeList::prototype(QScriptEngine *engine) QScriptValue proto = engine->newObject(); proto.setProperty(QLatin1String("length"), engine->newFunction(length), QScriptValue::ReadOnly | QScriptValue::PropertyGetter); - proto.setProperty(QLatin1String("item"), engine->newFunction(item, 1), QScriptValue::ReadOnly); return proto; } @@ -842,14 +811,6 @@ NodeList::NodeList(const NodeList &o) if (d) A(d); } -NodeList &NodeList::operator=(const NodeList &o) -{ - if (o.d) A(o.d); - if (d) D(d); - d = o.d; - return *this; -} - NodeList::~NodeList() { if (d) D(d); @@ -920,81 +881,36 @@ QScriptValue NodeListClass::property(const QScriptValue &object, const QScriptSt return Node::create(engine(), list.d->children.at(id)); } -Document::Document() -: d(0) -{ -} - -Document::Document(DocumentImpl *data) -: d(data) -{ -} - -Document::Document(const Document &o) -: Node(o), d(o.d) -{ - if (d) A(d); -} - -Document &Document::operator=(const Document &o) -{ - if (o.d) A(o.d); - if (d) D(d); - d = o.d; - return *this; -} - -Document::~Document() -{ - if (d) D(d); -} - -bool Document::isNull() const -{ - return d == 0; -} - QScriptValue Document::documentElement(QScriptContext *context, QScriptEngine *engine) { - Document document = qscriptvalue_cast<Document>(context->thisObject()); - if (document.isNull()) return engine->undefinedValue(); - - if (!document.d->root) return engine->nullValue(); + Node document = qscriptvalue_cast<Node>(context->thisObject()); + if (document.isNull() || document.d->type != NodeImpl::Document) return engine->undefinedValue(); - return Node::create(engine, document.d->root); + return Node::create(engine, static_cast<DocumentImpl *>(document.d)->root); } QScriptValue Document::xmlStandalone(QScriptContext *context, QScriptEngine *engine) { - Document document = qscriptvalue_cast<Document>(context->thisObject()); - if (document.isNull()) return engine->undefinedValue(); - - if (context->argumentCount()) - document.d->isStandalone = context->argument(0).toBool(); + Node document = qscriptvalue_cast<Node>(context->thisObject()); + if (document.isNull() || document.d->type != NodeImpl::Document) return engine->undefinedValue(); - return QScriptValue(document.d->isStandalone); + return QScriptValue(static_cast<DocumentImpl *>(document.d)->isStandalone); } QScriptValue Document::xmlVersion(QScriptContext *context, QScriptEngine *engine) { - Document document = qscriptvalue_cast<Document>(context->thisObject()); - if (document.isNull()) return engine->undefinedValue(); + Node document = qscriptvalue_cast<Node>(context->thisObject()); + if (document.isNull() || document.d->type != NodeImpl::Document) return engine->undefinedValue(); - if (context->argumentCount()) - document.d->version = context->argument(0).toString(); - - return QScriptValue(document.d->version); + return QScriptValue(static_cast<DocumentImpl *>(document.d)->version); } QScriptValue Document::xmlEncoding(QScriptContext *context, QScriptEngine *engine) { - Document document = qscriptvalue_cast<Document>(context->thisObject()); - if (document.isNull()) return engine->undefinedValue(); - - if (context->argumentCount()) - document.d->encoding = context->argument(0).toString(); + Node document = qscriptvalue_cast<Node>(context->thisObject()); + if (document.isNull() || document.d->type != NodeImpl::Document) return engine->undefinedValue(); - return QScriptValue(document.d->encoding); + return QScriptValue(static_cast<DocumentImpl *>(document.d)->encoding); } class QmlXMLHttpRequest : public QObject |