// Test we can read an outer classes private fields. class Outer {
#outer = 3;
test() {
let outerThis = this; class Inner {
#inner = 2;
test() { return outerThis.#outer;
}
} returnnew Inner().test();
}
}
var o = new Outer;
assertEq(o.test(), 3);
// IC tests:
var alreadyConstructedB = new B();
assertEq(B.gx(alreadyConstructedB), 12);
function initIC(o) { new B(o);
} var array = []; // warm up init IC for (var i = 1; i < 1000; i++) { var newB = {};
initIC(newB);
}
// Successfully catch double initialization type error.
assertThrows(() => initIC(alreadyConstructedB), TypeError); // Do it again, to make sure we didn't attach a stub that is invalid.
assertThrows(() => initIC(alreadyConstructedB), TypeError);
// Test getters work, and ICs can't be tricked. Setup an array of // // [B, B, B, B, ..., {}, {}] // // Then test that as we execute the sudden appearance of {} doesn't // trick our ICs into setting or getting anything -- do it twice // to make sure that we didn't get a stub that is invalid. var elements = []; for (var i = 0; i < 99; i++) {
elements.push(new B);
}
elements.push({});
elements.push({});
function getterCheck(e) {
assertEq(B.gx(e), 12);
}
function setterCheck(e) {
B.sx(e);
}
var checksPassed = 0; try { for (var e of elements) {
getterCheck(e);
checksPassed++;
} throw `Shouldn't arrive here`;
} catch (e) { if (!(e instanceof TypeError)) { throw e;
} // All but last element should have done the right thing.
assertEq(checksPassed, elements.length - 2);
}
checksPassed = 0; try { for (var e of elements) {
setterCheck(e);
checksPassed++;
} throw `Shouldn't arrive here`;
} catch (e) { if (!(e instanceof TypeError)) { throw e;
} // All but last element should have done the right thing.
assertEq(checksPassed, elements.length - 2);
}
// Verify setter did the thing, but throws in the correct places for (var index in elements) { if (index < elements.length - 2) {
assertEq(B.gx(elements[index]), 13);
} else {
assertThrows(() => {
B.gx(elements[index]);
}, TypeError);
}
}
// Megamorphic Cache Testing: for (var i = 0; i < 100; i++) { var inputs = [{ a: 1 }, { b: 2 }, { c: 3 }, { d: 4 }, { e: 5 }, new Proxy({}, {})]; for (var o of inputs) {
assertThrows(() => B.gx(o), TypeError);
assertThrows(() => B.sx(o), TypeError); new B(o);
assertEq(B.gx(o), 12);
B.sx(o);
assertEq(B.gx(o), 13);
}
}
Messung V0.5
[ Dauer der Verarbeitung: 0.4 Sekunden
(vorverarbeitet)
]