IntlDateTimeFormatConstructor.cpp [plain text]
#include "config.h"
#include "IntlDateTimeFormatConstructor.h"
#if ENABLE(INTL)
#include "Error.h"
#include "IntlDateTimeFormat.h"
#include "IntlDateTimeFormatPrototype.h"
#include "IntlObject.h"
#include "IntlObjectInlines.h"
#include "JSCInlines.h"
#include "Lookup.h"
namespace JSC {
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(IntlDateTimeFormatConstructor);
static EncodedJSValue JSC_HOST_CALL IntlDateTimeFormatConstructorFuncSupportedLocalesOf(ExecState*);
}
#include "IntlDateTimeFormatConstructor.lut.h"
namespace JSC {
const ClassInfo IntlDateTimeFormatConstructor::s_info = { "Function", &InternalFunction::s_info, &dateTimeFormatConstructorTable, nullptr, CREATE_METHOD_TABLE(IntlDateTimeFormatConstructor) };
IntlDateTimeFormatConstructor* IntlDateTimeFormatConstructor::create(VM& vm, Structure* structure, IntlDateTimeFormatPrototype* dateTimeFormatPrototype, Structure* dateTimeFormatStructure)
{
IntlDateTimeFormatConstructor* constructor = new (NotNull, allocateCell<IntlDateTimeFormatConstructor>(vm.heap)) IntlDateTimeFormatConstructor(vm, structure);
constructor->finishCreation(vm, dateTimeFormatPrototype, dateTimeFormatStructure);
return constructor;
}
Structure* IntlDateTimeFormatConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(InternalFunctionType, StructureFlags), info());
}
static EncodedJSValue JSC_HOST_CALL callIntlDateTimeFormat(ExecState*);
static EncodedJSValue JSC_HOST_CALL constructIntlDateTimeFormat(ExecState*);
IntlDateTimeFormatConstructor::IntlDateTimeFormatConstructor(VM& vm, Structure* structure)
: InternalFunction(vm, structure, callIntlDateTimeFormat, constructIntlDateTimeFormat)
{
}
void IntlDateTimeFormatConstructor::finishCreation(VM& vm, IntlDateTimeFormatPrototype* dateTimeFormatPrototype, Structure* dateTimeFormatStructure)
{
Base::finishCreation(vm, "DateTimeFormat"_s);
putDirectWithoutTransition(vm, vm.propertyNames->prototype, dateTimeFormatPrototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(0), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete);
dateTimeFormatPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, this, static_cast<unsigned>(PropertyAttribute::DontEnum));
m_dateTimeFormatStructure.set(vm, this, dateTimeFormatStructure);
}
static EncodedJSValue JSC_HOST_CALL constructIntlDateTimeFormat(ExecState* state)
{
VM& vm = state->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
Structure* structure = InternalFunction::createSubclassStructure(state, state->newTarget(), jsCast<IntlDateTimeFormatConstructor*>(state->jsCallee())->dateTimeFormatStructure());
RETURN_IF_EXCEPTION(scope, encodedJSValue());
IntlDateTimeFormat* dateTimeFormat = IntlDateTimeFormat::create(vm, structure);
ASSERT(dateTimeFormat);
scope.release();
dateTimeFormat->initializeDateTimeFormat(*state, state->argument(0), state->argument(1));
return JSValue::encode(dateTimeFormat);
}
static EncodedJSValue JSC_HOST_CALL callIntlDateTimeFormat(ExecState* state)
{
IntlDateTimeFormatConstructor* callee = jsCast<IntlDateTimeFormatConstructor*>(state->jsCallee());
return JSValue::encode(constructIntlInstanceWithWorkaroundForLegacyIntlConstructor<IntlDateTimeFormat>(*state, state->thisValue(), callee, [&] (VM& vm) {
IntlDateTimeFormat* dateTimeFormat = IntlDateTimeFormat::create(vm, callee->dateTimeFormatStructure());
ASSERT(dateTimeFormat);
dateTimeFormat->initializeDateTimeFormat(*state, state->argument(0), state->argument(1));
return dateTimeFormat;
}));
}
EncodedJSValue JSC_HOST_CALL IntlDateTimeFormatConstructorFuncSupportedLocalesOf(ExecState* state)
{
VM& vm = state->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSGlobalObject* globalObject = state->jsCallee()->globalObject(vm);
const HashSet<String> availableLocales = globalObject->intlDateTimeFormatAvailableLocales();
Vector<String> requestedLocales = canonicalizeLocaleList(*state, state->argument(0));
RETURN_IF_EXCEPTION(scope, encodedJSValue());
scope.release();
return JSValue::encode(supportedLocales(*state, availableLocales, requestedLocales, state->argument(1)));
}
void IntlDateTimeFormatConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
IntlDateTimeFormatConstructor* thisObject = jsCast<IntlDateTimeFormatConstructor*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);
visitor.append(thisObject->m_dateTimeFormatStructure);
}
}
#endif // ENABLE(INTL)