Skip to content

Commit 8ef693a

Browse files
committed
Remove Intl.js use of push:
- Intl.js internals made use of Array.push - This benefited from error in push implementation - However with push fixed - EditingArray proto could introduce undefined behaviour to Intl - remove all use of push in Intl.js
1 parent 0a39c8a commit 8ef693a

2 files changed

Lines changed: 22 additions & 20 deletions

File tree

lib/Runtime/Library/EngineInterfaceObjectBuiltIns.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ GlobalBuiltIn(JavascriptObject, Create)
6969
GlobalBuiltIn(JavascriptObject, GetOwnPropertyDescriptor)
7070
GlobalBuiltIn(JavascriptObject, PreventExtensions)
7171

72-
GlobalBuiltIn(JavascriptArray, Push) // TODO(jahorto): consider deleting (trivially implementable in JS)
7372
GlobalBuiltIn(JavascriptArray, Join)
7473
GlobalBuiltIn(JavascriptArray, Map)
7574
GlobalBuiltIn(JavascriptArray, Slice)

lib/Runtime/Library/InJavascript/Intl.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888

8989
var ArrayInstanceForEach = platform.builtInArray_prototype_forEach;
9090
var ArrayInstanceIndexOf = platform.builtInArray_prototype_indexOf;
91-
var ArrayInstancePush = platform.builtInJavascriptArrayEntryPush;
9291
var ArrayInstanceJoin = platform.builtInJavascriptArrayEntryJoin;
9392

9493
var FunctionInstanceBind = platform.builtInJavascriptFunctionEntryBind;
@@ -113,7 +112,6 @@
113112
repeat(str, count) { return callInstanceFunc(platform.builtInJavascriptStringEntryRepeat, str, count); },
114113

115114
forEach(array, func) { return callInstanceFunc(ArrayInstanceForEach, array, func); },
116-
push(array, ...els) { return callInstanceFunc(ArrayInstancePush, array, ...els); },
117115
join(array, sep) { return callInstanceFunc(ArrayInstanceJoin, array, sep); },
118116
arrayIndexOf(array, el, from) { return callInstanceFunc(ArrayInstanceIndexOf, array, el, from); },
119117
map(array, func) { return callInstanceFunc(platform.builtInJavascriptArrayEntryMap, array, func); },
@@ -697,7 +695,7 @@
697695
const seen = [];
698696
const O = typeof locales === "string" ? [locales] : Internal.ToObject(locales);
699697
const len = Internal.ToLength(O.length);
700-
let k = 0;
698+
let k = 0, i = 0;;
701699

702700
while (k < len) {
703701
const Pk = Internal.ToString(k);
@@ -717,7 +715,7 @@
717715
// See comment in platform.normalizeLanguageTag about when this happens
718716
platform.raiseLocaleNotWellFormed(tag);
719717
} else if (_.arrayIndexOf(seen, canonicalizedTag) === -1) {
720-
_.push(seen, canonicalizedTag);
718+
_.defineProperty(seen, i++, {value: canonicalizedTag, enumerable: true, configurable: true, writable: true});
721719
}
722720
}
723721

@@ -737,10 +735,11 @@
737735
*/
738736
const LookupSupportedLocales = function (isAvailableLocale, requestedLocales) {
739737
const subset = [];
738+
let i = 0;
740739
_.forEach(requestedLocales, function (locale) {
741740
const noExtensionsLocale = parseLangtag(locale).base;
742741
if (BestAvailableLocale(isAvailableLocale, noExtensionsLocale) !== undefined) {
743-
_.push(subset, locale);
742+
_.defineProperty(subset, i++, {value: locale, enumerable: true, configurable: true, writable: true});
744743
}
745744
});
746745

@@ -2206,11 +2205,12 @@
22062205

22072206
if (extensionFilter !== undefined) { // Filter to expected sub-tags
22082207
var filtered = [];
2208+
let i = 0;
22092209
callInstanceFunc(ArrayInstanceForEach, subTags, (function (subTag) {
22102210
var parts = platform.builtInRegexMatch(subTag, /([^-]*)-?(.*)?/); // [0] entire thing; [1] key; [2] value
22112211
var key = parts[1];
22122212
if (callInstanceFunc(ArrayInstanceIndexOf, extensionFilter, key) !== -1) {
2213-
callInstanceFunc(ArrayInstancePush, filtered, subTag);
2213+
_.defineProperty(filtered, i++, {value: subTag, enumerable: true, configurable: true, writable: true});
22142214
}
22152215
}));
22162216
subTags = filtered;
@@ -2463,6 +2463,7 @@
24632463

24642464
// TODO: Use sets here to prevent duplicates
24652465
let seen = [];
2466+
let i = 0;
24662467

24672468
forEachIfPresent(locales, length, function (locale) {
24682469
if ((typeof locale !== 'string' && typeof locale !== 'object') || locale === null) {
@@ -2478,7 +2479,7 @@
24782479
tag = platform.normalizeLanguageTag(tag);
24792480

24802481
if (tag !== undefined && callInstanceFunc(ArrayInstanceIndexOf, seen, tag) === -1) {
2481-
callInstanceFunc(ArrayInstancePush, seen, tag);
2482+
_.defineProperty(seen, i++, {value: tag, writable: true, enumerable: true, configurable: true});
24822483
}
24832484
});
24842485

@@ -3227,54 +3228,56 @@
32273228
// Currently you cannot format date pieces and time pieces together, so this builds up a format template for each separately.
32283229
function EcmaOptionsToWindowsTemplate(options) {
32293230
var template = [];
3231+
template.__proto__ = null;
3232+
let i = 0;
32303233

32313234
if (options.weekday) {
32323235
if (options.weekday === 'narrow' || options.weekday === 'short') {
3233-
callInstanceFunc(ArrayInstancePush, template, 'dayofweek.abbreviated');
3236+
template[i++] = 'dayofweek.abbreviated';
32343237
} else if (options.weekday === 'long') {
3235-
callInstanceFunc(ArrayInstancePush, template, 'dayofweek.full');
3238+
template[i++] = 'dayofweek.full';
32363239
}
32373240
}
32383241

32393242
// TODO: Era not supported
32403243
if (options.year) {
32413244
if (options.year === '2-digit') {
3242-
callInstanceFunc(ArrayInstancePush, template, 'year.abbreviated');
3245+
template[i++] = 'year.abbreviated';
32433246
} else if (options.year === 'numeric') {
3244-
callInstanceFunc(ArrayInstancePush, template, 'year.full');
3247+
template[i++] = 'year.full';
32453248
}
32463249
}
32473250

32483251
if (options.month) {
32493252
if (options.month === '2-digit' || options.month === 'numeric') {
3250-
callInstanceFunc(ArrayInstancePush, template, 'month.numeric')
3253+
template[i++] = 'month.numeric';
32513254
} else if (options.month === 'short' || options.month === 'narrow') {
3252-
callInstanceFunc(ArrayInstancePush, template, 'month.abbreviated');
3255+
template[i++] = 'month.abbreviated';
32533256
} else if (options.month === 'long') {
3254-
callInstanceFunc(ArrayInstancePush, template, 'month.full');
3257+
template[i++] = 'month.full';
32553258
}
32563259
}
32573260

32583261
if (options.day) {
3259-
callInstanceFunc(ArrayInstancePush, template, 'day');
3262+
template[i++] = 'day';
32603263
}
32613264

32623265
if (options.timeZoneName) {
32633266
if (options.timeZoneName === "short") {
3264-
callInstanceFunc(ArrayInstancePush, template, 'timezone.abbreviated');
3267+
template[i++] = 'timezone.abbreviated';
32653268
} else if (options.timeZoneName === "long") {
3266-
callInstanceFunc(ArrayInstancePush, template, 'timezone.full');
3269+
template[i++] = 'timezone.full';
32673270
}
32683271
}
32693272

32703273
callInstanceFunc(ArrayInstanceForEach, ['hour', 'minute', 'second'], function (opt) {
32713274
if (options[opt]) {
3272-
callInstanceFunc(ArrayInstancePush, template, opt);
3275+
template[i++] = opt;
32733276
}
32743277
});
32753278

32763279
// TODO: Timezone Name not supported.
3277-
return getArrayLength(template) > 0 ? callInstanceFunc(ArrayInstanceJoin, template, ' ') : undefined;
3280+
return i > 0 ? callInstanceFunc(ArrayInstanceJoin, template, ' ') : undefined;
32783281
}
32793282

32803283
var WindowsToEcmaCalendarMap = {

0 commit comments

Comments
 (0)