LibJS/Tests: Use canParseSource() for toEval()

We can now enable the "new.target is syntax error outside of function"
test :^)
This commit is contained in:
Linus Groh 2020-11-11 22:16:37 +00:00 committed by Andreas Kling
parent 7fc98a96a9
commit e77202fe0f
4 changed files with 10 additions and 19 deletions

View file

@ -1,18 +1,18 @@
test("Issue #1829, if-else without braces or semicolons", () => {
const source = `if (1)
return 1;
foo;
else
return 0;
bar;
if (1)
return 1
foo
else
return 0
bar
if (1)
return 1
foo
else
return 0;`;
bar;`;
expect(source).toEval();
});

View file

@ -20,7 +20,6 @@ test("basic functionality", () => {
expect(new baz().newTarget).toEqual(baz);
});
// FIXME: This does not work as expected as toEval() places the code inside a function :|
test.skip("syntax error outside of function", () => {
test("syntax error outside of function", () => {
expect("new.target").not.toEval();
});

View file

@ -326,13 +326,11 @@ test("toThrowWithMessage", () => {
expect(thrower).not.toThrowWithMessage(TypeError, "foo baz");
});
// FIXME: Will have to change when this matcher changes to use the
// "eval" function
test("toEval", () => {
expect("let a = 1").toEval();
expect("a < 1").toEval();
expect("&&*^%#%@").not.toEval();
expect("function foo() { return 1; }; return foo();").toEval();
expect("function foo() { return 1; }; foo();").toEval();
});
// FIXME: Will have to change when this matcher changes to use the

View file

@ -302,14 +302,8 @@ class ExpectationError extends Error {
// Test for syntax errors; target must be a string
toEval() {
this.__expect(typeof this.target === "string");
let threw = false;
try {
new Function(this.target);
} catch (e) {
threw = true;
}
this.__expect(this.inverted ? threw : !threw);
const success = canParseSource(this.target)
this.__expect(this.inverted ? !success : success);
}
// Must compile regardless of inverted-ness