utatane.tea@gmail.com | f2fde6a | 2015-11-02 05:46:17 +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 | testSyntax(` |
| 25 | function t1() { |
| 26 | var yield = 20; |
| 27 | } |
| 28 | `); |
| 29 | testSyntax(` |
| 30 | function t1() { |
| 31 | let yield = 20; |
| 32 | } |
| 33 | `); |
| 34 | testSyntax(` |
| 35 | function t1() { |
| 36 | const yield = 20; |
| 37 | } |
| 38 | `); |
| 39 | |
| 40 | testSyntaxError(` |
| 41 | function t1() { |
| 42 | "use strict"; |
| 43 | var yield = 20; |
| 44 | } |
commit-queue@webkit.org | 0068bf7 | 2017-04-24 16:06:33 +0000 | [diff] [blame] | 45 | `, `SyntaxError: Cannot use 'yield' as a variable name in strict mode.`); |
utatane.tea@gmail.com | f2fde6a | 2015-11-02 05:46:17 +0000 | [diff] [blame] | 46 | testSyntaxError(` |
| 47 | function t1() { |
| 48 | "use strict"; |
| 49 | let yield = 20; |
| 50 | } |
commit-queue@webkit.org | 0068bf7 | 2017-04-24 16:06:33 +0000 | [diff] [blame] | 51 | `, `SyntaxError: Cannot use 'yield' as a lexical variable name in strict mode.`); |
utatane.tea@gmail.com | f2fde6a | 2015-11-02 05:46:17 +0000 | [diff] [blame] | 52 | testSyntaxError(` |
| 53 | function t1() { |
| 54 | "use strict"; |
| 55 | const yield = 20; |
| 56 | } |
commit-queue@webkit.org | 0068bf7 | 2017-04-24 16:06:33 +0000 | [diff] [blame] | 57 | `, `SyntaxError: Cannot use 'yield' as a lexical variable name in strict mode.`); |
utatane.tea@gmail.com | f2fde6a | 2015-11-02 05:46:17 +0000 | [diff] [blame] | 58 | |
| 59 | testSyntax(` |
| 60 | function t1() { |
| 61 | var { yield } = 20; |
| 62 | } |
| 63 | `); |
| 64 | testSyntax(` |
| 65 | function t1() { |
| 66 | let { yield } = 20; |
| 67 | } |
| 68 | `); |
| 69 | testSyntax(` |
| 70 | function t1() { |
| 71 | const { yield } = 20; |
| 72 | } |
| 73 | `); |
| 74 | |
| 75 | testSyntaxError(` |
| 76 | function t1() { |
| 77 | "use strict"; |
| 78 | var { yield } = 20; |
| 79 | } |
| 80 | `, `SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'yield'.`); |
| 81 | testSyntaxError(` |
| 82 | function t1() { |
| 83 | "use strict"; |
| 84 | let { yield } = 20; |
| 85 | } |
| 86 | `, `SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'yield'.`); |
| 87 | testSyntaxError(` |
| 88 | function t1() { |
| 89 | "use strict"; |
| 90 | const { yield } = 20; |
| 91 | } |
| 92 | `, `SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'yield'.`); |
| 93 | |
| 94 | testSyntax(` |
| 95 | function t1() { |
| 96 | var { i: yield } = 20; |
| 97 | } |
| 98 | `); |
| 99 | testSyntax(` |
| 100 | function t1() { |
| 101 | let { i: yield } = 20; |
| 102 | } |
| 103 | `); |
| 104 | testSyntax(` |
| 105 | function t1() { |
| 106 | const { i: yield } = 20; |
| 107 | } |
| 108 | `); |
| 109 | |
| 110 | testSyntaxError(` |
| 111 | function t1() { |
| 112 | "use strict"; |
| 113 | var { i: yield } = 20; |
| 114 | } |
commit-queue@webkit.org | 0068bf7 | 2017-04-24 16:06:33 +0000 | [diff] [blame] | 115 | `, `SyntaxError: Cannot use 'yield' as a variable name in strict mode.`); |
utatane.tea@gmail.com | f2fde6a | 2015-11-02 05:46:17 +0000 | [diff] [blame] | 116 | testSyntaxError(` |
| 117 | function t1() { |
| 118 | "use strict"; |
| 119 | let { i: yield } = 20; |
| 120 | } |
commit-queue@webkit.org | 0068bf7 | 2017-04-24 16:06:33 +0000 | [diff] [blame] | 121 | `, `SyntaxError: Cannot use 'yield' as a lexical variable name in strict mode.`); |
utatane.tea@gmail.com | f2fde6a | 2015-11-02 05:46:17 +0000 | [diff] [blame] | 122 | testSyntaxError(` |
| 123 | function t1() { |
| 124 | "use strict"; |
| 125 | const { i: yield } = 20; |
| 126 | } |
commit-queue@webkit.org | 0068bf7 | 2017-04-24 16:06:33 +0000 | [diff] [blame] | 127 | `, `SyntaxError: Cannot use 'yield' as a lexical variable name in strict mode.`); |
utatane.tea@gmail.com | f2fde6a | 2015-11-02 05:46:17 +0000 | [diff] [blame] | 128 | |
| 129 | testSyntax(` |
| 130 | function t1() { |
| 131 | var [ yield ] = 20; |
| 132 | } |
| 133 | `); |
| 134 | testSyntax(` |
| 135 | function t1() { |
| 136 | let [ yield ] = 20; |
| 137 | } |
| 138 | `); |
| 139 | testSyntax(` |
| 140 | function t1() { |
| 141 | const [ yield ] = 20; |
| 142 | } |
| 143 | `); |
| 144 | |
| 145 | testSyntaxError(` |
| 146 | function t1() { |
| 147 | "use strict"; |
| 148 | var [ yield ] = 20; |
| 149 | } |
commit-queue@webkit.org | 0068bf7 | 2017-04-24 16:06:33 +0000 | [diff] [blame] | 150 | `, `SyntaxError: Cannot use 'yield' as a variable name in strict mode.`); |
utatane.tea@gmail.com | f2fde6a | 2015-11-02 05:46:17 +0000 | [diff] [blame] | 151 | testSyntaxError(` |
| 152 | function t1() { |
| 153 | "use strict"; |
| 154 | let [ yield ] = 20; |
| 155 | } |
commit-queue@webkit.org | 0068bf7 | 2017-04-24 16:06:33 +0000 | [diff] [blame] | 156 | `, `SyntaxError: Cannot use 'yield' as a lexical variable name in strict mode.`); |
utatane.tea@gmail.com | f2fde6a | 2015-11-02 05:46:17 +0000 | [diff] [blame] | 157 | testSyntaxError(` |
| 158 | function t1() { |
| 159 | "use strict"; |
| 160 | const [ yield ] = 20; |
| 161 | } |
commit-queue@webkit.org | 0068bf7 | 2017-04-24 16:06:33 +0000 | [diff] [blame] | 162 | `, `SyntaxError: Cannot use 'yield' as a lexical variable name in strict mode.`); |
utatane.tea@gmail.com | f2fde6a | 2015-11-02 05:46:17 +0000 | [diff] [blame] | 163 | |
| 164 | testSyntax(` |
| 165 | function t1() { |
| 166 | function yield() { } |
| 167 | } |
| 168 | `); |
| 169 | testSyntaxError(` |
| 170 | function t1() { |
| 171 | "use strict"; |
| 172 | function yield() { } |
| 173 | } |
commit-queue@webkit.org | 0068bf7 | 2017-04-24 16:06:33 +0000 | [diff] [blame] | 174 | `, `SyntaxError: Cannot use 'yield' as a function name in strict mode.`); |
utatane.tea@gmail.com | f2fde6a | 2015-11-02 05:46:17 +0000 | [diff] [blame] | 175 | |
| 176 | testSyntax(` |
| 177 | function t1() { |
| 178 | try { |
| 179 | } catch (yield) { |
| 180 | } |
| 181 | } |
| 182 | `); |
| 183 | testSyntaxError(` |
| 184 | function t1() { |
| 185 | "use strict"; |
| 186 | try { |
| 187 | } catch (yield) { |
| 188 | } |
| 189 | } |
commit-queue@webkit.org | 0068bf7 | 2017-04-24 16:06:33 +0000 | [diff] [blame] | 190 | `, `SyntaxError: Cannot use 'yield' as a catch parameter name in strict mode.`); |
utatane.tea@gmail.com | f2fde6a | 2015-11-02 05:46:17 +0000 | [diff] [blame] | 191 | |
| 192 | testSyntax(` |
| 193 | function t1() { |
| 194 | function yield() { |
| 195 | "use strict"; |
| 196 | } |
| 197 | } |
| 198 | `); |