IntlDateTimeFormatPrototype.cpp [plain text]
#include "config.h"
#include "IntlDateTimeFormatPrototype.h"
#if ENABLE(INTL)
#include "BuiltinNames.h"
#include "DateConstructor.h"
#include "Error.h"
#include "IntlDateTimeFormat.h"
#include "IntlObject.h"
#include "JSBoundFunction.h"
#include "JSCJSValueInlines.h"
#include "JSCellInlines.h"
#include "JSObject.h"
#include "StructureInlines.h"
namespace JSC {
static EncodedJSValue JSC_HOST_CALL IntlDateTimeFormatPrototypeGetterFormat(ExecState*);
static EncodedJSValue JSC_HOST_CALL IntlDateTimeFormatPrototypeFuncResolvedOptions(ExecState*);
}
#include "IntlDateTimeFormatPrototype.lut.h"
namespace JSC {
const ClassInfo IntlDateTimeFormatPrototype::s_info = { "Object", &IntlDateTimeFormat::s_info, &dateTimeFormatPrototypeTable, CREATE_METHOD_TABLE(IntlDateTimeFormatPrototype) };
IntlDateTimeFormatPrototype* IntlDateTimeFormatPrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
{
IntlDateTimeFormatPrototype* object = new (NotNull, allocateCell<IntlDateTimeFormatPrototype>(vm.heap)) IntlDateTimeFormatPrototype(vm, structure);
object->finishCreation(vm, structure);
return object;
}
Structure* IntlDateTimeFormatPrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
IntlDateTimeFormatPrototype::IntlDateTimeFormatPrototype(VM& vm, Structure* structure)
: IntlDateTimeFormat(vm, structure)
{
}
void IntlDateTimeFormatPrototype::finishCreation(VM& vm, Structure*)
{
Base::finishCreation(vm);
}
static EncodedJSValue JSC_HOST_CALL IntlDateTimeFormatFuncFormatDateTime(ExecState* state)
{
IntlDateTimeFormat* format = jsCast<IntlDateTimeFormat*>(state->thisValue());
JSValue date = state->argument(0);
double value;
if (date.isUndefined()) {
value = JSValue::decode(dateNow(state)).toNumber(state);
} else {
value = date.toNumber(state);
if (state->hadException())
return JSValue::encode(jsUndefined());
}
return JSValue::encode(format->format(*state, value));
}
EncodedJSValue JSC_HOST_CALL IntlDateTimeFormatPrototypeGetterFormat(ExecState* state)
{
IntlDateTimeFormat* dtf = jsDynamicCast<IntlDateTimeFormat*>(state->thisValue());
if (!dtf)
dtf = jsDynamicCast<IntlDateTimeFormat*>(state->thisValue().get(state, state->vm().propertyNames->builtinNames().intlSubstituteValuePrivateName()));
if (!dtf)
return JSValue::encode(throwTypeError(state, ASCIILiteral("Intl.DateTimeFormat.prototype.format called on value that's not an object initialized as a DateTimeFormat")));
JSBoundFunction* boundFormat = dtf->boundFormat();
if (!boundFormat) {
VM& vm = state->vm();
JSGlobalObject* globalObject = dtf->globalObject();
JSFunction* targetObject = JSFunction::create(vm, globalObject, 1, ASCIILiteral("format"), IntlDateTimeFormatFuncFormatDateTime, NoIntrinsic);
JSArray* boundArgs = JSArray::tryCreateUninitialized(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithUndecided), 0);
if (!boundArgs)
return JSValue::encode(throwOutOfMemoryError(state));
boundFormat = JSBoundFunction::create(vm, state, globalObject, targetObject, dtf, boundArgs, 1, ASCIILiteral("format"));
if (vm.exception())
return JSValue::encode(JSValue());
dtf->setBoundFormat(vm, boundFormat);
}
return JSValue::encode(boundFormat);
}
EncodedJSValue JSC_HOST_CALL IntlDateTimeFormatPrototypeFuncResolvedOptions(ExecState* state)
{
IntlDateTimeFormat* dateTimeFormat = jsDynamicCast<IntlDateTimeFormat*>(state->thisValue());
if (!dateTimeFormat)
dateTimeFormat = jsDynamicCast<IntlDateTimeFormat*>(state->thisValue().get(state, state->vm().propertyNames->builtinNames().intlSubstituteValuePrivateName()));
if (!dateTimeFormat)
return JSValue::encode(throwTypeError(state, ASCIILiteral("Intl.DateTimeFormat.prototype.resolvedOptions called on value that's not an object initialized as a DateTimeFormat")));
return JSValue::encode(dateTimeFormat->resolvedOptions(*state));
}
}
#endif // ENABLE(INTL)