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 */
11681168 || context_p -> token .type == LEXER_KEYW_LET
11691169 || context_p -> token .type == LEXER_KEYW_CONST )
11701170 {
1171+ if (context_p -> status_flags & PARSER_IS_STRICT )
1172+ {
1173+ parser_raise_error (context_p , PARSER_ERR_FOR_IN_OF_DECLARATION );
1174+ }
1175+
11711176 token_type = context_p -> token .type ;
11721177 has_context = (context_p -> token .type != LEXER_KEYW_VAR );
11731178 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 */
951951 {
952952 return "Incorrect use of yield keyword." ;
953953 }
954+ case PARSER_ERR_FOR_IN_OF_DECLARATION :
955+ {
956+ return "for in-of loop variable declaration may not have an initializer." ;
957+ }
954958#endif /* ENABLED (JERRY_ES2015) */
955959 case PARSER_ERR_DELETE_IDENT_NOT_ALLOWED :
956960 {
Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ typedef enum
8080#if ENABLED (JERRY_ES2015 )
8181 PARSER_ERR_USE_STRICT_NOT_ALLOWED , /**< use strict directive is not allowed */
8282 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 */
8384#endif /* ENABLED (JERRY_ES2015) */
8485 PARSER_ERR_DELETE_IDENT_NOT_ALLOWED , /**< identifier delete is not allowed in strict mode */
8586 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