Skip to content

Commit c08712a

Browse files
committed
[MERGE #5231 @jackhorton] Assorted Intl updates
Merge pull request #5231 from jackhorton:intl/assorted-fixes Fixes OS#17896974
2 parents 40a21ee + 4ff3f91 commit c08712a

File tree

9 files changed

+29186
-29078
lines changed

9 files changed

+29186
-29078
lines changed

lib/Runtime/Library/InJavascript/Intl.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@
136136

137137
keys: platform.builtInJavascriptObjectEntryKeys,
138138
hasOwnProperty(o, prop) { return callInstanceFunc(platform.builtInJavascriptObjectEntryHasOwnProperty, o, prop); },
139-
defineProperty: platform.builtInJavascriptObjectEntryDefineProperty,
139+
// If we don't set the descriptor's prototype to null, defining properties with `value`s can fail of Object.prototype.get is defined
140+
defineProperty(o, prop, desc) {
141+
_.setPrototypeOf(desc, null);
142+
platform.builtInJavascriptObjectEntryDefineProperty(o, prop, desc);
143+
},
140144
isExtensible: platform.builtInJavascriptObjectEntryIsExtensible,
141145
create(proto = null) { return platform.builtInJavascriptObjectCreate(proto); },
142146
setPrototypeOf(target, proto = null) { return platform.builtInSetPrototype(target, proto); },
@@ -846,19 +850,17 @@
846850
? BestFitSupportedLocales(isAvailableLocale, requestedLocales)
847851
: LookupSupportedLocales(isAvailableLocale, requestedLocales);
848852

849-
// make sure property descriptor is null-prototyped to avoid tainting of Object.prototype.{get|set}
850-
const descriptor = _.setPrototypeOf({ configurable: false, writable: false });
851853
for (let i = 0; i < supportedLocales.length; i++) {
852-
_.defineProperty(supportedLocales, Internal.ToString(i), descriptor);
854+
_.defineProperty(supportedLocales, Internal.ToString(i), { configurable: false, writable: false });
853855
}
854856

855857
// test262 supportedLocalesOf-returned-array-elements-are-frozen.js:
856858
// Property length of object returned by SupportedLocales should not be writable
857-
_.defineProperty(supportedLocales, "length", _.setPrototypeOf({
859+
_.defineProperty(supportedLocales, "length", {
858860
writable: false,
859861
configurable: false,
860862
enumerable: false,
861-
}));
863+
});
862864

863865
return supportedLocales;
864866
};
@@ -2015,7 +2017,7 @@
20152017
};
20162018

20172019
// params are explicitly `= undefined` to make PluralRules.length === 0
2018-
const PluralRules = function (locales = undefined, options = undefined) {
2020+
const PluralRules = function PluralRules(locales = undefined, options = undefined) {
20192021
if (new.target === undefined) {
20202022
platform.raiseNeedObjectOfType("Intl.PluralRules", "PluralRules");
20212023
}
@@ -2058,7 +2060,7 @@
20582060
});
20592061

20602062
// ECMA 402: #sec-intl.pluralrules.prototype.select
2061-
const select = function (value) {
2063+
const select = function select(value) {
20622064
const pr = platform.getHiddenObject(this);
20632065
if (!pr || !pr.initializedPluralRules) {
20642066
platform.raiseNeedObjectOfType("Intl.PluralRules.prototype.select", "PluralRules");
@@ -2075,31 +2077,29 @@
20752077
writable: true,
20762078
});
20772079

2078-
const resolvedOptions = function () {
2080+
const resolvedOptions = function resolvedOptions() {
20792081
const pr = platform.getHiddenObject(this);
20802082
if (!pr || !pr.initializedPluralRules) {
20812083
platform.raiseNeedObjectOfType("Intl.PluralRules.prototype.select", "PluralRules");
20822084
}
20832085

2084-
const options = {};
2085-
_.forEach([
2086+
return createResolvedOptions([
20862087
"locale",
20872088
"type",
20882089
"minimumIntegerDigits",
20892090
"minimumFractionDigits",
20902091
"maximumFractionDigits",
20912092
"minimumSignificantDigits",
2092-
"maximumSignificantDigits"
2093-
], (prop) => {
2094-
if (pr[prop] !== undefined) {
2095-
options[prop] = pr[prop];
2093+
"maximumSignificantDigits",
2094+
"pluralCategories"
2095+
], pr, (prop, resolved) => {
2096+
if (prop === "pluralCategories") {
2097+
// https://github.com/tc39/ecma402/issues/224: create a copy of the pluralCategories array
2098+
resolved.pluralCategories = _.slice(pr.pluralCategories, 0);
2099+
} else {
2100+
resolved[prop] = pr[prop];
20962101
}
20972102
});
2098-
2099-
// https://github.com/tc39/ecma402/issues/224: create a copy of the pluralCategories array
2100-
options.pluralCategories = _.slice(pr.pluralCategories, 0);
2101-
2102-
return options;
21032103
};
21042104
tagPublicFunction("Intl.PluralRules.prototype.resolvedOptions", resolvedOptions);
21052105
_.defineProperty(PluralRules.prototype, "resolvedOptions", {
@@ -2114,10 +2114,10 @@
21142114

21152115
// Initialize Intl properties only if needed
21162116
if (InitType === "Intl") {
2117-
ObjectDefineProperty(Intl, "Collator", { value: Collator, writable: true, enumerable: false, configurable: true });
2118-
ObjectDefineProperty(Intl, "NumberFormat", { value: NumberFormat, writable: true, enumerable: false, configurable: true });
2119-
ObjectDefineProperty(Intl, "DateTimeFormat", { value: DateTimeFormat, writable: true, enumerable: false, configurable: true });
2120-
ObjectDefineProperty(Intl, "PluralRules", { value: PluralRules, writable: true, enumerable: false, configurable: true });
2117+
_.defineProperty(Intl, "Collator", { value: Collator, writable: true, enumerable: false, configurable: true });
2118+
_.defineProperty(Intl, "NumberFormat", { value: NumberFormat, writable: true, enumerable: false, configurable: true });
2119+
_.defineProperty(Intl, "DateTimeFormat", { value: DateTimeFormat, writable: true, enumerable: false, configurable: true });
2120+
_.defineProperty(Intl, "PluralRules", { value: PluralRules, writable: true, enumerable: false, configurable: true });
21212121
}
21222122

21232123
}

0 commit comments

Comments
 (0)