Showing the changes to libraries/script-engine/src/ArrayBufferViewClass.cpp (1 of 2 files). Show all
Unified · Split
| @@ -0,0 +1,103 @@ | ||
| 1 | +// | |
| 2 | +// ArrayBufferViewClass.cpp | |
| 3 | +// | |
| 4 | +// | |
| 5 | +// Created by Clement on 7/8/14. | |
| 6 | +// Copyright 2014 High Fidelity, Inc. | |
| 7 | +// | |
| 8 | +// Distributed under the Apache License, Version 2.0. | |
| 9 | +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | |
| 10 | +// | |
| 11 | + | |
| 12 | +#include "ArrayBufferViewClass.h" | |
| 13 | + | |
| 14 | +Q_DECLARE_METATYPE(QByteArray*) | |
| 15 | + | |
| 16 | +ArrayBufferViewClass::ArrayBufferViewClass(QScriptEngine* engine) : | |
| 17 | +QObject(engine), | |
| 18 | +QScriptClass(engine) { | |
| 19 | + // Save string handles for quick lookup | |
| 20 | + _bufferName = engine->toStringHandle(BUFFER_PROPERTY_NAME.toLatin1()); | |
| 21 | + _byteOffsetName = engine->toStringHandle(BYTE_OFFSET_PROPERTY_NAME.toLatin1()); | |
| 22 | + _byteLengthName = engine->toStringHandle(BYTE_LENGTH_PROPERTY_NAME.toLatin1()); | |
| 23 | +} | |
| 24 | + | |
| 25 | +QScriptClass::QueryFlags ArrayBufferViewClass::queryProperty(const QScriptValue& object, | |
| 26 | + const QScriptString& name, | |
| 27 | + QueryFlags flags, uint* id) { | |
| 28 | + if (name == _bufferName || name == _byteOffsetName || name == _byteLengthName) { | |
| 29 | + return flags &= HandlesReadAccess; // Only keep read access flags | |
| 30 | + } | |
| 31 | + return 0; // No access | |
| 32 | +} | |
| 33 | + | |
| 34 | +QScriptValue ArrayBufferViewClass::property(const QScriptValue &object, | |
| 35 | + const QScriptString &name, uint id) { | |
| 36 | + if (name == _bufferName) { | |
| 37 | + return object.data().property(_bufferName); | |
| 38 | + } | |
| 39 | + if (name == _byteOffsetName) { | |
| 40 | + return object.data().property(_byteOffsetName); | |
| 41 | + } | |
| 42 | + if (name == _byteLengthName) { | |
| 43 | + return object.data().property(_byteLengthName); | |
| 44 | + } | |
| 45 | + return QScriptValue(); | |
| 46 | +} | |
| 47 | + | |
| 48 | +QScriptValue::PropertyFlags ArrayBufferViewClass::propertyFlags(const QScriptValue& object, | |
| 49 | + const QScriptString& name, uint id) { | |
| 50 | + return QScriptValue::Undeletable; | |
| 51 | +} | |
| 52 | + | |
| 53 | +//QScriptClass::QueryFlags DataViewClass::queryProperty(const QScriptValue& object, | |
| 54 | +// const QScriptString& name, | |
| 55 | +// QueryFlags flags, uint* id) { | |
| 56 | +// QByteArray* arrayBuffer = qscriptvalue_cast<QByteArray*>(object.property(_bufferName).data()); | |
| 57 | +// bool ok = false; | |
| 58 | +// int pos = name.toArrayIndex(&ok); | |
| 59 | +// | |
| 60 | +// // Check that name is a valid index and arrayBuffer exists | |
| 61 | +// if (ok && arrayBuffer && pos > 0 && pos < arrayBuffer->size()) { | |
| 62 | +// *id = pos; // save pos to avoid recomputation | |
| 63 | +// return HandlesReadAccess | HandlesWriteAccess; // Read/Write access | |
| 64 | +// } | |
| 65 | +// | |
| 66 | +// return ArrayBufferViewClass::queryProperty(object, name, flags, id); | |
| 67 | +//} | |
| 68 | +// | |
| 69 | +//QScriptValue DataViewClass::property(const QScriptValue &object, | |
| 70 | +// const QScriptString &name, uint id) { | |
| 71 | +// QByteArray* arrayBuffer = qscriptvalue_cast<QByteArray*>(object.property(_bufferName).data()); | |
| 72 | +// bool ok = false; | |
| 73 | +// name.toArrayIndex(&ok); | |
| 74 | +// | |
| 75 | +// if (ok && arrayBuffer) { | |
| 76 | +// return (*arrayBuffer)[id]; | |
| 77 | +// } | |
| 78 | +// | |
| 79 | +// return ArrayBufferViewClass::queryProperty(object, name, flags, id); | |
| 80 | +//} | |
| 81 | +// | |
| 82 | +//void DataViewClass::setProperty(QScriptValue &object, | |
| 83 | +// const QScriptString &name, | |
| 84 | +// uint id, const QScriptValue &value) { | |
| 85 | +// QByteArray *ba = qscriptvalue_cast<QByteArray*>(object.data()); | |
| 86 | +// if (!ba) | |
| 87 | +// return; | |
| 88 | +// if (name == length) { | |
| 89 | +// resize(*ba, value.toInt32()); | |
| 90 | +// } else { | |
| 91 | +// qint32 pos = id; | |
| 92 | +// if (pos < 0) | |
| 93 | +// return; | |
| 94 | +// if (ba->size() <= pos) | |
| 95 | +// resize(*ba, pos + 1); | |
| 96 | +// (*ba)[pos] = char(value.toInt32()); | |
| 97 | +// } | |
| 98 | +//} | |
| 99 | +// | |
| 100 | +//QScriptValue::PropertyFlags DataViewClass::propertyFlags(const QScriptValue& object, | |
| 101 | +// const QScriptString& name, uint id) { | |
| 102 | +// return QScriptValue::Undeletable; | |
| 103 | +//} | |