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 "JSCInlines.h"
#include "Lookup.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, nullptr, 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(InternalFunctionType, StructureFlags), info());
}
static EncodedJSValue JSC_HOST_CALL callIntlNumberFormat(ExecState*);
static EncodedJSValue JSC_HOST_CALL constructIntlNumberFormat(ExecState*);
IntlNumberFormatConstructor::IntlNumberFormatConstructor(VM& vm, Structure* structure)
: InternalFunction(vm, structure, callIntlNumberFormat, constructIntlNumberFormat)
{
}
void IntlNumberFormatConstructor::finishCreation(VM& vm, IntlNumberFormatPrototype* numberFormatPrototype, Structure* numberFormatStructure)
{
Base::finishCreation(vm, "NumberFormat"_s);
putDirectWithoutTransition(vm, vm.propertyNames->prototype, numberFormatPrototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(0), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete);
numberFormatPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, this, static_cast<unsigned>(PropertyAttribute::DontEnum));
m_numberFormatStructure.set(vm, this, numberFormatStructure);
}
static EncodedJSValue JSC_HOST_CALL constructIntlNumberFormat(ExecState* state)
{
VM& vm = state->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
Structure* structure = InternalFunction::createSubclassStructure(state, state->newTarget(), jsCast<IntlNumberFormatConstructor*>(state->jsCallee())->numberFormatStructure());
RETURN_IF_EXCEPTION(scope, encodedJSValue());
IntlNumberFormat* numberFormat = IntlNumberFormat::create(vm, structure);
ASSERT(numberFormat);
scope.release();
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->jsCallee());
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;
}));
}
EncodedJSValue JSC_HOST_CALL IntlNumberFormatConstructorFuncSupportedLocalesOf(ExecState* state)
{
VM& vm = state->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSGlobalObject* globalObject = state->jsCallee()->globalObject(vm);
const HashSet<String> availableLocales = globalObject->intlNumberFormatAvailableLocales();
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 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)