ArrayConstructor.cpp [plain text]
#include "config.h"
#include "ArrayConstructor.h"
#include "ArrayPrototype.h"
#include "ButterflyInlines.h"
#include "CopiedSpaceInlines.h"
#include "Error.h"
#include "ExceptionHelpers.h"
#include "JSArray.h"
#include "JSFunction.h"
#include "Lookup.h"
#include "JSCInlines.h"
namespace JSC {
static EncodedJSValue JSC_HOST_CALL arrayConstructorIsArray(ExecState*);
}
#include "ArrayConstructor.lut.h"
namespace JSC {
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(ArrayConstructor);
const ClassInfo ArrayConstructor::s_info = { "Function", &InternalFunction::s_info, &arrayConstructorTable, CREATE_METHOD_TABLE(ArrayConstructor) };
ArrayConstructor::ArrayConstructor(VM& vm, Structure* structure)
: InternalFunction(vm, structure)
{
}
void ArrayConstructor::finishCreation(VM& vm, ArrayPrototype* arrayPrototype)
{
Base::finishCreation(vm, arrayPrototype->classInfo()->className);
putDirectWithoutTransition(vm, vm.propertyNames->prototype, arrayPrototype, DontEnum | DontDelete | ReadOnly);
putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete);
}
bool ArrayConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot &slot)
{
return getStaticFunctionSlot<InternalFunction>(exec, arrayConstructorTable, jsCast<ArrayConstructor*>(object), propertyName, slot);
}
JSObject* constructArrayWithSizeQuirk(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, JSValue length)
{
if (!length.isNumber())
return constructArrayNegativeIndexed(exec, profile, globalObject, &length, 1);
uint32_t n = length.toUInt32(exec);
if (n != length.toNumber(exec))
return exec->vm().throwException(exec, createRangeError(exec, ASCIILiteral("Array size is not a small enough positive integer.")));
return constructEmptyArray(exec, profile, globalObject, n);
}
static inline JSObject* constructArrayWithSizeQuirk(ExecState* exec, const ArgList& args)
{
JSGlobalObject* globalObject = asInternalFunction(exec->callee())->globalObject();
if (args.size() == 1)
return constructArrayWithSizeQuirk(exec, 0, globalObject, args.at(0));
return constructArray(exec, 0, globalObject, args);
}
static EncodedJSValue JSC_HOST_CALL constructWithArrayConstructor(ExecState* exec)
{
ArgList args(exec);
return JSValue::encode(constructArrayWithSizeQuirk(exec, args));
}
ConstructType ArrayConstructor::getConstructData(JSCell*, ConstructData& constructData)
{
constructData.native.function = constructWithArrayConstructor;
return ConstructTypeHost;
}
static EncodedJSValue JSC_HOST_CALL callArrayConstructor(ExecState* exec)
{
ArgList args(exec);
return JSValue::encode(constructArrayWithSizeQuirk(exec, args));
}
CallType ArrayConstructor::getCallData(JSCell*, CallData& callData)
{
callData.native.function = callArrayConstructor;
return CallTypeHost;
}
EncodedJSValue JSC_HOST_CALL arrayConstructorIsArray(ExecState* exec)
{
return JSValue::encode(jsBoolean(exec->argument(0).inherits(JSArray::info())));
}
}