File tree Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -1168,6 +1168,11 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */
1168
1168
|| context_p -> token .type == LEXER_KEYW_LET
1169
1169
|| context_p -> token .type == LEXER_KEYW_CONST )
1170
1170
{
1171
+ if (context_p -> status_flags & PARSER_IS_STRICT )
1172
+ {
1173
+ parser_raise_error (context_p , PARSER_ERR_FOR_IN_OF_DECLARATION );
1174
+ }
1175
+
1171
1176
token_type = context_p -> token .type ;
1172
1177
has_context = (context_p -> token .type != LEXER_KEYW_VAR );
1173
1178
scanner_get_location (& start_location , context_p );
Original file line number Diff line number Diff line change @@ -951,6 +951,10 @@ parser_error_to_string (parser_error_t error) /**< error code */
951
951
{
952
952
return "Incorrect use of yield keyword." ;
953
953
}
954
+ case PARSER_ERR_FOR_IN_OF_DECLARATION :
955
+ {
956
+ return "for in-of loop variable declaration may not have an initializer." ;
957
+ }
954
958
#endif /* ENABLED (JERRY_ES2015) */
955
959
case PARSER_ERR_DELETE_IDENT_NOT_ALLOWED :
956
960
{
Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ typedef enum
80
80
#if ENABLED (JERRY_ES2015 )
81
81
PARSER_ERR_USE_STRICT_NOT_ALLOWED , /**< use strict directive is not allowed */
82
82
PARSER_ERR_YIELD_NOT_ALLOWED , /**< yield keyword is not allowed */
83
+ PARSER_ERR_FOR_IN_OF_DECLARATION , /**< variable declaration in for-in or for-of loop */
83
84
#endif /* ENABLED (JERRY_ES2015) */
84
85
PARSER_ERR_DELETE_IDENT_NOT_ALLOWED , /**< identifier delete is not allowed in strict mode */
85
86
PARSER_ERR_EVAL_CANNOT_ASSIGNED , /**< eval cannot be assigned in strict mode */
Original file line number Diff line number Diff line change
1
+ /* Copyright JS Foundation and other contributors, http://js.foundation
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ 'use strict' ;
17
+ try {
18
+ eval ( 'for (var i = 0 in {}) {}' ) ;
19
+ assert ( false ) ;
20
+ } catch ( e ) {
21
+ assert ( e instanceof SyntaxError ) ;
22
+ }
23
+
24
+ try {
25
+ eval ( 'for (var = i of {}) {}' ) ;
26
+ assert ( false ) ;
27
+ } catch ( e ) {
28
+ assert ( e instanceof SyntaxError ) ;
29
+ }
You can’t perform that action at this time.
0 commit comments