Exemple #1
0
QString Stringify::JO(ObjectRef o)
{
    if (stack.contains(o.getPointer())) {
        ctx->throwTypeError();
        return QString();
    }

    Scope scope(ctx);

    QString result;
    stack.push(o.getPointer());
    QString stepback = indent;
    indent += gap;

    QStringList partial;
    if (propertyList.isEmpty()) {
        ObjectIterator it(scope, o, ObjectIterator::EnumerableOnly);
        ScopedValue name(scope);

        ScopedValue val(scope);
        while (1) {
            name = it.nextPropertyNameAsString(val);
            if (name->isNull())
                break;
            QString key = name->toQString();
            QString member = makeMember(key, val);
            if (!member.isEmpty())
                partial += member;
        }
    } else {
        ScopedString s(scope);
        for (int i = 0; i < propertyList.size(); ++i) {
            bool exists;
            s = propertyList.at(i);
            ScopedValue v(scope, o->get(s, &exists));
            if (!exists)
                continue;
            QString member = makeMember(s->toQString(), v);
            if (!member.isEmpty())
                partial += member;
        }
    }

    if (partial.isEmpty()) {
        result = QStringLiteral("{}");
    } else if (gap.isEmpty()) {
        result = QStringLiteral("{") + partial.join(QLatin1Char(',')) + QStringLiteral("}");
    } else {
        QString separator = QStringLiteral(",\n") + indent;
        result = QStringLiteral("{\n") + indent + partial.join(separator) + QStringLiteral("\n") + stepback + QStringLiteral("}");
    }

    indent = stepback;
    stack.pop();
    return result;
}
ObjectIterator::ObjectIterator(Value *scratch1, Value *scratch2, const ObjectRef o, uint flags)
    : object(ObjectRef::fromValuePointer(scratch1))
    , current(ObjectRef::fromValuePointer(scratch2))
    , arrayNode(0)
    , arrayIndex(0)
    , memberIndex(0)
    , flags(flags)
{
    object = o.getPointer();
    current = o.getPointer();

    if (!!object && object->asArgumentsObject()) {
        Scope scope(object->engine());
        Scoped<ArgumentsObject> (scope, object->asReturnedValue())->fullyCreate();
    }
}
Exemple #3
0
WithContext::WithContext(ExecutionEngine *engine, ObjectRef with)
    : ExecutionContext(engine, Type_WithContext)
{
    callData = parent->callData;
    outer = parent;
    lookups = parent->lookups;
    compilationUnit = parent->compilationUnit;

    withObject = with.getPointer();
}
Exemple #4
0
CallContext::CallContext(ExecutionEngine *engine, ObjectRef qml, FunctionObject *function)
    : ExecutionContext(engine, Type_QmlContext)
{
    this->function = function;
    callData = reinterpret_cast<CallData *>(this + 1);
    callData->tag = QV4::Value::_Integer_Type;
    callData->argc = 0;
    callData->thisObject = Primitive::undefinedValue();

    strictMode = true;
    outer = function->scope;

    activation = qml.getPointer();

    if (function->function) {
        compilationUnit = function->function->compilationUnit;
        lookups = compilationUnit->runtimeLookups;
    }

    locals = (SafeValue *)(this + 1);
    if (function->varCount)
        std::fill(locals, locals + function->varCount, Primitive::undefinedValue());
}