#pragma once
#include "JSArray.h"
#include "JSCellInlines.h"
#include "Structure.h"
namespace JSC {
inline IndexingType JSArray::mergeIndexingTypeForCopying(IndexingType other)
{
IndexingType type = indexingType();
if (!(type & IsArray && other & IsArray))
return NonArray;
if (hasAnyArrayStorage(type) || hasAnyArrayStorage(other))
return NonArray;
if (type == ArrayWithUndecided)
return other;
if (other == ArrayWithUndecided)
return type;
if ((type == ArrayWithInt32 || type == ArrayWithContiguous)
&& (other == ArrayWithInt32 || other == ArrayWithContiguous)) {
if (other == ArrayWithContiguous)
return other;
return type;
}
if (type != other)
return NonArray;
return type;
}
inline bool JSArray::canFastCopy(VM& vm, JSArray* otherArray)
{
if (hasAnyArrayStorage(indexingType()) || hasAnyArrayStorage(otherArray->indexingType()))
return false;
if (structure(vm)->holesMustForwardToPrototype(vm)
|| otherArray->structure(vm)->holesMustForwardToPrototype(vm))
return false;
return true;
}
ALWAYS_INLINE double toLength(ExecState* exec, JSObject* obj)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (isJSArray(obj))
return jsCast<JSArray*>(obj)->length();
JSValue lengthValue = obj->get(exec, vm.propertyNames->length);
RETURN_IF_EXCEPTION(scope, PNaN);
scope.release();
return lengthValue.toLength(exec);
}
}