Ejemplo n.º 1
0
// ### merge with Evaluator::handleEvaluationError
static ErrorInfo errorInfoFromScriptValue(const QScriptValue &value, const QString &filePath)
{
    if (!value.isError())
        return ErrorInfo(value.toString(), CodeLocation(filePath));

    return ErrorInfo(value.property(QStringLiteral("message")).toString(),
                     CodeLocation(value.property(QStringLiteral("fileName")).toString(),
                                  value.property(QStringLiteral("lineNumber")).toInt32(),
                                  false));
}
Ejemplo n.º 2
0
void ScriptImporter::importSourceCode(const QString &sourceCode, const QString &filePath,
        QScriptValue &targetObject)
{
    Q_ASSERT(targetObject.isObject());
    // The targetObject doesn't get overwritten but enhanced by the contents of the .js file.
    // This is necessary for library imports that consist of multiple js files.

    QString &code = m_sourceCodeCache[filePath];
    if (code.isEmpty()) {
        QbsQmlJS::Engine engine;
        QbsQmlJS::Lexer lexer(&engine);
        lexer.setCode(sourceCode, 1, false);
        QbsQmlJS::Parser parser(&engine);
        if (!parser.parseProgram()) {
            throw ErrorInfo(parser.errorMessage(), CodeLocation(filePath, parser.errorLineNumber(),
                                                                parser.errorColumnNumber()));
        }

        IdentifierExtractor extractor;
        extractor.start(parser.rootNode());
        code = QLatin1String("(function(){\n") + sourceCode + extractor.suffix();
    }

    QScriptValue result = m_engine->evaluate(code, filePath, 0);
    if (m_engine->hasUncaughtException())
        throw errorInfoFromScriptValue(result, filePath);
    copyProperties(result, targetObject);
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void Logger::info(const String& message)
{
    info(message, CodeLocation());
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void Logger::warning(const String& message)
{
    warning(message, CodeLocation());
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void Logger::error(const String& message)
{
    error(message, CodeLocation());
}
Ejemplo n.º 6
0
void throwAssertLocation(const char *condition, const char *file, int line)
{
    throw ErrorInfo(QString::fromLatin1("ASSERT: %1").arg(QLatin1String(condition)),
                    CodeLocation(QString::fromLocal8Bit(file), line, -1, false), true);
}
Ejemplo n.º 7
0
CodeLocation JSSourceValue::location() const
{
    return CodeLocation(m_file->filePath(), m_line, m_column);
}
CodeLocation ItemReaderASTVisitor::toCodeLocation(const AST::SourceLocation &location) const
{
    return CodeLocation(m_file->filePath(), location.startLine, location.startColumn);
}