QScriptClass::QueryFlags ScShiftPropertyContainer::queryProperty(const QScriptValue &object, const QScriptString &name, QueryFlags flags, uint *id)
  {
  ScProfileFunction
  SPropertyContainer *prop = (*unpackValue(object))->uncheckedCastTo<SPropertyContainer>();
  if (!prop)
    {
    xAssertFail();
    return 0;
    }

  *id = (uint)-1;
  bool isArrayIndex = false;
  qint32 pos = name.toArrayIndex(&isArrayIndex);
  if(isArrayIndex)
    {
    *id = pos;
    return flags;
    }
  else
    {
    SProperty *child = prop->findChild(name);
    if(child)
      {
      return flags;
      }
    }
  return 0;
  }
示例#2
0
QScriptValue propertyHelper(const QByteArray* arrayBuffer, const QScriptString& name, uint id) {
    bool ok = false;
    name.toArrayIndex(&ok);
    
    if (ok && arrayBuffer) {
        QDataStream stream(*arrayBuffer);
        stream.skipRawData(id);
        
        T result;
        stream >> result;
        return result;
    }
示例#3
0
QScriptClass::QueryFlags ByteArrayClass::queryProperty(const QScriptValue &object,
                                                    const QScriptString &name,
                                                    QueryFlags flags, uint *id) {
    QByteArray *ba = qscriptvalue_cast<QByteArray*>(object.data());
    if (!ba)
        return 0;
    if (name == length) {
        return flags;
    } else {
        bool isArrayIndex;
        qint32 pos = name.toArrayIndex(&isArrayIndex);
        if (!isArrayIndex)
            return 0;
        *id = pos;
        if ((flags & HandlesReadAccess) && (pos >= ba->size()))
            flags &= ~HandlesReadAccess;
        return flags;
    }
}
示例#4
0
QScriptClass::QueryFlags TypedArray::queryProperty(const QScriptValue& object,
                                                   const QScriptString& name,
                                                   QueryFlags flags, uint* id) {
    if (name == _bytesPerElementName || name == _lengthName) {
        return flags &= HandlesReadAccess; // Only keep read access flags
    }
    
    quint32 byteOffset = object.data().property(_byteOffsetName).toInt32();
    quint32 length = object.data().property(_lengthName).toInt32();
    bool ok = false;
    quint32 pos = name.toArrayIndex(&ok);
    
    // Check that name is a valid index and arrayBuffer exists
    if (ok && pos < length) {
        *id = byteOffset + pos * _bytesPerElement; // save pos to avoid recomputation
        return HandlesReadAccess | HandlesWriteAccess; // Read/Write access
    }
    
    return ArrayBufferViewClass::queryProperty(object, name, flags, id);
}
	QScriptClass::QueryFlags AudioOutputCollection::queryProperty(
		const QScriptValue &object, const QScriptString &name, QueryFlags flags, uint *id)
	{
		ActiveAudioTracks* tracks = this->_editor->getPoolOfActiveAudioTrack();
		bool isArrayIndex;
		quint32 pos = name.toArrayIndex(&isArrayIndex);

		if (!isArrayIndex)
		{
			return 0;
		}

		*id = pos;

		if (pos >= tracks->size())
		{
			return 0;
		}

		return flags;
	}
void tst_QScriptString::test()
{
    QScriptEngine eng;
    {
        QScriptString str;
        QVERIFY(!str.isValid());
        QVERIFY(str == str);
        QVERIFY(!(str != str));
        QVERIFY(str.toString().isNull());

        QScriptString str1(str);
        QVERIFY(!str1.isValid());

        QScriptString str2 = str;
        QVERIFY(!str2.isValid());

        QCOMPARE(str.toArrayIndex(), quint32(0xffffffff));
    }
    for (int x = 0; x < 2; ++x) {
        QString ciao = QString::fromLatin1("ciao");
        QScriptString str = eng.toStringHandle(ciao);
        QVERIFY(str.isValid());
        QVERIFY(str == str);
        QVERIFY(!(str != str));
        QCOMPARE(str.toString(), ciao);

        QScriptString str1(str);
        QCOMPARE(str, str1);

        QScriptString str2 = str;
        QCOMPARE(str, str2);

        QScriptString str3 = eng.toStringHandle(ciao);
        QVERIFY(str3.isValid());
        QCOMPARE(str, str3);

        eng.collectGarbage();

        QVERIFY(str.isValid());
        QCOMPARE(str.toString(), ciao);
        QVERIFY(str1.isValid());
        QCOMPARE(str1.toString(), ciao);
        QVERIFY(str2.isValid());
        QCOMPARE(str2.toString(), ciao);
        QVERIFY(str3.isValid());
        QCOMPARE(str3.toString(), ciao);
    }
    {
        QScriptEngine* eng2 = new QScriptEngine;
        QString one = QString::fromLatin1("one");
        QString two = QString::fromLatin1("two");
        QScriptString oneInterned = eng2->toStringHandle(one);
        QCOMPARE(oneInterned.toString(), one);
        QScriptString twoInterned = eng2->toStringHandle(two);
        QCOMPARE(twoInterned.toString(), two);
        QVERIFY(oneInterned != twoInterned);
        QVERIFY(!(oneInterned == twoInterned));

        delete eng2;
    }
}
示例#7
0
    QString ActionInstance::evaluateTextString(bool &ok, const QString &toEvaluate, int &position)
	{
		ok = true;

		int startIndex = position;

		QString result;

		while(position < toEvaluate.length())
		{
			if(toEvaluate[position] == QLatin1Char('$'))
			{
				//find a variable name
				if(VariableRegExp.indexIn(toEvaluate, position) != -1)
				{
					QString foundVariableName = VariableRegExp.cap(1);
					QScriptValue foundVariable = d->scriptEngine->globalObject().property(foundVariableName);

					position += foundVariableName.length();

					if(!foundVariable.isValid())
					{
						ok = false;

						emit executionException(ActionException::InvalidParameterException, tr("Undefined variable \"%1\"").arg(foundVariableName));
						return QString();
					}

					QString stringEvaluationResult;

					if(foundVariable.isNull())
						stringEvaluationResult = QStringLiteral("[Null]");
					else if(foundVariable.isUndefined())
						stringEvaluationResult = QStringLiteral("[Undefined]");
					else if(foundVariable.isArray())
					{
						while((position + 1 < toEvaluate.length()) && toEvaluate[position + 1] == QLatin1Char('['))
						{
							position += 2;
							QString indexArray = evaluateTextString(ok, toEvaluate, position);

							if((position < toEvaluate.length()) && toEvaluate[position] == QLatin1Char(']'))
							{
								QScriptString internalIndexArray = d->scriptEngine->toStringHandle(indexArray);
								bool flag = true;
								int numIndex = internalIndexArray.toArrayIndex(&flag);

								if(flag) //numIndex is valid
									foundVariable = foundVariable.property(numIndex);
								else //use internalIndexArray
									foundVariable = foundVariable.property(internalIndexArray);
							}
							else
							{
								//syntax error
								ok = false;

								emit executionException(ActionException::InvalidParameterException, tr("Invalid parameter. Unable to evaluate string"));
								return QString();
							}

							//COMPATIBILITY: we break the while loop if foundVariable is no more of Array type
							if(!foundVariable.isArray())
								break;
						}
						//end of while, no more '['
						if(foundVariable.isArray())
							stringEvaluationResult = evaluateVariableArray(ok, foundVariable);
						else
							stringEvaluationResult = foundVariable.toString();
					}
					else if(foundVariable.isVariant())
					{
						QVariant variantEvaluationResult = foundVariable.toVariant();
						switch(variantEvaluationResult.type())
						{
						case QVariant::StringList:
							stringEvaluationResult = variantEvaluationResult.toStringList().join(QStringLiteral("\n"));
							break;
						case QVariant::ByteArray:
							stringEvaluationResult = QStringLiteral("[Raw data]");
							break;
						default:
							stringEvaluationResult = foundVariable.toString();
							break;
						}
					}
					else
						stringEvaluationResult = foundVariable.toString();

					result.append(stringEvaluationResult);
				}

			}
			else if (toEvaluate[position] == QLatin1Char(']'))
			{
				if(startIndex == 0)
					//in top level evaluation isolated character ']' is accepted (for compatibility reason), now prefer "\]"
					//i.e without matching '['
					result.append(toEvaluate[position]);
				else
					//on other levels, the parsing is stopped at this point
					return result;
			}
			else if(toEvaluate[position] == QLatin1Char('\\'))
			{
				if(startIndex == 0)
				{
					//for ascendant compatibility reason
					//in top level evaluation '\' is not only an escape character,
					//but can also be a standard character in some cases
					if((position + 1) < toEvaluate.length())
					{
						position++;
						if(toEvaluate[position] == QLatin1Char('$') || toEvaluate[position] == QLatin1Char('[') || toEvaluate[position] == QLatin1Char(']') || toEvaluate[position] == QLatin1Char('\\'))
							result.append(toEvaluate[position]);
						else
						{
							position--;
							result.append(toEvaluate[position]);
						}
					}
					else
						result.append(toEvaluate[position]);
				}
				else
				{
					position++;
					if( position < toEvaluate.length() )
						result.append(toEvaluate[position]);
				}
			}
			else
				result.append(toEvaluate[position]);

			position++;
		}

		return result;
	}