From 7ea1937507e12181ffce69ea05b0bd840c657436 Mon Sep 17 00:00:00 2001 From: tangbin <2387440390@qq.com> Date: Tue, 22 Jul 2025 19:24:37 +0800 Subject: [PATCH] Fix the access error caused when a class is implemented to be empty JerryScript-DCO-1.0-Signed-off-by: tangbin 2387440390@qq.com --- jerry-core/parser/js/js-parser-expr.c | 2 +- tests/jerry/class-empty-context.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/jerry/class-empty-context.js diff --git a/jerry-core/parser/js/js-parser-expr.c b/jerry-core/parser/js/js-parser-expr.c index ef9170dce4..668b5a0bd8 100644 --- a/jerry-core/parser/js/js-parser-expr.c +++ b/jerry-core/parser/js/js-parser-expr.c @@ -1088,7 +1088,7 @@ parser_parse_class (parser_context_t *context_p, /**< context */ } } - if (class_name_index != PARSER_INVALID_LITERAL_INDEX) + if (class_name_index != PARSER_INVALID_LITERAL_INDEX && context_p->scope_stack_p != NULL) { if (JERRY_UNLIKELY (context_p->scope_stack_top >= context_p->scope_stack_size)) { diff --git a/tests/jerry/class-empty-context.js b/tests/jerry/class-empty-context.js new file mode 100644 index 0000000000..e79eebcb53 --- /dev/null +++ b/tests/jerry/class-empty-context.js @@ -0,0 +1,15 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +class v0 {v1 = class v2 { }}