|
136 | 136 |
|
137 | 137 | keys: platform.builtInJavascriptObjectEntryKeys,
|
138 | 138 | 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 | + }, |
140 | 144 | isExtensible: platform.builtInJavascriptObjectEntryIsExtensible,
|
141 | 145 | create(proto = null) { return platform.builtInJavascriptObjectCreate(proto); },
|
142 | 146 | setPrototypeOf(target, proto = null) { return platform.builtInSetPrototype(target, proto); },
|
|
846 | 850 | ? BestFitSupportedLocales(isAvailableLocale, requestedLocales)
|
847 | 851 | : LookupSupportedLocales(isAvailableLocale, requestedLocales);
|
848 | 852 |
|
849 |
| - // make sure property descriptor is null-prototyped to avoid tainting of Object.prototype.{get|set} |
850 |
| - const descriptor = _.setPrototypeOf({ configurable: false, writable: false }); |
851 | 853 | 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 }); |
853 | 855 | }
|
854 | 856 |
|
855 | 857 | // test262 supportedLocalesOf-returned-array-elements-are-frozen.js:
|
856 | 858 | // Property length of object returned by SupportedLocales should not be writable
|
857 |
| - _.defineProperty(supportedLocales, "length", _.setPrototypeOf({ |
| 859 | + _.defineProperty(supportedLocales, "length", { |
858 | 860 | writable: false,
|
859 | 861 | configurable: false,
|
860 | 862 | enumerable: false,
|
861 |
| - })); |
| 863 | + }); |
862 | 864 |
|
863 | 865 | return supportedLocales;
|
864 | 866 | };
|
|
2015 | 2017 | };
|
2016 | 2018 |
|
2017 | 2019 | // 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) { |
2019 | 2021 | if (new.target === undefined) {
|
2020 | 2022 | platform.raiseNeedObjectOfType("Intl.PluralRules", "PluralRules");
|
2021 | 2023 | }
|
|
2058 | 2060 | });
|
2059 | 2061 |
|
2060 | 2062 | // ECMA 402: #sec-intl.pluralrules.prototype.select
|
2061 |
| - const select = function (value) { |
| 2063 | + const select = function select(value) { |
2062 | 2064 | const pr = platform.getHiddenObject(this);
|
2063 | 2065 | if (!pr || !pr.initializedPluralRules) {
|
2064 | 2066 | platform.raiseNeedObjectOfType("Intl.PluralRules.prototype.select", "PluralRules");
|
|
2075 | 2077 | writable: true,
|
2076 | 2078 | });
|
2077 | 2079 |
|
2078 |
| - const resolvedOptions = function () { |
| 2080 | + const resolvedOptions = function resolvedOptions() { |
2079 | 2081 | const pr = platform.getHiddenObject(this);
|
2080 | 2082 | if (!pr || !pr.initializedPluralRules) {
|
2081 | 2083 | platform.raiseNeedObjectOfType("Intl.PluralRules.prototype.select", "PluralRules");
|
2082 | 2084 | }
|
2083 | 2085 |
|
2084 |
| - const options = {}; |
2085 |
| - _.forEach([ |
| 2086 | + return createResolvedOptions([ |
2086 | 2087 | "locale",
|
2087 | 2088 | "type",
|
2088 | 2089 | "minimumIntegerDigits",
|
2089 | 2090 | "minimumFractionDigits",
|
2090 | 2091 | "maximumFractionDigits",
|
2091 | 2092 | "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]; |
2096 | 2101 | }
|
2097 | 2102 | });
|
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; |
2103 | 2103 | };
|
2104 | 2104 | tagPublicFunction("Intl.PluralRules.prototype.resolvedOptions", resolvedOptions);
|
2105 | 2105 | _.defineProperty(PluralRules.prototype, "resolvedOptions", {
|
|
2114 | 2114 |
|
2115 | 2115 | // Initialize Intl properties only if needed
|
2116 | 2116 | 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 }); |
2121 | 2121 | }
|
2122 | 2122 |
|
2123 | 2123 | }
|
|
0 commit comments