зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1260858 - "Update the DateTimeFormat.prototype.formatToParts to the final spec". r=waldo
--HG-- extra : rebase_source : 8060e7894b59d1e313f1623e56c15b7fa0549712
This commit is contained in:
Родитель
1bddf4ac22
Коммит
ffad6a6151
|
@ -1762,20 +1762,18 @@ InitDateTimeFormatClass(JSContext* cx, HandleObject Intl, Handle<GlobalObject*>
|
|||
}
|
||||
|
||||
// If the still-experimental DateTimeFormat.prototype.formatToParts method
|
||||
// is enabled, also add its getter.
|
||||
// is enabled, also add it.
|
||||
if (cx->compartment()->creationOptions().experimentalDateTimeFormatFormatToPartsEnabled()) {
|
||||
RootedValue ftp(cx);
|
||||
if (!GlobalObject::getIntrinsicValue(cx, cx->global(),
|
||||
cx->names().DateTimeFormatFormatToPartsGet, &getter))
|
||||
cx->names().DateTimeFormatFormatToParts, &ftp))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
if (!DefineProperty(cx, proto, cx->names().formatToParts, UndefinedHandleValue,
|
||||
JS_DATA_TO_FUNC_PTR(JSGetterOp, &getter.toObject()),
|
||||
nullptr, JSPROP_GETTER | JSPROP_SHARED))
|
||||
{
|
||||
|
||||
if (!DefineProperty(cx, proto, cx->names().formatToParts, ftp, nullptr, nullptr, 0))
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
RootedValue options(cx);
|
||||
if (!CreateDefaultOptions(cx, &options))
|
||||
|
@ -2127,7 +2125,7 @@ GetFieldTypeForFormatField(UDateFormatField fieldName)
|
|||
return &JSAtomState::weekday;
|
||||
|
||||
case UDAT_AM_PM_FIELD:
|
||||
return &JSAtomState::dayperiod;
|
||||
return &JSAtomState::dayPeriod;
|
||||
|
||||
case UDAT_TIMEZONE_FIELD:
|
||||
return &JSAtomState::timeZoneName;
|
||||
|
@ -2264,7 +2262,7 @@ intl_FormatToPartsDateTime(JSContext* cx, UDateFormat* df, double x, MutableHand
|
|||
|
||||
if (FieldType type = GetFieldTypeForFormatField(static_cast<UDateFormatField>(fieldInt))) {
|
||||
if (lastEndIndex < beginIndex) {
|
||||
if (!AppendPart(&JSAtomState::separator, lastEndIndex, beginIndex))
|
||||
if (!AppendPart(&JSAtomState::literal, lastEndIndex, beginIndex))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2273,9 +2271,9 @@ intl_FormatToPartsDateTime(JSContext* cx, UDateFormat* df, double x, MutableHand
|
|||
}
|
||||
}
|
||||
|
||||
// Append any final separator.
|
||||
// Append any final literal.
|
||||
if (lastEndIndex < overallResult->length()) {
|
||||
if (!AppendPart(&JSAtomState::separator, lastEndIndex, overallResult->length()))
|
||||
if (!AppendPart(&JSAtomState::literal, lastEndIndex, overallResult->length()))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -2736,7 +2736,10 @@ function Intl_DateTimeFormat_format_get() {
|
|||
}
|
||||
|
||||
|
||||
function dateTimeFormatFormatToPartsToBind() {
|
||||
function Intl_DateTimeFormat_formatToParts() {
|
||||
// Check "this DateTimeFormat object" per introduction of section 12.3.
|
||||
getDateTimeFormatInternals(this, "formatToParts");
|
||||
|
||||
// Steps 1.a.i-ii
|
||||
var date = arguments.length > 0 ? arguments[0] : undefined;
|
||||
var x = (date === undefined) ? std_Date_now() : ToNumber(date);
|
||||
|
@ -2746,25 +2749,6 @@ function dateTimeFormatFormatToPartsToBind() {
|
|||
}
|
||||
|
||||
|
||||
function Intl_DateTimeFormat_formatToParts_get() {
|
||||
// Check "this DateTimeFormat object" per introduction of section 12.3.
|
||||
var internals = getDateTimeFormatInternals(this, "formatToParts");
|
||||
|
||||
// Step 1.
|
||||
if (internals.boundFormatToParts === undefined) {
|
||||
// Step 1.a.
|
||||
var F = dateTimeFormatFormatToPartsToBind;
|
||||
|
||||
// Step 1.b-d.
|
||||
var bf = callFunction(FunctionBind, F, this);
|
||||
internals.boundFormatToParts = bf;
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
return internals.boundFormatToParts;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the resolved options for a DateTimeFormat object.
|
||||
*
|
||||
|
|
|
@ -57,9 +57,9 @@ var DateTimeFormat =
|
|||
format = new DateTimeFormat("en-us", {timeZone: "UTC"});
|
||||
assertEq(deepEqual(format.formatToParts(date), [
|
||||
{ type: 'month', value: '12' },
|
||||
{ type: 'separator', value: '/' },
|
||||
{ type: 'literal', value: '/' },
|
||||
{ type: 'day', value: '17' },
|
||||
{ type: 'separator', value: '/' },
|
||||
{ type: 'literal', value: '/' },
|
||||
{ type: 'year', value: '2012' }
|
||||
]), true);
|
||||
|
||||
|
@ -71,9 +71,9 @@ format = new DateTimeFormat("en-us", {
|
|||
timeZone: "UTC"});
|
||||
assertEq(deepEqual(format.formatToParts(date), [
|
||||
{ type: 'month', value: '12' },
|
||||
{ type: 'separator', value: '/' },
|
||||
{ type: 'literal', value: '/' },
|
||||
{ type: 'day', value: '17' },
|
||||
{ type: 'separator', value: '/' },
|
||||
{ type: 'literal', value: '/' },
|
||||
{ type: 'year', value: '2012' }
|
||||
]), true);
|
||||
assertEq(composeDate(format.formatToParts(date)), format.format(date));
|
||||
|
@ -87,9 +87,9 @@ format = new DateTimeFormat("en-us", {
|
|||
timeZone: "UTC"});
|
||||
assertEq(deepEqual(format.formatToParts(date), [
|
||||
{ type: 'hour', value: '03' },
|
||||
{ type: 'separator', value: ':' },
|
||||
{ type: 'literal', value: ':' },
|
||||
{ type: 'minute', value: '00' },
|
||||
{ type: 'separator', value: ':' },
|
||||
{ type: 'literal', value: ':' },
|
||||
{ type: 'second', value: '42' }
|
||||
]), true);
|
||||
assertEq(composeDate(format.formatToParts(date)), format.format(date));
|
||||
|
@ -103,12 +103,12 @@ format = new DateTimeFormat("en-us", {
|
|||
timeZone: "UTC"});
|
||||
assertEq(deepEqual(format.formatToParts(date), [
|
||||
{ type: 'hour', value: '3' },
|
||||
{ type: 'separator', value: ':' },
|
||||
{ type: 'literal', value: ':' },
|
||||
{ type: 'minute', value: '00' },
|
||||
{ type: 'separator', value: ':' },
|
||||
{ type: 'literal', value: ':' },
|
||||
{ type: 'second', value: '42' },
|
||||
{ type: 'separator', value: ' ' },
|
||||
{ type: 'dayperiod', value: 'AM' }
|
||||
{ type: 'literal', value: ' ' },
|
||||
{ type: 'dayPeriod', value: 'AM' }
|
||||
]), true);
|
||||
assertEq(composeDate(format.formatToParts(date)), format.format(date));
|
||||
|
||||
|
@ -137,7 +137,7 @@ format = new DateTimeFormat("en-us", {
|
|||
timeZone: "UTC"});
|
||||
assertEq(deepEqual(format.formatToParts(date), [
|
||||
{ type: 'year', value: '2012' },
|
||||
{ type: 'separator', value: ' ' },
|
||||
{ type: 'literal', value: ' ' },
|
||||
{ type: 'era', value: 'AD' }
|
||||
]), true);
|
||||
assertEq(composeDate(format.formatToParts(date)), format.format(date));
|
||||
|
@ -155,20 +155,20 @@ format = new DateTimeFormat("en-us", {
|
|||
timeZone: "UTC"});
|
||||
assertEq(deepEqual(format.formatToParts(date), [
|
||||
{ type: 'weekday', value: 'Monday' },
|
||||
{ type: 'separator', value: ', ' },
|
||||
{ type: 'literal', value: ', ' },
|
||||
{ type: 'month', value: '12' },
|
||||
{ type: 'separator', value: '/' },
|
||||
{ type: 'literal', value: '/' },
|
||||
{ type: 'day', value: '17' },
|
||||
{ type: 'separator', value: '/' },
|
||||
{ type: 'literal', value: '/' },
|
||||
{ type: 'year', value: '2012' },
|
||||
{ type: 'separator', value: ', ' },
|
||||
{ type: 'literal', value: ', ' },
|
||||
{ type: 'hour', value: '3' },
|
||||
{ type: 'separator', value: ':' },
|
||||
{ type: 'literal', value: ':' },
|
||||
{ type: 'minute', value: '00' },
|
||||
{ type: 'separator', value: ':' },
|
||||
{ type: 'literal', value: ':' },
|
||||
{ type: 'second', value: '42' },
|
||||
{ type: 'separator', value: ' ' },
|
||||
{ type: 'dayperiod', value: 'AM' }
|
||||
{ type: 'literal', value: ' ' },
|
||||
{ type: 'dayPeriod', value: 'AM' }
|
||||
]), true);
|
||||
assertEq(composeDate(format.formatToParts(date)), format.format(date));
|
||||
|
||||
|
|
|
@ -66,9 +66,9 @@
|
|||
macro(currencyDisplay, currencyDisplay, "currencyDisplay") \
|
||||
macro(DateTimeFormat, DateTimeFormat, "DateTimeFormat") \
|
||||
macro(DateTimeFormatFormatGet, DateTimeFormatFormatGet, "Intl_DateTimeFormat_format_get") \
|
||||
macro(DateTimeFormatFormatToPartsGet, DateTimeFormatFormatToPartsGet, "Intl_DateTimeFormat_formatToParts_get") \
|
||||
macro(DateTimeFormatFormatToParts, DateTimeFormatFormatToParts, "Intl_DateTimeFormat_formatToParts") \
|
||||
macro(day, day, "day") \
|
||||
macro(dayperiod, dayperiod, "dayperiod") \
|
||||
macro(dayPeriod, dayPeriod, "dayPeriod") \
|
||||
macro(decodeURI, decodeURI, "decodeURI") \
|
||||
macro(decodeURIComponent, decodeURIComponent, "decodeURIComponent") \
|
||||
macro(default_, default_, "default") \
|
||||
|
@ -169,6 +169,7 @@
|
|||
macro(let, let, "let") \
|
||||
macro(line, line, "line") \
|
||||
macro(lineNumber, lineNumber, "lineNumber") \
|
||||
macro(literal, literal, "literal") \
|
||||
macro(loc, loc, "loc") \
|
||||
macro(locale, locale, "locale") \
|
||||
macro(lookupGetter, lookupGetter, "__lookupGetter__") \
|
||||
|
@ -238,7 +239,6 @@
|
|||
macro(scripts, scripts, "scripts") \
|
||||
macro(second, second, "second") \
|
||||
macro(sensitivity, sensitivity, "sensitivity") \
|
||||
macro(separator, separator, "separator") \
|
||||
macro(set, set, "set") \
|
||||
macro(setPrefix, setPrefix, "set ") \
|
||||
macro(setPrototypeOf, setPrototypeOf, "setPrototypeOf") \
|
||||
|
|
Загрузка…
Ссылка в новой задаче