summaryrefslogtreecommitdiff
path: root/src/libs/qmljs/qmljsvalueowner.cpp
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2011-08-08 14:22:22 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2011-08-09 08:36:35 +0200
commit197c60e928ac6120bfb6201ad438b9916a945f4a (patch)
treef2b2e58a37efd4a05b6c077b2668d7a528387cb6 /src/libs/qmljs/qmljsvalueowner.cpp
parentc42e96618454a7315680a96718bf8d20a7f67e68 (diff)
downloadqt-creator-197c60e928ac6120bfb6201ad438b9916a945f4a.tar.gz
QmlJS: Add XMLHttpRequest, DB API and JSON completion.
Change-Id: I30773e8879086c1f85d331fabf9380e217b32dd7 Reviewed-on: http://codereview.qt.nokia.com/2745 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
Diffstat (limited to 'src/libs/qmljs/qmljsvalueowner.cpp')
-rw-r--r--src/libs/qmljs/qmljsvalueowner.cpp70
1 files changed, 68 insertions, 2 deletions
diff --git a/src/libs/qmljs/qmljsvalueowner.cpp b/src/libs/qmljs/qmljsvalueowner.cpp
index 68c84bec1d..8a5b5ced37 100644
--- a/src/libs/qmljs/qmljsvalueowner.cpp
+++ b/src/libs/qmljs/qmljsvalueowner.cpp
@@ -481,21 +481,23 @@ QString ValueOwner::typeId(const Value *value)
return _typeId(value);
}
-void ValueOwner::addFunction(ObjectValue *object, const QString &name, const Value *result, int argumentCount)
+Function *ValueOwner::addFunction(ObjectValue *object, const QString &name, const Value *result, int argumentCount)
{
Function *function = newFunction();
function->setReturnValue(result);
for (int i = 0; i < argumentCount; ++i)
function->addArgument(undefinedValue()); // ### introduce unknownValue
object->setMember(name, function);
+ return function;
}
-void ValueOwner::addFunction(ObjectValue *object, const QString &name, int argumentCount)
+Function *ValueOwner::addFunction(ObjectValue *object, const QString &name, int argumentCount)
{
Function *function = newFunction();
for (int i = 0; i < argumentCount; ++i)
function->addArgument(undefinedValue()); // ### introduce unknownValue
object->setMember(name, function);
+ return function;
}
void ValueOwner::initializePrototypes()
@@ -750,6 +752,70 @@ void ValueOwner::initializePrototypes()
_globalObject->setMember("Date", dateCtor());
_globalObject->setMember("RegExp", regexpCtor());
+ Function *f = 0;
+
+ // XMLHttpRequest
+ ObjectValue *xmlHttpRequest = newObject();
+ xmlHttpRequest->setMember("onreadystatechange", functionPrototype());
+ xmlHttpRequest->setMember("UNSENT", numberValue());
+ xmlHttpRequest->setMember("OPENED", numberValue());
+ xmlHttpRequest->setMember("HEADERS_RECEIVED", numberValue());
+ xmlHttpRequest->setMember("LOADING", numberValue());
+ xmlHttpRequest->setMember("DONE", numberValue());
+ xmlHttpRequest->setMember("readyState", numberValue());
+ f = addFunction(xmlHttpRequest, "open");
+ f->addArgument(stringValue(), "method");
+ f->addArgument(stringValue(), "url");
+ f->addArgument(booleanValue(), "async");
+ f->addArgument(stringValue(), "user");
+ f->addArgument(stringValue(), "password");
+ f = addFunction(xmlHttpRequest, "setRequestHeader");
+ f->addArgument(stringValue(), "header");
+ f->addArgument(stringValue(), "value");
+ f = addFunction(xmlHttpRequest, "send");
+ f->addArgument(undefinedValue(), "data");
+ f = addFunction(xmlHttpRequest, "abort");
+ xmlHttpRequest->setMember("status", numberValue());
+ xmlHttpRequest->setMember("statusText", stringValue());
+ f = addFunction(xmlHttpRequest, "getResponseHeader");
+ f->addArgument(stringValue(), "header");
+ f = addFunction(xmlHttpRequest, "getAllResponseHeaders");
+ xmlHttpRequest->setMember("responseText", stringValue());
+ xmlHttpRequest->setMember("responseXML", undefinedValue());
+
+ f = addFunction(_globalObject, "XMLHttpRequest", xmlHttpRequest);
+ f->setMember("prototype", xmlHttpRequest);
+ xmlHttpRequest->setMember("constructor", f);
+
+ // Database API
+ ObjectValue *db = newObject();
+ f = addFunction(db, "transaction");
+ f->addArgument(functionPrototype(), "callback");
+ f = addFunction(db, "readTransaction");
+ f->addArgument(functionPrototype(), "callback");
+ f->setMember("version", stringValue());
+ f = addFunction(db, "changeVersion");
+ f->addArgument(stringValue(), "oldVersion");
+ f->addArgument(stringValue(), "newVersion");
+ f->addArgument(functionPrototype(), "callback");
+
+ f = addFunction(_globalObject, "openDatabaseSync", db);
+ f->addArgument(stringValue(), "name");
+ f->addArgument(stringValue(), "version");
+ f->addArgument(stringValue(), "displayName");
+ f->addArgument(numberValue(), "estimatedSize");
+ f->addArgument(functionPrototype(), "callback");
+
+ // JSON
+ ObjectValue *json = newObject();
+ f = addFunction(json, "parse", objectPrototype());
+ f->addArgument(stringValue(), "text");
+ f->addArgument(functionPrototype(), "reviver");
+ f = addFunction(json, "stringify", stringValue());
+ f->addArgument(undefinedValue(), "value");
+ f->addArgument(undefinedValue(), "replacer");
+ f->addArgument(undefinedValue(), "space");
+ _globalObject->setMember("JSON", json);
// global Qt object, in alphabetic order
_qtObject = newObject(/*prototype */ 0);