forked from qt-creator/qt-creator
QmlJS: Compile with QT_NO_CAST_FROM_ASCII
Change-Id: I0c5654a978f47a4db5428936fd44633f21394830 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
964c01a460
commit
5ea0937167
@@ -1,6 +1,6 @@
|
||||
TEMPLATE = lib
|
||||
TARGET = QmlJS
|
||||
DEFINES += QMLJS_BUILD_DIR QT_CREATOR
|
||||
DEFINES += QMLJS_BUILD_DIR QT_CREATOR QT_NO_CAST_FROM_ASCII
|
||||
|
||||
QT +=script
|
||||
include(../../qtcreatorlibrary.pri)
|
||||
|
||||
@@ -7,7 +7,8 @@ QtcLibrary {
|
||||
cpp.includePaths: base.concat("parser")
|
||||
cpp.defines: base.concat([
|
||||
"QMLJS_BUILD_DIR",
|
||||
"QT_CREATOR"
|
||||
"QT_CREATOR",
|
||||
"QT_NO_CAST_FROM_ASCII"
|
||||
])
|
||||
cpp.optimization: "fast"
|
||||
|
||||
|
||||
@@ -710,7 +710,7 @@ static bool checkTopLevelBindingForParentReference(ExpressionStatement *expStmt,
|
||||
SourceLocation location = locationFromRange(expStmt->firstSourceLocation(), expStmt->lastSourceLocation());
|
||||
QString stmtSource = source.mid(location.begin(), location.length);
|
||||
|
||||
if (stmtSource.contains(QRegExp("(^|\\W)parent\\.")))
|
||||
if (stmtSource.contains(QRegExp(QLatin1String("(^|\\W)parent\\."))))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@@ -804,7 +804,7 @@ bool Check::visit(UiScriptBinding *ast)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (id.isEmpty() || (!id.at(0).isLower() && id.at(0) != '_')) {
|
||||
if (id.isEmpty() || (!id.at(0).isLower() && id.at(0) != QLatin1Char('_'))) {
|
||||
addMessage(ErrInvalidId, loc);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -940,10 +940,10 @@ CodeFormatter::TokenKind CodeFormatter::extendedTokenKind(const QmlJS::Token &to
|
||||
if (text == "list")
|
||||
return List;
|
||||
} else if (kind == Keyword) {
|
||||
const QChar char1 = text.at(0);
|
||||
const QChar char2 = text.at(1);
|
||||
const QChar char3 = (text.size() > 2 ? text.at(2) : QChar());
|
||||
switch (char1.toLatin1()) {
|
||||
const char char1 = text.at(0).toLatin1();
|
||||
const char char2 = text.at(1).toLatin1();
|
||||
const char char3 = (text.size() > 2 ? text.at(2).toLatin1() : 0);
|
||||
switch (char1) {
|
||||
case 'v':
|
||||
return Var;
|
||||
case 'i':
|
||||
@@ -1019,7 +1019,7 @@ void CodeFormatter::dump() const
|
||||
qDebug() << "Current indent depth:" << m_indentDepth;
|
||||
}
|
||||
|
||||
QString CodeFormatter::stateToString(int type) const
|
||||
QByteArray CodeFormatter::stateToString(int type) const
|
||||
{
|
||||
const QMetaEnum &metaEnum = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("StateType"));
|
||||
return metaEnum.valueToKey(type);
|
||||
|
||||
@@ -278,7 +278,7 @@ protected:
|
||||
bool isExpressionEndState(int type) const;
|
||||
|
||||
void dump() const;
|
||||
QString stateToString(int type) const;
|
||||
QByteArray stateToString(int type) const;
|
||||
|
||||
private:
|
||||
void recalculateStateAfter(const QTextBlock &block);
|
||||
|
||||
@@ -125,11 +125,11 @@ Document::MutablePtr Document::create(const QString &fileName, Language language
|
||||
|
||||
Document::Language Document::guessLanguageFromSuffix(const QString &fileName)
|
||||
{
|
||||
if (fileName.endsWith(".qml", Qt::CaseInsensitive))
|
||||
if (fileName.endsWith(QLatin1String(".qml"), Qt::CaseInsensitive))
|
||||
return QmlLanguage;
|
||||
if (fileName.endsWith(".js", Qt::CaseInsensitive))
|
||||
if (fileName.endsWith(QLatin1String(".js"), Qt::CaseInsensitive))
|
||||
return JavaScriptLanguage;
|
||||
if (fileName.endsWith(".json", Qt::CaseInsensitive))
|
||||
if (fileName.endsWith(QLatin1String(".json"), Qt::CaseInsensitive))
|
||||
return JsonLanguage;
|
||||
return UnknownLanguage;
|
||||
}
|
||||
|
||||
@@ -186,10 +186,10 @@ QChar QmlJSIndenter::lastParen() const
|
||||
const Token &token = yyLinizerState.tokens.at(index);
|
||||
|
||||
if (token.is(Token::LeftParenthesis))
|
||||
return QChar('(');
|
||||
return QLatin1Char('(');
|
||||
|
||||
else if (token.is(Token::RightParenthesis))
|
||||
return QChar(')');
|
||||
return QLatin1Char(')');
|
||||
}
|
||||
|
||||
return QChar();
|
||||
@@ -324,7 +324,7 @@ int QmlJSIndenter::indentForContinuationLine()
|
||||
Q_ASSERT(j - 1 >= 0);
|
||||
|
||||
if (QString::fromLatin1("!=<>").indexOf(yyLine->at(j - 1)) == -1 &&
|
||||
j + 1 < yyLine->length() && yyLine->at(j + 1) != '=') {
|
||||
j + 1 < yyLine->length() && yyLine->at(j + 1) != QLatin1Char('=')) {
|
||||
if (braceDepth == 0 && delimDepth == 0 &&
|
||||
j < yyLine->length() - 1 &&
|
||||
!yyLine->endsWith(QLatin1Char(',')) &&
|
||||
|
||||
@@ -1131,7 +1131,7 @@ QList<const ObjectValue *> PrototypeIterator::all()
|
||||
FunctionValue::FunctionValue(ValueOwner *valueOwner)
|
||||
: ObjectValue(valueOwner)
|
||||
{
|
||||
setClassName("Function");
|
||||
setClassName(QLatin1String("Function"));
|
||||
setMember(QLatin1String("length"), valueOwner->numberValue());
|
||||
setPrototype(valueOwner->functionPrototype());
|
||||
}
|
||||
@@ -1450,7 +1450,7 @@ bool CppQmlTypes::hasModule(const QString &module) const
|
||||
|
||||
QString CppQmlTypes::qualifiedName(const QString &module, const QString &type, ComponentVersion version)
|
||||
{
|
||||
return QString("%1/%2 %3").arg(
|
||||
return QString::fromLatin1("%1/%2 %3").arg(
|
||||
module, type,
|
||||
version.toString());
|
||||
|
||||
@@ -1532,14 +1532,16 @@ void ConvertToNumber::visit(const StringValue *)
|
||||
|
||||
void ConvertToNumber::visit(const ObjectValue *object)
|
||||
{
|
||||
if (const FunctionValue *valueOfMember = value_cast<FunctionValue>(object->lookupMember("valueOf", ContextPtr()))) {
|
||||
if (const FunctionValue *valueOfMember = value_cast<FunctionValue>(
|
||||
object->lookupMember(QLatin1String("valueOf"), ContextPtr()))) {
|
||||
_result = value_cast<NumberValue>(valueOfMember->returnValue());
|
||||
}
|
||||
}
|
||||
|
||||
void ConvertToNumber::visit(const FunctionValue *object)
|
||||
{
|
||||
if (const FunctionValue *valueOfMember = value_cast<FunctionValue>(object->lookupMember("valueOf", ContextPtr()))) {
|
||||
if (const FunctionValue *valueOfMember = value_cast<FunctionValue>(
|
||||
object->lookupMember(QLatin1String("valueOf"), ContextPtr()))) {
|
||||
_result = value_cast<NumberValue>(valueOfMember->returnValue());
|
||||
}
|
||||
}
|
||||
@@ -1593,14 +1595,16 @@ void ConvertToString::visit(const StringValue *value)
|
||||
|
||||
void ConvertToString::visit(const ObjectValue *object)
|
||||
{
|
||||
if (const FunctionValue *toStringMember = value_cast<FunctionValue>(object->lookupMember("toString", ContextPtr()))) {
|
||||
if (const FunctionValue *toStringMember = value_cast<FunctionValue>(
|
||||
object->lookupMember(QLatin1String("toString"), ContextPtr()))) {
|
||||
_result = value_cast<StringValue>(toStringMember->returnValue());
|
||||
}
|
||||
}
|
||||
|
||||
void ConvertToString::visit(const FunctionValue *object)
|
||||
{
|
||||
if (const FunctionValue *toStringMember = value_cast<FunctionValue>(object->lookupMember("toString", ContextPtr()))) {
|
||||
if (const FunctionValue *toStringMember = value_cast<FunctionValue>(
|
||||
object->lookupMember(QLatin1String("toString"), ContextPtr()))) {
|
||||
_result = value_cast<StringValue>(toStringMember->returnValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,8 +334,8 @@ bool LineInfo::readLine()
|
||||
the other way around, as we are parsing backwards.
|
||||
*/
|
||||
yyLinizerState.braceDepth +=
|
||||
yyLinizerState.line.count('}') + yyLinizerState.line.count(']') -
|
||||
yyLinizerState.line.count('{') - yyLinizerState.line.count('[');
|
||||
yyLinizerState.line.count(QLatin1Char('}')) + yyLinizerState.line.count(QLatin1Char(']')) -
|
||||
yyLinizerState.line.count(QLatin1Char('{')) - yyLinizerState.line.count(QLatin1Char('['));
|
||||
|
||||
/*
|
||||
We use a dirty trick for
|
||||
|
||||
@@ -342,7 +342,7 @@ Import LinkPrivate::importNonFile(Document::Ptr doc, const ImportInfo &importInf
|
||||
const QString &packagePath = importInfo.path();
|
||||
// check the filesystem with full version
|
||||
foreach (const QString &importPath, importPaths) {
|
||||
QString libraryPath = QString("%1/%2.%3").arg(importPath, packagePath, version.toString());
|
||||
QString libraryPath = QString::fromLatin1("%1/%2.%3").arg(importPath, packagePath, version.toString());
|
||||
if (importLibrary(doc, libraryPath, &import, importPath)) {
|
||||
importFound = true;
|
||||
break;
|
||||
@@ -351,7 +351,7 @@ Import LinkPrivate::importNonFile(Document::Ptr doc, const ImportInfo &importInf
|
||||
if (!importFound) {
|
||||
// check the filesystem with major version
|
||||
foreach (const QString &importPath, importPaths) {
|
||||
QString libraryPath = QString("%1/%2.%3").arg(importPath, packagePath,
|
||||
QString libraryPath = QString::fromLatin1("%1/%2.%3").arg(importPath, packagePath,
|
||||
QString::number(version.majorVersion()));
|
||||
if (importLibrary(doc, libraryPath, &import, importPath)) {
|
||||
importFound = true;
|
||||
@@ -362,7 +362,7 @@ Import LinkPrivate::importNonFile(Document::Ptr doc, const ImportInfo &importInf
|
||||
if (!importFound) {
|
||||
// check the filesystem with no version
|
||||
foreach (const QString &importPath, importPaths) {
|
||||
QString libraryPath = QString("%1/%2").arg(importPath, packagePath);
|
||||
QString libraryPath = QString::fromLatin1("%1/%2").arg(importPath, packagePath);
|
||||
if (importLibrary(doc, libraryPath, &import, importPath)) {
|
||||
importFound = true;
|
||||
break;
|
||||
|
||||
@@ -194,10 +194,11 @@ PropertyReader::PropertyReader(Document::Ptr doc, AST::UiObjectInitializer *ast)
|
||||
property->statement->firstSourceLocation(),
|
||||
property->statement->lastSourceLocation()));
|
||||
if (isLiteralValue(property)) {
|
||||
m_properties.insert(propertyName + '.' + propertyNamePart2, QVariant(deEscape(stripQuotes(astValue))));
|
||||
m_properties.insert(propertyName + QLatin1Char('.') + propertyNamePart2,
|
||||
QVariant(deEscape(stripQuotes(astValue))));
|
||||
} else if (isEnum(property->statement)) { //enum
|
||||
m_properties.insert(propertyName + '.' + propertyNamePart2, QVariant(astValue));
|
||||
m_bindingOrEnum.append(propertyName + '.' + propertyNamePart2);
|
||||
m_properties.insert(propertyName + QLatin1Char('.') + propertyNamePart2, QVariant(astValue));
|
||||
m_bindingOrEnum.append(propertyName + QLatin1Char('.') + propertyNamePart2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -230,7 +231,7 @@ QLinearGradient PropertyReader::parseGradient(const QString &propertyName, bool
|
||||
initializer->rbraceToken));
|
||||
const QString objectPropertyName = objectBinding->qualifiedId->name.toString();
|
||||
const QString typeName = objectBinding->qualifiedTypeNameId->name.toString();
|
||||
if (objectPropertyName == propertyName && typeName.contains("Gradient")) {
|
||||
if (objectPropertyName == propertyName && typeName.contains(QLatin1String("Gradient"))) {
|
||||
QLinearGradient gradient;
|
||||
QVector<QGradientStop> stops;
|
||||
|
||||
@@ -238,10 +239,10 @@ QLinearGradient PropertyReader::parseGradient(const QString &propertyName, bool
|
||||
UiObjectMember *member = members->member;
|
||||
if (UiObjectDefinition *objectDefinition = cast<UiObjectDefinition *>(member)) {
|
||||
PropertyReader localParser(m_doc, objectDefinition->initializer);
|
||||
if (localParser.hasProperty("color") && localParser.hasProperty("position")) {
|
||||
QColor color = QmlJS::toQColor(localParser.readProperty("color").toString());
|
||||
qreal position = localParser.readProperty("position").toReal();
|
||||
if (localParser.isBindingOrEnum("color") || localParser.isBindingOrEnum("position"))
|
||||
if (localParser.hasProperty(QLatin1String("color")) && localParser.hasProperty(QLatin1String("position"))) {
|
||||
QColor color = QmlJS::toQColor(localParser.readProperty(QLatin1String("color")).toString());
|
||||
qreal position = localParser.readProperty(QLatin1String("position")).toReal();
|
||||
if (localParser.isBindingOrEnum(QLatin1String("color")) || localParser.isBindingOrEnum(QLatin1String("position")))
|
||||
*isBound = true;
|
||||
stops.append( QPair<qreal, QColor>(position, color));
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public:
|
||||
}
|
||||
|
||||
// ensure good ending
|
||||
if (!_result.endsWith("\n\n") || !_line.isEmpty())
|
||||
if (!_result.endsWith(QLatin1String("\n\n")) || !_line.isEmpty())
|
||||
newLine();
|
||||
|
||||
return _result;
|
||||
@@ -287,7 +287,7 @@ protected:
|
||||
while (startSpaces < line->size() && line->at(startSpaces).isSpace())
|
||||
++startSpaces;
|
||||
|
||||
line->replace(0, startSpaces, QString(indent, ' '));
|
||||
line->replace(0, startSpaces, QString(indent, QLatin1Char(' ')));
|
||||
for (int i = 0; i < splits->size(); ++i) {
|
||||
(*splits)[i].offset = splits->at(i).offset - startSpaces + indent;
|
||||
}
|
||||
@@ -313,7 +313,7 @@ protected:
|
||||
continue;
|
||||
|
||||
// the extra space is to avoid // comments sticking to the 0 offset
|
||||
QString indentLine = newContext.join("\n") + QLatin1String("\n ") + restLine;
|
||||
QString indentLine = newContext.join(QLatin1String("\n")) + QLatin1String("\n ") + restLine;
|
||||
int indent = tryIndent(indentLine);
|
||||
|
||||
QList<Split> newSplits = possibleSplits.mid(i + 1);
|
||||
@@ -511,7 +511,7 @@ protected:
|
||||
{
|
||||
out("import ", ast->importToken);
|
||||
if (!ast->fileName.isNull()) {
|
||||
out(QString("\"%1\"").arg(ast->fileName.toString()));
|
||||
out(QString::fromLatin1("\"%1\"").arg(ast->fileName.toString()));
|
||||
} else {
|
||||
accept(ast->importUri);
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ void Rewriter::replaceMemberValue(UiObjectMember *propertyMember,
|
||||
}
|
||||
|
||||
if (needsSemicolon)
|
||||
replacement += ';';
|
||||
replacement += QLatin1Char(';');
|
||||
|
||||
m_changeSet->replace(startOffset, endOffset, replacement);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ bool SimpleAbstractStreamReader::readFromSource(const QString &source)
|
||||
lexer.setCode(source, /*line = */ 1, /*qmlMode = */true);
|
||||
|
||||
if (!parser.parse()) {
|
||||
QString errorMessage = QString("%1:%2: %3").arg(
|
||||
QString errorMessage = QString::fromLatin1("%1:%2: %3").arg(
|
||||
QString::number(parser.errorLineNumber()),
|
||||
QString::number(parser.errorColumnNumber()),
|
||||
parser.errorMessage());
|
||||
@@ -162,7 +162,7 @@ QStringList SimpleAbstractStreamReader::errors() const
|
||||
|
||||
void SimpleAbstractStreamReader::addError(const QString &error, const AST::SourceLocation &sourceLocation)
|
||||
{
|
||||
m_errors << QString("%1:%2: %3\n").arg(
|
||||
m_errors << QString::fromLatin1("%1:%2: %3\n").arg(
|
||||
QString::number(sourceLocation.startLine),
|
||||
QString::number(sourceLocation.startColumn),
|
||||
error);
|
||||
|
||||
@@ -264,7 +264,7 @@ Message::Message(Type type,
|
||||
message = message.arg(arg1, arg2);
|
||||
}
|
||||
if (appendTypeId)
|
||||
message.append(QString(" (M%1)").arg(QString::number(prototype.type)));
|
||||
message.append(QString::fromLatin1(" (M%1)").arg(QString::number(prototype.type)));
|
||||
}
|
||||
|
||||
bool Message::isValid() const
|
||||
@@ -292,7 +292,7 @@ DiagnosticMessage Message::toDiagnosticMessage() const
|
||||
|
||||
QString Message::suppressionString() const
|
||||
{
|
||||
return QString("@disable-check M%1").arg(QString::number(type));
|
||||
return QString::fromLatin1("@disable-check M%1").arg(QString::number(type));
|
||||
}
|
||||
|
||||
QRegExp Message::suppressionPattern()
|
||||
|
||||
@@ -68,7 +68,7 @@ bool TypeDescriptionReader::operator()(
|
||||
lexer.setCode(_source, /*line = */ 1, /*qmlMode = */true);
|
||||
|
||||
if (!parser.parse()) {
|
||||
_errorMessage = QString("%1:%2: %3").arg(
|
||||
_errorMessage = QString::fromLatin1("%1:%2: %3").arg(
|
||||
QString::number(parser.errorLineNumber()),
|
||||
QString::number(parser.errorColumnNumber()),
|
||||
parser.errorMessage());
|
||||
@@ -95,18 +95,18 @@ QString TypeDescriptionReader::warningMessage() const
|
||||
void TypeDescriptionReader::readDocument(UiProgram *ast)
|
||||
{
|
||||
if (!ast) {
|
||||
addError(SourceLocation(), "Could not parse document");
|
||||
addError(SourceLocation(), tr("Could not parse document"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ast->imports || ast->imports->next) {
|
||||
addError(SourceLocation(), "Expected a single import");
|
||||
addError(SourceLocation(), tr("Expected a single import"));
|
||||
return;
|
||||
}
|
||||
|
||||
UiImport *import = ast->imports->import;
|
||||
if (toString(import->importUri) != QLatin1String("QtQuick.tooling")) {
|
||||
addError(import->importToken, "Expected import of QtQuick.tooling");
|
||||
addError(import->importToken, tr("Expected import of QtQuick.tooling"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -118,23 +118,23 @@ void TypeDescriptionReader::readDocument(UiProgram *ast)
|
||||
versionString.mid(dotIdx + 1).toInt());
|
||||
}
|
||||
if (version > ComponentVersion(1, 1)) {
|
||||
addError(import->versionToken, "Expected version 1.1 or lower");
|
||||
addError(import->versionToken, tr("Expected version 1.1 or lower"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ast->members || !ast->members->member || ast->members->next) {
|
||||
addError(SourceLocation(), "Expected document to contain a single object definition");
|
||||
addError(SourceLocation(), tr("Expected document to contain a single object definition"));
|
||||
return;
|
||||
}
|
||||
|
||||
UiObjectDefinition *module = dynamic_cast<UiObjectDefinition *>(ast->members->member);
|
||||
if (!module) {
|
||||
addError(SourceLocation(), "Expected document to contain a single object definition");
|
||||
addError(SourceLocation(), tr("Expected document to contain a single object definition"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (toString(module->qualifiedTypeNameId) != "Module") {
|
||||
addError(SourceLocation(), "Expected document to contain a Module {} member");
|
||||
if (toString(module->qualifiedTypeNameId) != QLatin1String("Module")) {
|
||||
addError(SourceLocation(), tr("Expected document to contain a Module {} member"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -151,8 +151,9 @@ void TypeDescriptionReader::readModule(UiObjectDefinition *ast)
|
||||
if (component)
|
||||
typeName = toString(component->qualifiedTypeNameId);
|
||||
|
||||
if (!component || (typeName != "Component" && typeName != "ModuleApi")) {
|
||||
addWarning(member->firstSourceLocation(), "Expected only 'Component' and 'ModuleApi' object definitions");
|
||||
if (!component || (typeName != QLatin1String("Component") && typeName != QLatin1String("ModuleApi"))) {
|
||||
addWarning(member->firstSourceLocation(),
|
||||
tr("Expected only 'Component' and 'ModuleApi' object definitions"));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -166,7 +167,7 @@ void TypeDescriptionReader::readModule(UiObjectDefinition *ast)
|
||||
|
||||
void TypeDescriptionReader::addError(const SourceLocation &loc, const QString &message)
|
||||
{
|
||||
_errorMessage += QString("%1:%2: %3\n").arg(
|
||||
_errorMessage += QString::fromLatin1("%1:%2: %3\n").arg(
|
||||
QString::number(loc.startLine),
|
||||
QString::number(loc.startColumn),
|
||||
message);
|
||||
@@ -174,7 +175,7 @@ void TypeDescriptionReader::addError(const SourceLocation &loc, const QString &m
|
||||
|
||||
void TypeDescriptionReader::addWarning(const SourceLocation &loc, const QString &message)
|
||||
{
|
||||
_warningMessage += QString("%1:%2: %3\n").arg(
|
||||
_warningMessage += QString::fromLatin1("%1:%2: %3\n").arg(
|
||||
QString::number(loc.startLine),
|
||||
QString::number(loc.startColumn),
|
||||
message);
|
||||
@@ -190,41 +191,41 @@ void TypeDescriptionReader::readComponent(UiObjectDefinition *ast)
|
||||
UiScriptBinding *script = dynamic_cast<UiScriptBinding *>(member);
|
||||
if (component) {
|
||||
QString name = toString(component->qualifiedTypeNameId);
|
||||
if (name == "Property") {
|
||||
if (name == QLatin1String("Property")) {
|
||||
readProperty(component, fmo);
|
||||
} else if (name == "Method" || name == "Signal") {
|
||||
readSignalOrMethod(component, name == "Method", fmo);
|
||||
} else if (name == "Enum") {
|
||||
} else if (name == QLatin1String("Method") || name == QLatin1String("Signal")) {
|
||||
readSignalOrMethod(component, name == QLatin1String("Method"), fmo);
|
||||
} else if (name == QLatin1String("Enum")) {
|
||||
readEnum(component, fmo);
|
||||
} else {
|
||||
addWarning(component->firstSourceLocation(), "Expected only Property, Method, Signal and Enum object definitions");
|
||||
addWarning(component->firstSourceLocation(), tr("Expected only Property, Method, Signal and Enum object definitions"));
|
||||
}
|
||||
} else if (script) {
|
||||
QString name = toString(script->qualifiedId);
|
||||
if (name == "name") {
|
||||
if (name == QLatin1String("name")) {
|
||||
fmo->setClassName(readStringBinding(script));
|
||||
} else if (name == "prototype") {
|
||||
} else if (name == QLatin1String("prototype")) {
|
||||
fmo->setSuperclassName(readStringBinding(script));
|
||||
} else if (name == "defaultProperty") {
|
||||
} else if (name == QLatin1String("defaultProperty")) {
|
||||
fmo->setDefaultPropertyName(readStringBinding(script));
|
||||
} else if (name == "exports") {
|
||||
} else if (name == QLatin1String("exports")) {
|
||||
readExports(script, fmo);
|
||||
} else if (name == "exportMetaObjectRevisions") {
|
||||
} else if (name == QLatin1String("exportMetaObjectRevisions")) {
|
||||
readMetaObjectRevisions(script, fmo);
|
||||
} else if (name == "attachedType") {
|
||||
} else if (name == QLatin1String("attachedType")) {
|
||||
fmo->setAttachedTypeName(readStringBinding(script));
|
||||
} else {
|
||||
addWarning(script->firstSourceLocation(),
|
||||
"Expected only name, prototype, defaultProperty, attachedType, exports "
|
||||
"and exportMetaObjectRevisions script bindings");
|
||||
tr("Expected only name, prototype, defaultProperty, attachedType, exports "
|
||||
"and exportMetaObjectRevisions script bindings"));
|
||||
}
|
||||
} else {
|
||||
addWarning(member->firstSourceLocation(), "Expected only script bindings and object definitions");
|
||||
addWarning(member->firstSourceLocation(), tr("Expected only script bindings and object definitions"));
|
||||
}
|
||||
}
|
||||
|
||||
if (fmo->className().isEmpty()) {
|
||||
addError(ast->firstSourceLocation(), "Component definition is missing a name binding");
|
||||
addError(ast->firstSourceLocation(), tr("Component definition is missing a name binding"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -243,23 +244,23 @@ void TypeDescriptionReader::readModuleApi(UiObjectDefinition *ast)
|
||||
|
||||
if (script) {
|
||||
const QString name = toString(script->qualifiedId);
|
||||
if (name == "uri") {
|
||||
if (name == QLatin1String("uri")) {
|
||||
apiInfo.uri = readStringBinding(script);
|
||||
} else if (name == "version") {
|
||||
} else if (name == QLatin1String("version")) {
|
||||
apiInfo.version = readNumericVersionBinding(script);
|
||||
} else if (name == "name") {
|
||||
} else if (name == QLatin1String("name")) {
|
||||
apiInfo.cppName = readStringBinding(script);
|
||||
} else {
|
||||
addWarning(script->firstSourceLocation(),
|
||||
"Expected only uri, version and name script bindings");
|
||||
tr("Expected only uri, version and name script bindings"));
|
||||
}
|
||||
} else {
|
||||
addWarning(member->firstSourceLocation(), "Expected only script bindings");
|
||||
addWarning(member->firstSourceLocation(), tr("Expected only script bindings"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!apiInfo.version.isValid()) {
|
||||
addError(ast->firstSourceLocation(), "ModuleApi definition has no or invalid 'version' binding");
|
||||
addError(ast->firstSourceLocation(), tr("ModuleApi definition has no or invalid 'version' binding"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -282,30 +283,30 @@ void TypeDescriptionReader::readSignalOrMethod(UiObjectDefinition *ast, bool isM
|
||||
UiScriptBinding *script = dynamic_cast<UiScriptBinding *>(member);
|
||||
if (component) {
|
||||
QString name = toString(component->qualifiedTypeNameId);
|
||||
if (name == "Parameter") {
|
||||
if (name == QLatin1String("Parameter")) {
|
||||
readParameter(component, &fmm);
|
||||
} else {
|
||||
addWarning(component->firstSourceLocation(), "Expected only Parameter object definitions");
|
||||
addWarning(component->firstSourceLocation(), tr("Expected only Parameter object definitions"));
|
||||
}
|
||||
} else if (script) {
|
||||
QString name = toString(script->qualifiedId);
|
||||
if (name == "name") {
|
||||
if (name == QLatin1String("name")) {
|
||||
fmm.setMethodName(readStringBinding(script));
|
||||
} else if (name == "type") {
|
||||
} else if (name == QLatin1String("type")) {
|
||||
fmm.setReturnType(readStringBinding(script));
|
||||
} else if (name == "revision") {
|
||||
} else if (name == QLatin1String("revision")) {
|
||||
fmm.setRevision(readIntBinding(script));
|
||||
} else {
|
||||
addWarning(script->firstSourceLocation(), "Expected only name and type script bindings");
|
||||
addWarning(script->firstSourceLocation(), tr("Expected only name and type script bindings"));
|
||||
}
|
||||
|
||||
} else {
|
||||
addWarning(member->firstSourceLocation(), "Expected only script bindings and object definitions");
|
||||
addWarning(member->firstSourceLocation(), tr("Expected only script bindings and object definitions"));
|
||||
}
|
||||
}
|
||||
|
||||
if (fmm.methodName().isEmpty()) {
|
||||
addError(ast->firstSourceLocation(), "Method or Signal is missing a name script binding");
|
||||
addError(ast->firstSourceLocation(), tr("Method or Signal is missing a name script binding"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -325,30 +326,30 @@ void TypeDescriptionReader::readProperty(UiObjectDefinition *ast, FakeMetaObject
|
||||
UiObjectMember *member = it->member;
|
||||
UiScriptBinding *script = dynamic_cast<UiScriptBinding *>(member);
|
||||
if (!script) {
|
||||
addWarning(member->firstSourceLocation(), "Expected script binding");
|
||||
addWarning(member->firstSourceLocation(), tr("Expected script binding"));
|
||||
continue;
|
||||
}
|
||||
|
||||
QString id = toString(script->qualifiedId);
|
||||
if (id == "name") {
|
||||
if (id == QLatin1String("name")) {
|
||||
name = readStringBinding(script);
|
||||
} else if (id == "type") {
|
||||
} else if (id == QLatin1String("type")) {
|
||||
type = readStringBinding(script);
|
||||
} else if (id == "isPointer") {
|
||||
} else if (id == QLatin1String("isPointer")) {
|
||||
isPointer = readBoolBinding(script);
|
||||
} else if (id == "isReadonly") {
|
||||
} else if (id == QLatin1String("isReadonly")) {
|
||||
isReadonly = readBoolBinding(script);
|
||||
} else if (id == "isList") {
|
||||
} else if (id == QLatin1String("isList")) {
|
||||
isList = readBoolBinding(script);
|
||||
} else if (id == "revision") {
|
||||
} else if (id == QLatin1String("revision")) {
|
||||
revision = readIntBinding(script);
|
||||
} else {
|
||||
addWarning(script->firstSourceLocation(), "Expected only type, name, revision, isPointer, isReadonly and isList script bindings");
|
||||
addWarning(script->firstSourceLocation(), tr("Expected only type, name, revision, isPointer, isReadonly and isList script bindings"));
|
||||
}
|
||||
}
|
||||
|
||||
if (name.isEmpty() || type.isEmpty()) {
|
||||
addError(ast->firstSourceLocation(), "Property object is missing a name or type script binding");
|
||||
addError(ast->firstSourceLocation(), tr("Property object is missing a name or type script binding"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -363,17 +364,17 @@ void TypeDescriptionReader::readEnum(UiObjectDefinition *ast, FakeMetaObject::Pt
|
||||
UiObjectMember *member = it->member;
|
||||
UiScriptBinding *script = dynamic_cast<UiScriptBinding *>(member);
|
||||
if (!script) {
|
||||
addWarning(member->firstSourceLocation(), "Expected script binding");
|
||||
addWarning(member->firstSourceLocation(), tr("Expected script binding"));
|
||||
continue;
|
||||
}
|
||||
|
||||
QString name = toString(script->qualifiedId);
|
||||
if (name == "name") {
|
||||
if (name == QLatin1String("name")) {
|
||||
fme.setName(readStringBinding(script));
|
||||
} else if (name == "values") {
|
||||
} else if (name == QLatin1String("values")) {
|
||||
readEnumValues(script, &fme);
|
||||
} else {
|
||||
addWarning(script->firstSourceLocation(), "Expected only name and values script bindings");
|
||||
addWarning(script->firstSourceLocation(), tr("Expected only name and values script bindings"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,23 +390,23 @@ void TypeDescriptionReader::readParameter(UiObjectDefinition *ast, FakeMetaMetho
|
||||
UiObjectMember *member = it->member;
|
||||
UiScriptBinding *script = dynamic_cast<UiScriptBinding *>(member);
|
||||
if (!script) {
|
||||
addWarning(member->firstSourceLocation(), "Expected script binding");
|
||||
addWarning(member->firstSourceLocation(), tr("Expected script binding"));
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString id = toString(script->qualifiedId);
|
||||
if (id == "name") {
|
||||
if (id == QLatin1String("name")) {
|
||||
name = readStringBinding(script);
|
||||
} else if (id == "type") {
|
||||
} else if (id == QLatin1String("type")) {
|
||||
type = readStringBinding(script);
|
||||
} else if (id == "isPointer") {
|
||||
} else if (id == QLatin1String("isPointer")) {
|
||||
// ### unhandled
|
||||
} else if (id == "isReadonly") {
|
||||
} else if (id == QLatin1String("isReadonly")) {
|
||||
// ### unhandled
|
||||
} else if (id == "isList") {
|
||||
} else if (id == QLatin1String("isList")) {
|
||||
// ### unhandled
|
||||
} else {
|
||||
addWarning(script->firstSourceLocation(), "Expected only name and type script bindings");
|
||||
addWarning(script->firstSourceLocation(), tr("Expected only name and type script bindings"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,19 +416,19 @@ void TypeDescriptionReader::readParameter(UiObjectDefinition *ast, FakeMetaMetho
|
||||
QString TypeDescriptionReader::readStringBinding(UiScriptBinding *ast)
|
||||
{
|
||||
if (!ast || !ast->statement) {
|
||||
addError(ast->colonToken, "Expected string after colon");
|
||||
addError(ast->colonToken, tr("Expected string after colon"));
|
||||
return QString();
|
||||
}
|
||||
|
||||
ExpressionStatement *expStmt = dynamic_cast<ExpressionStatement *>(ast->statement);
|
||||
if (!expStmt) {
|
||||
addError(ast->statement->firstSourceLocation(), "Expected string after colon");
|
||||
addError(ast->statement->firstSourceLocation(), tr("Expected string after colon"));
|
||||
return QString();
|
||||
}
|
||||
|
||||
StringLiteral *stringLit = dynamic_cast<StringLiteral *>(expStmt->expression);
|
||||
if (!stringLit) {
|
||||
addError(expStmt->firstSourceLocation(), "Expected string after colon");
|
||||
addError(expStmt->firstSourceLocation(), tr("Expected string after colon"));
|
||||
return QString();
|
||||
}
|
||||
|
||||
@@ -437,20 +438,20 @@ QString TypeDescriptionReader::readStringBinding(UiScriptBinding *ast)
|
||||
bool TypeDescriptionReader::readBoolBinding(AST::UiScriptBinding *ast)
|
||||
{
|
||||
if (!ast || !ast->statement) {
|
||||
addError(ast->colonToken, "Expected boolean after colon");
|
||||
addError(ast->colonToken, tr("Expected boolean after colon"));
|
||||
return false;
|
||||
}
|
||||
|
||||
ExpressionStatement *expStmt = dynamic_cast<ExpressionStatement *>(ast->statement);
|
||||
if (!expStmt) {
|
||||
addError(ast->statement->firstSourceLocation(), "Expected boolean after colon");
|
||||
addError(ast->statement->firstSourceLocation(), tr("Expected boolean after colon"));
|
||||
return false;
|
||||
}
|
||||
|
||||
TrueLiteral *trueLit = dynamic_cast<TrueLiteral *>(expStmt->expression);
|
||||
FalseLiteral *falseLit = dynamic_cast<FalseLiteral *>(expStmt->expression);
|
||||
if (!trueLit && !falseLit) {
|
||||
addError(expStmt->firstSourceLocation(), "Expected true or false after colon");
|
||||
addError(expStmt->firstSourceLocation(), tr("Expected true or false after colon"));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -460,19 +461,19 @@ bool TypeDescriptionReader::readBoolBinding(AST::UiScriptBinding *ast)
|
||||
double TypeDescriptionReader::readNumericBinding(AST::UiScriptBinding *ast)
|
||||
{
|
||||
if (!ast || !ast->statement) {
|
||||
addError(ast->colonToken, "Expected numeric literal after colon");
|
||||
addError(ast->colonToken, tr("Expected numeric literal after colon"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
ExpressionStatement *expStmt = AST::cast<ExpressionStatement *>(ast->statement);
|
||||
if (!expStmt) {
|
||||
addError(ast->statement->firstSourceLocation(), "Expected numeric literal after colon");
|
||||
addError(ast->statement->firstSourceLocation(), tr("Expected numeric literal after colon"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
NumericLiteral *numericLit = AST::cast<NumericLiteral *>(expStmt->expression);
|
||||
if (!numericLit) {
|
||||
addError(expStmt->firstSourceLocation(), "Expected numeric literal after colon");
|
||||
addError(expStmt->firstSourceLocation(), tr("Expected numeric literal after colon"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -484,19 +485,19 @@ ComponentVersion TypeDescriptionReader::readNumericVersionBinding(UiScriptBindin
|
||||
ComponentVersion invalidVersion;
|
||||
|
||||
if (!ast || !ast->statement) {
|
||||
addError(ast->colonToken, "Expected numeric literal after colon");
|
||||
addError(ast->colonToken, tr("Expected numeric literal after colon"));
|
||||
return invalidVersion;
|
||||
}
|
||||
|
||||
ExpressionStatement *expStmt = AST::cast<ExpressionStatement *>(ast->statement);
|
||||
if (!expStmt) {
|
||||
addError(ast->statement->firstSourceLocation(), "Expected numeric literal after colon");
|
||||
addError(ast->statement->firstSourceLocation(), tr("Expected numeric literal after colon"));
|
||||
return invalidVersion;
|
||||
}
|
||||
|
||||
NumericLiteral *numericLit = AST::cast<NumericLiteral *>(expStmt->expression);
|
||||
if (!numericLit) {
|
||||
addError(expStmt->firstSourceLocation(), "Expected numeric literal after colon");
|
||||
addError(expStmt->firstSourceLocation(), tr("Expected numeric literal after colon"));
|
||||
return invalidVersion;
|
||||
}
|
||||
|
||||
@@ -509,7 +510,7 @@ int TypeDescriptionReader::readIntBinding(AST::UiScriptBinding *ast)
|
||||
int i = static_cast<int>(v);
|
||||
|
||||
if (i != v) {
|
||||
addError(ast->firstSourceLocation(), "Expected integer after colon");
|
||||
addError(ast->firstSourceLocation(), tr("Expected integer after colon"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -519,26 +520,26 @@ int TypeDescriptionReader::readIntBinding(AST::UiScriptBinding *ast)
|
||||
void TypeDescriptionReader::readExports(UiScriptBinding *ast, FakeMetaObject::Ptr fmo)
|
||||
{
|
||||
if (!ast || !ast->statement) {
|
||||
addError(ast->colonToken, "Expected array of strings after colon");
|
||||
addError(ast->colonToken, tr("Expected array of strings after colon"));
|
||||
return;
|
||||
}
|
||||
|
||||
ExpressionStatement *expStmt = dynamic_cast<ExpressionStatement *>(ast->statement);
|
||||
if (!expStmt) {
|
||||
addError(ast->statement->firstSourceLocation(), "Expected array of strings after colon");
|
||||
addError(ast->statement->firstSourceLocation(), tr("Expected array of strings after colon"));
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayLiteral *arrayLit = dynamic_cast<ArrayLiteral *>(expStmt->expression);
|
||||
if (!arrayLit) {
|
||||
addError(expStmt->firstSourceLocation(), "Expected array of strings after colon");
|
||||
addError(expStmt->firstSourceLocation(), tr("Expected array of strings after colon"));
|
||||
return;
|
||||
}
|
||||
|
||||
for (ElementList *it = arrayLit->elements; it; it = it->next) {
|
||||
StringLiteral *stringLit = dynamic_cast<StringLiteral *>(it->expression);
|
||||
if (!stringLit) {
|
||||
addError(arrayLit->firstSourceLocation(), "Expected array literal with only string literal members");
|
||||
addError(arrayLit->firstSourceLocation(), tr("Expected array literal with only string literal members"));
|
||||
return;
|
||||
}
|
||||
QString exp = stringLit->value.toString();
|
||||
@@ -547,7 +548,7 @@ void TypeDescriptionReader::readExports(UiScriptBinding *ast, FakeMetaObject::Pt
|
||||
ComponentVersion version(exp.mid(spaceIdx + 1));
|
||||
|
||||
if (spaceIdx == -1 || !version.isValid()) {
|
||||
addError(stringLit->firstSourceLocation(), "Expected string literal to contain 'Package/Name major.minor' or 'Name major.minor'");
|
||||
addError(stringLit->firstSourceLocation(), tr("Expected string literal to contain 'Package/Name major.minor' or 'Name major.minor'"));
|
||||
continue;
|
||||
}
|
||||
QString package;
|
||||
@@ -563,19 +564,19 @@ void TypeDescriptionReader::readExports(UiScriptBinding *ast, FakeMetaObject::Pt
|
||||
void TypeDescriptionReader::readMetaObjectRevisions(UiScriptBinding *ast, FakeMetaObject::Ptr fmo)
|
||||
{
|
||||
if (!ast || !ast->statement) {
|
||||
addError(ast->colonToken, "Expected array of numbers after colon");
|
||||
addError(ast->colonToken, tr("Expected array of numbers after colon"));
|
||||
return;
|
||||
}
|
||||
|
||||
ExpressionStatement *expStmt = dynamic_cast<ExpressionStatement *>(ast->statement);
|
||||
if (!expStmt) {
|
||||
addError(ast->statement->firstSourceLocation(), "Expected array of numbers after colon");
|
||||
addError(ast->statement->firstSourceLocation(), tr("Expected array of numbers after colon"));
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayLiteral *arrayLit = dynamic_cast<ArrayLiteral *>(expStmt->expression);
|
||||
if (!arrayLit) {
|
||||
addError(expStmt->firstSourceLocation(), "Expected array of numbers after colon");
|
||||
addError(expStmt->firstSourceLocation(), tr("Expected array of numbers after colon"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -584,19 +585,19 @@ void TypeDescriptionReader::readMetaObjectRevisions(UiScriptBinding *ast, FakeMe
|
||||
for (ElementList *it = arrayLit->elements; it; it = it->next, ++exportIndex) {
|
||||
NumericLiteral *numberLit = cast<NumericLiteral *>(it->expression);
|
||||
if (!numberLit) {
|
||||
addError(arrayLit->firstSourceLocation(), "Expected array literal with only number literal members");
|
||||
addError(arrayLit->firstSourceLocation(), tr("Expected array literal with only number literal members"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (exportIndex >= exportCount) {
|
||||
addError(numberLit->firstSourceLocation(), "Meta object revision without matching export");
|
||||
addError(numberLit->firstSourceLocation(), tr("Meta object revision without matching export"));
|
||||
return;
|
||||
}
|
||||
|
||||
const double v = numberLit->value;
|
||||
const int metaObjectRevision = static_cast<int>(v);
|
||||
if (metaObjectRevision != v) {
|
||||
addError(numberLit->firstSourceLocation(), "Expected integer");
|
||||
addError(numberLit->firstSourceLocation(), tr("Expected integer"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -607,19 +608,19 @@ void TypeDescriptionReader::readMetaObjectRevisions(UiScriptBinding *ast, FakeMe
|
||||
void TypeDescriptionReader::readEnumValues(AST::UiScriptBinding *ast, LanguageUtils::FakeMetaEnum *fme)
|
||||
{
|
||||
if (!ast || !ast->statement) {
|
||||
addError(ast->colonToken, "Expected object literal after colon");
|
||||
addError(ast->colonToken, tr("Expected object literal after colon"));
|
||||
return;
|
||||
}
|
||||
|
||||
ExpressionStatement *expStmt = dynamic_cast<ExpressionStatement *>(ast->statement);
|
||||
if (!expStmt) {
|
||||
addError(ast->statement->firstSourceLocation(), "Expected object literal after colon");
|
||||
addError(ast->statement->firstSourceLocation(), tr("Expected object literal after colon"));
|
||||
return;
|
||||
}
|
||||
|
||||
ObjectLiteral *objectLit = dynamic_cast<ObjectLiteral *>(expStmt->expression);
|
||||
if (!objectLit) {
|
||||
addError(expStmt->firstSourceLocation(), "Expected object literal after colon");
|
||||
addError(expStmt->firstSourceLocation(), tr("Expected object literal after colon"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -630,7 +631,7 @@ void TypeDescriptionReader::readEnumValues(AST::UiScriptBinding *ast, LanguageUt
|
||||
if (minus)
|
||||
value = dynamic_cast<NumericLiteral *>(minus->expression);
|
||||
if (!propName || !value) {
|
||||
addError(objectLit->firstSourceLocation(), "Expected object literal to contain only 'string: number' elements");
|
||||
addError(objectLit->firstSourceLocation(), tr("Expected object literal to contain only 'string: number' elements"));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -125,377 +125,377 @@ SharedValueOwner::SharedValueOwner()
|
||||
|
||||
// set up the Global object
|
||||
_globalObject = newObject();
|
||||
_globalObject->setClassName("Global");
|
||||
_globalObject->setClassName(QLatin1String("Global"));
|
||||
|
||||
ObjectValue *objectInstance = newObject();
|
||||
objectInstance->setClassName("Object");
|
||||
objectInstance->setMember("length", numberValue());
|
||||
objectInstance->setClassName(QLatin1String("Object"));
|
||||
objectInstance->setMember(QLatin1String("length"), numberValue());
|
||||
_objectCtor = new Function(this);
|
||||
_objectCtor->setMember("prototype", _objectPrototype);
|
||||
_objectCtor->setMember(QLatin1String("prototype"), _objectPrototype);
|
||||
_objectCtor->setReturnValue(objectInstance);
|
||||
_objectCtor->addArgument(unknownValue(), "value");
|
||||
_objectCtor->addArgument(unknownValue(), QLatin1String("value"));
|
||||
_objectCtor->setOptionalNamedArgumentCount(1);
|
||||
|
||||
FunctionValue *functionInstance = new FunctionValue(this);
|
||||
_functionCtor = new Function(this);
|
||||
_functionCtor->setMember("prototype", _functionPrototype);
|
||||
_functionCtor->setMember(QLatin1String("prototype"), _functionPrototype);
|
||||
_functionCtor->setReturnValue(functionInstance);
|
||||
_functionCtor->setVariadic(true);
|
||||
|
||||
ObjectValue *arrayInstance = newObject(_arrayPrototype);
|
||||
arrayInstance->setClassName("Array");
|
||||
arrayInstance->setMember("length", numberValue());
|
||||
arrayInstance->setClassName(QLatin1String("Array"));
|
||||
arrayInstance->setMember(QLatin1String("length"), numberValue());
|
||||
_arrayCtor = new Function(this);
|
||||
_arrayCtor->setMember("prototype", _arrayPrototype);
|
||||
_arrayCtor->setMember(QLatin1String("prototype"), _arrayPrototype);
|
||||
_arrayCtor->setReturnValue(arrayInstance);
|
||||
_arrayCtor->setVariadic(true);
|
||||
|
||||
ObjectValue *stringInstance = newObject(_stringPrototype);
|
||||
stringInstance->setClassName("String");
|
||||
stringInstance->setMember("length", numberValue());
|
||||
stringInstance->setClassName(QLatin1String("String"));
|
||||
stringInstance->setMember(QLatin1String("length"), numberValue());
|
||||
_stringCtor = new Function(this);
|
||||
_stringCtor->setMember("prototype", _stringPrototype);
|
||||
_stringCtor->setMember(QLatin1String("prototype"), _stringPrototype);
|
||||
_stringCtor->setReturnValue(stringInstance);
|
||||
_stringCtor->addArgument(unknownValue(), "value");
|
||||
_stringCtor->addArgument(unknownValue(), QLatin1String("value"));
|
||||
_stringCtor->setOptionalNamedArgumentCount(1);
|
||||
|
||||
ObjectValue *booleanInstance = newObject(_booleanPrototype);
|
||||
booleanInstance->setClassName("Boolean");
|
||||
booleanInstance->setClassName(QLatin1String("Boolean"));
|
||||
_booleanCtor = new Function(this);
|
||||
_booleanCtor->setMember("prototype", _booleanPrototype);
|
||||
_booleanCtor->setMember(QLatin1String("prototype"), _booleanPrototype);
|
||||
_booleanCtor->setReturnValue(booleanInstance);
|
||||
_booleanCtor->addArgument(unknownValue(), "value");
|
||||
_booleanCtor->addArgument(unknownValue(), QLatin1String("value"));
|
||||
|
||||
ObjectValue *numberInstance = newObject(_numberPrototype);
|
||||
numberInstance->setClassName("Number");
|
||||
numberInstance->setClassName(QLatin1String("Number"));
|
||||
_numberCtor = new Function(this);
|
||||
_numberCtor->setMember("prototype", _numberPrototype);
|
||||
_numberCtor->setMember(QLatin1String("prototype"), _numberPrototype);
|
||||
_numberCtor->setReturnValue(numberInstance);
|
||||
_numberCtor->addArgument(unknownValue(), "value");
|
||||
_numberCtor->addArgument(unknownValue(), QLatin1String("value"));
|
||||
_numberCtor->setOptionalNamedArgumentCount(1);
|
||||
|
||||
ObjectValue *dateInstance = newObject(_datePrototype);
|
||||
dateInstance->setClassName("Date");
|
||||
dateInstance->setClassName(QLatin1String("Date"));
|
||||
_dateCtor = new Function(this);
|
||||
_dateCtor->setMember("prototype", _datePrototype);
|
||||
_dateCtor->setMember(QLatin1String("prototype"), _datePrototype);
|
||||
_dateCtor->setReturnValue(dateInstance);
|
||||
_dateCtor->setVariadic(true);
|
||||
|
||||
ObjectValue *regexpInstance = newObject(_regexpPrototype);
|
||||
regexpInstance->setClassName("RegExp");
|
||||
regexpInstance->setMember("source", stringValue());
|
||||
regexpInstance->setMember("global", booleanValue());
|
||||
regexpInstance->setMember("ignoreCase", booleanValue());
|
||||
regexpInstance->setMember("multiline", booleanValue());
|
||||
regexpInstance->setMember("lastIndex", numberValue());
|
||||
regexpInstance->setClassName(QLatin1String("RegExp"));
|
||||
regexpInstance->setMember(QLatin1String("source"), stringValue());
|
||||
regexpInstance->setMember(QLatin1String("global"), booleanValue());
|
||||
regexpInstance->setMember(QLatin1String("ignoreCase"), booleanValue());
|
||||
regexpInstance->setMember(QLatin1String("multiline"), booleanValue());
|
||||
regexpInstance->setMember(QLatin1String("lastIndex"), numberValue());
|
||||
_regexpCtor = new Function(this);
|
||||
_regexpCtor->setMember("prototype", _regexpPrototype);
|
||||
_regexpCtor->setMember(QLatin1String("prototype"), _regexpPrototype);
|
||||
_regexpCtor->setReturnValue(regexpInstance);
|
||||
_regexpCtor->addArgument(unknownValue(), "pattern");
|
||||
_regexpCtor->addArgument(unknownValue(), "flags");
|
||||
_regexpCtor->addArgument(unknownValue(), QLatin1String("pattern"));
|
||||
_regexpCtor->addArgument(unknownValue(), QLatin1String("flags"));
|
||||
|
||||
addFunction(_objectCtor, "getPrototypeOf", 1);
|
||||
addFunction(_objectCtor, "getOwnPropertyDescriptor", 2);
|
||||
addFunction(_objectCtor, "getOwnPropertyNames", arrayInstance, 1);
|
||||
addFunction(_objectCtor, "create", 1, 1);
|
||||
addFunction(_objectCtor, "defineProperty", 3);
|
||||
addFunction(_objectCtor, "defineProperties", 2);
|
||||
addFunction(_objectCtor, "seal", 1);
|
||||
addFunction(_objectCtor, "freeze", 1);
|
||||
addFunction(_objectCtor, "preventExtensions", 1);
|
||||
addFunction(_objectCtor, "isSealed", booleanValue(), 1);
|
||||
addFunction(_objectCtor, "isFrozen", booleanValue(), 1);
|
||||
addFunction(_objectCtor, "isExtensible", booleanValue(), 1);
|
||||
addFunction(_objectCtor, "keys", arrayInstance, 1);
|
||||
addFunction(_objectCtor, QLatin1String("getPrototypeOf"), 1);
|
||||
addFunction(_objectCtor, QLatin1String("getOwnPropertyDescriptor"), 2);
|
||||
addFunction(_objectCtor, QLatin1String("getOwnPropertyNames"), arrayInstance, 1);
|
||||
addFunction(_objectCtor, QLatin1String("create"), 1, 1);
|
||||
addFunction(_objectCtor, QLatin1String("defineProperty"), 3);
|
||||
addFunction(_objectCtor, QLatin1String("defineProperties"), 2);
|
||||
addFunction(_objectCtor, QLatin1String("seal"), 1);
|
||||
addFunction(_objectCtor, QLatin1String("freeze"), 1);
|
||||
addFunction(_objectCtor, QLatin1String("preventExtensions"), 1);
|
||||
addFunction(_objectCtor, QLatin1String("isSealed"), booleanValue(), 1);
|
||||
addFunction(_objectCtor, QLatin1String("isFrozen"), booleanValue(), 1);
|
||||
addFunction(_objectCtor, QLatin1String("isExtensible"), booleanValue(), 1);
|
||||
addFunction(_objectCtor, QLatin1String("keys"), arrayInstance, 1);
|
||||
|
||||
addFunction(_objectPrototype, "toString", stringValue(), 0);
|
||||
addFunction(_objectPrototype, "toLocaleString", stringValue(), 0);
|
||||
addFunction(_objectPrototype, "valueOf", 0); // ### FIXME it should return thisObject
|
||||
addFunction(_objectPrototype, "hasOwnProperty", booleanValue(), 1);
|
||||
addFunction(_objectPrototype, "isPrototypeOf", booleanValue(), 1);
|
||||
addFunction(_objectPrototype, "propertyIsEnumerable", booleanValue(), 1);
|
||||
addFunction(_objectPrototype, QLatin1String("toString"), stringValue(), 0);
|
||||
addFunction(_objectPrototype, QLatin1String("toLocaleString"), stringValue(), 0);
|
||||
addFunction(_objectPrototype, QLatin1String("valueOf"), 0); // ### FIXME it should return thisObject
|
||||
addFunction(_objectPrototype, QLatin1String("hasOwnProperty"), booleanValue(), 1);
|
||||
addFunction(_objectPrototype, QLatin1String("isPrototypeOf"), booleanValue(), 1);
|
||||
addFunction(_objectPrototype, QLatin1String("propertyIsEnumerable"), booleanValue(), 1);
|
||||
|
||||
// set up the default Function prototype
|
||||
_functionPrototype->setMember("constructor", _functionCtor);
|
||||
addFunction(_functionPrototype, "toString", stringValue(), 0);
|
||||
addFunction(_functionPrototype, "apply", 2);
|
||||
addFunction(_functionPrototype, "call", 1, 0, true);
|
||||
addFunction(_functionPrototype, "bind", 1, 0, true);
|
||||
_functionPrototype->setMember(QLatin1String("constructor"), _functionCtor);
|
||||
addFunction(_functionPrototype, QLatin1String("toString"), stringValue(), 0);
|
||||
addFunction(_functionPrototype, QLatin1String("apply"), 2);
|
||||
addFunction(_functionPrototype, QLatin1String("call"), 1, 0, true);
|
||||
addFunction(_functionPrototype, QLatin1String("bind"), 1, 0, true);
|
||||
|
||||
// set up the default Array prototype
|
||||
addFunction(_arrayCtor, "isArray", booleanValue(), 1);
|
||||
addFunction(_arrayCtor, QLatin1String("isArray"), booleanValue(), 1);
|
||||
|
||||
_arrayPrototype->setMember("constructor", _arrayCtor);
|
||||
addFunction(_arrayPrototype, "toString", stringValue(), 0);
|
||||
addFunction(_arrayPrototype, "toLocalString", stringValue(), 0);
|
||||
addFunction(_arrayPrototype, "concat", 0, 0, true);
|
||||
addFunction(_arrayPrototype, "join", 1);
|
||||
addFunction(_arrayPrototype, "pop", 0);
|
||||
addFunction(_arrayPrototype, "push", 0, 0, true);
|
||||
addFunction(_arrayPrototype, "reverse", 0);
|
||||
addFunction(_arrayPrototype, "shift", 0);
|
||||
addFunction(_arrayPrototype, "slice", 2);
|
||||
addFunction(_arrayPrototype, "sort", 1);
|
||||
addFunction(_arrayPrototype, "splice", 2);
|
||||
addFunction(_arrayPrototype, "unshift", 0, 0, true);
|
||||
addFunction(_arrayPrototype, "indexOf", numberValue(), 2, 1);
|
||||
addFunction(_arrayPrototype, "lastIndexOf", numberValue(), 2, 1);
|
||||
addFunction(_arrayPrototype, "every", 2, 1);
|
||||
addFunction(_arrayPrototype, "some", 2, 1);
|
||||
addFunction(_arrayPrototype, "forEach", 2, 1);
|
||||
addFunction(_arrayPrototype, "map", 2, 1);
|
||||
addFunction(_arrayPrototype, "filter", 2, 1);
|
||||
addFunction(_arrayPrototype, "reduce", 2, 1);
|
||||
addFunction(_arrayPrototype, "reduceRight", 2, 1);
|
||||
_arrayPrototype->setMember(QLatin1String("constructor"), _arrayCtor);
|
||||
addFunction(_arrayPrototype, QLatin1String("toString"), stringValue(), 0);
|
||||
addFunction(_arrayPrototype, QLatin1String("toLocalString"), stringValue(), 0);
|
||||
addFunction(_arrayPrototype, QLatin1String("concat"), 0, 0, true);
|
||||
addFunction(_arrayPrototype, QLatin1String("join"), 1);
|
||||
addFunction(_arrayPrototype, QLatin1String("pop"), 0);
|
||||
addFunction(_arrayPrototype, QLatin1String("push"), 0, 0, true);
|
||||
addFunction(_arrayPrototype, QLatin1String("reverse"), 0);
|
||||
addFunction(_arrayPrototype, QLatin1String("shift"), 0);
|
||||
addFunction(_arrayPrototype, QLatin1String("slice"), 2);
|
||||
addFunction(_arrayPrototype, QLatin1String("sort"), 1);
|
||||
addFunction(_arrayPrototype, QLatin1String("splice"), 2);
|
||||
addFunction(_arrayPrototype, QLatin1String("unshift"), 0, 0, true);
|
||||
addFunction(_arrayPrototype, QLatin1String("indexOf"), numberValue(), 2, 1);
|
||||
addFunction(_arrayPrototype, QLatin1String("lastIndexOf"), numberValue(), 2, 1);
|
||||
addFunction(_arrayPrototype, QLatin1String("every"), 2, 1);
|
||||
addFunction(_arrayPrototype, QLatin1String("some"), 2, 1);
|
||||
addFunction(_arrayPrototype, QLatin1String("forEach"), 2, 1);
|
||||
addFunction(_arrayPrototype, QLatin1String("map"), 2, 1);
|
||||
addFunction(_arrayPrototype, QLatin1String("filter"), 2, 1);
|
||||
addFunction(_arrayPrototype, QLatin1String("reduce"), 2, 1);
|
||||
addFunction(_arrayPrototype, QLatin1String("reduceRight"), 2, 1);
|
||||
|
||||
// set up the default String prototype
|
||||
addFunction(_stringCtor, "fromCharCode", stringValue(), 0, 0, true);
|
||||
addFunction(_stringCtor, QLatin1String("fromCharCode"), stringValue(), 0, 0, true);
|
||||
|
||||
_stringPrototype->setMember("constructor", _stringCtor);
|
||||
addFunction(_stringPrototype, "toString", stringValue(), 0);
|
||||
addFunction(_stringPrototype, "valueOf", stringValue(), 0);
|
||||
addFunction(_stringPrototype, "charAt", stringValue(), 1);
|
||||
addFunction(_stringPrototype, "charCodeAt", stringValue(), 1);
|
||||
addFunction(_stringPrototype, "concat", stringValue(), 0, 0, true);
|
||||
addFunction(_stringPrototype, "indexOf", numberValue(), 2);
|
||||
addFunction(_stringPrototype, "lastIndexOf", numberValue(), 2);
|
||||
addFunction(_stringPrototype, "localeCompare", booleanValue(), 1);
|
||||
addFunction(_stringPrototype, "match", arrayInstance, 1);
|
||||
addFunction(_stringPrototype, "replace", stringValue(), 2);
|
||||
addFunction(_stringPrototype, "search", numberValue(), 1);
|
||||
addFunction(_stringPrototype, "slice", stringValue(), 2);
|
||||
addFunction(_stringPrototype, "split", arrayInstance, 1);
|
||||
addFunction(_stringPrototype, "substring", stringValue(), 2);
|
||||
addFunction(_stringPrototype, "toLowerCase", stringValue(), 0);
|
||||
addFunction(_stringPrototype, "toLocaleLowerCase", stringValue(), 0);
|
||||
addFunction(_stringPrototype, "toUpperCase", stringValue(), 0);
|
||||
addFunction(_stringPrototype, "toLocaleUpperCase", stringValue(), 0);
|
||||
addFunction(_stringPrototype, "trim", stringValue(), 0);
|
||||
_stringPrototype->setMember(QLatin1String("constructor"), _stringCtor);
|
||||
addFunction(_stringPrototype, QLatin1String("toString"), stringValue(), 0);
|
||||
addFunction(_stringPrototype, QLatin1String("valueOf"), stringValue(), 0);
|
||||
addFunction(_stringPrototype, QLatin1String("charAt"), stringValue(), 1);
|
||||
addFunction(_stringPrototype, QLatin1String("charCodeAt"), stringValue(), 1);
|
||||
addFunction(_stringPrototype, QLatin1String("concat"), stringValue(), 0, 0, true);
|
||||
addFunction(_stringPrototype, QLatin1String("indexOf"), numberValue(), 2);
|
||||
addFunction(_stringPrototype, QLatin1String("lastIndexOf"), numberValue(), 2);
|
||||
addFunction(_stringPrototype, QLatin1String("localeCompare"), booleanValue(), 1);
|
||||
addFunction(_stringPrototype, QLatin1String("match"), arrayInstance, 1);
|
||||
addFunction(_stringPrototype, QLatin1String("replace"), stringValue(), 2);
|
||||
addFunction(_stringPrototype, QLatin1String("search"), numberValue(), 1);
|
||||
addFunction(_stringPrototype, QLatin1String("slice"), stringValue(), 2);
|
||||
addFunction(_stringPrototype, QLatin1String("split"), arrayInstance, 1);
|
||||
addFunction(_stringPrototype, QLatin1String("substring"), stringValue(), 2);
|
||||
addFunction(_stringPrototype, QLatin1String("toLowerCase"), stringValue(), 0);
|
||||
addFunction(_stringPrototype, QLatin1String("toLocaleLowerCase"), stringValue(), 0);
|
||||
addFunction(_stringPrototype, QLatin1String("toUpperCase"), stringValue(), 0);
|
||||
addFunction(_stringPrototype, QLatin1String("toLocaleUpperCase"), stringValue(), 0);
|
||||
addFunction(_stringPrototype, QLatin1String("trim"), stringValue(), 0);
|
||||
|
||||
// set up the default Boolean prototype
|
||||
addFunction(_booleanCtor, "fromCharCode", 0);
|
||||
addFunction(_booleanCtor, QLatin1String("fromCharCode"), 0);
|
||||
|
||||
_booleanPrototype->setMember("constructor", _booleanCtor);
|
||||
addFunction(_booleanPrototype, "toString", stringValue(), 0);
|
||||
addFunction(_booleanPrototype, "valueOf", booleanValue(), 0);
|
||||
_booleanPrototype->setMember(QLatin1String("constructor"), _booleanCtor);
|
||||
addFunction(_booleanPrototype, QLatin1String("toString"), stringValue(), 0);
|
||||
addFunction(_booleanPrototype, QLatin1String("valueOf"), booleanValue(), 0);
|
||||
|
||||
// set up the default Number prototype
|
||||
_numberCtor->setMember("MAX_VALUE", numberValue());
|
||||
_numberCtor->setMember("MIN_VALUE", numberValue());
|
||||
_numberCtor->setMember("NaN", numberValue());
|
||||
_numberCtor->setMember("NEGATIVE_INFINITY", numberValue());
|
||||
_numberCtor->setMember("POSITIVE_INFINITY", numberValue());
|
||||
_numberCtor->setMember(QLatin1String("MAX_VALUE"), numberValue());
|
||||
_numberCtor->setMember(QLatin1String("MIN_VALUE"), numberValue());
|
||||
_numberCtor->setMember(QLatin1String("NaN"), numberValue());
|
||||
_numberCtor->setMember(QLatin1String("NEGATIVE_INFINITY"), numberValue());
|
||||
_numberCtor->setMember(QLatin1String("POSITIVE_INFINITY"), numberValue());
|
||||
|
||||
addFunction(_numberCtor, "fromCharCode", 0);
|
||||
addFunction(_numberCtor, QLatin1String("fromCharCode"), 0);
|
||||
|
||||
_numberPrototype->setMember("constructor", _numberCtor);
|
||||
addFunction(_numberPrototype, "toString", stringValue(), 1, 1);
|
||||
addFunction(_numberPrototype, "toLocaleString", stringValue(), 0);
|
||||
addFunction(_numberPrototype, "valueOf", numberValue(), 0);
|
||||
addFunction(_numberPrototype, "toFixed", numberValue(), 1);
|
||||
addFunction(_numberPrototype, "toExponential", numberValue(), 1);
|
||||
addFunction(_numberPrototype, "toPrecision", numberValue(), 1);
|
||||
_numberPrototype->setMember(QLatin1String("constructor"), _numberCtor);
|
||||
addFunction(_numberPrototype, QLatin1String("toString"), stringValue(), 1, 1);
|
||||
addFunction(_numberPrototype, QLatin1String("toLocaleString"), stringValue(), 0);
|
||||
addFunction(_numberPrototype, QLatin1String("valueOf"), numberValue(), 0);
|
||||
addFunction(_numberPrototype, QLatin1String("toFixed"), numberValue(), 1);
|
||||
addFunction(_numberPrototype, QLatin1String("toExponential"), numberValue(), 1);
|
||||
addFunction(_numberPrototype, QLatin1String("toPrecision"), numberValue(), 1);
|
||||
|
||||
// set up the Math object
|
||||
_mathObject = newObject();
|
||||
_mathObject->setMember("E", numberValue());
|
||||
_mathObject->setMember("LN10", numberValue());
|
||||
_mathObject->setMember("LN2", numberValue());
|
||||
_mathObject->setMember("LOG2E", numberValue());
|
||||
_mathObject->setMember("LOG10E", numberValue());
|
||||
_mathObject->setMember("PI", numberValue());
|
||||
_mathObject->setMember("SQRT1_2", numberValue());
|
||||
_mathObject->setMember("SQRT2", numberValue());
|
||||
_mathObject->setMember(QLatin1String("E"), numberValue());
|
||||
_mathObject->setMember(QLatin1String("LN10"), numberValue());
|
||||
_mathObject->setMember(QLatin1String("LN2"), numberValue());
|
||||
_mathObject->setMember(QLatin1String("LOG2E"), numberValue());
|
||||
_mathObject->setMember(QLatin1String("LOG10E"), numberValue());
|
||||
_mathObject->setMember(QLatin1String("PI"), numberValue());
|
||||
_mathObject->setMember(QLatin1String("SQRT1_2"), numberValue());
|
||||
_mathObject->setMember(QLatin1String("SQRT2"), numberValue());
|
||||
|
||||
addFunction(_mathObject, "abs", numberValue(), 1);
|
||||
addFunction(_mathObject, "acos", numberValue(), 1);
|
||||
addFunction(_mathObject, "asin", numberValue(), 1);
|
||||
addFunction(_mathObject, "atan", numberValue(), 1);
|
||||
addFunction(_mathObject, "atan2", numberValue(), 2);
|
||||
addFunction(_mathObject, "ceil", numberValue(), 1);
|
||||
addFunction(_mathObject, "cos", numberValue(), 1);
|
||||
addFunction(_mathObject, "exp", numberValue(), 1);
|
||||
addFunction(_mathObject, "floor", numberValue(), 1);
|
||||
addFunction(_mathObject, "log", numberValue(), 1);
|
||||
addFunction(_mathObject, "max", numberValue(), 0, 0, true);
|
||||
addFunction(_mathObject, "min", numberValue(), 0, 0, true);
|
||||
addFunction(_mathObject, "pow", numberValue(), 2);
|
||||
addFunction(_mathObject, "random", numberValue(), 1);
|
||||
addFunction(_mathObject, "round", numberValue(), 1);
|
||||
addFunction(_mathObject, "sin", numberValue(), 1);
|
||||
addFunction(_mathObject, "sqrt", numberValue(), 1);
|
||||
addFunction(_mathObject, "tan", numberValue(), 1);
|
||||
addFunction(_mathObject, QLatin1String("abs"), numberValue(), 1);
|
||||
addFunction(_mathObject, QLatin1String("acos"), numberValue(), 1);
|
||||
addFunction(_mathObject, QLatin1String("asin"), numberValue(), 1);
|
||||
addFunction(_mathObject, QLatin1String("atan"), numberValue(), 1);
|
||||
addFunction(_mathObject, QLatin1String("atan2"), numberValue(), 2);
|
||||
addFunction(_mathObject, QLatin1String("ceil"), numberValue(), 1);
|
||||
addFunction(_mathObject, QLatin1String("cos"), numberValue(), 1);
|
||||
addFunction(_mathObject, QLatin1String("exp"), numberValue(), 1);
|
||||
addFunction(_mathObject, QLatin1String("floor"), numberValue(), 1);
|
||||
addFunction(_mathObject, QLatin1String("log"), numberValue(), 1);
|
||||
addFunction(_mathObject, QLatin1String("max"), numberValue(), 0, 0, true);
|
||||
addFunction(_mathObject, QLatin1String("min"), numberValue(), 0, 0, true);
|
||||
addFunction(_mathObject, QLatin1String("pow"), numberValue(), 2);
|
||||
addFunction(_mathObject, QLatin1String("random"), numberValue(), 1);
|
||||
addFunction(_mathObject, QLatin1String("round"), numberValue(), 1);
|
||||
addFunction(_mathObject, QLatin1String("sin"), numberValue(), 1);
|
||||
addFunction(_mathObject, QLatin1String("sqrt"), numberValue(), 1);
|
||||
addFunction(_mathObject, QLatin1String("tan"), numberValue(), 1);
|
||||
|
||||
// set up the default Boolean prototype
|
||||
addFunction(_dateCtor, "parse", numberValue(), 1);
|
||||
addFunction(_dateCtor, "UTC", numberValue(), 7, 5);
|
||||
addFunction(_dateCtor, "now", numberValue(), 0);
|
||||
addFunction(_dateCtor, QLatin1String("parse"), numberValue(), 1);
|
||||
addFunction(_dateCtor, QLatin1String("UTC"), numberValue(), 7, 5);
|
||||
addFunction(_dateCtor, QLatin1String("now"), numberValue(), 0);
|
||||
|
||||
_datePrototype->setMember("constructor", _dateCtor);
|
||||
addFunction(_datePrototype, "toString", stringValue(), 0);
|
||||
addFunction(_datePrototype, "toDateString", stringValue(), 0);
|
||||
addFunction(_datePrototype, "toTimeString", stringValue(), 0);
|
||||
addFunction(_datePrototype, "toLocaleString", stringValue(), 0);
|
||||
addFunction(_datePrototype, "toLocaleDateString", stringValue(), 0);
|
||||
addFunction(_datePrototype, "toLocaleTimeString", stringValue(), 0);
|
||||
addFunction(_datePrototype, "valueOf", numberValue(), 0);
|
||||
addFunction(_datePrototype, "getTime", numberValue(), 0);
|
||||
addFunction(_datePrototype, "getFullYear", numberValue(), 0);
|
||||
addFunction(_datePrototype, "getUTCFullYear", numberValue(), 0);
|
||||
addFunction(_datePrototype, "getMonth", numberValue(), 0);
|
||||
addFunction(_datePrototype, "getUTCMonth", numberValue(), 0);
|
||||
addFunction(_datePrototype, "getDate", numberValue(), 0);
|
||||
addFunction(_datePrototype, "getUTCDate", numberValue(), 0);
|
||||
addFunction(_datePrototype, "getHours", numberValue(), 0);
|
||||
addFunction(_datePrototype, "getUTCHours", numberValue(), 0);
|
||||
addFunction(_datePrototype, "getMinutes", numberValue(), 0);
|
||||
addFunction(_datePrototype, "getUTCMinutes", numberValue(), 0);
|
||||
addFunction(_datePrototype, "getSeconds", numberValue(), 0);
|
||||
addFunction(_datePrototype, "getUTCSeconds", numberValue(), 0);
|
||||
addFunction(_datePrototype, "getMilliseconds", numberValue(), 0);
|
||||
addFunction(_datePrototype, "getUTCMilliseconds", numberValue(), 0);
|
||||
addFunction(_datePrototype, "getTimezoneOffset", numberValue(), 0);
|
||||
addFunction(_datePrototype, "setTime", 1);
|
||||
addFunction(_datePrototype, "setMilliseconds", 1);
|
||||
addFunction(_datePrototype, "setUTCMilliseconds", 1);
|
||||
addFunction(_datePrototype, "setSeconds", 2, 1);
|
||||
addFunction(_datePrototype, "setUTCSeconds", 2, 1);
|
||||
addFunction(_datePrototype, "setMinutes", 3, 2);
|
||||
addFunction(_datePrototype, "setUTCMinutes", 3, 2);
|
||||
addFunction(_datePrototype, "setHours", 4, 3);
|
||||
addFunction(_datePrototype, "setUTCHours", 4, 3);
|
||||
addFunction(_datePrototype, "setDate", 1);
|
||||
addFunction(_datePrototype, "setUTCDate", 1);
|
||||
addFunction(_datePrototype, "setMonth", 2, 1);
|
||||
addFunction(_datePrototype, "setUTCMonth", 2, 1);
|
||||
addFunction(_datePrototype, "setFullYear", 3, 2);
|
||||
addFunction(_datePrototype, "setUTCFullYear", 3, 2);
|
||||
addFunction(_datePrototype, "toUTCString", stringValue(), 0);
|
||||
addFunction(_datePrototype, "toISOString", stringValue(), 0);
|
||||
addFunction(_datePrototype, "toJSON", stringValue(), 1);
|
||||
_datePrototype->setMember(QLatin1String("constructor"), _dateCtor);
|
||||
addFunction(_datePrototype, QLatin1String("toString"), stringValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("toDateString"), stringValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("toTimeString"), stringValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("toLocaleString"), stringValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("toLocaleDateString"), stringValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("toLocaleTimeString"), stringValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("valueOf"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("getTime"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("getFullYear"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("getUTCFullYear"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("getMonth"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("getUTCMonth"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("getDate"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("getUTCDate"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("getHours"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("getUTCHours"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("getMinutes"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("getUTCMinutes"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("getSeconds"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("getUTCSeconds"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("getMilliseconds"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("getUTCMilliseconds"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("getTimezoneOffset"), numberValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("setTime"), 1);
|
||||
addFunction(_datePrototype, QLatin1String("setMilliseconds"), 1);
|
||||
addFunction(_datePrototype, QLatin1String("setUTCMilliseconds"), 1);
|
||||
addFunction(_datePrototype, QLatin1String("setSeconds"), 2, 1);
|
||||
addFunction(_datePrototype, QLatin1String("setUTCSeconds"), 2, 1);
|
||||
addFunction(_datePrototype, QLatin1String("setMinutes"), 3, 2);
|
||||
addFunction(_datePrototype, QLatin1String("setUTCMinutes"), 3, 2);
|
||||
addFunction(_datePrototype, QLatin1String("setHours"), 4, 3);
|
||||
addFunction(_datePrototype, QLatin1String("setUTCHours"), 4, 3);
|
||||
addFunction(_datePrototype, QLatin1String("setDate"), 1);
|
||||
addFunction(_datePrototype, QLatin1String("setUTCDate"), 1);
|
||||
addFunction(_datePrototype, QLatin1String("setMonth"), 2, 1);
|
||||
addFunction(_datePrototype, QLatin1String("setUTCMonth"), 2, 1);
|
||||
addFunction(_datePrototype, QLatin1String("setFullYear"), 3, 2);
|
||||
addFunction(_datePrototype, QLatin1String("setUTCFullYear"), 3, 2);
|
||||
addFunction(_datePrototype, QLatin1String("toUTCString"), stringValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("toISOString"), stringValue(), 0);
|
||||
addFunction(_datePrototype, QLatin1String("toJSON"), stringValue(), 1);
|
||||
|
||||
// set up the default Boolean prototype
|
||||
_regexpPrototype->setMember("constructor", _regexpCtor);
|
||||
addFunction(_regexpPrototype, "exec", arrayInstance, 1);
|
||||
addFunction(_regexpPrototype, "test", booleanValue(), 1);
|
||||
addFunction(_regexpPrototype, "toString", stringValue(), 0);
|
||||
_regexpPrototype->setMember(QLatin1String("constructor"), _regexpCtor);
|
||||
addFunction(_regexpPrototype, QLatin1String("exec"), arrayInstance, 1);
|
||||
addFunction(_regexpPrototype, QLatin1String("test"), booleanValue(), 1);
|
||||
addFunction(_regexpPrototype, QLatin1String("toString"), stringValue(), 0);
|
||||
|
||||
// fill the Global object
|
||||
_globalObject->setMember("Math", _mathObject);
|
||||
_globalObject->setMember("Object", objectCtor());
|
||||
_globalObject->setMember("Function", functionCtor());
|
||||
_globalObject->setMember("Array", arrayCtor());
|
||||
_globalObject->setMember("String", stringCtor());
|
||||
_globalObject->setMember("Boolean", booleanCtor());
|
||||
_globalObject->setMember("Number", numberCtor());
|
||||
_globalObject->setMember("Date", dateCtor());
|
||||
_globalObject->setMember("RegExp", regexpCtor());
|
||||
_globalObject->setMember(QLatin1String("Math"), _mathObject);
|
||||
_globalObject->setMember(QLatin1String("Object"), objectCtor());
|
||||
_globalObject->setMember(QLatin1String("Function"), functionCtor());
|
||||
_globalObject->setMember(QLatin1String("Array"), arrayCtor());
|
||||
_globalObject->setMember(QLatin1String("String"), stringCtor());
|
||||
_globalObject->setMember(QLatin1String("Boolean"), booleanCtor());
|
||||
_globalObject->setMember(QLatin1String("Number"), numberCtor());
|
||||
_globalObject->setMember(QLatin1String("Date"), dateCtor());
|
||||
_globalObject->setMember(QLatin1String("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(unknownValue(), "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", unknownValue());
|
||||
xmlHttpRequest->setMember(QLatin1String("onreadystatechange"), functionPrototype());
|
||||
xmlHttpRequest->setMember(QLatin1String("UNSENT"), numberValue());
|
||||
xmlHttpRequest->setMember(QLatin1String("OPENED"), numberValue());
|
||||
xmlHttpRequest->setMember(QLatin1String("HEADERS_RECEIVED"), numberValue());
|
||||
xmlHttpRequest->setMember(QLatin1String("LOADING"), numberValue());
|
||||
xmlHttpRequest->setMember(QLatin1String("DONE"), numberValue());
|
||||
xmlHttpRequest->setMember(QLatin1String("readyState"), numberValue());
|
||||
f = addFunction(xmlHttpRequest, QLatin1String("open"));
|
||||
f->addArgument(stringValue(), QLatin1String("method"));
|
||||
f->addArgument(stringValue(), QLatin1String("url"));
|
||||
f->addArgument(booleanValue(), QLatin1String("async"));
|
||||
f->addArgument(stringValue(), QLatin1String("user"));
|
||||
f->addArgument(stringValue(), QLatin1String("password"));
|
||||
f = addFunction(xmlHttpRequest, QLatin1String("setRequestHeader"));
|
||||
f->addArgument(stringValue(), QLatin1String("header"));
|
||||
f->addArgument(stringValue(), QLatin1String("value"));
|
||||
f = addFunction(xmlHttpRequest, QLatin1String("send"));
|
||||
f->addArgument(unknownValue(), QLatin1String("data"));
|
||||
f = addFunction(xmlHttpRequest, QLatin1String("abort"));
|
||||
xmlHttpRequest->setMember(QLatin1String("status"), numberValue());
|
||||
xmlHttpRequest->setMember(QLatin1String("statusText"), stringValue());
|
||||
f = addFunction(xmlHttpRequest, QLatin1String("getResponseHeader"));
|
||||
f->addArgument(stringValue(), QLatin1String("header"));
|
||||
f = addFunction(xmlHttpRequest, QLatin1String("getAllResponseHeaders"));
|
||||
xmlHttpRequest->setMember(QLatin1String("responseText"), stringValue());
|
||||
xmlHttpRequest->setMember(QLatin1String("responseXML"), unknownValue());
|
||||
|
||||
f = addFunction(_globalObject, "XMLHttpRequest", xmlHttpRequest);
|
||||
f->setMember("prototype", xmlHttpRequest);
|
||||
xmlHttpRequest->setMember("constructor", f);
|
||||
f = addFunction(_globalObject, QLatin1String("XMLHttpRequest"), xmlHttpRequest);
|
||||
f->setMember(QLatin1String("prototype"), xmlHttpRequest);
|
||||
xmlHttpRequest->setMember(QLatin1String("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(db, QLatin1String("transaction"));
|
||||
f->addArgument(functionPrototype(), QLatin1String("callback"));
|
||||
f = addFunction(db, QLatin1String("readTransaction"));
|
||||
f->addArgument(functionPrototype(), QLatin1String("callback"));
|
||||
f->setMember(QLatin1String("version"), stringValue());
|
||||
f = addFunction(db, QLatin1String("changeVersion"));
|
||||
f->addArgument(stringValue(), QLatin1String("oldVersion"));
|
||||
f->addArgument(stringValue(), QLatin1String("newVersion"));
|
||||
f->addArgument(functionPrototype(), QLatin1String("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");
|
||||
f = addFunction(_globalObject, QLatin1String("openDatabaseSync"), db);
|
||||
f->addArgument(stringValue(), QLatin1String("name"));
|
||||
f->addArgument(stringValue(), QLatin1String("version"));
|
||||
f->addArgument(stringValue(), QLatin1String("displayName"));
|
||||
f->addArgument(numberValue(), QLatin1String("estimatedSize"));
|
||||
f->addArgument(functionPrototype(), QLatin1String("callback"));
|
||||
|
||||
// JSON
|
||||
ObjectValue *json = newObject();
|
||||
f = addFunction(json, "parse", objectPrototype());
|
||||
f->addArgument(stringValue(), "text");
|
||||
f->addArgument(functionPrototype(), "reviver");
|
||||
f = addFunction(json, QLatin1String("parse"), objectPrototype());
|
||||
f->addArgument(stringValue(), QLatin1String("text"));
|
||||
f->addArgument(functionPrototype(), QLatin1String("reviver"));
|
||||
f->setOptionalNamedArgumentCount(1);
|
||||
f = addFunction(json, "stringify", stringValue());
|
||||
f->addArgument(unknownValue(), "value");
|
||||
f->addArgument(unknownValue(), "replacer");
|
||||
f->addArgument(unknownValue(), "space");
|
||||
f = addFunction(json, QLatin1String("stringify"), stringValue());
|
||||
f->addArgument(unknownValue(), QLatin1String("value"));
|
||||
f->addArgument(unknownValue(), QLatin1String("replacer"));
|
||||
f->addArgument(unknownValue(), QLatin1String("space"));
|
||||
f->setOptionalNamedArgumentCount(2);
|
||||
_globalObject->setMember("JSON", json);
|
||||
_globalObject->setMember(QLatin1String("JSON"), json);
|
||||
|
||||
// QML objects
|
||||
_qmlFontObject = newObject(/*prototype =*/ 0);
|
||||
_qmlFontObject->setClassName(QLatin1String("Font"));
|
||||
_qmlFontObject->setMember("family", stringValue());
|
||||
_qmlFontObject->setMember("weight", unknownValue()); // ### make me an object
|
||||
_qmlFontObject->setMember("capitalization", unknownValue()); // ### make me an object
|
||||
_qmlFontObject->setMember("bold", booleanValue());
|
||||
_qmlFontObject->setMember("italic", booleanValue());
|
||||
_qmlFontObject->setMember("underline", booleanValue());
|
||||
_qmlFontObject->setMember("overline", booleanValue());
|
||||
_qmlFontObject->setMember("strikeout", booleanValue());
|
||||
_qmlFontObject->setMember("pointSize", intValue());
|
||||
_qmlFontObject->setMember("pixelSize", intValue());
|
||||
_qmlFontObject->setMember("letterSpacing", realValue());
|
||||
_qmlFontObject->setMember("wordSpacing", realValue());
|
||||
_qmlFontObject->setMember(QLatin1String("family"), stringValue());
|
||||
_qmlFontObject->setMember(QLatin1String("weight"), unknownValue()); // ### make me an object
|
||||
_qmlFontObject->setMember(QLatin1String("capitalization"), unknownValue()); // ### make me an object
|
||||
_qmlFontObject->setMember(QLatin1String("bold"), booleanValue());
|
||||
_qmlFontObject->setMember(QLatin1String("italic"), booleanValue());
|
||||
_qmlFontObject->setMember(QLatin1String("underline"), booleanValue());
|
||||
_qmlFontObject->setMember(QLatin1String("overline"), booleanValue());
|
||||
_qmlFontObject->setMember(QLatin1String("strikeout"), booleanValue());
|
||||
_qmlFontObject->setMember(QLatin1String("pointSize"), intValue());
|
||||
_qmlFontObject->setMember(QLatin1String("pixelSize"), intValue());
|
||||
_qmlFontObject->setMember(QLatin1String("letterSpacing"), realValue());
|
||||
_qmlFontObject->setMember(QLatin1String("wordSpacing"), realValue());
|
||||
|
||||
_qmlPointObject = newObject(/*prototype =*/ 0);
|
||||
_qmlPointObject->setClassName(QLatin1String("Point"));
|
||||
_qmlPointObject->setMember("x", numberValue());
|
||||
_qmlPointObject->setMember("y", numberValue());
|
||||
_qmlPointObject->setMember(QLatin1String("x"), numberValue());
|
||||
_qmlPointObject->setMember(QLatin1String("y"), numberValue());
|
||||
|
||||
_qmlSizeObject = newObject(/*prototype =*/ 0);
|
||||
_qmlSizeObject->setClassName(QLatin1String("Size"));
|
||||
_qmlSizeObject->setMember("width", numberValue());
|
||||
_qmlSizeObject->setMember("height", numberValue());
|
||||
_qmlSizeObject->setMember(QLatin1String("width"), numberValue());
|
||||
_qmlSizeObject->setMember(QLatin1String("height"), numberValue());
|
||||
|
||||
_qmlRectObject = newObject(/*prototype =*/ 0);
|
||||
_qmlRectObject->setClassName("Rect");
|
||||
_qmlRectObject->setMember("x", numberValue());
|
||||
_qmlRectObject->setMember("y", numberValue());
|
||||
_qmlRectObject->setMember("width", numberValue());
|
||||
_qmlRectObject->setMember("height", numberValue());
|
||||
_qmlRectObject->setClassName(QLatin1String("Rect"));
|
||||
_qmlRectObject->setMember(QLatin1String("x"), numberValue());
|
||||
_qmlRectObject->setMember(QLatin1String("y"), numberValue());
|
||||
_qmlRectObject->setMember(QLatin1String("width"), numberValue());
|
||||
_qmlRectObject->setMember(QLatin1String("height"), numberValue());
|
||||
|
||||
_qmlVector3DObject = newObject(/*prototype =*/ 0);
|
||||
_qmlVector3DObject->setClassName(QLatin1String("Vector3D"));
|
||||
_qmlVector3DObject->setMember("x", realValue());
|
||||
_qmlVector3DObject->setMember("y", realValue());
|
||||
_qmlVector3DObject->setMember("z", realValue());
|
||||
_qmlVector3DObject->setMember(QLatin1String("x"), realValue());
|
||||
_qmlVector3DObject->setMember(QLatin1String("y"), realValue());
|
||||
_qmlVector3DObject->setMember(QLatin1String("z"), realValue());
|
||||
|
||||
// global Qt object, in alphabetic order
|
||||
_qtObject = newObject(new QtObjectPrototypeReference(this));
|
||||
|
||||
Reference in New Issue
Block a user