unsigned ArrayInstance::compactForSorting()
{
    JSValue *undefined = jsUndefined();

    unsigned o = 0;
    
    for (unsigned i = 0; i != storageLength; ++i) {
        JSValue *v = storage[i];
        if (v && v != undefined) {
            if (o != i)
                storage[o] = v;
            o++;
        }
    }
   
    PropertyNameArray sparseProperties;
    _prop.getSparseArrayPropertyNames(sparseProperties);
    unsigned newLength = o + sparseProperties.size();
    
    if (newLength > storageLength)
        resizeStorage(newLength);
    
    PropertyNameArrayIterator end = sparseProperties.end();
    for (PropertyNameArrayIterator it = sparseProperties.begin(); it != end; ++it) {
        Identifier name = *it;
        storage[o] = getDirect(name);
        _prop.remove(name);
        o++;
    }
    
    if (newLength != storageLength)
        memset(storage + o, 0, sizeof(JSValue *) * (storageLength - o));
    
    return o;
}
void ArrayInstance::setLength(unsigned newLength, ExecState *exec)
{
  if (newLength <= storageLength) {
    resizeStorage(newLength);
  }

  if (newLength < length) {
    PropertyNameArray sparseProperties;
    
    _prop.getSparseArrayPropertyNames(sparseProperties);
    
    PropertyNameArrayIterator end = sparseProperties.end();
    
    for (PropertyNameArrayIterator it = sparseProperties.begin(); it != end; ++it) {
      Identifier name = *it;
      bool ok;
      unsigned index = name.toArrayIndex(&ok);
      if (ok && index > newLength)
        deleteProperty(exec, name);
    }
  }
  
  length = newLength;
}