LibJS: Simplify toEval() implementation

This commit is contained in:
Linus Groh 2020-09-16 23:03:42 +01:00 committed by Andreas Kling
commit a9f5b0339d
Notes: sideshowbarker 2024-07-19 02:21:19 +09:00

View file

@ -285,22 +285,13 @@ class ExpectationError extends Error {
toEval() { toEval() {
this.__expect(typeof this.target === "string"); this.__expect(typeof this.target === "string");
if (!this.inverted) { let threw = false;
try { try {
new Function(this.target)(); new Function(this.target)();
} catch (e) { } catch (e) {
throw new ExpectationError(); threw = true;
}
} else {
let threw;
try {
new Function(this.target)();
threw = false;
} catch (e) {
threw = true;
}
this.__expect(threw);
} }
this.__expect(this.inverted ? threw : !threw);
} }
// Must compile regardless of inverted-ness // Must compile regardless of inverted-ness