IntlCollatorConstructor.cpp [plain text]
#include "config.h"
#include "IntlCollatorConstructor.h"
#if ENABLE(INTL)
#include "Error.h"
#include "IntlCollator.h"
#include "IntlCollatorPrototype.h"
#include "IntlObject.h"
#include "JSCInlines.h"
#include "Lookup.h"
namespace JSC {
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(IntlCollatorConstructor);
static EncodedJSValue JSC_HOST_CALL IntlCollatorConstructorFuncSupportedLocalesOf(ExecState*);
}
#include "IntlCollatorConstructor.lut.h"
namespace JSC {
static EncodedJSValue JSC_HOST_CALL callIntlCollator(ExecState*);
static EncodedJSValue JSC_HOST_CALL constructIntlCollator(ExecState*);
const ClassInfo IntlCollatorConstructor::s_info = { "Function", &InternalFunction::s_info, &collatorConstructorTable, nullptr, CREATE_METHOD_TABLE(IntlCollatorConstructor) };
IntlCollatorConstructor* IntlCollatorConstructor::create(VM& vm, Structure* structure, IntlCollatorPrototype* collatorPrototype, Structure* collatorStructure)
{
IntlCollatorConstructor* constructor = new (NotNull, allocateCell<IntlCollatorConstructor>(vm.heap)) IntlCollatorConstructor(vm, structure);
constructor->finishCreation(vm, collatorPrototype, collatorStructure);
return constructor;
}
Structure* IntlCollatorConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(InternalFunctionType, StructureFlags), info());
}
IntlCollatorConstructor::IntlCollatorConstructor(VM& vm, Structure* structure)
: InternalFunction(vm, structure, callIntlCollator, constructIntlCollator)
{
}
void IntlCollatorConstructor::finishCreation(VM& vm, IntlCollatorPrototype* collatorPrototype, Structure* collatorStructure)
{
Base::finishCreation(vm, "Collator"_s);
putDirectWithoutTransition(vm, vm.propertyNames->prototype, collatorPrototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(0), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete);
collatorPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, this, static_cast<unsigned>(PropertyAttribute::DontEnum));
m_collatorStructure.set(vm, this, collatorStructure);
}
static EncodedJSValue JSC_HOST_CALL constructIntlCollator(ExecState* state)
{
VM& vm = state->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
Structure* structure = InternalFunction::createSubclassStructure(state, state->newTarget(), jsCast<IntlCollatorConstructor*>(state->jsCallee())->collatorStructure());
RETURN_IF_EXCEPTION(scope, encodedJSValue());
IntlCollator* collator = IntlCollator::create(vm, structure);
ASSERT(collator);
scope.release();
collator->initializeCollator(*state, state->argument(0), state->argument(1));
return JSValue::encode(collator);
}
static EncodedJSValue JSC_HOST_CALL callIntlCollator(ExecState* state)
{
VM& vm = state->vm();
IntlCollatorConstructor* callee = jsCast<IntlCollatorConstructor*>(state->jsCallee());
IntlCollator* collator = IntlCollator::create(vm, callee->collatorStructure());
ASSERT(collator);
collator->initializeCollator(*state, state->argument(0), state->argument(1));
return JSValue::encode(collator);
}
EncodedJSValue JSC_HOST_CALL IntlCollatorConstructorFuncSupportedLocalesOf(ExecState* state)
{
VM& vm = state->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
Vector<String> requestedLocales = canonicalizeLocaleList(*state, state->argument(0));
RETURN_IF_EXCEPTION(scope, encodedJSValue());
JSGlobalObject* globalObject = state->jsCallee()->globalObject(vm);
scope.release();
return JSValue::encode(supportedLocales(*state, globalObject->intlCollatorAvailableLocales(), requestedLocales, state->argument(1)));
}
void IntlCollatorConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
IntlCollatorConstructor* thisObject = jsCast<IntlCollatorConstructor*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);
visitor.append(thisObject->m_collatorStructure);
}
}
#endif // ENABLE(INTL)