IntlNumberFormatConstructor.cpp [plain text]
#include "config.h"
#include "IntlNumberFormatConstructor.h"
#if ENABLE(INTL)
#include "Error.h"
#include "IntlNumberFormat.h"
#include "IntlNumberFormatPrototype.h"
#include "IntlObject.h"
#include "IntlObjectInlines.h"
#include "JSCJSValueInlines.h"
#include "JSCellInlines.h"
#include "Lookup.h"
#include "SlotVisitorInlines.h"
#include "StructureInlines.h"
namespace JSC {
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(IntlNumberFormatConstructor);
static EncodedJSValue JSC_HOST_CALL IntlNumberFormatConstructorFuncSupportedLocalesOf(ExecState*);
}
#include "IntlNumberFormatConstructor.lut.h"
namespace JSC {
const ClassInfo IntlNumberFormatConstructor::s_info = { "Function", &Base::s_info, &numberFormatConstructorTable, CREATE_METHOD_TABLE(IntlNumberFormatConstructor) };
IntlNumberFormatConstructor* IntlNumberFormatConstructor::create(VM& vm, Structure* structure, IntlNumberFormatPrototype* numberFormatPrototype, Structure* numberFormatStructure)
{
IntlNumberFormatConstructor* constructor = new (NotNull, allocateCell<IntlNumberFormatConstructor>(vm.heap)) IntlNumberFormatConstructor(vm, structure);
constructor->finishCreation(vm, numberFormatPrototype, numberFormatStructure);
return constructor;
}
Structure* IntlNumberFormatConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
IntlNumberFormatConstructor::IntlNumberFormatConstructor(VM& vm, Structure* structure)
: InternalFunction(vm, structure)
{
}
void IntlNumberFormatConstructor::finishCreation(VM& vm, IntlNumberFormatPrototype* numberFormatPrototype, Structure* numberFormatStructure)
{
Base::finishCreation(vm, ASCIILiteral("NumberFormat"));
putDirectWithoutTransition(vm, vm.propertyNames->prototype, numberFormatPrototype, DontEnum | DontDelete | ReadOnly);
putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum | DontDelete);
m_numberFormatStructure.set(vm, this, numberFormatStructure);
}
static EncodedJSValue JSC_HOST_CALL constructIntlNumberFormat(ExecState* state)
{
Structure* structure = InternalFunction::createSubclassStructure(state, state->newTarget(), jsCast<IntlNumberFormatConstructor*>(state->callee())->numberFormatStructure());
if (state->hadException())
return JSValue::encode(jsUndefined());
IntlNumberFormat* numberFormat = IntlNumberFormat::create(state->vm(), structure);
ASSERT(numberFormat);
numberFormat->initializeNumberFormat(*state, state->argument(0), state->argument(1));
return JSValue::encode(numberFormat);
}
static EncodedJSValue JSC_HOST_CALL callIntlNumberFormat(ExecState* state)
{
IntlNumberFormatConstructor* callee = jsCast<IntlNumberFormatConstructor*>(state->callee());
return JSValue::encode(constructIntlInstanceWithWorkaroundForLegacyIntlConstructor<IntlNumberFormat>(*state, state->thisValue(), callee, [&] (VM& vm) {
IntlNumberFormat* numberFormat = IntlNumberFormat::create(vm, callee->numberFormatStructure());
ASSERT(numberFormat);
numberFormat->initializeNumberFormat(*state, state->argument(0), state->argument(1));
return numberFormat;
}));
}
ConstructType IntlNumberFormatConstructor::getConstructData(JSCell*, ConstructData& constructData)
{
constructData.native.function = constructIntlNumberFormat;
return ConstructType::Host;
}
CallType IntlNumberFormatConstructor::getCallData(JSCell*, CallData& callData)
{
callData.native.function = callIntlNumberFormat;
return CallType::Host;
}
EncodedJSValue JSC_HOST_CALL IntlNumberFormatConstructorFuncSupportedLocalesOf(ExecState* state)
{
JSGlobalObject* globalObject = state->callee()->globalObject();
const HashSet<String> availableLocales = globalObject->intlNumberFormatAvailableLocales();
Vector<String> requestedLocales = canonicalizeLocaleList(*state, state->argument(0));
if (state->hadException())
return JSValue::encode(jsUndefined());
return JSValue::encode(supportedLocales(*state, availableLocales, requestedLocales, state->argument(1)));
}
void IntlNumberFormatConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
IntlNumberFormatConstructor* thisObject = jsCast<IntlNumberFormatConstructor*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);
visitor.append(&thisObject->m_numberFormatStructure);
}
}
#endif // ENABLE(INTL)