#include <identifier.h>
#include <interpreter.h>
#include <runtime.h>
#include <runtime_array.h>
using namespace KJS;
const ClassInfo RuntimeArrayImp::info = {"RuntimeArray", &ArrayInstanceImp::info, 0, 0};
RuntimeArrayImp::RuntimeArrayImp(ExecState *exec, Bindings::Array *a) : ArrayInstanceImp (exec->lexicalInterpreter()->builtinArrayPrototype().imp(), a->getLength())
{
_array = a;
}
RuntimeArrayImp::~RuntimeArrayImp()
{
delete _array;
}
Value RuntimeArrayImp::get(ExecState *exec, const Identifier &propertyName) const
{
if (propertyName == lengthPropertyName)
return Number(getLength());
bool ok;
unsigned index = propertyName.toArrayIndex(&ok);
if (ok) {
if (index >= getLength())
return Undefined();
return getConcreteArray()->valueAt(exec, index);
}
return ObjectImp::get(exec, propertyName);
}
Value RuntimeArrayImp::get(ExecState *exec, unsigned index) const
{
if (index >= getLength())
return Undefined();
return getConcreteArray()->valueAt(exec, index);
}
void RuntimeArrayImp::put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr)
{
if (propertyName == lengthPropertyName) {
Object err = Error::create(exec,RangeError);
exec->setException(err);
return;
}
bool ok;
unsigned index = propertyName.toArrayIndex(&ok);
if (ok) {
getConcreteArray()->setValueAt(exec, index, value);
return;
}
ObjectImp::put(exec, propertyName, value, attr);
}
void RuntimeArrayImp::put(ExecState *exec, unsigned index, const Value &value, int attr)
{
if (index >= getLength()) {
Object err = Error::create(exec,RangeError);
exec->setException(err);
return;
}
getConcreteArray()->setValueAt(exec, index, value);
}
bool RuntimeArrayImp::hasOwnProperty(ExecState *exec, const Identifier &propertyName) const
{
if (propertyName == lengthPropertyName)
return true;
bool ok;
unsigned index = propertyName.toArrayIndex(&ok);
if (ok) {
if (index >= getLength())
return false;
return true;
}
return ObjectImp::hasOwnProperty(exec, propertyName);
}
bool RuntimeArrayImp::hasOwnProperty(ExecState *exec, unsigned index) const
{
if (index >= getLength())
return false;
return true;
}
bool RuntimeArrayImp::deleteProperty(ExecState *exec, const Identifier &propertyName)
{
return false;
}
bool RuntimeArrayImp::deleteProperty(ExecState *exec, unsigned index)
{
return false;
}