Skip to content

Commit 3599600

Browse files
Fix the access error caused when a class is implemented to be empty
JerryScript-DCO-1.0-Signed-off-by: tangbin 2387440390@qq.com
1 parent 5020015 commit 3599600

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

jerry-core/parser/js/js-parser-expr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
488488
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR);
489489
}
490490

491-
if (class_name_index != PARSER_INVALID_LITERAL_INDEX)
491+
if (class_name_index != PARSER_INVALID_LITERAL_INDEX && context_p->scope_stack_p != NULL)
492492
{
493493
parser_emit_cbc_ext_literal (context_p, CBC_EXT_SET_CLASS_NAME, class_name_index);
494494
}

tests/jerry/class-empty-context.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
class v0 {v1 = class v2 { }}

0 commit comments

Comments
 (0)