Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

Commit 6851426

Browse files
zbranieckicaridy
authored andcommitted
Minor fixes to make DateTimeFormat's and NumberFormat's formatToParts pass test262 (#216)
tests
1 parent ac6926f commit 6851426

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

src/11.numberformat.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -415,14 +415,21 @@ function GetFormatNumber() {
415415
return internal['[[boundFormat]]'];
416416
}
417417

418-
Intl.NumberFormat.prototype.formatToParts = function(value) {
418+
function formatToParts(value = undefined) {
419419
let internal = this !== null && typeof this === 'object' && getInternalProperties(this);
420420
if (!internal || !internal['[[initializedNumberFormat]]'])
421421
throw new TypeError('`this` value for formatToParts() is not an initialized Intl.NumberFormat object.');
422422

423423
let x = Number(value);
424424
return FormatNumberToParts(this, x);
425-
};
425+
}
426+
427+
Object.defineProperty(Intl.NumberFormat.prototype, 'formatToParts', {
428+
configurable: true,
429+
enumerable: false,
430+
writable: true,
431+
value: formatToParts
432+
});
426433

427434
/*
428435
* @spec[stasm/ecma402/number-format-to-parts/spec/numberformat.html]

src/12.datetimeformat.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
List,
3939
hop,
4040
objCreate,
41+
toNumber,
4142
arrPush,
4243
arrIndexOf
4344
} from './util.js';
@@ -840,14 +841,14 @@ function GetFormatDateTime() {
840841
// specified for built-in functions in ES5, 15, or successor, and the
841842
// length property set to 0, that takes the argument date and
842843
// performs the following steps:
843-
let F = function () {
844+
let F = function (date = undefined) {
844845
// i. If date is not provided or is undefined, then let x be the
845846
// result as if by the expression Date.now() where Date.now is
846847
// the standard built-in function defined in ES5, 15.9.4.4.
847848
// ii. Else let x be ToNumber(date).
848849
// iii. Return the result of calling the FormatDateTime abstract
849850
// operation (defined below) with arguments this and x.
850-
let x = Number(arguments.length === 0 ? Date.now() : arguments[0]);
851+
let x = date === undefined ? Date.now() : toNumber(date);
851852
return FormatDateTime(this, x);
852853
};
853854
// b. Let bind be the standard built-in function object defined in ES5,
@@ -865,22 +866,22 @@ function GetFormatDateTime() {
865866
return internal['[[boundFormat]]'];
866867
}
867868

868-
Intl.DateTimeFormat.prototype.formatToParts = function formatToParts() {
869+
function formatToParts(date = undefined) {
869870
let internal = this !== null && typeof this === 'object' && getInternalProperties(this);
870871

871872
if (!internal || !internal['[[initializedDateTimeFormat]]'])
872873
throw new TypeError('`this` value for formatToParts() is not an initialized Intl.DateTimeFormat object.');
873874

874-
if (internal['[[boundFormatToParts]]'] === undefined) {
875-
let F = function () {
876-
let x = Number(arguments.length === 0 ? Date.now() : arguments[0]);
877-
return FormatToPartsDateTime(this, x);
878-
};
879-
let bf = fnBind.call(F, this);
880-
internal['[[boundFormatToParts]]'] = bf;
881-
}
882-
return internal['[[boundFormatToParts]]'];
883-
};
875+
let x = date === undefined ? Date.now() : toNumber(date);
876+
return FormatToPartsDateTime(this, x);
877+
}
878+
879+
Object.defineProperty(Intl.DateTimeFormat.prototype, 'formatToParts', {
880+
enumerable: false,
881+
writable: true,
882+
configurable: true,
883+
value: formatToParts
884+
});
884885

885886
function CreateDateTimeParts(dateTimeFormat, x) {
886887
// 1. If x is not a finite Number, then throw a RangeError exception.

0 commit comments

Comments
 (0)