Object *o = object.objectValue();
if (idx < UINT_MAX) {
- const PropertyDescriptor *p = o->array.nonSparseAt(idx);
+ const PropertyDescriptor *p = o->array.nonSparseArrayAt(idx);
if (p && p->type == PropertyDescriptor::Data)
return p->value;
uint idx = index.asArrayIndex();
if (idx < UINT_MAX) {
- PropertyDescriptor *p = o->array.nonSparseAtRef(idx);
+ PropertyDescriptor *p = o->array.nonSparseArrayAtRef(idx);
if (p && p->type == PropertyDescriptor::Data && p->isWritable()) {
p->value = value;
return;
bool ArgumentsObject::defineOwnProperty(ExecutionContext *ctx, uint index, const PropertyDescriptor *desc)
{
- PropertyDescriptor *pd = array.at(index);
+ PropertyDescriptor *pd = array.arrayAt(index);
PropertyDescriptor map;
bool isMapped = false;
if (pd && index < (uint)mappedArguments.size())
}
Array::Array(const Array &other)
- : len(other.len)
+ : arrayLen(other.arrayLen)
, arrayObject(0)
- , values(other.values)
- , sparse(0)
+ , arrayData(other.arrayData)
+ , sparseArray(0)
{
- freeList = other.freeList;
- if (other.sparse)
- sparse = new SparseArray(*other.sparse);
+ arrayFreeList = other.arrayFreeList;
+ if (other.sparseArray)
+ sparseArray = new SparseArray(*other.sparseArray);
}
-Value Array::indexOf(Value v, uint fromIndex, uint endIndex, ExecutionContext *ctx, Object *o)
+Value Array::arrayIndexOf(Value v, uint fromIndex, uint endIndex, ExecutionContext *ctx, Object *o)
{
bool protoHasArray = false;
Object *p = o;
while ((p = p->prototype))
- if (p->array.length())
+ if (p->array.arrayLength())
protoHasArray = true;
if (protoHasArray) {
if (exists && __qmljs_strict_equal(value, v))
return Value::fromDouble(i);
}
- } else if (sparse) {
- for (SparseArrayNode *n = sparse->lowerBound(fromIndex); n && n->key() < endIndex; n = n->nextNode()) {
+ } else if (sparseArray) {
+ for (SparseArrayNode *n = sparseArray->lowerBound(fromIndex); n && n->key() < endIndex; n = n->nextNode()) {
bool exists;
- Value value = o->getValueChecked(ctx, descriptor(n->value), &exists);
+ Value value = o->getValueChecked(ctx, arrayDecriptor(n->value), &exists);
if (exists && __qmljs_strict_equal(value, v))
return Value::fromDouble(n->key());
}
} else {
- if ((int) endIndex > values.size())
- endIndex = values.size();
- PropertyDescriptor *pd = values.data() + offset;
+ if ((int) endIndex > arrayData.size())
+ endIndex = arrayData.size();
+ PropertyDescriptor *pd = arrayData.data() + arrayOffset;
PropertyDescriptor *end = pd + endIndex;
pd += fromIndex;
while (pd < end) {
bool exists;
Value value = o->getValueChecked(ctx, pd, &exists);
if (exists && __qmljs_strict_equal(value, v))
- return Value::fromDouble(pd - offset - values.constData());
+ return Value::fromDouble(pd - arrayOffset - arrayData.constData());
++pd;
}
}
return Value::fromInt32(-1);
}
-void Array::concat(const Array &other)
+void Array::arrayConcat(const Array &other)
{
initSparse();
- int newLen = len + other.length();
- if (other.sparse)
+ int newLen = arrayLen + other.arrayLength();
+ if (other.sparseArray)
initSparse();
- if (sparse) {
- if (other.sparse) {
- for (const SparseArrayNode *it = other.sparse->begin(); it != other.sparse->end(); it = it->nextNode())
- set(len + it->key(), other.descriptor(it->value));
+ if (sparseArray) {
+ if (other.sparseArray) {
+ for (const SparseArrayNode *it = other.sparseArray->begin(); it != other.sparseArray->end(); it = it->nextNode())
+ arraySet(arrayLen + it->key(), other.arrayDecriptor(it->value));
} else {
- int oldSize = values.size();
- values.resize(oldSize + other.length());
- memcpy(values.data() + oldSize, other.values.constData() + other.offset, other.length()*sizeof(PropertyDescriptor));
- for (uint i = 0; i < other.length(); ++i) {
- SparseArrayNode *n = sparse->insert(len + i);
+ int oldSize = arrayData.size();
+ arrayData.resize(oldSize + other.arrayLength());
+ memcpy(arrayData.data() + oldSize, other.arrayData.constData() + other.arrayOffset, other.arrayLength()*sizeof(PropertyDescriptor));
+ for (uint i = 0; i < other.arrayLength(); ++i) {
+ SparseArrayNode *n = sparseArray->insert(arrayLen + i);
n->value = oldSize + i;
}
}
} else {
- int oldSize = values.size();
- values.resize(oldSize + other.length());
- memcpy(values.data() + oldSize, other.values.constData() + other.offset, other.length()*sizeof(PropertyDescriptor));
+ int oldSize = arrayData.size();
+ arrayData.resize(oldSize + other.arrayLength());
+ memcpy(arrayData.data() + oldSize, other.arrayData.constData() + other.arrayOffset, other.arrayLength()*sizeof(PropertyDescriptor));
}
- setLengthUnchecked(newLen);
+ setArrayLengthUnchecked(newLen);
}
-void Array::sort(ExecutionContext *context, Object *thisObject, const Value &comparefn, uint len)
+void Array::arraySort(ExecutionContext *context, Object *thisObject, const Value &comparefn, uint len)
{
- if (sparse) {
+ if (sparseArray) {
context->throwUnimplemented("Array::sort unimplemented for sparse arrays");
return;
- delete sparse;
+ delete sparseArray;
}
ArrayElementLessThan lessThan(context, thisObject, comparefn);
- if (len > values.size() - offset)
- len = values.size() - offset;
- PropertyDescriptor *begin = values.begin() + offset;
+ if (len > arrayData.size() - arrayOffset)
+ len = arrayData.size() - arrayOffset;
+ PropertyDescriptor *begin = arrayData.begin() + arrayOffset;
std::sort(begin, begin + len, lessThan);
}
void Array::initSparse()
{
- if (!sparse) {
- sparse = new SparseArray;
- for (int i = offset; i < values.size(); ++i) {
- SparseArrayNode *n = sparse->insert(i - offset);
+ if (!sparseArray) {
+ sparseArray = new SparseArray;
+ for (int i = arrayOffset; i < arrayData.size(); ++i) {
+ SparseArrayNode *n = sparseArray->insert(i - arrayOffset);
n->value = i;
}
- if (offset) {
- int o = offset;
+ if (arrayOffset) {
+ int o = arrayOffset;
for (int i = 0; i < o - 1; ++i) {
- values[i].type = PropertyDescriptor::Generic;
- values[i].value = Value::fromInt32(i + 1);
+ arrayData[i].type = PropertyDescriptor::Generic;
+ arrayData[i].value = Value::fromInt32(i + 1);
}
- values[o - 1].type = PropertyDescriptor::Generic;
- values[o - 1].value = Value::fromInt32(values.size());
- freeList = 0;
+ arrayData[o - 1].type = PropertyDescriptor::Generic;
+ arrayData[o - 1].value = Value::fromInt32(arrayData.size());
+ arrayFreeList = 0;
} else {
- freeList = values.size();
+ arrayFreeList = arrayData.size();
}
}
}
-void Array::setLengthUnchecked(uint l)
+void Array::setArrayLengthUnchecked(uint l)
{
- len = l;
+ arrayLen = l;
if (arrayObject) {
// length is always the first property of an array
PropertyDescriptor &lengthProperty = arrayObject->memberData[ArrayObject::LengthPropertyIndex];
}
}
-bool Array::setLength(uint newLen) {
+bool Array::setArrayLength(uint newLen) {
const PropertyDescriptor *lengthProperty = arrayObject->memberData.constData() + ArrayObject::LengthPropertyIndex;
if (lengthProperty && !lengthProperty->isWritable())
return false;
- uint oldLen = length();
+ uint oldLen = arrayLength();
bool ok = true;
if (newLen < oldLen) {
- if (sparse) {
- SparseArrayNode *begin = sparse->lowerBound(newLen);
- SparseArrayNode *it = sparse->end()->previousNode();
+ if (sparseArray) {
+ SparseArrayNode *begin = sparseArray->lowerBound(newLen);
+ SparseArrayNode *it = sparseArray->end()->previousNode();
while (1) {
- PropertyDescriptor &pd = values[it->value];
+ PropertyDescriptor &pd = arrayData[it->value];
if (pd.type != PropertyDescriptor::Generic && !pd.isConfigurable()) {
ok = false;
newLen = it->key() + 1;
}
pd.type = PropertyDescriptor::Generic;
pd.value.tag = Value::_Undefined_Type;
- pd.value.int_32 = freeList;
- freeList = it->value;
+ pd.value.int_32 = arrayFreeList;
+ arrayFreeList = it->value;
bool brk = (it == begin);
SparseArrayNode *prev = it->previousNode();
- sparse->erase(it);
+ sparseArray->erase(it);
if (brk)
break;
it = prev;
}
} else {
- PropertyDescriptor *it = values.data() + values.size();
- const PropertyDescriptor *begin = values.constData() + offset + newLen;
+ PropertyDescriptor *it = arrayData.data() + arrayData.size();
+ const PropertyDescriptor *begin = arrayData.constData() + arrayOffset + newLen;
while (--it >= begin) {
if (it->type != PropertyDescriptor::Generic && !it->isConfigurable()) {
ok = false;
- newLen = it - values.data() + offset + 1;
+ newLen = it - arrayData.data() + arrayOffset + 1;
break;
}
}
- values.resize(newLen + offset);
+ arrayData.resize(newLen + arrayOffset);
}
} else {
if (newLen >= 0x100000)
initSparse();
}
- setLengthUnchecked(newLen);
+ setArrayLengthUnchecked(newLen);
return ok;
}
-void Array::markObjects() const
+void Array::markArrayObjects() const
{
- uint i = sparse ? 0 : offset;
- for (; i < (uint)values.size(); ++i) {
- const PropertyDescriptor &pd = values.at(i);
+ uint i = sparseArray ? 0 : arrayOffset;
+ for (; i < (uint)arrayData.size(); ++i) {
+ const PropertyDescriptor &pd = arrayData.at(i);
if (pd.isData()) {
if (Managed *m = pd.value.asManaged())
m->mark();
{
friend struct ArrayPrototype;
- uint len;
+ uint arrayLen;
ArrayObject *arrayObject;
union {
- uint freeList;
- uint offset;
+ uint arrayFreeList;
+ uint arrayOffset;
};
- QVector<PropertyDescriptor> values;
- SparseArray *sparse;
+ QVector<PropertyDescriptor> arrayData;
+ SparseArray *sparseArray;
void fillDescriptor(PropertyDescriptor *pd, Value v)
{
pd->value = v;
}
- uint allocValue() {
- uint idx = freeList;
- if (values.size() <= (int)freeList)
- values.resize(++freeList);
+ uint allocArrayValue() {
+ uint idx = arrayFreeList;
+ if (arrayData.size() <= (int)arrayFreeList)
+ arrayData.resize(++arrayFreeList);
else
- freeList = values.at(freeList).value.integerValue();
+ arrayFreeList = arrayData.at(arrayFreeList).value.integerValue();
return idx;
}
- uint allocValue(Value v) {
- uint idx = allocValue();
- PropertyDescriptor *pd = &values[idx];
+ uint allocArrayValue(Value v) {
+ uint idx = allocArrayValue();
+ PropertyDescriptor *pd = &arrayData[idx];
fillDescriptor(pd, v);
return idx;
}
- void freeValue(int idx) {
- PropertyDescriptor &pd = values[idx];
+ void freeArrayValue(int idx) {
+ PropertyDescriptor &pd = arrayData[idx];
pd.type = PropertyDescriptor::Generic;
pd.value.tag = Value::_Undefined_Type;
- pd.value.int_32 = freeList;
- freeList = idx;
+ pd.value.int_32 = arrayFreeList;
+ arrayFreeList = idx;
}
- PropertyDescriptor *descriptor(uint index) {
- PropertyDescriptor *pd = values.data() + index;
- if (!sparse)
- pd += offset;
+ PropertyDescriptor *arrayDecriptor(uint index) {
+ PropertyDescriptor *pd = arrayData.data() + index;
+ if (!sparseArray)
+ pd += arrayOffset;
return pd;
}
- const PropertyDescriptor *descriptor(uint index) const {
- const PropertyDescriptor *pd = values.data() + index;
- if (!sparse)
- pd += offset;
+ const PropertyDescriptor *arrayDecriptor(uint index) const {
+ const PropertyDescriptor *pd = arrayData.data() + index;
+ if (!sparseArray)
+ pd += arrayOffset;
return pd;
}
- void getHeadRoom() {
- assert(!sparse && !offset);
- offset = qMax(values.size() >> 2, 16);
- QVector<PropertyDescriptor> newValues(values.size() + offset);
- memcpy(newValues.data() + offset, values.constData(), values.size()*sizeof(PropertyDescriptor));
- values = newValues;
+ void getArrayHeadRoom() {
+ assert(!sparseArray && !arrayOffset);
+ arrayOffset = qMax(arrayData.size() >> 2, 16);
+ QVector<PropertyDescriptor> newValues(arrayData.size() + arrayOffset);
+ memcpy(newValues.data() + arrayOffset, arrayData.constData(), arrayData.size()*sizeof(PropertyDescriptor));
+ arrayData = newValues;
}
public:
- Array() : len(0), arrayObject(0), offset(0), sparse(0) {}
+ Array() : arrayLen(0), arrayObject(0), arrayOffset(0), sparseArray(0) {}
Array(const Array &other);
- ~Array() { delete sparse; }
+ ~Array() { delete sparseArray; }
void initSparse();
- uint length() const { return len; }
- bool setLength(uint newLen);
+ uint arrayLength() const { return arrayLen; }
+ bool setArrayLength(uint newLen);
void setArrayObject(ArrayObject *a) { arrayObject = a; }
- void setLengthUnchecked(uint l);
+ void setArrayLengthUnchecked(uint l);
- PropertyDescriptor *insert(uint index) {
+ PropertyDescriptor *arrayInsert(uint index) {
PropertyDescriptor *pd;
- if (!sparse && (index < 0x1000 || index < len + (len >> 2))) {
- if (index + offset >= (uint)values.size()) {
- values.resize(offset + index + 1);
- for (uint i = len + 1; i < index; ++i) {
- values[i].type = PropertyDescriptor::Generic;
- values[i].value.tag = Value::_Undefined_Type;
+ if (!sparseArray && (index < 0x1000 || index < arrayLen + (arrayLen >> 2))) {
+ if (index + arrayOffset >= (uint)arrayData.size()) {
+ arrayData.resize(arrayOffset + index + 1);
+ for (uint i = arrayLen + 1; i < index; ++i) {
+ arrayData[i].type = PropertyDescriptor::Generic;
+ arrayData[i].value.tag = Value::_Undefined_Type;
}
}
- pd = descriptor(index);
+ pd = arrayDecriptor(index);
} else {
initSparse();
- SparseArrayNode *n = sparse->insert(index);
+ SparseArrayNode *n = sparseArray->insert(index);
if (n->value == UINT_MAX)
- n->value = allocValue();
- pd = descriptor(n->value);
+ n->value = allocArrayValue();
+ pd = arrayDecriptor(n->value);
}
- if (index >= len)
- setLengthUnchecked(index + 1);
+ if (index >= arrayLen)
+ setArrayLengthUnchecked(index + 1);
return pd;
}
- void set(uint index, const PropertyDescriptor *pd) {
- *insert(index) = *pd;
+ void arraySet(uint index, const PropertyDescriptor *pd) {
+ *arrayInsert(index) = *pd;
}
- void set(uint index, Value value) {
- PropertyDescriptor *pd = insert(index);
+ void arraySet(uint index, Value value) {
+ PropertyDescriptor *pd = arrayInsert(index);
fillDescriptor(pd, value);
}
- bool deleteIndex(uint index) {
- if (index >= len)
+ bool deleteArrayIndex(uint index) {
+ if (index >= arrayLen)
return true;
PropertyDescriptor *pd = 0;
- if (!sparse) {
- pd = at(index);
+ if (!sparseArray) {
+ pd = arrayAt(index);
} else {
- SparseArrayNode *n = sparse->findNode(index);
+ SparseArrayNode *n = sparseArray->findNode(index);
if (n)
- pd = descriptor(n->value);
+ pd = arrayDecriptor(n->value);
}
if (!pd || pd->type == PropertyDescriptor::Generic)
return true;
return false;
pd->type = PropertyDescriptor::Generic;
pd->value.tag = Value::_Undefined_Type;
- if (sparse) {
- pd->value.int_32 = freeList;
- freeList = pd - values.constData();
+ if (sparseArray) {
+ pd->value.int_32 = arrayFreeList;
+ arrayFreeList = pd - arrayData.constData();
}
return true;
}
- PropertyDescriptor *at(uint index) {
- if (!sparse) {
- if (index >= values.size() - offset)
+ PropertyDescriptor *arrayAt(uint index) {
+ if (!sparseArray) {
+ if (index >= arrayData.size() - arrayOffset)
return 0;
- return values.data() + index + offset;
+ return arrayData.data() + index + arrayOffset;
} else {
- SparseArrayNode *n = sparse->findNode(index);
+ SparseArrayNode *n = sparseArray->findNode(index);
if (!n)
return 0;
- return values.data() + n->value;
+ return arrayData.data() + n->value;
}
}
- const PropertyDescriptor *nonSparseAt(uint index) const {
- if (sparse)
+ const PropertyDescriptor *nonSparseArrayAt(uint index) const {
+ if (sparseArray)
return 0;
- index += offset;
- if (index >= (uint)values.size())
+ index += arrayOffset;
+ if (index >= (uint)arrayData.size())
return 0;
- return values.constData() + index;
+ return arrayData.constData() + index;
}
- PropertyDescriptor *nonSparseAtRef(uint index) {
- if (sparse)
+ PropertyDescriptor *nonSparseArrayAtRef(uint index) {
+ if (sparseArray)
return 0;
- index += offset;
- if (index >= (uint)values.size())
+ index += arrayOffset;
+ if (index >= (uint)arrayData.size())
return 0;
- return values.data() + index;
+ return arrayData.data() + index;
}
- const PropertyDescriptor *at(uint index) const {
- if (!sparse) {
- if (index >= values.size() - offset)
+ const PropertyDescriptor *arrayAt(uint index) const {
+ if (!sparseArray) {
+ if (index >= arrayData.size() - arrayOffset)
return 0;
- return values.constData() + index + offset;
+ return arrayData.constData() + index + arrayOffset;
} else {
- SparseArrayNode *n = sparse->findNode(index);
+ SparseArrayNode *n = sparseArray->findNode(index);
if (!n)
return 0;
- return values.constData() + n->value;
+ return arrayData.constData() + n->value;
}
}
- void markObjects() const;
+ void markArrayObjects() const;
void push_front(Value v) {
- if (!sparse) {
- if (!offset)
- getHeadRoom();
+ if (!sparseArray) {
+ if (!arrayOffset)
+ getArrayHeadRoom();
- --offset;
+ --arrayOffset;
PropertyDescriptor &pd = values[offset];
fillDescriptor(&pd, v);
} else {
- uint idx = allocValue(v);
- sparse->push_front(idx);
+ uint idx = allocArrayValue(v);
+ sparseArray->push_front(idx);
}
- setLengthUnchecked(len + 1);
+ setArrayLengthUnchecked(arrayLen + 1);
}
PropertyDescriptor *front() {
PropertyDescriptor *pd = 0;
- if (!sparse) {
- if (len)
- pd = values.data() + offset;
+ if (!sparseArray) {
+ if (arrayLen)
+ pd = arrayData.data() + arrayOffset;
} else {
- SparseArrayNode *n = sparse->findNode(0);
+ SparseArrayNode *n = sparseArray->findNode(0);
if (n)
- pd = descriptor(n->value);
+ pd = arrayDecriptor(n->value);
}
if (pd && pd->type == PropertyDescriptor::Generic)
return 0;
return pd;
}
void pop_front() {
- if (!len)
+ if (!arrayLen)
return;
- if (!sparse) {
- ++offset;
+ if (!sparseArray) {
+ ++arrayOffset;
} else {
- uint idx = sparse->pop_front();
- freeValue(idx);
+ uint idx = sparseArray->pop_front();
+ freeArrayValue(idx);
}
- setLengthUnchecked(len - 1);
+ setArrayLengthUnchecked(arrayLen - 1);
}
void push_back(Value v) {
- if (!sparse) {
- if (len + offset >= (uint)values.size())
- values.resize(values.size() + 1);
- PropertyDescriptor &pd = values[len + offset];
+ if (!sparseArray) {
+ PropertyDescriptor pd;
fillDescriptor(&pd, v);
+ arrayData.append(pd);
} else {
- uint idx = allocValue(v);
- sparse->push_back(idx, len);
+ uint idx = allocArrayValue(v);
+ sparseArray->push_back(idx, arrayLen);
}
- setLengthUnchecked(len + 1);
+ setArrayLengthUnchecked(arrayLen + 1);
}
PropertyDescriptor *back() {
PropertyDescriptor *pd = 0;
- if (!sparse) {
- if (len)
- pd = values.data() + offset + len;
+ if (!sparseArray) {
+ if (arrayLen)
+ pd = arrayData.data() + arrayOffset + arrayLen;
} else {
- SparseArrayNode *n = sparse->findNode(len - 1);
+ SparseArrayNode *n = sparseArray->findNode(arrayLen - 1);
if (n)
- pd = descriptor(n->value);
+ pd = arrayDecriptor(n->value);
}
if (pd && pd->type == PropertyDescriptor::Generic)
return 0;
return pd;
}
void pop_back() {
- if (!len)
+ if (!arrayLen)
return;
- if (!sparse) {
- values.resize(values.size() - 1);
+ if (!sparseArray) {
+ arrayData.resize(arrayData.size() - 1);
} else {
- uint idx = sparse->pop_back(len);
+ uint idx = sparseArray->pop_back(arrayLen);
if (idx != UINT_MAX)
- freeValue(idx);
+ freeArrayValue(idx);
}
- setLengthUnchecked(len - 1);
+ setArrayLengthUnchecked(arrayLen - 1);
}
- SparseArrayNode *sparseLowerBound(uint idx) { return sparse ? sparse->lowerBound(idx) : 0; }
- SparseArrayNode *sparseBegin() { return sparse ? sparse->begin() : 0; }
- SparseArrayNode *sparseEnd() { return sparse ? sparse->end() : 0; }
+ SparseArrayNode *sparseArrayLowerBound(uint idx) { return sparseArray ? sparseArray->lowerBound(idx) : 0; }
+ SparseArrayNode *sparseArrayBegin() { return sparseArray ? sparseArray->begin() : 0; }
+ SparseArrayNode *sparseArrayEnd() { return sparseArray ? sparseArray->end() : 0; }
- void concat(const Array &other);
- void sort(ExecutionContext *context, Object *thisObject, const Value &comparefn, uint len);
- Value indexOf(Value v, uint fromIndex, uint len, ExecutionContext *ctx, Object *o);
+ void arrayConcat(const Array &other);
+ void arraySort(ExecutionContext *context, Object *thisObject, const Value &comparefn, uint arrayLen);
+ Value arrayIndexOf(Value v, uint fromIndex, uint arrayLen, ExecutionContext *ctx, Object *o);
};
}
return Value::undefinedValue();
}
- value.setLengthUnchecked(len);
+ value.setArrayLengthUnchecked(len);
} else {
for (unsigned int i = 0; i < ctx->argumentCount; ++i) {
- value.set(i, ctx->argument(i));
+ value.arraySet(i, ctx->argument(i));
}
}
uint ArrayPrototype::getLength(ExecutionContext *ctx, Object *o)
{
if (o->isArrayObject())
- return o->array.length();
+ return o->array.arrayLength();
return o->__get__(ctx, ctx->engine->id_length).toUInt32(ctx);
}
result = instance->array;
else {
QString v = ctx->thisObject.toString(ctx)->toQString();
- result.set(0, Value::fromString(ctx, v));
+ result.arraySet(0, Value::fromString(ctx, v));
}
for (uint i = 0; i < ctx->argumentCount; ++i) {
- quint32 k = result.length();
+ quint32 k = result.arrayLength();
Value arg = ctx->argument(i);
if (ArrayObject *elt = arg.asArrayObject())
- result.concat(elt->array);
+ result.arrayConcat(elt->array);
else
- result.set(k, arg);
+ result.arraySet(k, arg);
}
return Value::fromObject(ctx->engine->newArrayObject(ctx, result));
// ### FIXME
if (ArrayObject *a = self.asArrayObject()) {
- for (uint i = 0; i < a->array.length(); ++i) {
+ for (uint i = 0; i < a->array.arrayLength(); ++i) {
if (i)
R += r4;
instance->__delete__(ctx, len - 1);
if (instance->isArrayObject())
- instance->array.setLengthUnchecked(len - 1);
+ instance->array.setArrayLengthUnchecked(len - 1);
else
instance->__put__(ctx, ctx->engine->id_length, Value::fromDouble(len - 1));
return result;
bool protoHasArray = false;
Object *p = instance;
while ((p = p->prototype))
- if (p->array.length())
+ if (p->array.arrayLength())
protoHasArray = true;
- if (!protoHasArray && len == instance->array.length()) {
+ if (!protoHasArray && len == instance->array.arrayLength()) {
for (uint i = 0; i < ctx->argumentCount; ++i) {
Value v = ctx->argument(i);
instance->array.push_back(v);
bool protoHasArray = false;
Object *p = instance;
while ((p = p->prototype))
- if (p->array.length())
+ if (p->array.arrayLength())
protoHasArray = true;
- if (!protoHasArray && len >= instance->array.length()) {
+ if (!protoHasArray && len >= instance->array.arrayLength()) {
instance->array.pop_front();
} else {
// do it the slow way
bool exists;
Value v = o->__get__(ctx, i, &exists);
if (exists)
- result.set(n, v);
+ result.arraySet(n, v);
++n;
}
return Value::fromObject(ctx->engine->newArrayObject(ctx, result));
uint len = getLength(ctx, instance);
Value comparefn = ctx->argument(0);
- instance->array.sort(ctx, instance, comparefn, len);
+ instance->array.arraySort(ctx, instance, comparefn, len);
return ctx->thisObject;
}
uint deleteCount = (uint)qMin(qMax(ctx->argument(1).toInteger(ctx), 0.), (double)(len - start));
- newArray->array.values.resize(deleteCount);
- PropertyDescriptor *pd = newArray->array.values.data();
+ newArray->array.arrayData.resize(deleteCount);
+ PropertyDescriptor *pd = newArray->array.arrayData.data();
for (uint i = 0; i < deleteCount; ++i) {
pd->type = PropertyDescriptor::Data;
pd->writable = PropertyDescriptor::Enabled;
pd->value = instance->__get__(ctx, start + i);
++pd;
}
- newArray->array.setLengthUnchecked(deleteCount);
+ newArray->array.setArrayLengthUnchecked(deleteCount);
uint itemCount = ctx->argumentCount < 2 ? 0 : ctx->argumentCount - 2;
bool exists;
Value v = instance->__get__(ctx, k + deleteCount, &exists);
if (exists)
- instance->array.set(k + itemCount, v);
+ instance->array.arraySet(k + itemCount, v);
else
instance->__delete__(ctx, k + itemCount);
}
bool exists;
Value v = instance->__get__(ctx, k + deleteCount - 1, &exists);
if (exists)
- instance->array.set(k + itemCount - 1, v);
+ instance->array.arraySet(k + itemCount - 1, v);
else
instance->__delete__(ctx, k + itemCount - 1);
--k;
}
for (uint i = 0; i < itemCount; ++i)
- instance->array.set(start + i, ctx->argument(i + 2));
+ instance->array.arraySet(start + i, ctx->argument(i + 2));
ctx->strictMode = true;
instance->__put__(ctx, ctx->engine->id_length, Value::fromDouble(len - deleteCount + itemCount));
bool protoHasArray = false;
Object *p = instance;
while ((p = p->prototype))
- if (p->array.length())
+ if (p->array.arrayLength())
protoHasArray = true;
- if (!protoHasArray && len >= instance->array.length()) {
+ if (!protoHasArray && len >= instance->array.arrayLength()) {
for (int i = ctx->argumentCount - 1; i >= 0; --i) {
Value v = ctx->argument(i);
instance->array.push_front(v);
return Value::fromInt32(-1);
}
- return instance->array.indexOf(searchValue, fromIndex, len, ctx, instance);
+ return instance->array.arrayIndexOf(searchValue, fromIndex, len, ctx, instance);
}
Value ArrayPrototype::method_lastIndexOf(ExecutionContext *ctx)
Value thisArg = ctx->argument(1);
ArrayObject *a = ctx->engine->newArrayObject(ctx);
- a->array.setLengthUnchecked(len);
+ a->array.setArrayLengthUnchecked(len);
for (uint k = 0; k < len; ++k) {
bool exists;
args[1] = Value::fromDouble(k);
args[2] = ctx->thisObject;
Value mapped = callback->call(ctx, thisArg, args, 3);
- a->array.set(k, mapped);
+ a->array.arraySet(k, mapped);
}
return Value::fromObject(a);
}
args[2] = ctx->thisObject;
Value selected = callback->call(ctx, thisArg, args, 3);
if (__qmljs_to_boolean(selected, ctx)) {
- a->array.set(to, v);
+ a->array.arraySet(to, v);
++to;
}
}
Value val;
if (!parseValue(&val))
return Value::undefinedValue();
- array.set(index, val);
+ array.arraySet(index, val);
QChar token = nextToken();
if (token == EndArray)
break;
}
}
- DEBUG << "size =" << array.length();
+ DEBUG << "size =" << array.arrayLength();
END;
--nestingLevel;
indent += gap;
QStringList partial;
- uint len = a->array.length();
+ uint len = a->array.arrayLength();
for (uint i = 0; i < len; ++i) {
bool exists;
Value v = a->__get__(ctx, i, &exists);
if (o) {
stringify.replacerFunction = o->asFunctionObject();
if (o->isArrayObject()) {
- for (uint i = 0; i < o->array.length(); ++i) {
+ for (uint i = 0; i < o->array.arrayLength(); ++i) {
Value v = o->__get__(ctx, i);
if (v.asNumberObject() || v.asStringObject() || v.isNumber())
v = __qmljs_to_string(v, ctx);
}
}
}
- array.markObjects();
+ array.markArrayObjects();
}
PropertyDescriptor *Object::insertMember(String *s)
PropertyDescriptor *Object::__getOwnProperty__(ExecutionContext *ctx, uint index)
{
- PropertyDescriptor *p = array.at(index);
+ PropertyDescriptor *p = array.arrayAt(index);
if(p && p->type != PropertyDescriptor::Generic)
return p;
if (isStringObject())
{
Object *o = this;
while (o) {
- PropertyDescriptor *p = o->array.at(index);
+ PropertyDescriptor *p = o->array.arrayAt(index);
if(p && p->type != PropertyDescriptor::Generic)
return p;
if (o->isStringObject()) {
PropertyDescriptor *pd = 0;
Object *o = this;
while (o) {
- PropertyDescriptor *p = o->array.at(index);
+ PropertyDescriptor *p = o->array.arrayAt(index);
if (p && p->type != PropertyDescriptor::Generic) {
pd = p;
break;
uint l = value.asArrayLength(ctx, &ok);
if (!ok)
ctx->throwRangeError(value);
- ok = array.setLength(l);
+ ok = array.setArrayLength(l);
if (!ok)
goto reject;
} else {
return;
}
- array.set(index, value);
+ array.arraySet(index, value);
return;
reject:
bool Object::__hasProperty__(const ExecutionContext *ctx, uint index) const
{
- const PropertyDescriptor *p = array.at(index);
+ const PropertyDescriptor *p = array.arrayAt(index);
if (p && p->type != PropertyDescriptor::Generic)
return true;
bool Object::__delete__(ExecutionContext *ctx, uint index)
{
- if (array.deleteIndex(index))
+ if (array.deleteArrayIndex(index))
return true;
if (ctx->strictMode)
__qmljs_throw_type_error(ctx);
uint l = desc->value.asArrayLength(ctx, &ok);
if (!ok)
ctx->throwRangeError(desc->value);
- succeeded = array.setLength(l);
+ succeeded = array.setArrayLength(l);
}
if (desc->writable == PropertyDescriptor::Disabled)
lp->writable = PropertyDescriptor::Disabled;
PropertyDescriptor *current;
// 15.4.5.1, 4b
- if (isArrayObject() && index >= array.length() && !memberData.at(ArrayObject::LengthPropertyIndex).isWritable())
+ if (isArrayObject() && index >= array.arrayLength() && !memberData.at(ArrayObject::LengthPropertyIndex).isWritable())
goto reject;
if (isNonStrictArgumentsObject)
if (!extensible)
goto reject;
// clause 4
- PropertyDescriptor *pd = array.insert(index);
+ PropertyDescriptor *pd = array.arrayInsert(index);
*pd = *desc;
pd->fullyPopulated();
return true;
};
ArrayObject(ExecutionContext *ctx) { init(ctx); }
- ArrayObject(ExecutionContext *ctx, const Array &value): Object(value) { init(ctx); array.setLengthUnchecked(array.length()); }
+ ArrayObject(ExecutionContext *ctx, const Array &value): Object(value) { init(ctx); array.setArrayLengthUnchecked(array.arrayLength()); }
void init(ExecutionContext *context);
};
return s->__getOwnProperty__(context, *index);
}
flags &= ~CurrentIsString;
- arrayNode = current->array.sparseBegin();
+ arrayNode = current->array.sparseArrayBegin();
// iterate until we're past the end of the string
while (arrayNode && arrayNode->key() < slen)
arrayNode = arrayNode->nextNode();
}
if (!arrayIndex)
- arrayNode = current->array.sparseBegin();
+ arrayNode = current->array.sparseArrayBegin();
// sparse arrays
if (arrayNode) {
- while (arrayNode != current->array.sparseEnd()) {
+ while (arrayNode != current->array.sparseArrayEnd()) {
int k = arrayNode->key();
- p = current->array.at(k);
+ p = current->array.arrayAt(k);
arrayNode = arrayNode->nextNode();
if (p && (!(flags & EnumberableOnly) || p->isEnumerable())) {
arrayIndex = k + 1;
arrayIndex = UINT_MAX;
}
// dense arrays
- while (arrayIndex < current->array.length()) {
- p = current->array.at(arrayIndex);
+ while (arrayIndex < current->array.arrayLength()) {
+ p = current->array.arrayAt(arrayIndex);
++arrayIndex;
if (p && p->type != PropertyDescriptor::Generic && (!(flags & EnumberableOnly) || p->isEnumerable())) {
*index = arrayIndex - 1;
previousLastIndex = thisIndex;
}
Value matchStr = result.objectValue()->__get__(parentCtx, (uint)0, (bool *)0);
- a->array.set(n, matchStr);
+ a->array.arraySet(n, matchStr);
++n;
}
if (!n)
array->array.push_back(Value::fromString(ctx, text.mid(offset, matchOffsets[0] - offset)));
offset = qMax(offset + 1, matchOffsets[1]);
- if (array->array.length() >= limit)
+ if (array->array.arrayLength() >= limit)
break;
for (int i = 1; i < re->value->captureCount(); ++i) {
uint start = matchOffsets[i * 2];
uint end = matchOffsets[i * 2 + 1];
array->array.push_back(Value::fromString(ctx, text.mid(start, end - start)));
- if (array->array.length() >= limit)
+ if (array->array.arrayLength() >= limit)
break;
}
}
- if (array->array.length() < limit)
+ if (array->array.arrayLength() < limit)
array->array.push_back(Value::fromString(ctx, text.mid(offset)));
} else {
QString separator = separatorValue.toString(ctx)->toQString();
while ((end = text.indexOf(separator, start)) != -1) {
array->array.push_back(Value::fromString(ctx, text.mid(start, end - start)));
start = end + separator.size();
- if (array->array.length() >= limit)
+ if (array->array.arrayLength() >= limit)
break;
}
- if (array->array.length() < limit && start != -1)
+ if (array->array.arrayLength() < limit && start != -1)
array->array.push_back(Value::fromString(ctx, text.mid(start)));
}
return result;