Skip to content

Commit 58ad552

Browse files
committed
Polyfill: Make Intl.DateTimeFormat replacement more conformant
Previously we did not care very much about fidelity for the replacement Intl.DateTimeFormat object, since the point of this code is to run the Temporal tests. Occasionally people want to run the Intl.DateTimeFormat tests and are surprised that it doesn't work. Things we have to do to get the Intl.DateTimeFormat tests to pass: - Change ASCIILowercase not to use a RegExp, so that it doesn't clobber legacy RegExp variables like RegExp.$_. (Probably this means that for a 100% conformant polyfill, you can't use any RegExp anywhere. I'm not bothering with that.) - Change DateTimeFormat to be a class, DateTimeFormatImpl. Methods defined in a class body don't have a 'prototype' property and can't be called as constructors, whereas regular functions do. (However, we still need a regular function to construct DateTimeFormat, because it needs to be able to be invoked without 'new'.) - Use CreateSlots/GetSlot/SetSlot like the other Temporal objects, instead of symbol-valued properties. The symbol-valued properties were observably present for user code. - In the constructor, observably read all the options from the options bag in the expected order, and copy them to a null-prototype object with which we do subsequent operations unobservably. - Implement the behaviour of format() already having bound the correct this-object. - Previously we only half-implemented the normative optional behaviour of being able to 'bless' a plain object into becoming a DateTimeFormat object. Instead, just don't implement it at all. (A real production polyfill should probably check if the existing Intl.DateTimeFormat has that behaviour, and match that.) Closes: #2471
1 parent 5a81aae commit 58ad552

File tree

4 files changed

+172
-85
lines changed

4 files changed

+172
-85
lines changed

polyfill/ci_codecov_test262.sh

+3-7
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@ for subdir in $subdirs; do
2424
node runtest262.mjs "$subdir/**" || failed=1
2525
done
2626
node runtest262.mjs "test262/test/staging/Intl402/Temporal/**/*.js" || failed=1
27-
node runtest262.mjs "test262/test/intl402/**/*[tT]emporal*.js" || failed=1
28-
# TODO: remove the line above and uncomment the three lines below to run tests for all localized
29-
# date formatting, because the Temporal polyfill replaces the entire DateTimeFormat object.
30-
# See https://github.com/tc39/proposal-temporal/issues/2471 for more info.
31-
# node runtest262.mjs "test262/test/intl402/DateTimeFormat/**/*.js" || failed=1
32-
# node runtest262.mjs "test262/test/intl402/Intl/DateTimeFormat/**/*.js" || [ $? = 66 ] || failed=1
33-
# node runtest262.mjs "test262/test/built-ins/Date/*/toLocale*String/*.js" || failed=1
27+
node runtest262.mjs "test262/test/intl402/DateTimeFormat/**/*.js" || failed=1
28+
node runtest262.mjs "test262/test/intl402/Intl/DateTimeFormat/**/*.js" || failed=1
29+
node runtest262.mjs "test262/test/built-ins/Date/*/toLocale*String/*.js" || failed=1
3430

3531
c8 report --reporter=text-lcov --temp-directory=$NODE_V8_COVERAGE \
3632
--exclude=polyfill/runtest262.mjs \

polyfill/lib/ecmascript.mjs

+9-6
Original file line numberDiff line numberDiff line change
@@ -5722,13 +5722,16 @@ export function ASCIILowercase(str) {
57225722
// values. For example, Turkish's "I" character was the source of a security
57235723
// issue involving "file://" URLs. See
57245724
// https://haacked.com/archive/2012/07/05/turkish-i-problem-and-why-you-should-care.aspx/.
5725-
return Call(StringPrototypeReplace, str, [
5726-
/[A-Z]/g,
5727-
(l) => {
5728-
const code = Call(StringPrototypeCharCodeAt, l, [0]);
5729-
return StringFromCharCode(code + 0x20);
5725+
let lowercase = '';
5726+
for (let ix = 0; ix < str.length; ix++) {
5727+
const code = Call(StringPrototypeCharCodeAt, str, [ix]);
5728+
if (code >= 0x41 && code <= 0x5a) {
5729+
lowercase += StringFromCharCode(code + 0x20);
5730+
} else {
5731+
lowercase += StringFromCharCode(code);
57305732
}
5731-
]);
5733+
}
5734+
return lowercase;
57325735
}
57335736

57345737
// This function isn't in the spec, but we put it in the polyfill to avoid

0 commit comments

Comments
 (0)