EncodedJSValue JSC_HOST_CALL IntlDateTimeFormatFuncFormatDateTime(ExecState* state)
{
    // 12.3.4 DateTime Format Functions (ECMA-402 2.0)
    // 1. Let dtf be the this value.
    IntlDateTimeFormat* format = jsDynamicCast<IntlDateTimeFormat*>(state->thisValue());
    // 2. Assert: Type(dtf) is Object and dtf has an [[initializedDateTimeFormat]] internal slot whose value is true.
    if (!format)
        return JSValue::encode(throwTypeError(state));

    JSValue date = state->argument(0);
    double value;

    // 3. If date is not provided or is undefined, then
    if (date.isUndefined()) {
        // a. Let x be %Date_now%().
        value = JSValue::decode(dateNow(state)).toNumber(state);
    } else {
        // 4. Else
        // a. Let x be ToNumber(date).
        value = date.toNumber(state);
        // b. ReturnIfAbrupt(x).
        if (state->hadException())
            return JSValue::encode(jsUndefined());
    }

    // 5. Return FormatDateTime(dtf, x).

    // 12.3.4 FormatDateTime abstract operation (ECMA-402 2.0)

    // 1. If x is not a finite Number, then throw a RangeError exception.
    if (!std::isfinite(value))
        return JSValue::encode(throwRangeError(state, ASCIILiteral("date value is not finite in DateTimeFormat.format()")));

    // FIXME: implement 2 - 9

    // Return new Date(value).toString() until properly implemented.
    VM& vm = state->vm();
    JSGlobalObject* globalObject = state->callee()->globalObject();
    DateInstance* d = DateInstance::create(vm, globalObject->dateStructure(), value);
    return JSValue::encode(JSValue(d).toString(state));
}