utatane.tea@gmail.com | fdd9bf4 | 2015-12-02 03:16:28 +0000 | [diff] [blame] | 1 | function testSyntax(script) { |
| 2 | try { |
| 3 | eval(script); |
| 4 | } catch (error) { |
| 5 | if (error instanceof SyntaxError) |
| 6 | throw new Error("Bad error: " + String(error)); |
| 7 | } |
| 8 | } |
| 9 | |
| 10 | function testSyntaxError(script, message) { |
| 11 | var error = null; |
| 12 | try { |
| 13 | eval(script); |
| 14 | } catch (e) { |
| 15 | error = e; |
| 16 | } |
| 17 | if (!error) |
| 18 | throw new Error("Expected syntax error not thrown"); |
| 19 | |
| 20 | if (String(error) !== message) |
| 21 | throw new Error("Bad error: " + String(error)); |
| 22 | } |
| 23 | |
| 24 | testSyntaxError(` |
| 25 | class Cocoa { |
| 26 | *constructor() |
| 27 | { |
| 28 | } |
| 29 | } |
| 30 | `, `SyntaxError: Cannot declare a generator named 'constructor'.`); |
| 31 | |
| 32 | testSyntax(` |
| 33 | class Cocoa { |
| 34 | *ok() |
| 35 | { |
| 36 | yield 42; |
| 37 | } |
| 38 | } |
| 39 | `); |
| 40 | |
| 41 | testSyntax(` |
| 42 | class Cocoa { |
| 43 | static *ok() |
| 44 | { |
| 45 | yield 42; |
| 46 | } |
| 47 | } |
| 48 | `); |