コード例 #1
0
QScriptValue ArrayBufferClass::toScriptValue(QScriptEngine* engine, const QByteArray& ba) {
    QScriptValue ctor = engine->globalObject().property(CLASS_NAME);
    ArrayBufferClass* cls = qscriptvalue_cast<ArrayBufferClass*>(ctor.data());
    if (!cls) {
        if (engine->currentContext()) {
            engine->currentContext()->throwError("arrayBufferClass::toScriptValue -- could not get " + CLASS_NAME + " class constructor");
        }
        return QScriptValue::NullValue;
    }
    return cls->newInstance(ba);
}
コード例 #2
0
QScriptValue ArrayBufferClass::construct(QScriptContext* context, QScriptEngine* engine) {
    ArrayBufferClass* cls = qscriptvalue_cast<ArrayBufferClass*>(context->callee().data());
    if (!cls) {
        // return if callee (function called) is not of type ArrayBuffer
        return QScriptValue();
    }
    QScriptValue arg = context->argument(0);
    if (!arg.isValid() || !arg.isNumber()) {
        return QScriptValue();
    }
    
    quint32 size = arg.toInt32();
    QScriptValue newObject = cls->newInstance(size);
    
    if (context->isCalledAsConstructor()) {
        // if called with keyword new, replace this object.
        context->setThisObject(newObject);
        return engine->undefinedValue();
    }
    
    return newObject;
}
コード例 #3
0
ファイル: TypedArrays.cpp プロジェクト: CoderPaulK/hifi
QScriptValue TypedArray::newInstance(quint32 length) {
    ArrayBufferClass* array = getScriptEngine()->getArrayBufferClass();
    QScriptValue buffer = array->newInstance(length * _bytesPerElement);
    return newInstance(buffer, 0, length);
}