Skip to content

Commit

Permalink
LibJS/Tests: Use canParseSource() for toEval()
Browse files Browse the repository at this point in the history
We can now enable the "new.target is syntax error outside of function"
test :^)
  • Loading branch information
linusg authored and awesomekling committed Nov 12, 2020
1 parent 7fc98a9 commit e77202f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
12 changes: 6 additions & 6 deletions Libraries/LibJS/Tests/automatic-semicolon-insertion.js
Original file line number Diff line number Diff line change
@@ -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();
});
Expand Down
3 changes: 1 addition & 2 deletions Libraries/LibJS/Tests/functions/function-new-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
4 changes: 1 addition & 3 deletions Libraries/LibJS/Tests/test-common-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions Libraries/LibJS/Tests/test-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e77202f

Please sign in to comment.