diff --git a/common/models/templates/src/priority-queue.ts b/common/models/templates/src/priority-queue.ts index bb4945d573..6a1344fd89 100644 --- a/common/models/templates/src/priority-queue.ts +++ b/common/models/templates/src/priority-queue.ts @@ -46,7 +46,7 @@ export default class PriorityQueue { // https://en.wikipedia.org/wiki/Min-max_heap this.comparator = comparator; - this.heap = Array.from(initialEntries ?? []); + this.heap = (initialEntries ?? []).slice(0); this.heapify(); } @@ -228,6 +228,6 @@ export default class PriorityQueue { * they will almost certainly be unsorted. */ toArray(): Type[] { - return Array.from(this.heap); + return this.heap.slice(0); } } \ No newline at end of file diff --git a/common/models/templates/test/test-priority-queue.js b/common/models/templates/test/test-priority-queue.js index 5fdd0caa3d..0887a19d22 100644 --- a/common/models/templates/test/test-priority-queue.js +++ b/common/models/templates/test/test-priority-queue.js @@ -24,7 +24,7 @@ describe('Priority queue', function() { it('initializes well from pre-existing values', function() { let input = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]; - let originalInput = Array.from(input); + let originalInput = input.slice(0); let queue = new PriorityQueue((a, b) => a - b, input); assert.deepEqual(input, originalInput); diff --git a/common/web/lm-worker/build-polyfill-concatenator.js b/common/web/lm-worker/build-polyfill-concatenator.js index 3b350eb55e..9dfb901130 100644 --- a/common/web/lm-worker/build-polyfill-concatenator.js +++ b/common/web/lm-worker/build-polyfill-concatenator.js @@ -81,8 +81,6 @@ let sourceFileSet = [ loadPolyfill('src/polyfills/array.fill.js', 'src/polyfills/array.fill.js'), // Needed for Android / Chromium browser pre-45. loadPolyfill('src/polyfills/array.findIndex.js', 'src/polyfills/array.findIndex.js'), - // Needed for Android / Chromium browser pre-45. - loadPolyfill('src/polyfills/array.from.js', 'src/polyfills/array.from.js'), // Needed for Android / Chromium browser pre-47. loadPolyfill('src/polyfills/array.includes.js', 'src/polyfills/array.includes.js'), // For Object.values, for iteration over object-based associate arrays. diff --git a/common/web/lm-worker/src/main/correction/classical-calculation.ts b/common/web/lm-worker/src/main/correction/classical-calculation.ts index 50ddf93551..296476b098 100644 --- a/common/web/lm-worker/src/main/correction/classical-calculation.ts +++ b/common/web/lm-worker/src/main/correction/classical-calculation.ts @@ -69,11 +69,11 @@ export class ClassicalDistanceCalculation 0 ? 1 : -1) * Math.floor(Math.abs(number)); - }; - var maxSafeInteger = Math.pow(2, 53) - 1; - var toLength = function (value) { - var len = toInteger(value); - return Math.min(Math.max(len, 0), maxSafeInteger); - }; - - // The length property of the from method is 1. - return function from(arrayLike/*, mapFn, thisArg */) { - // 1. Let C be the this value. - var C = this; - - // 2. Let items be ToObject(arrayLike). - var items = Object(arrayLike); - - // 3. ReturnIfAbrupt(items). - if (arrayLike == null) { - throw new TypeError('Array.from requires an array-like object - not null or undefined'); - } - - // 4. If mapfn is undefined, then let mapping be false. - var mapFn = arguments.length > 1 ? arguments[1] : void undefined; - var T; - if (typeof mapFn !== 'undefined') { - // 5. else - // 5. a If IsCallable(mapfn) is false, throw a TypeError exception. - if (!isCallable(mapFn)) { - throw new TypeError('Array.from: when provided, the second argument must be a function'); - } - - // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined. - if (arguments.length > 2) { - T = arguments[2]; - } - } - - // 10. Let lenValue be Get(items, "length"). - // 11. Let len be ToLength(lenValue). - var len = toLength(items.length); - - // 13. If IsConstructor(C) is true, then - // 13. a. Let A be the result of calling the [[Construct]] internal method - // of C with an argument list containing the single item len. - // 14. a. Else, Let A be ArrayCreate(len). - var A = isCallable(C) ? Object(new C(len)) : new Array(len); - - // 16. Let k be 0. - var k = 0; - // 17. Repeat, while k < len… (also steps a - h) - var kValue; - while (k < len) { - kValue = items[k]; - if (mapFn) { - A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k); - } else { - A[k] = kValue; - } - k += 1; - } - // 18. Let putStatus be Put(A, "length", len, true). - A.length = len; - // 20. Return A. - return A; - }; - }()); -} diff --git a/common/web/lm-worker/src/polyfills/symbol-es6.min.js b/common/web/lm-worker/src/polyfills/symbol-es6.min.js index 411bfde7d5..67d87dc45e 100644 --- a/common/web/lm-worker/src/polyfills/symbol-es6.min.js +++ b/common/web/lm-worker/src/polyfills/symbol-es6.min.js @@ -1,2 +1,7 @@ // From https://rousan.io/symbol-es6/, lightly modified to be worker-compatible for Android Lollipop. -!function(global,factory){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=factory(global):factory(global)}("undefined"!=typeof window?window:(self?self:global),function(global){"use strict";var defineProperty=Object.defineProperty,defineProperties=Object.defineProperties,symbolHiddenCounter=0,globalSymbolRegistry=[],slice=Array.prototype.slice,ES6="object"==typeof global.ES6?global.ES6:global.ES6={},isArray=Array.isArray,objectToString=Object.prototype.toString,push=Array.prototype.push,emptyFunction=function(){},simpleFunction=function(arg){return arg},isCallable=function(fn){return"function"==typeof fn},Iterator=function(){},ArrayIterator=function(array,flag){this._array=array,this._flag=flag,this._nextIndex=0},StringIterator=function(string,flag){this._string=string,this._flag=flag,this._nextIndex=0},isObject=function(value){return null!==value&&("object"==typeof value||"function"==typeof value)},setupSymbolInternals=function(symbol,desc){return defineProperties(symbol,{_description:{value:desc},_isSymbol:{value:!0},_id:{value:symbolHiddenCounter++}}),symbol},appendArray=function(array1,array2){if("number"==typeof array1.length&&array1.length>=0&&"number"==typeof array2.length&&array2.length>=0){var length1=Math.floor(array1.length),length2=Math.floor(array2.length),i=0;for(array1.length=length1+length2;i=0&&this._nextIndex=0))return(outputs=new constructor(0)).length=0,outputs;for(length=Math.floor(arrayLike.length),(outputs=new constructor(length)).length=length;i=0&&"number"==typeof array2.length&&array2.length>=0){var length1=Math.floor(array1.length),length2=Math.floor(array2.length),i=0;for(array1.length=length1+length2;i=0&&this._nextIndex=0))return(outputs=new constructor(0)).length=0,outputs;for(length=Math.floor(arrayLike.length),(outputs=new constructor(length)).length=length;i