IntlNumberFormatPrototype.cpp [plain text]
#include "config.h"
#include "IntlNumberFormatPrototype.h"
#if ENABLE(INTL)
#include "BuiltinNames.h"
#include "Error.h"
#include "IntlNumberFormat.h"
#include "JSBoundFunction.h"
#include "JSCJSValueInlines.h"
#include "JSCellInlines.h"
#include "JSObject.h"
#include "StructureInlines.h"
namespace JSC {
static EncodedJSValue JSC_HOST_CALL IntlNumberFormatPrototypeGetterFormat(ExecState*);
static EncodedJSValue JSC_HOST_CALL IntlNumberFormatPrototypeFuncResolvedOptions(ExecState*);
}
#include "IntlNumberFormatPrototype.lut.h"
namespace JSC {
const ClassInfo IntlNumberFormatPrototype::s_info = { "Object", &IntlNumberFormat::s_info, &numberFormatPrototypeTable, CREATE_METHOD_TABLE(IntlNumberFormatPrototype) };
IntlNumberFormatPrototype* IntlNumberFormatPrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
{
IntlNumberFormatPrototype* object = new (NotNull, allocateCell<IntlNumberFormatPrototype>(vm.heap)) IntlNumberFormatPrototype(vm, structure);
object->finishCreation(vm, structure);
return object;
}
Structure* IntlNumberFormatPrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
IntlNumberFormatPrototype::IntlNumberFormatPrototype(VM& vm, Structure* structure)
: IntlNumberFormat(vm, structure)
{
}
void IntlNumberFormatPrototype::finishCreation(VM& vm, Structure*)
{
Base::finishCreation(vm);
}
static EncodedJSValue JSC_HOST_CALL IntlNumberFormatFuncFormatNumber(ExecState* state)
{
IntlNumberFormat* numberFormat = jsCast<IntlNumberFormat*>(state->thisValue());
double number = state->argument(0).toNumber(state);
if (state->hadException())
return JSValue::encode(jsUndefined());
return JSValue::encode(numberFormat->formatNumber(*state, number));
}
EncodedJSValue JSC_HOST_CALL IntlNumberFormatPrototypeGetterFormat(ExecState* state)
{
IntlNumberFormat* nf = jsDynamicCast<IntlNumberFormat*>(state->thisValue());
if (!nf)
nf = jsDynamicCast<IntlNumberFormat*>(state->thisValue().get(state, state->vm().propertyNames->builtinNames().intlSubstituteValuePrivateName()));
if (!nf)
return JSValue::encode(throwTypeError(state, ASCIILiteral("Intl.NumberFormat.prototype.format called on value that's not an object initialized as a NumberFormat")));
JSBoundFunction* boundFormat = nf->boundFormat();
if (!boundFormat) {
VM& vm = state->vm();
JSGlobalObject* globalObject = nf->globalObject();
JSFunction* targetObject = JSFunction::create(vm, globalObject, 1, ASCIILiteral("format"), IntlNumberFormatFuncFormatNumber, NoIntrinsic);
JSArray* boundArgs = JSArray::tryCreateUninitialized(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithUndecided), 0);
if (!boundArgs)
return JSValue::encode(throwOutOfMemoryError(state));
boundFormat = JSBoundFunction::create(vm, state, globalObject, targetObject, nf, boundArgs, 1, ASCIILiteral("format"));
if (vm.exception())
return JSValue::encode(JSValue());
nf->setBoundFormat(vm, boundFormat);
}
return JSValue::encode(boundFormat);
}
EncodedJSValue JSC_HOST_CALL IntlNumberFormatPrototypeFuncResolvedOptions(ExecState* state)
{
IntlNumberFormat* numberFormat = jsDynamicCast<IntlNumberFormat*>(state->thisValue());
if (!numberFormat)
numberFormat = jsDynamicCast<IntlNumberFormat*>(state->thisValue().get(state, state->vm().propertyNames->builtinNames().intlSubstituteValuePrivateName()));
if (!numberFormat)
return JSValue::encode(throwTypeError(state, ASCIILiteral("Intl.NumberFormat.prototype.resolvedOptions called on value that's not an object initialized as a NumberFormat")));
return JSValue::encode(numberFormat->resolvedOptions(*state));
}
}
#endif // ENABLE(INTL)