MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1const failures = [];
2
3function assertOrder(name, got, expected) {
4 const ok = got.length === expected.length && got.every((v, i) => v === expected[i]);
5 if (!ok) failures.push(`${name}: expected [${expected.join(', ')}], got [${got.join(', ')}]`);
6}
7
8{
9 const order = [];
10 const base = {};
11 const getObj = () => { order.push('obj'); return base; };
12 const key = () => { order.push('key'); return 'k'; };
13 const rhs = () => { order.push('rhs'); return 1; };
14 getObj()[key()] = rhs();
15 assertOrder('computed assignment order', order, ['obj', 'key', 'rhs']);
16}
17
18{
19 const order = [];
20 const base = {};
21 const getObj = () => { order.push('obj'); return base; };
22 const rhs = () => { order.push('rhs'); return 1; };
23 getObj().x = rhs();
24 assertOrder('named assignment order', order, ['obj', 'rhs']);
25}
26
27if (failures.length) {
28 console.log('Assignment order failures:');
29 for (let i = 0; i < failures.length; i++) {
30 console.log(` ${i + 1}. ${failures[i]}`);
31 }
32 throw new Error(`Found ${failures.length} assignment-order regression(s)`);
33}
34
35console.log('PASS: assignment evaluation order');