IntlLocaleConstructor.cpp [plain text]
#include "config.h"
#include "IntlLocaleConstructor.h"
#include "IntlLocale.h"
#include "IntlLocalePrototype.h"
#include "JSCInlines.h"
namespace JSC {
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(IntlLocaleConstructor);
const ClassInfo IntlLocaleConstructor::s_info = { "Function", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(IntlLocaleConstructor) };
IntlLocaleConstructor* IntlLocaleConstructor::create(VM& vm, Structure* structure, IntlLocalePrototype* localePrototype)
{
auto* constructor = new (NotNull, allocateCell<IntlLocaleConstructor>(vm.heap)) IntlLocaleConstructor(vm, structure);
constructor->finishCreation(vm, localePrototype);
return constructor;
}
Structure* IntlLocaleConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(InternalFunctionType, StructureFlags), info());
}
static JSC_DECLARE_HOST_FUNCTION(callIntlLocale);
static JSC_DECLARE_HOST_FUNCTION(constructIntlLocale);
IntlLocaleConstructor::IntlLocaleConstructor(VM& vm, Structure* structure)
: Base(vm, structure, callIntlLocale, constructIntlLocale)
{
}
void IntlLocaleConstructor::finishCreation(VM& vm, IntlLocalePrototype* localePrototype)
{
Base::finishCreation(vm, 1, "Locale"_s, PropertyAdditionMode::WithoutStructureTransition);
putDirectWithoutTransition(vm, vm.propertyNames->prototype, localePrototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
localePrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, this, static_cast<unsigned>(PropertyAttribute::DontEnum));
}
JSC_DEFINE_HOST_FUNCTION(constructIntlLocale, (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->localeStructure()
: InternalFunction::createSubclassStructure(globalObject, newTarget, getFunctionRealm(vm, newTarget)->localeStructure());
RETURN_IF_EXCEPTION(scope, { });
IntlLocale* locale = IntlLocale::create(vm, structure);
ASSERT(locale);
JSValue tag = callFrame->argument(0);
if (!tag.isString() && !tag.isObject())
return throwVMTypeError(globalObject, scope, "First argument to Intl.Locale must be a string or an object"_s);
scope.release();
locale->initializeLocale(globalObject, tag, callFrame->argument(1));
return JSValue::encode(locale);
}
JSC_DEFINE_HOST_FUNCTION(callIntlLocale, (JSGlobalObject* globalObject, CallFrame*))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(globalObject, scope, "Locale"));
}
}