diff options
41 files changed, 103 insertions, 582 deletions
diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp index 4a47fc6..6596aba 100644 --- a/src/declarative/qml/qdeclarativecompiledbindings.cpp +++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp @@ -888,13 +888,6 @@ void QDeclarativeCompiledBindingsPrivate::findgeneric(Register *output, return; } - for (int ii = 0; ii < context->scripts.count(); ++ii) { - QScriptValue function = QScriptDeclarativeClass::function(context->scripts.at(ii), name); - if (function.isValid()) { - qFatal("Binding optimizer resolved name to QScript method"); - } - } - if (QObject *root = context->contextObject) { if (findproperty(root, output, enginePriv, subIdx, name, isTerminal)) diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index cced7b1..2614764 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -733,10 +733,6 @@ bool QDeclarativeCompiler::buildObject(Object *obj, const BindingContext &ctxt) return true; } - // Build any script blocks for this type - for (int ii = 0; ii < obj->scriptBlockObjects.count(); ++ii) - COMPILE_CHECK(buildScript(obj, obj->scriptBlockObjects.at(ii))); - // Object instantiations reset the binding context BindingContext objCtxt(obj); @@ -961,17 +957,6 @@ void QDeclarativeCompiler::genObject(QDeclarativeParser::Object *obj) output->bytecode << id; } - // Set any script blocks - for (int ii = 0; ii < obj->scripts.count(); ++ii) { - QDeclarativeInstruction script; - script.type = QDeclarativeInstruction::StoreScript; - script.line = 0; // ### - int idx = output->scripts.count(); - output->scripts << obj->scripts.at(ii); - script.storeScript.value = idx; - output->bytecode << script; - } - // Begin the class if (obj->parserStatusCast != -1) { QDeclarativeInstruction begin; @@ -1177,9 +1162,6 @@ bool QDeclarativeCompiler::buildComponent(QDeclarativeParser::Object *obj, (obj->properties.count() == 1 && obj->properties.begin().key() != "id")) COMPILE_EXCEPTION(*obj->properties.begin(), tr("Component elements may not contain properties other than id")); - if (!obj->scriptBlockObjects.isEmpty()) - COMPILE_EXCEPTION(obj->scriptBlockObjects.first(), tr("Component elements may not contain script blocks")); - if (obj->properties.count()) idProp = *obj->properties.begin(); @@ -1216,101 +1198,6 @@ bool QDeclarativeCompiler::buildComponent(QDeclarativeParser::Object *obj, return true; } -bool QDeclarativeCompiler::buildScript(QDeclarativeParser::Object *obj, QDeclarativeParser::Object *script) -{ - { - QDeclarativeError warning; - warning.setUrl(output->url); - warning.setLine(obj->location.start.line); - warning.setColumn(obj->location.start.column); - warning.setDescription(tr("Script blocks have been deprecated. Support will be removed entirely shortly.")); - qWarning() << warning.toString(); - } - - Object::ScriptBlock scriptBlock; - - if (script->properties.count() == 1 && - script->properties.begin().key() == QByteArray("source")) { - - Property *source = *script->properties.begin(); - if (script->defaultProperty) - COMPILE_EXCEPTION(source, tr("Invalid Script block. Specify either the source property or inline script")); - - if (source->value || source->values.count() != 1 || - source->values.at(0)->object || !source->values.at(0)->value.isStringList()) - COMPILE_EXCEPTION(source, tr("Invalid Script source value")); - - QStringList sources = source->values.at(0)->value.asStringList(); - - for (int jj = 0; jj < sources.count(); ++jj) { - QString sourceUrl = output->url.resolved(QUrl(sources.at(jj))).toString(); - QString scriptCode; - int lineNumber = 1; - - for (int ii = 0; ii < unit->resources.count(); ++ii) { - if (unit->resources.at(ii)->url == sourceUrl) { - scriptCode = QString::fromUtf8(unit->resources.at(ii)->data); - break; - } - } - - if (!scriptCode.isEmpty()) { - scriptBlock.codes.append(scriptCode); - scriptBlock.files.append(sourceUrl); - scriptBlock.lineNumbers.append(lineNumber); - scriptBlock.pragmas.append(Object::ScriptBlock::None); - } - } - - } else if (!script->properties.isEmpty()) { - COMPILE_EXCEPTION(*script->properties.begin(), tr("Properties cannot be set on Script block")); - } else if (script->defaultProperty) { - - QString scriptCode; - int lineNumber = 1; - QString sourceUrl = output->url.toString(); - - QDeclarativeParser::Location currentLocation; - - for (int ii = 0; ii < script->defaultProperty->values.count(); ++ii) { - Value *v = script->defaultProperty->values.at(ii); - if (lineNumber == 1) - lineNumber = v->location.start.line; - if (v->object || !v->value.isString()) - COMPILE_EXCEPTION(v, tr("Invalid Script block")); - - if (ii == 0) { - currentLocation = v->location.start; - scriptCode.append(QString(currentLocation.column, QLatin1Char(' '))); - } - - while (currentLocation.line < v->location.start.line) { - scriptCode.append(QLatin1Char('\n')); - currentLocation.line++; - currentLocation.column = 0; - } - - scriptCode.append(QString(v->location.start.column - currentLocation.column, QLatin1Char(' '))); - - scriptCode += v->value.asString(); - currentLocation = v->location.end; - currentLocation.column++; - } - - if (!scriptCode.isEmpty()) { - scriptBlock.codes.append(scriptCode); - scriptBlock.files.append(sourceUrl); - scriptBlock.lineNumbers.append(lineNumber); - scriptBlock.pragmas.append(Object::ScriptBlock::None); - } - } - - if (!scriptBlock.codes.isEmpty()) - obj->scripts << scriptBlock; - - return true; -} - bool QDeclarativeCompiler::buildComponentFromRoot(QDeclarativeParser::Object *obj, const BindingContext &ctxt) { diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h index 867db2c..cdc514d 100644 --- a/src/declarative/qml/qdeclarativecompiler_p.h +++ b/src/declarative/qml/qdeclarativecompiler_p.h @@ -186,7 +186,6 @@ private: bool buildObject(QDeclarativeParser::Object *obj, const BindingContext &); - bool buildScript(QDeclarativeParser::Object *obj, QDeclarativeParser::Object *script); bool buildComponent(QDeclarativeParser::Object *obj, const BindingContext &); bool buildSubObject(QDeclarativeParser::Object *obj, const BindingContext &); bool buildSignal(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj, diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp index 31430c7..2041e0a 100644 --- a/src/declarative/qml/qdeclarativecontext.cpp +++ b/src/declarative/qml/qdeclarativecontext.cpp @@ -696,39 +696,6 @@ void QDeclarativeContextData::addImportedScript(const QDeclarativeParser::Object } } -void QDeclarativeContextData::addScript(const QDeclarativeParser::Object::ScriptBlock &script, - QObject *scopeObject) -{ - if (!engine) - return; - - QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine); - QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine); - - QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); - - scriptContext->pushScope(enginePriv->contextClass->newContext(this, scopeObject)); - scriptContext->pushScope(enginePriv->globalClass->globalObject()); - - QScriptValue scope = scriptEngine->newObject(); - scriptContext->setActivationObject(scope); - scriptContext->pushScope(scope); - - for (int ii = 0; ii < script.codes.count(); ++ii) { - scriptEngine->evaluate(script.codes.at(ii), script.files.at(ii), script.lineNumbers.at(ii)); - - if (scriptEngine->hasUncaughtException()) { - QDeclarativeError error; - QDeclarativeExpressionPrivate::exceptionToError(scriptEngine, error); - enginePriv->warning(error); - } - } - - scriptEngine->popContext(); - - scripts.append(scope); -} - void QDeclarativeContextData::setIdProperty(int idx, QObject *obj) { idValues[idx] = obj; diff --git a/src/declarative/qml/qdeclarativecontext_p.h b/src/declarative/qml/qdeclarativecontext_p.h index 77a6d94..c7fb099 100644 --- a/src/declarative/qml/qdeclarativecontext_p.h +++ b/src/declarative/qml/qdeclarativecontext_p.h @@ -145,10 +145,8 @@ public: QObject *contextObject; // Any script blocks that exist on this context - QList<QScriptValue> scripts; QList<QScriptValue> importedScripts; void addImportedScript(const QDeclarativeParser::Object::ScriptBlock &script); - void addScript(const QDeclarativeParser::Object::ScriptBlock &script, QObject *scopeObject); // Context base url QUrl url; diff --git a/src/declarative/qml/qdeclarativecontextscriptclass.cpp b/src/declarative/qml/qdeclarativecontextscriptclass.cpp index 461fab5..1336a1a 100644 --- a/src/declarative/qml/qdeclarativecontextscriptclass.cpp +++ b/src/declarative/qml/qdeclarativecontextscriptclass.cpp @@ -189,14 +189,6 @@ QDeclarativeContextScriptClass::queryProperty(QDeclarativeContextData *bindConte } } - for (int ii = 0; ii < bindContext->scripts.count(); ++ii) { - lastFunction = QScriptDeclarativeClass::function(bindContext->scripts.at(ii), name); - if (lastFunction.isValid()) { - lastContext = bindContext; - return QScriptClass::HandlesReadAccess; - } - } - if (scopeObject) { QScriptClass::QueryFlags rv = ep->objectClass->queryProperty(scopeObject, name, flags, bindContext, diff --git a/src/declarative/qml/qdeclarativeinstruction.cpp b/src/declarative/qml/qdeclarativeinstruction.cpp index d88d06a..99f1cc8 100644 --- a/src/declarative/qml/qdeclarativeinstruction.cpp +++ b/src/declarative/qml/qdeclarativeinstruction.cpp @@ -149,9 +149,6 @@ void QDeclarativeCompiledData::dump(QDeclarativeInstruction *instr, int idx) case QDeclarativeInstruction::StoreSignal: qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_SIGNAL\t\t" << instr->storeSignal.signalIndex << "\t" << instr->storeSignal.value << "\t\t" << primitives.at(instr->storeSignal.value); break; - case QDeclarativeInstruction::StoreScript: - qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_SCRIPT\t\t" << instr->storeScript.value; - break; case QDeclarativeInstruction::StoreImportedScript: qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_IMPORTED_SCRIPT\t" << instr->storeScript.value; break; diff --git a/src/declarative/qml/qdeclarativeinstruction_p.h b/src/declarative/qml/qdeclarativeinstruction_p.h index e8287c0..c09b157 100644 --- a/src/declarative/qml/qdeclarativeinstruction_p.h +++ b/src/declarative/qml/qdeclarativeinstruction_p.h @@ -121,7 +121,6 @@ public: StoreInterface, /* storeObject */ StoreSignal, /* storeSignal */ - StoreScript, /* storeScript */ StoreImportedScript, /* storeScript */ StoreScriptString, /* storeScriptString */ diff --git a/src/declarative/qml/qdeclarativeparser.cpp b/src/declarative/qml/qdeclarativeparser.cpp index d1f209a..b38bd76 100644 --- a/src/declarative/qml/qdeclarativeparser.cpp +++ b/src/declarative/qml/qdeclarativeparser.cpp @@ -89,8 +89,6 @@ QDeclarativeParser::Object::~Object() prop.first->release(); foreach(const DynamicProperty &prop, dynamicProperties) if (prop.defaultValue) prop.defaultValue->release(); - foreach(Object *obj, scriptBlockObjects) - obj->release(); } void Object::setBindingBit(int b) diff --git a/src/declarative/qml/qdeclarativeparser_p.h b/src/declarative/qml/qdeclarativeparser_p.h index 00fc65b..0870cfb 100644 --- a/src/declarative/qml/qdeclarativeparser_p.h +++ b/src/declarative/qml/qdeclarativeparser_p.h @@ -160,8 +160,6 @@ namespace QDeclarativeParser Property *defaultProperty; QHash<QByteArray, Property *> properties; - QList<Object *> scriptBlockObjects; - // Output of the compilation phase (these properties continue to exist // in either the defaultProperty or properties members too) void addValueProperty(Property *); @@ -190,7 +188,9 @@ namespace QDeclarativeParser QList<int> lineNumbers; QList<Pragmas> pragmas; }; +#if 0 QList<ScriptBlock> scripts; +#endif // The bytes to cast instances by to get to the QDeclarativeParserStatus // interface. -1 indicates the type doesn't support this interface. diff --git a/src/declarative/qml/qdeclarativescriptparser.cpp b/src/declarative/qml/qdeclarativescriptparser.cpp index ac49332..674df9d 100644 --- a/src/declarative/qml/qdeclarativescriptparser.cpp +++ b/src/declarative/qml/qdeclarativescriptparser.cpp @@ -296,27 +296,12 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName, if (lastTypeDot >= 0) resolvableObjectType.replace(QLatin1Char('.'),QLatin1Char('/')); - bool isScript = resolvableObjectType == QLatin1String("Script"); - - if (isScript) { - if (_stateStack.isEmpty() || _stateStack.top().property) { - QDeclarativeError error; - error.setDescription(QCoreApplication::translate("QDeclarativeParser","Invalid use of Script block")); - error.setLine(typeLocation.startLine); - error.setColumn(typeLocation.startColumn); - _parser->_errors << error; - return 0; - } - } - Object *obj = new Object; - if (!isScript) { - QDeclarativeScriptParser::TypeReference *typeRef = _parser->findOrCreateType(resolvableObjectType); - obj->type = typeRef->id; + QDeclarativeScriptParser::TypeReference *typeRef = _parser->findOrCreateType(resolvableObjectType); + obj->type = typeRef->id; - typeRef->refObjects.append(obj); - } + typeRef->refObjects.append(obj); // XXX this doesn't do anything (_scope never builds up) _scope.append(resolvableObjectType); @@ -325,11 +310,7 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName, obj->location = location; - if (isScript) { - - _stateStack.top().object->scriptBlockObjects.append(obj); - - } else if (propertyCount) { + if (propertyCount) { Property *prop = currentProperty(); Value *v = new Value; @@ -827,62 +808,29 @@ bool ProcessAST::visit(AST::UiSourceElement *node) { QDeclarativeParser::Object *obj = currentObject(); - bool isScript = (obj && obj->typeName == "Script"); - - if (!isScript) { - - if (AST::FunctionDeclaration *funDecl = AST::cast<AST::FunctionDeclaration *>(node->sourceElement)) { - - Object::DynamicSlot slot; - slot.location = location(funDecl->firstSourceLocation(), funDecl->lastSourceLocation()); - - AST::FormalParameterList *f = funDecl->formals; - while (f) { - slot.parameterNames << f->name->asString().toUtf8(); - f = f->finish(); - } - - QString body = textAt(funDecl->lbraceToken, funDecl->rbraceToken); - slot.name = funDecl->name->asString().toUtf8(); - slot.body = body; - obj->dynamicSlots << slot; + if (AST::FunctionDeclaration *funDecl = AST::cast<AST::FunctionDeclaration *>(node->sourceElement)) { - } else { - QDeclarativeError error; - error.setDescription(QCoreApplication::translate("QDeclarativeParser","JavaScript declaration outside Script element")); - error.setLine(node->firstSourceLocation().startLine); - error.setColumn(node->firstSourceLocation().startColumn); - _parser->_errors << error; - } - return false; - - } else { - QString source; - - int line = 0; - if (AST::FunctionDeclaration *funDecl = AST::cast<AST::FunctionDeclaration *>(node->sourceElement)) { - line = funDecl->functionToken.startLine; - source = asString(funDecl); - } else if (AST::VariableStatement *varStmt = AST::cast<AST::VariableStatement *>(node->sourceElement)) { - // ignore variable declarations - line = varStmt->declarationKindToken.startLine; + Object::DynamicSlot slot; + slot.location = location(funDecl->firstSourceLocation(), funDecl->lastSourceLocation()); - QDeclarativeError error; - error.setDescription(QCoreApplication::translate("QDeclarativeParser", "Variable declarations not allow in inline Script blocks")); - error.setLine(node->firstSourceLocation().startLine); - error.setColumn(node->firstSourceLocation().startColumn); - _parser->_errors << error; - return false; + AST::FormalParameterList *f = funDecl->formals; + while (f) { + slot.parameterNames << f->name->asString().toUtf8(); + f = f->finish(); } - Value *value = new Value; - value->location = location(node->firstSourceLocation(), - node->lastSourceLocation()); - value->value = QDeclarativeParser::Variant(source); + QString body = textAt(funDecl->lbraceToken, funDecl->rbraceToken); + slot.name = funDecl->name->asString().toUtf8(); + slot.body = body; + obj->dynamicSlots << slot; - obj->getDefaultProperty()->addValue(value); + } else { + QDeclarativeError error; + error.setDescription(QCoreApplication::translate("QDeclarativeParser","JavaScript declaration outside Script element")); + error.setLine(node->firstSourceLocation().startLine); + error.setColumn(node->firstSourceLocation().startColumn); + _parser->_errors << error; } - return false; } diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp index fdcbeee..57bf726 100644 --- a/src/declarative/qml/qdeclarativevme.cpp +++ b/src/declarative/qml/qdeclarativevme.cpp @@ -623,13 +623,6 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack, } break; - case QDeclarativeInstruction::StoreScript: - { - QObject *target = stack.top(); - ctxt->addScript(scripts.at(instr.storeScript.value), target); - } - break; - case QDeclarativeInstruction::StoreImportedScript: { ctxt->addImportedScript(scripts.at(instr.storeScript.value)); diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/ScopeObject.qml b/tests/auto/declarative/qdeclarativeecmascript/data/ScopeObject.qml index b7bec63..12ac754 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/ScopeObject.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/ScopeObject.qml @@ -5,10 +5,8 @@ Item { property int binding: myFunction(); property int binding2: myCompFunction(); - Script { - function myCompFunction() { - return a; - } + function myCompFunction() { + return a; } } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.1.qml b/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.1.qml deleted file mode 100644 index 2ac7b6e..0000000 --- a/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.1.qml +++ /dev/null @@ -1,11 +0,0 @@ -import Qt 4.6 - -QtObject { - property int test: external_script_func(); - - Script { - // Single source as non-array literal - source: "externalScript.js" - } -} - diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.2.js b/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.2.js deleted file mode 100644 index 78c3a86..0000000 --- a/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.2.js +++ /dev/null @@ -1,8 +0,0 @@ -function external_script_func2() { - return a; -} - -function is_a_undefined() { - return a == undefined; -} - diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.2.qml deleted file mode 100644 index dec657c..0000000 --- a/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.2.qml +++ /dev/null @@ -1,11 +0,0 @@ -import Qt 4.6 - -QtObject { - property int test: external_script_func(); - - Script { - // Single source as array - source: [ "externalScript.js" ] - } -} - diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.3.qml b/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.3.qml deleted file mode 100644 index d7acf38..0000000 --- a/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.3.qml +++ /dev/null @@ -1,13 +0,0 @@ -import Qt 4.6 - -QtObject { - property int test: external_script_func(); - property int test2: external_script_func2(); - property bool test3: is_a_undefined(); - - Script { - // Multiple script - source: [ "externalScript.js", "externalScript.2.js" ] - } -} - diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.4.qml b/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.4.qml deleted file mode 100644 index 16211aa..0000000 --- a/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.4.qml +++ /dev/null @@ -1,15 +0,0 @@ -import Qt 4.6 - -QtObject { - property int test: external_script_func(); - property bool test2: is_a_undefined(); - - // Disconnected scripts - Script { - source: "externalScript.js" - } - - Script { - source: "externalScript.2.js" - } -} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.js b/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.js deleted file mode 100644 index 8928652..0000000 --- a/tests/auto/declarative/qdeclarativeecmascript/data/externalScript.js +++ /dev/null @@ -1,6 +0,0 @@ -var a = 92; - -function external_script_func() { - return a; -} - diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scope.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scope.2.qml index 8e5aa0b..9beda6a 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scope.2.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scope.2.qml @@ -4,10 +4,8 @@ Item { property int a: 0 property int b: 0 - Script { - function b() { return 11; } - function c() { return 33; } - } + function b() { return 11; } + function c() { return 33; } QtObject { id: a diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scope.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scope.qml index cccd3d3..1c0be98 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scope.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scope.qml @@ -7,21 +7,17 @@ Item { property int binding: a property string binding2: a + "Test" property int binding3: myFunction() - property int binding4: myNestedFunction() + property int binding4: nestedObject.myNestedFunction() - Script { - function myFunction() { - return a; - } + function myFunction() { + return a; } Item { id: nestedObject - Script { - function myNestedFunction() { - return a; - } + function myNestedFunction() { + return a; } property int a: 2 diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptAccess.js b/tests/auto/declarative/qdeclarativeecmascript/data/scriptAccess.js deleted file mode 100644 index c00d285..0000000 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptAccess.js +++ /dev/null @@ -1,7 +0,0 @@ -var extVariable = 19; - -function extMethod() -{ - return extVariable; -} - diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptAccess.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptAccess.qml deleted file mode 100644 index feb6d16..0000000 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptAccess.qml +++ /dev/null @@ -1,17 +0,0 @@ -import Qt 4.6 - -Item { - Script { - function method() { - return 10; - } - } - - Script { - source: "scriptAccess.js" - } - - property int test1: method() - property int test2: extMethod() - property int test3: extVariable -} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.1.js b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.1.js new file mode 100644 index 0000000..54284fe --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.1.js @@ -0,0 +1,4 @@ +function testFunction() { + test = true; +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.1.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.1.qml index 2bdd706..d6e4207 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.1.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.1.qml @@ -1,16 +1,10 @@ import Qt.test 1.0 import Qt 4.6 - +import "scriptConnect.1.js" as Script MyQmlObject { property bool test: false id: root - Script { - function testFunction() { - test = true; - } - } - - Component.onCompleted: root.argumentSignal.connect(testFunction); + Component.onCompleted: root.argumentSignal.connect(Script.testFunction); } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.2.js b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.2.js new file mode 100644 index 0000000..595c778 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.2.js @@ -0,0 +1,5 @@ +function testFunction() { + if (this.b == 12) + test = true; +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.2.qml index fa90918..7992ba5 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.2.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.2.qml @@ -1,22 +1,16 @@ import Qt.test 1.0 import Qt 4.6 +import "scriptConnect.2.js" as Script MyQmlObject { property bool test: false id: root - Script { - function testFunction() { - if (this.b == 12) - test = true; - } - } - Component.onCompleted: { var a = new Object; a.b = 12; - root.argumentSignal.connect(a, testFunction); + root.argumentSignal.connect(a, Script.testFunction); } } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.6.js b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.6.js new file mode 100644 index 0000000..71bdd08 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.6.js @@ -0,0 +1,3 @@ +function testFunction() { + test++; +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.6.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.6.qml index 8c35db1..d546495 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.6.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptConnect.6.qml @@ -1,20 +1,15 @@ import Qt.test 1.0 import Qt 4.6 +import "scriptConnect.6.js" as Script MyQmlObject { property int test: 0 id: root - - Script { - function testFunction() { - test++; - } - } Component.onCompleted: { - root.argumentSignal.connect(testFunction); - root.argumentSignal.connect(testFunction); + root.argumentSignal.connect(Script.testFunction); + root.argumentSignal.connect(Script.testFunction); } } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.1.js b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.1.js new file mode 100644 index 0000000..407426f --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.1.js @@ -0,0 +1,6 @@ +function testFunction() { + test++; +} + +function otherFunction() { +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.1.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.1.qml index 45c4f73..0d262c6 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.1.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.1.qml @@ -1,18 +1,13 @@ import Qt.test 1.0 import Qt 4.6 +import "scriptDisconnect.1.js" as Script MyQmlObject { property int test: 0 id: root - Script { - function testFunction() { - test++; - } - } + Component.onCompleted: root.argumentSignal.connect(Script.testFunction); - Component.onCompleted: root.argumentSignal.connect(testFunction); - - onBasicSignal: root.argumentSignal.disconnect(testFunction); + onBasicSignal: root.argumentSignal.disconnect(Script.testFunction); } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.2.qml index a47fe74..6d379e6 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.2.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.2.qml @@ -1,19 +1,14 @@ import Qt.test 1.0 import Qt 4.6 +import "scriptDisconnect.1.js" as Script MyQmlObject { property int test: 0 id: root - Script { - function testFunction() { - test++; - } - } + Component.onCompleted: root.argumentSignal.connect(root, Script.testFunction); - Component.onCompleted: root.argumentSignal.connect(root, testFunction); - - onBasicSignal: root.argumentSignal.disconnect(root, testFunction); + onBasicSignal: root.argumentSignal.disconnect(root, Script.testFunction); } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.3.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.3.qml index c95ffbf..526580a 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.3.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.3.qml @@ -1,19 +1,14 @@ import Qt.test 1.0 import Qt 4.6 +import "scriptDisconnect.1.js" as Script MyQmlObject { property int test: 0 id: root - Script { - function testFunction() { - test++; - } - } + Component.onCompleted: root.argumentSignal.connect(root, Script.testFunction); - Component.onCompleted: root.argumentSignal.connect(root, testFunction); - - onBasicSignal: root.argumentSignal.disconnect(testFunction); + onBasicSignal: root.argumentSignal.disconnect(Script.testFunction); } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.4.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.4.qml index 342f24a..18b05ad 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.4.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptDisconnect.4.qml @@ -1,20 +1,13 @@ import Qt.test 1.0 import Qt 4.6 +import "scriptDisconnect.1.js" as Script MyQmlObject { property int test: 0 id: root - Script { - function testFunction() { - test++; - } - function otherFunction() { - } - } + Component.onCompleted: root.argumentSignal.connect(Script.testFunction); - Component.onCompleted: root.argumentSignal.connect(testFunction); - - onBasicSignal: root.argumentSignal.disconnect(otherFunction); + onBasicSignal: root.argumentSignal.disconnect(Script.otherFunction); } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.js b/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.js index 1d7b357..d22f623 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.js +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.js @@ -1,2 +1,4 @@ // Comment a = 10 + +function getValue() { a = 10; return 0; } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml index c2edb41..e8f7b62 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml @@ -1,11 +1,9 @@ import Qt.test 1.0 +import "scriptErrors.js" as Script MyQmlObject { - Script { source: "scriptErrors.js" } - Script { function getValue() { a = 10; return 0; } } - property int t: a.value - property int w: getValue(); + property int w: Script.getValue(); property int x: undefinedObject property int y: (a.value, undefinedObject) diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.1.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.1.qml deleted file mode 100644 index 9b11fa9..0000000 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.1.qml +++ /dev/null @@ -1,13 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - property string result - - Script{ - function f() { - result = b - } - - } - onArgumentSignal: f() -} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.2.qml deleted file mode 100644 index ec727e2..0000000 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.2.qml +++ /dev/null @@ -1,11 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - property string result - property string aProp: "hello" - - Script{ - source: "scriptScope.js" - } - onBasicSignal: f() -} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.js b/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.js deleted file mode 100644 index 5689930..0000000 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.js +++ /dev/null @@ -1,5 +0,0 @@ -var aProp = "world"; - -function f() { - result = aProp; -} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 4036507..33629b8 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -100,7 +100,6 @@ private slots: void scope(); void signalParameterTypes(); void objectsCompareAsEqual(); - void scriptAccess(); void dynamicCreation_data(); void dynamicCreation(); void dynamicDestruction(); @@ -117,14 +116,12 @@ private slots: void exceptionBindingProducesWarning(); void transientErrors(); void shutdownErrors(); - void externalScript(); void compositePropertyType(); void jsObject(); void undefinedResetsProperty(); void listToVariant(); void multiEngineObject(); void deletedObject(); - void scriptScope(); void attachedPropertyScope(); void scriptConnect(); void scriptDisconnect(); @@ -837,24 +834,6 @@ void tst_qdeclarativeecmascript::aliasPropertyAndBinding() QCOMPARE(object->property("c3").toInt(), 19); } -/* -Tests that only methods of Script {} blocks are exposed. -*/ -void tst_qdeclarativeecmascript::scriptAccess() -{ - QDeclarativeComponent component(&engine, TEST_FILE("scriptAccess.qml")); - - QString warning = component.url().toString() + ":16: Unable to assign [undefined] to int"; - QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); - - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("test1").toInt(), 10); - QCOMPARE(object->property("test2").toInt(), 19); - QCOMPARE(object->property("test3").toInt(), 0); -} - void tst_qdeclarativeecmascript::dynamicCreation_data() { QTest::addColumn<QString>("method"); @@ -977,13 +956,13 @@ void tst_qdeclarativeecmascript::scriptErrors() QString url = component.url().toString(); QString warning1 = url.left(url.length() - 3) + "js:2: Error: Invalid write to global property \"a\""; - QString warning2 = url + ":7: TypeError: Result of expression 'a' [undefined] is not an object."; - QString warning3 = url + ":5: Error: Invalid write to global property \"a\""; - QString warning4 = url + ":12: TypeError: Result of expression 'a' [undefined] is not an object."; - QString warning5 = url + ":10: TypeError: Result of expression 'a' [undefined] is not an object."; - QString warning6 = url + ":9: Unable to assign [undefined] to int"; - QString warning7 = url + ":14: Error: Cannot assign to read-only property \"trueProperty\""; - QString warning8 = url + ":15: Error: Cannot assign to non-existent property \"fakeProperty\""; + QString warning2 = url + ":5: TypeError: Result of expression 'a' [undefined] is not an object."; + QString warning3 = url.left(url.length() - 3) + "js:4: Error: Invalid write to global property \"a\""; + QString warning4 = url + ":10: TypeError: Result of expression 'a' [undefined] is not an object."; + QString warning5 = url + ":8: TypeError: Result of expression 'a' [undefined] is not an object."; + QString warning6 = url + ":7: Unable to assign [undefined] to int"; + QString warning7 = url + ":12: Error: Cannot assign to read-only property \"trueProperty\""; + QString warning8 = url + ":13: Error: Cannot assign to non-existent property \"fakeProperty\""; QTest::ignoreMessage(QtWarningMsg, warning1.toLatin1().constData()); QTest::ignoreMessage(QtWarningMsg, warning2.toLatin1().constData()); @@ -1166,53 +1145,6 @@ void tst_qdeclarativeecmascript::shutdownErrors() QCOMPARE(transientErrorsMsgCount, 0); } -// Check that Script::source property works as expected -void tst_qdeclarativeecmascript::externalScript() -{ - { - QDeclarativeComponent component(&engine, TEST_FILE("externalScript.1.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("test").toInt(), 92); - - delete object; - } - - { - QDeclarativeComponent component(&engine, TEST_FILE("externalScript.2.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("test").toInt(), 92); - - delete object; - } - - { - QDeclarativeComponent component(&engine, TEST_FILE("externalScript.3.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("test").toInt(), 92); - QCOMPARE(object->property("test2").toInt(), 92); - QCOMPARE(object->property("test3").toBool(), false); - - delete object; - } - - { - QDeclarativeComponent component(&engine, TEST_FILE("externalScript.4.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("test").toInt(), 92); - QCOMPARE(object->property("test2").toBool(), true); - - delete object; - } -} - void tst_qdeclarativeecmascript::compositePropertyType() { QDeclarativeComponent component(&engine, TEST_FILE("compositePropertyType.qml")); @@ -1769,31 +1701,6 @@ void tst_qdeclarativeecmascript::deletedObject() delete object; } -void tst_qdeclarativeecmascript::scriptScope() -{ - { - QDeclarativeComponent component(&engine, TEST_FILE("scriptScope.1.qml")); - - MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); - QVERIFY(object != 0); - emit object->argumentSignal(19, "Hello world!", 10.3); - QCOMPARE(object->property("result").toString(), QString()); - - delete object; - } - - { - QDeclarativeComponent component(&engine, TEST_FILE("scriptScope.2.qml")); - - MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); - QVERIFY(object != 0); - emit object->basicSignal(); - QCOMPARE(object->property("result").toString(), QLatin1String("world")); - - delete object; - } -} - void tst_qdeclarativeecmascript::attachedPropertyScope() { QDeclarativeComponent component(&engine, TEST_FILE("attachedPropertyScope.qml")); diff --git a/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp b/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp index f4df130..9ae26f2 100644 --- a/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp +++ b/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp @@ -332,16 +332,6 @@ void tst_qdeclarativeinstruction::dump() { QDeclarativeInstruction i; - i.line = 28; - i.type = QDeclarativeInstruction::StoreScript; - i.storeScript.value = 2; - //i.storeScript.fileName = 18; - //i.storeScript.lineNumber = 28; - data->bytecode << i; - } - - { - QDeclarativeInstruction i; i.line = 29; i.type = QDeclarativeInstruction::StoreScriptString; i.storeScriptString.propertyIndex = 24; @@ -571,30 +561,29 @@ void tst_qdeclarativeinstruction::dump() << "25\t\t25\tSTORE_VARIANT_OBJECT\t22" << "26\t\t26\tSTORE_INTERFACE\t\t23" << "27\t\t27\tSTORE_SIGNAL\t\t2\t3\t\t\"console.log(1921)\"" - << "28\t\t28\tSTORE_SCRIPT\t\t2" - << "29\t\t29\tSTORE_SCRIPT_STRING\t24\t3\t1" - << "30\t\t30\tASSIGN_SIGNAL_OBJECT\t0\t\t\t\"mySignal\"" - << "31\t\t31\tASSIGN_CUSTOMTYPE\t25\t4" - << "32\t\t32\tSTORE_BINDING\t26\t3\t2" - << "33\t\t33\tSTORE_COMPILED_BINDING\t27\t2\t4" - << "34\t\t34\tSTORE_VALUE_SOURCE\t29\t4" - << "35\t\t35\tSTORE_VALUE_INTERCEPTOR\t30\t-4" - << "36\t\t36\tBEGIN\t\t\t4" - << "37\t\t38\tSTORE_OBJECT_QLIST" - << "38\t\t39\tASSIGN_OBJECT_LIST" - << "39\t\t40\tFETCH_ATTACHED\t\t23" - << "40\t\t42\tFETCH_QLIST\t\t32" - << "41\t\t43\tFETCH\t\t\t33" - << "42\t\t44\tFETCH_VALUE\t\t34\t6" - << "43\t\t45\tPOP" - << "44\t\t46\tPOP_QLIST" - << "45\t\t47\tPOP_VALUE\t\t35\t8" - << "46\t\t48\tDEFER\t\t\t7" - << "47\t\tNA\tDEFER\t\t\t7" - << "48\t\t48\tSTORE_IMPORTED_SCRIPT\t2" - << "49\t\t50\tXXX UNKOWN INSTRUCTION\t1234" - << "50\t\t51\tSTORE_VARIANT_INTEGER\t\t32\t11" - << "51\t\t52\tSTORE_VARIANT_DOUBLE\t\t19\t33.7" + << "28\t\t29\tSTORE_SCRIPT_STRING\t24\t3\t1" + << "29\t\t30\tASSIGN_SIGNAL_OBJECT\t0\t\t\t\"mySignal\"" + << "30\t\t31\tASSIGN_CUSTOMTYPE\t25\t4" + << "31\t\t32\tSTORE_BINDING\t26\t3\t2" + << "32\t\t33\tSTORE_COMPILED_BINDING\t27\t2\t4" + << "33\t\t34\tSTORE_VALUE_SOURCE\t29\t4" + << "34\t\t35\tSTORE_VALUE_INTERCEPTOR\t30\t-4" + << "35\t\t36\tBEGIN\t\t\t4" + << "36\t\t38\tSTORE_OBJECT_QLIST" + << "37\t\t39\tASSIGN_OBJECT_LIST" + << "38\t\t40\tFETCH_ATTACHED\t\t23" + << "39\t\t42\tFETCH_QLIST\t\t32" + << "40\t\t43\tFETCH\t\t\t33" + << "41\t\t44\tFETCH_VALUE\t\t34\t6" + << "42\t\t45\tPOP" + << "43\t\t46\tPOP_QLIST" + << "44\t\t47\tPOP_VALUE\t\t35\t8" + << "45\t\t48\tDEFER\t\t\t7" + << "46\t\tNA\tDEFER\t\t\t7" + << "47\t\t48\tSTORE_IMPORTED_SCRIPT\t2" + << "48\t\t50\tXXX UNKOWN INSTRUCTION\t1234" + << "49\t\t51\tSTORE_VARIANT_INTEGER\t\t32\t11" + << "50\t\t52\tSTORE_VARIANT_DOUBLE\t\t19\t33.7" << "-------------------------------------------------------------------------------"; messages = QStringList(); |