IntlPluralRulesConstructor.cpp [plain text]
#include "config.h"
#include "IntlPluralRulesConstructor.h"
#if ENABLE(INTL)
#include "Error.h"
#include "IntlObject.h"
#include "IntlPluralRules.h"
#include "IntlPluralRulesPrototype.h"
#include "JSCInlines.h"
#include "Lookup.h"
namespace JSC {
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(IntlPluralRulesConstructor);
static EncodedJSValue JSC_HOST_CALL IntlPluralRulesConstructorFuncSupportedLocalesOf(ExecState*);
}
#include "IntlPluralRulesConstructor.lut.h"
namespace JSC {
const ClassInfo IntlPluralRulesConstructor::s_info = { "Function", &InternalFunction::s_info, &pluralRulesConstructorTable, nullptr, CREATE_METHOD_TABLE(IntlPluralRulesConstructor) };
IntlPluralRulesConstructor* IntlPluralRulesConstructor::create(VM& vm, Structure* structure, IntlPluralRulesPrototype* pluralRulesPrototype, Structure* pluralRulesStructure)
{
IntlPluralRulesConstructor* constructor = new (NotNull, allocateCell<IntlPluralRulesConstructor>(vm.heap)) IntlPluralRulesConstructor(vm, structure);
constructor->finishCreation(vm, pluralRulesPrototype, pluralRulesStructure);
return constructor;
}
Structure* IntlPluralRulesConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(InternalFunctionType, StructureFlags), info());
}
static EncodedJSValue JSC_HOST_CALL callIntlPluralRules(ExecState*);
static EncodedJSValue JSC_HOST_CALL constructIntlPluralRules(ExecState*);
IntlPluralRulesConstructor::IntlPluralRulesConstructor(VM& vm, Structure* structure)
: InternalFunction(vm, structure, callIntlPluralRules, constructIntlPluralRules)
{
}
void IntlPluralRulesConstructor::finishCreation(VM& vm, IntlPluralRulesPrototype* pluralRulesPrototype, Structure* pluralRulesStructure)
{
Base::finishCreation(vm, "PluralRules"_s);
putDirectWithoutTransition(vm, vm.propertyNames->prototype, pluralRulesPrototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(0), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum);
pluralRulesPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, this, static_cast<unsigned>(PropertyAttribute::DontEnum));
m_pluralRulesStructure.set(vm, this, pluralRulesStructure);
}
static EncodedJSValue JSC_HOST_CALL constructIntlPluralRules(ExecState* state)
{
VM& vm = state->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
Structure* structure = InternalFunction::createSubclassStructure(state, state->newTarget(), jsCast<IntlPluralRulesConstructor*>(state->jsCallee())->pluralRulesStructure());
RETURN_IF_EXCEPTION(scope, encodedJSValue());
IntlPluralRules* pluralRules = IntlPluralRules::create(vm, structure);
ASSERT(pluralRules);
scope.release();
pluralRules->initializePluralRules(*state, state->argument(0), state->argument(1));
return JSValue::encode(pluralRules);
}
static EncodedJSValue JSC_HOST_CALL callIntlPluralRules(ExecState* state)
{
VM& vm = state->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(state, scope, "PluralRules"));
}
EncodedJSValue JSC_HOST_CALL IntlPluralRulesConstructorFuncSupportedLocalesOf(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());
RELEASE_AND_RETURN(scope, JSValue::encode(supportedLocales(*state, availableLocales, requestedLocales, state->argument(1))));
}
void IntlPluralRulesConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
IntlPluralRulesConstructor* thisObject = jsCast<IntlPluralRulesConstructor*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);
visitor.append(thisObject->m_pluralRulesStructure);
}
}
#endif // ENABLE(INTL)