Files
palemoon27/js/src/jit-test/tests/basic/destructuring-iterator.js
T
roytam1 eb69bdde8b import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1238859: ARM: MoveEmitter should only copying float32 instead of double during spilling, r=nbp (13c87beccb)
- Bug 1233343: SharedStubs: Count frames pushed correctly on ARM when entering an ion stub frame, r=jandem (c2a1050f11)
- Bug 1249493 - IonMonkey: MIPS: Fix crash after enable shared stubs. r=h4writer (a823579cae)
- Bug 1239754 - Remove HashKeyRef now that all of its users are using stable hashing; r=jonco (d08fb10121)
- Bug 1245485 - Only decommit newly unused Nursery Chunks; r=sfink (611cfa4d14)
- Bug 1242691 - Merge overlapping SlotsEdges in the store buffer. r=terrence (a31875df9d)
- Bug 1242072 - Continue using getPropertyDescriptor for get in ScriptedIndirectProxyHandler. r=jorendorff (e42f5a2ee2)
- Bug 1235410 - Centralize StmtType enumeration in a higher-order macro, so as not to have types and string descriptions of them go out of sync. As they happen to be now. #_# r=arai (91c3b6497f)
- Bug 1243793 - Fix handling of labels when emitting hoisted function definitions. (r=jorendorff) (34a36e7f5a)
- Bug 1111386 - Support nested rest in destructuring assignment; r=jorendorff (aab810e579)
- Bug 1247789: Fix comment for js::Fifo DONTBUILD r=fitzgen (e6947b44ae)
- Bug 1231965 - Change references to ./mach build-docs to ./mach doc. r=gps (fbcfdedeef)
- Bug 1247666 - Do not require all functions to have a PEdgeCallInstance, r=jonco (e06fbf58c8)
- Bug 1247666 - Correctly test isSuppressConstructor, r=jonco (9ef1760f0f)
- Bug 1247813 - Add a very specific annotation for paramBuffer usage to avoid changing a whole bunch of platform-specific code just to avoid a false positive, r=terrence (b3d1918239)
- Bug 1249448 - Handled unified (C4) constructors, r=terrence (3b1b1a8060)
- Bug 1237230 - Fix ctypes MOZ_WARN_UNUSED_RESULT warnings for Vector methods. r=jorendorff (fd7d0d8675)
- minor update (e0a035fd89)
2023-12-08 10:08:54 +08:00

125 lines
3.5 KiB
JavaScript

load(libdir + 'asserts.js');
load(libdir + 'iteration.js');
load(libdir + 'eqArrayHelper.js');
// throw on non-iterables
assertThrowsInstanceOf(() => { [a, b, c] = {0: 0, 1: 1, 2: 2} }, TypeError);
var nextcalls = 0, donecalls = 0, valuecalls = 0;
var doneafter = 0;
var iterable = {};
iterable[Symbol.iterator] = function () {
return {
next: function () {
assertEq(arguments.length, 0, 'iterator.next() should be called with no arguments');
nextcalls++;
return {
get done() {
donecalls++;
return --doneafter < 0;
},
get value() {
valuecalls++;
return valuecalls;
}
};
}
}
};
function assertIterable(expectCalls, fn, expectResult) {
[nextcalls, donecalls, valuecalls, doneafter] = [0,0,0, expectCalls[3]];
assertEqArray(fn(iterable), expectResult);
assertEq(nextcalls, expectCalls[0], 'calls to iterator.next()');
assertEq(donecalls, expectCalls[1], 'getting iterator.next().done');
assertEq(valuecalls, expectCalls[2], 'getting iterator.next().value');
}
assertIterable([1,1,1,1],
it => { var [a] = it; return [a]; },
[1]);
assertIterable([3,3,1,1],
it => { var [a,b,c] = it; return [a,b,c]; },
[1,undefined,undefined]);
assertIterable([3,3,1,1],
it => { var [a,b,...rest] = it; return [a,b,...rest]; },
[1,undefined]);
assertIterable([5,5,4,4],
it => { var [,,...rest] = it; return rest; },
[3,4]);
// the iterator should be exhausted before any error is thrown
assertIterable([5,5,4,4],
it => {
assertThrowsInstanceOf(function () {
"use strict";
[...{0: "".x}] = it;
}, TypeError);
return [];
},
[]);
var arraycalls = 0;
var ArrayIterator = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function () {
arraycalls++;
return ArrayIterator.apply(this, arguments);
};
// [...rest] should not call Array#@@iterator for the LHS
var [...rest] = iterable;
assertEq(arraycalls, 0, 'calls to Array#@@iterator');
// [...[...rest]] should do so, since it creates an implicit array for the
// first rest pattern, then destructures that again using @@iterator() for the
// second rest pattern.
var [...[...rest]] = iterable;
assertEq(arraycalls, 1, 'calls to Array#@@iterator');
// loop `fn` a few times, to get it JIT-compiled
function loop(fn) {
var i = 1e4;
while (i--) fn();
}
loop(() => { doneafter = 4; var [a] = iterable; return a; });
loop(() => { doneafter = 4; var [a,b,...[...rest]] = iterable; return rest; });
// destructuring assignment should always use iterators and not optimize
// to a "group assignment"
delete Array.prototype[Symbol.iterator];
assertThrowsInstanceOf(() => { var [a,b] = [1,2]; }, TypeError);
Array.prototype[Symbol.iterator] = ArrayIterator;
// observe the binding order
a = undefined, b = undefined, c = undefined;
var obj = {};
obj[Symbol.iterator] = function* () {
// normal fields should be initialized right after |.next()|
yield 1;
assertEq(a, 1);
yield 2;
yield 3;
assertEq(b, 3);
yield 4;
yield 5;
// rest should be initialized after the iterator is exhausted
assertEq(c, undefined);
};
[a, , b, ...c] = obj;
assertEqArray(c, [4,5]);
// a throw inside the destructuring of the "catch" value should not enter
// the "catch" block
assertThrowsValue(function () {
try {
Array.prototype[Symbol.iterator] = function () { throw 'from iterator'; };
throw [1, 2];
} catch ([x, y]) {
throw 'not reached';
}
}, 'from iterator');
Array.prototype[Symbol.iterator] = ArrayIterator;