|
54 | 54 | return { value: undefined, done: true };
|
55 | 55 | } else {
|
56 | 56 | let index = o.__$nextIndex$__;
|
57 |
| - let len = __chakraLibrary.isArray(a) ? a.length : __chakraLibrary.GetLength(a); |
| 57 | + let len = @@ToLength(a.length); |
58 | 58 |
|
59 | 59 | if (index < len) { // < comparison should happen instead of >= , because len can be NaN
|
60 | 60 | let itemKind = o.__$kind$__;
|
|
118 | 118 |
|
119 | 119 | platform.registerFunction(platform.FunctionKind.Array_indexOf, function (searchElement, fromIndex = undefined) {
|
120 | 120 | // ECMAScript 2017 #sec-array.prototype.indexof
|
121 |
| - |
122 |
| - let {o, len} = __chakraLibrary.CheckArrayAndGetLen(this, "Array.prototype.indexOf"); |
| 121 | + const o = @@Conv_Obj(this); |
| 122 | + const len = @@ToLength(o.length); |
123 | 123 |
|
124 | 124 | if (len === 0) {
|
125 | 125 | return -1;
|
126 | 126 | }
|
127 | 127 |
|
128 |
| - let n = __chakraLibrary.toInteger(fromIndex); |
| 128 | + const n = @@ToInteger(fromIndex); |
129 | 129 | if (n >= len) {
|
130 | 130 | return -1;
|
131 | 131 | }
|
|
163 | 163 | return -1;
|
164 | 164 | });
|
165 | 165 |
|
166 |
| - platform.registerChakraLibraryFunction("CheckArrayAndGetLen", function (obj, builtInFunc) { |
167 |
| - if (__chakraLibrary.isArray(obj)) { |
168 |
| - return { o: obj, len: obj.length }; |
169 |
| - } else { |
170 |
| - if (obj === null || obj === undefined) { |
171 |
| - __chakraLibrary.raiseThis_NullOrUndefined(builtInFunc); |
172 |
| - } |
173 |
| - return { o: @@Conv_Obj(obj), len: __chakraLibrary.toLength(obj["length"]) }; |
174 |
| - } |
175 |
| - }); |
176 |
| - |
177 | 166 | platform.registerChakraLibraryFunction("MergeSort", function(array, length, compareFn) {
|
178 | 167 | const buffer = [];
|
179 | 168 | buffer.__proto__ = null;
|
|
269 | 258 | compareFn = __chakraLibrary.DefaultSortCompare;
|
270 | 259 | }
|
271 | 260 |
|
272 |
| - const {o, len} = __chakraLibrary.CheckArrayAndGetLen(this, "Array.prototype.sort"); |
| 261 | + const o = @@Conv_Obj(this); |
| 262 | + const len = @@ToLength(o.length); |
273 | 263 |
|
274 | 264 | if (len < 2) { // early return if length < 2
|
275 | 265 | return o;
|
|
321 | 311 |
|
322 | 312 | platform.registerFunction(platform.FunctionKind.Array_filter, function (callbackfn, thisArg = undefined) {
|
323 | 313 | // ECMAScript 2017 #sec-array.prototype.filter
|
| 314 | + const o = @@Conv_Obj(this); |
| 315 | + const len = @@ToLength(o.length); |
324 | 316 |
|
325 |
| - let {o, len} = __chakraLibrary.CheckArrayAndGetLen(this, "Array.prototype.filter"); |
326 |
| - |
327 | 317 | if (typeof callbackfn !== "function") {
|
328 | 318 | __chakraLibrary.raiseFunctionArgument_NeedFunction("Array.prototype.filter");
|
329 | 319 | }
|
|
349 | 339 | platform.registerChakraLibraryFunction("FlattenIntoArray", function(target, source, sourceLen, start, depth)
|
350 | 340 | {
|
351 | 341 | // this is FlattenIntoArray from the flat/flatMap proposal BUT with no mapperFunction
|
352 |
| - // a seperate function has been made to handle the case where there is a mapperFunction |
| 342 | + // a separate function has been made to handle the case where there is a mapperFunction |
353 | 343 |
|
354 | 344 | //1. Let targetIndex be start.
|
355 | 345 | let targetIndex = start;
|
|
372 | 362 | // v. If shouldFlatten is true, then
|
373 | 363 | // 1. Let elementLen be ? ToLength(? Get(element, "length")).
|
374 | 364 | // 2. Set targetIndex to ? FlattenIntoArray(target, element, elementLen, targetIndex, depth - 1).
|
375 |
| - targetIndex = __chakraLibrary.FlattenIntoArray(target, element, __chakraLibrary.toLength(element.length), targetIndex, depth - 1); |
| 365 | + targetIndex = __chakraLibrary.FlattenIntoArray(target, element, @@ToLength(element.length), targetIndex, depth - 1); |
376 | 366 | } else {
|
377 | 367 | // vi. Else,
|
378 | 368 | // 1. If targetIndex >= 2^53-1, throw a TypeError exception.
|
|
422 | 412 | // 2. Set targetIndex to ? FlattenIntoArray(target, element, elementLen, targetIndex, depth - 1).
|
423 | 413 | if (__chakraLibrary.isArray(element)) {
|
424 | 414 | // instead of calling FlattenIntoArray use a simple loop here - as depth is always 0
|
425 |
| - innerLength = __chakraLibrary.toLength(element.length); |
| 415 | + innerLength = @@ToLength(element.length); |
426 | 416 | innerIndex = 0;
|
427 | 417 | while (innerIndex < innerLength) {
|
428 | 418 | if (innerIndex in element) {
|
|
459 | 449 | platform.registerFunction(platform.FunctionKind.Array_flat, function (depth = undefined) {
|
460 | 450 | //1. Let O be ? ToObject(this value).
|
461 | 451 | //2. Let sourceLen be ? ToLength(? Get(O, "length")).
|
462 |
| - let {o, len} = __chakraLibrary.CheckArrayAndGetLen(this, "Array.prototype.flat"); |
| 452 | + const o = @@Conv_Obj(this); |
| 453 | + const len = @@ToLength(o.length); |
463 | 454 |
|
464 | 455 | //3. Let depthNum be 1.
|
465 | 456 | //4. If depth is not undefined, then
|
466 | 457 | //5. Set depthNum to ? ToInteger(depth).
|
467 |
| - const depthNum = depth !== undefined ? __chakraLibrary.toInteger(depth) : 1; |
| 458 | + const depthNum = depth !== undefined ? @@ToInteger(depth) : 1; |
468 | 459 | //6. Let A be ? ArraySpeciesCreate(O, 0).
|
469 | 460 | const A = __chakraLibrary.arraySpeciesCreate(o, 0);
|
470 | 461 | //7. Perform ? FlattenIntoArray(A, O, sourceLen, 0, depthNum).
|
|
476 | 467 | platform.registerFunction(platform.FunctionKind.Array_flatMap, function (mapperFunction, thisArg = undefined) {
|
477 | 468 | //1. Let O be ? ToObject(this value).
|
478 | 469 | //2. Let sourceLen be ? ToLength(? Get(O, "length")).
|
479 |
| - let {o, len} = __chakraLibrary.CheckArrayAndGetLen(this, "Array.prototype.flatMap"); |
| 470 | + const o = @@Conv_Obj(this); |
| 471 | + const len = @@ToLength(o.length); |
480 | 472 |
|
481 | 473 | //3. If IsCallable(mapperFunction) is false throw a TypeError exception
|
482 | 474 | if (typeof mapperFunction !== "function") {
|
|
496 | 488 |
|
497 | 489 | //Let O be ? ToObject(this value).
|
498 | 490 | //Let len be ? ToLength(? Get(O, "length")).
|
499 |
| - let {o, len} = __chakraLibrary.CheckArrayAndGetLen(this, "Array.prototype.forEach"); |
| 491 | + const o = @@Conv_Obj(this); |
| 492 | + const len = @@ToLength(o.length); |
500 | 493 |
|
501 | 494 | //If IsCallable(callbackfn) is false, throw a TypeError exception.
|
502 | 495 | if (typeof callbackfn !== "function") {
|
|
530 | 523 |
|
531 | 524 | //Let O be ? ToObject(this value).
|
532 | 525 | //Let len be ? ToLength(? Get(O, "length")).
|
533 |
| - let {o, len} = __chakraLibrary.CheckArrayAndGetLen(this, "Array.prototype.some"); |
| 526 | + const o = @@Conv_Obj(this); |
| 527 | + const len = @@ToLength(o.length); |
534 | 528 |
|
535 | 529 | //If IsCallable(callbackfn) is false, throw a TypeError exception.
|
536 | 530 | if (typeof callbackfn !== "function") {
|
|
567 | 561 |
|
568 | 562 | //Let O be ? ToObject(this value).
|
569 | 563 | //Let len be ? ToLength(? Get(O, "length")).
|
570 |
| - let {o, len} = __chakraLibrary.CheckArrayAndGetLen(this, "Array.prototype.every"); |
| 564 | + const o = @@Conv_Obj(this); |
| 565 | + const len = @@ToLength(o.length); |
571 | 566 |
|
572 | 567 | //If IsCallable(callbackfn) is false, throw a TypeError exception.
|
573 | 568 | if (typeof callbackfn !== "function") {
|
|
604 | 599 |
|
605 | 600 | //Let O be ? ToObject(this value).
|
606 | 601 | //Let len be ? ToLength(? Get(O, "length")).
|
607 |
| - let {o, len} = __chakraLibrary.CheckArrayAndGetLen(this,"Array.prototype.includes"); |
| 602 | + const o = @@Conv_Obj(this); |
| 603 | + const len = @@ToLength(o.length); |
608 | 604 |
|
609 | 605 | //If len is 0, return false.
|
610 | 606 | if (len === 0) {
|
|
613 | 609 |
|
614 | 610 | //Let n be ? ToInteger(fromIndex).
|
615 | 611 | //Assert: If fromIndex is undefined, then n is 0.
|
616 |
| - let n = __chakraLibrary.toInteger(fromIndex); |
| 612 | + let n = @@ToInteger(fromIndex); |
617 | 613 | let k;
|
618 | 614 |
|
619 | 615 | //If n >= 0, then
|
|
652 | 648 |
|
653 | 649 | //Let O be ? ToObject(this value).
|
654 | 650 | //Let len be ? ToLength(? Get(O, "length")).
|
655 |
| - let {o, len} = __chakraLibrary.CheckArrayAndGetLen(this, "Array.prototype.reduce"); |
| 651 | + const o = @@Conv_Obj(this); |
| 652 | + const len = @@ToLength(o.length); |
656 | 653 |
|
657 | 654 | //If IsCallable(callbackfn) is false, throw a TypeError exception.
|
658 | 655 | if (typeof callbackfn !== "function") {
|
|
671 | 668 |
|
672 | 669 | //If initialValue is present, then
|
673 | 670 | //Set accumulator to initialValue.
|
674 |
| - if (arguments.length > 1) { //Checking for array length because intialValue could be passed in as undefined |
| 671 | + if (arguments.length > 1) { //Checking for array length because initialValue could be passed in as undefined |
675 | 672 | accumulator = initialValue;
|
676 | 673 | }
|
677 | 674 | //Else initialValue is not present,
|
|
0 commit comments