IntlPluralRulesConstructor.cpp [plain text]
#include "config.h"
#include "IntlPluralRulesConstructor.h"
#include "IntlObject.h"
#include "IntlPluralRules.h"
#include "IntlPluralRulesPrototype.h"
#include "JSCInlines.h"
namespace JSC {
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(IntlPluralRulesConstructor);
static EncodedJSValue JSC_HOST_CALL IntlPluralRulesConstructorFuncSupportedLocalesOf(JSGlobalObject*, CallFrame*);
}
#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)
{
IntlPluralRulesConstructor* constructor = new (NotNull, allocateCell<IntlPluralRulesConstructor>(vm.heap)) IntlPluralRulesConstructor(vm, structure);
constructor->finishCreation(vm, pluralRulesPrototype);
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(JSGlobalObject*, CallFrame*);
static EncodedJSValue JSC_HOST_CALL constructIntlPluralRules(JSGlobalObject*, CallFrame*);
IntlPluralRulesConstructor::IntlPluralRulesConstructor(VM& vm, Structure* structure)
: InternalFunction(vm, structure, callIntlPluralRules, constructIntlPluralRules)
{
}
void IntlPluralRulesConstructor::finishCreation(VM& vm, IntlPluralRulesPrototype* pluralRulesPrototype)
{
Base::finishCreation(vm, "PluralRules"_s, NameAdditionMode::WithoutStructureTransition);
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));
}
static EncodedJSValue JSC_HOST_CALL constructIntlPluralRules(JSGlobalObject* globalObject, CallFrame* callFrame)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSObject* newTarget = asObject(callFrame->newTarget());
Structure* structure = newTarget == callFrame->jsCallee()
? globalObject->pluralRulesStructure()
: InternalFunction::createSubclassStructure(globalObject, newTarget, getFunctionRealm(vm, newTarget)->pluralRulesStructure());
RETURN_IF_EXCEPTION(scope, { });
IntlPluralRules* pluralRules = IntlPluralRules::create(vm, structure);
ASSERT(pluralRules);
scope.release();
pluralRules->initializePluralRules(globalObject, callFrame->argument(0), callFrame->argument(1));
return JSValue::encode(pluralRules);
}
static EncodedJSValue JSC_HOST_CALL callIntlPluralRules(JSGlobalObject* globalObject, CallFrame*)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(globalObject, scope, "PluralRules"));
}
EncodedJSValue JSC_HOST_CALL IntlPluralRulesConstructorFuncSupportedLocalesOf(JSGlobalObject* globalObject, CallFrame* callFrame)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
const HashSet<String>& availableLocales = intlPluralRulesAvailableLocales();
Vector<String> requestedLocales = canonicalizeLocaleList(globalObject, callFrame->argument(0));
RETURN_IF_EXCEPTION(scope, encodedJSValue());
RELEASE_AND_RETURN(scope, JSValue::encode(supportedLocales(globalObject, availableLocales, requestedLocales, callFrame->argument(1))));
}
}