EncodedJSValue RuntimeArray::lengthGetter(ExecState* exec, JSObject*, EncodedJSValue thisValue, PropertyName) { RuntimeArray* thisObject = jsDynamicCast<RuntimeArray*>(JSValue::decode(thisValue)); if (!thisObject) return throwVMTypeError(exec); return JSValue::encode(jsNumber(thisObject->getLength())); }
void RuntimeArray::putByIndex(JSCell* cell, ExecState* exec, unsigned index, JSValue value, bool) { RuntimeArray* thisObject = jsCast<RuntimeArray*>(cell); if (index >= thisObject->getLength()) { exec->vm().throwException(exec, createRangeError(exec, "Range error")); return; } thisObject->getConcreteArray()->setValueAt(exec, index, value); }
bool RuntimeArray::getOwnPropertySlotByIndex(JSCell* cell, ExecState *exec, unsigned index, PropertySlot& slot) { RuntimeArray* thisObject = jsCast<RuntimeArray*>(cell); if (index < thisObject->getLength()) { slot.setCustomIndex(thisObject, index, thisObject->indexGetter); return true; } return JSObject::getOwnPropertySlotByIndex(thisObject, exec, index, slot); }
EncodedJSValue RuntimeArray::lengthGetter(ExecState* exec, EncodedJSValue thisValue, PropertyName) { VM& vm = exec->vm(); auto scope = DECLARE_THROW_SCOPE(vm); RuntimeArray* thisObject = jsDynamicDowncast<RuntimeArray*>(JSValue::decode(thisValue)); if (!thisObject) return throwVMTypeError(exec, scope); return JSValue::encode(jsNumber(thisObject->getLength())); }
bool RuntimeArray::getOwnPropertySlotByIndex(JSObject* object, ExecState *exec, unsigned index, PropertySlot& slot) { RuntimeArray* thisObject = jsCast<RuntimeArray*>(object); if (index < thisObject->getLength()) { slot.setValue(thisObject, DontDelete | DontEnum, thisObject->getConcreteArray()->valueAt(exec, index)); return true; } return JSObject::getOwnPropertySlotByIndex(thisObject, exec, index, slot); }
void RuntimeArray::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) { RuntimeArray* thisObject = jsCast<RuntimeArray*>(object); unsigned length = thisObject->getLength(); for (unsigned i = 0; i < length; ++i) propertyNames.add(Identifier::from(exec, i)); if (mode.includeDontEnumProperties()) propertyNames.add(exec->propertyNames().length); JSObject::getOwnPropertyNames(thisObject, exec, propertyNames, mode); }
bool RuntimeArray::putByIndex(JSCell* cell, ExecState* exec, unsigned index, JSValue value, bool) { VM& vm = exec->vm(); auto scope = DECLARE_THROW_SCOPE(vm); RuntimeArray* thisObject = jsCast<RuntimeArray*>(cell); if (index >= thisObject->getLength()) { throwException(exec, scope, createRangeError(exec, "Range error")); return false; } return thisObject->getConcreteArray()->setValueAt(exec, index, value); }
bool RuntimeArray::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot) { RuntimeArray* thisObject = jsCast<RuntimeArray*>(object); if (propertyName == exec->propertyNames().length) { slot.setCacheableCustom(thisObject, DontDelete | ReadOnly | DontEnum, thisObject->lengthGetter); return true; } Optional<uint32_t> index = parseIndex(propertyName); if (index && index.value() < thisObject->getLength()) { slot.setValue(thisObject, DontDelete | DontEnum, thisObject->getConcreteArray()->valueAt(exec, index.value())); return true; } return JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot); }
bool RuntimeArray::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot) { RuntimeArray* thisObject = jsCast<RuntimeArray*>(cell); if (propertyName == exec->propertyNames().length) { slot.setCacheableCustom(thisObject, thisObject->lengthGetter); return true; } unsigned index = propertyName.asIndex(); if (index < thisObject->getLength()) { ASSERT(index != PropertyName::NotAnIndex); slot.setCustomIndex(thisObject, index, thisObject->indexGetter); return true; } return JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot); }
bool RuntimeArray::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot) { RuntimeArray* thisObject = static_cast<RuntimeArray*>(cell); if (propertyName == exec->propertyNames().length) { slot.setCacheableCustom(thisObject, thisObject->lengthGetter); return true; } bool ok; unsigned index = propertyName.toArrayIndex(ok); if (ok) { if (index < thisObject->getLength()) { slot.setCustomIndex(thisObject, index, thisObject->indexGetter); return true; } } return JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot); }
bool RuntimeArray::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor) { RuntimeArray* thisObject = jsCast<RuntimeArray*>(object); if (propertyName == exec->propertyNames().length) { PropertySlot slot; slot.setCustom(thisObject, lengthGetter); descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum); return true; } unsigned index = propertyName.asIndex(); if (index < thisObject->getLength()) { ASSERT(index != PropertyName::NotAnIndex); PropertySlot slot; slot.setCustomIndex(thisObject, index, indexGetter); descriptor.setDescriptor(slot.getValue(exec, propertyName), DontDelete | DontEnum); return true; } return JSObject::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor); }
JSValue RuntimeArray::lengthGetter(ExecState*, JSValue slotBase, PropertyName) { RuntimeArray* thisObj = static_cast<RuntimeArray*>(asObject(slotBase)); return jsNumber(thisObj->getLength()); }
JSValue RuntimeArray::lengthGetter(ExecState*, JSValue slotBase, const Identifier&) { RuntimeArray* thisObj = static_cast<RuntimeArray*>(asObject(slotBase)); return jsNumber(thisObj->getLength()); }
EncodedJSValue RuntimeArray::lengthGetter(ExecState*, EncodedJSValue slotBase, EncodedJSValue, PropertyName) { RuntimeArray* thisObj = jsCast<RuntimeArray*>(JSValue::decode(slotBase)); return JSValue::encode(jsNumber(thisObj->getLength())); }
JSValue* RuntimeArray::lengthGetter(ExecState* exec, const Identifier&, const PropertySlot& slot) { RuntimeArray* thisObj = static_cast<RuntimeArray*>(asObject(slot.slotBase())); return jsNumber(exec, thisObj->getLength()); }