|
929 | 929 | *
|
930 | 930 | * @param {String[]} props The list of properties to extract from hiddenObject and add to the final resolved options
|
931 | 931 | * @param {Object} hiddenObject The hiddenObject of the calling constructor that contains values for each prop in props
|
932 |
| - * @param {Function} func An optional custom function(prop, resolved) run for each prop; if omitted, default logic will be used |
| 932 | + * @param {Function} func An optional custom function(prop, resolved) run for each prop; it should return true when |
| 933 | + * it handles a property itself. If it does not return true, the default logic will be used. |
933 | 934 | */
|
934 | 935 | const createResolvedOptions = function (props, hiddenObject, func = null) {
|
935 | 936 | const resolved = _.create();
|
936 | 937 | _.forEach(props, function (prop) {
|
937 |
| - if (func !== null) { |
938 |
| - func(prop, resolved); |
939 |
| - } else if (typeof hiddenObject[prop] !== "undefined") { |
| 938 | + if (func !== null && func(prop, resolved) === true) { |
| 939 | + // the callback returned true, which means this property was handled and we can go to the next one |
| 940 | + return; |
| 941 | + } |
| 942 | + |
| 943 | + if (typeof hiddenObject[prop] !== "undefined") { |
940 | 944 | resolved[prop] = hiddenObject[prop];
|
941 | 945 | }
|
942 | 946 | });
|
|
1220 | 1224 | InitializeNumberFormat(stateObject, arguments[0], arguments[1]);
|
1221 | 1225 |
|
1222 | 1226 | const n = Internal.ToNumber(this);
|
1223 |
| - // Need to special case the "-0" case to format as 0 instead of -0. |
1224 |
| - return platform.formatNumber(n === -0 ? 0 : n, stateObject, /* toParts */ false, /* forNumberPrototypeToLocaleString */ true); |
| 1227 | + return platform.formatNumber(n, stateObject, /* toParts */ false, /* forNumberPrototypeToLocaleString */ true); |
1225 | 1228 | }), IntlBuiltInFunctionID.NumberToLocaleString);
|
1226 | 1229 |
|
1227 | 1230 | if (InitType === "Number") {
|
|
1266 | 1269 | platform.raiseNeedObjectOfType("NumberFormat.prototype.format", "NumberFormat");
|
1267 | 1270 | }
|
1268 | 1271 |
|
1269 |
| - // Need to special case the '-0' case to format as 0 instead of -0. |
1270 |
| - return platform.formatNumber(n === -0 ? 0 : n, hiddenObject, /* toParts */ false, /* forNumberPrototypeToLocaleString */ false); |
| 1272 | + return platform.formatNumber(n, hiddenObject, /* toParts */ false, /* forNumberPrototypeToLocaleString */ false); |
1271 | 1273 | });
|
1272 | 1274 |
|
1273 | 1275 | const formatToParts = tagPublicFunction("Intl.NumberFormat.prototype.formatToParts", function formatToParts(n) {
|
|
1282 | 1284 | platform.raiseNeedObjectOfType("NumberFormat.prototype.formatToParts", "NumberFormat");
|
1283 | 1285 | }
|
1284 | 1286 |
|
1285 |
| - // Need to special case the '-0' case to format as 0 instead of -0. |
1286 |
| - return platform.formatNumber(n === -0 ? 0 : n, hiddenObject, /* toParts */ true, /* forNumberPrototypeToLocaleString */ false); |
| 1287 | + return platform.formatNumber(n, hiddenObject, /* toParts */ true, /* forNumberPrototypeToLocaleString */ false); |
1287 | 1288 | });
|
1288 | 1289 |
|
1289 | 1290 | // See explanation of `getCanonicalLocales`
|
|
1933 | 1934 | resolved.hourCycle = hc;
|
1934 | 1935 | resolved.hour12 = hc === "h11" || hc === "h12";
|
1935 | 1936 | }
|
1936 |
| - } else if (hiddenObject[prop] !== undefined && hiddenObject[prop] !== null) { |
1937 |
| - resolved[prop] = hiddenObject[prop]; |
| 1937 | + |
| 1938 | + return true; |
1938 | 1939 | }
|
1939 | 1940 | });
|
1940 | 1941 | },
|
|
2096 | 2097 | if (prop === "pluralCategories") {
|
2097 | 2098 | // https://github.com/tc39/ecma402/issues/224: create a copy of the pluralCategories array
|
2098 | 2099 | resolved.pluralCategories = _.slice(pr.pluralCategories, 0);
|
2099 |
| - } else { |
2100 |
| - resolved[prop] = pr[prop]; |
| 2100 | + return true; |
2101 | 2101 | }
|
2102 | 2102 | });
|
2103 | 2103 | };
|
|
3181 | 3181 | InitializeNumberFormat(stateObject, arguments[0], arguments[1]);
|
3182 | 3182 |
|
3183 | 3183 | var n = Internal.ToNumber(this);
|
3184 |
| - // Need to special case the '-0' case to format as 0 instead of -0. |
3185 |
| - return String(platform.formatNumber(n === -0 ? 0 : n, stateObject)); |
| 3184 | + return String(platform.formatNumber(n, stateObject)); |
3186 | 3185 | }), IntlBuiltInFunctionID.NumberToLocaleString);
|
3187 | 3186 |
|
3188 | 3187 | if (InitType === 'Intl') {
|
|
3226 | 3225 | platform.raiseNeedObjectOfType("NumberFormat.prototype.format", "NumberFormat");
|
3227 | 3226 | }
|
3228 | 3227 |
|
3229 |
| - // Need to special case the '-0' case to format as 0 instead of -0. |
3230 |
| - return String(platform.formatNumber(n === -0 ? 0 : n, hiddenObject)); |
| 3228 | + return String(platform.formatNumber(n, hiddenObject)); |
3231 | 3229 | }
|
3232 | 3230 | tagPublicFunction("Intl.NumberFormat.prototype.format", format);
|
3233 | 3231 |
|
|
0 commit comments