Skip to content

Commit

Permalink
Fix arguments object in eval-ed functions in static class initializers
Browse files Browse the repository at this point in the history
JerryScript-DCO-1.0-Signed-off-by: Máté Tokodi mate.tokodi@szteszoftver.hu
  • Loading branch information
matetokodi committed May 27, 2024
1 parent 35465ed commit d25af88
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions jerry-core/parser/js/js-scanner-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ typedef enum
#if JERRY_DEBUGGER
SCANNER_CONTEXT_DEBUGGER_ENABLED = (1 << 1), /**< debugger is enabled */
#endif /* JERRY_DEBUGGER */
SCANNER_CONTEXT_RESTORE_INSIDE_CLASS_FIELD_FLAG =
(1 << 2), /**< restore the PARSER_INSIDE_CLASS_FIELD flag of the main context */
} scanner_context_flags_t;

/**
Expand Down
11 changes: 11 additions & 0 deletions jerry-core/parser/js/js-scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,11 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
}
case LEXER_KEYW_FUNCTION:
{
if (context_p->status_flags & PARSER_INSIDE_CLASS_FIELD)
{
scanner_context_p->status_flags |= SCANNER_CONTEXT_RESTORE_INSIDE_CLASS_FIELD_FLAG;
context_p->status_flags &= (uint32_t) ~(PARSER_INSIDE_CLASS_FIELD);
}
uint16_t status_flags = SCANNER_LITERAL_POOL_FUNCTION | SCANNER_LITERAL_POOL_FUNCTION_STATEMENT;

if (scanner_context_p->async_source_p != NULL)
Expand Down Expand Up @@ -2016,6 +2021,12 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */
break;
}

if (scanner_context_p->status_flags & SCANNER_CONTEXT_RESTORE_INSIDE_CLASS_FIELD_FLAG)
{
context_p->status_flags |= PARSER_INSIDE_CLASS_FIELD;
scanner_context_p->status_flags &= (uint16_t) ~(SCANNER_CONTEXT_RESTORE_INSIDE_CLASS_FIELD_FLAG);
}

if (context_p->stack_top_uint8 != SCAN_STACK_CLASS_STATEMENT)
{
scanner_pop_literal_pool (context_p, scanner_context_p);
Expand Down
26 changes: 26 additions & 0 deletions tests/jerry/regression-test-issue-5117.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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 Outer {
static {
eval(`
function staticfunc() {
arguments;
}

class Inner {
}
`);
}
}

0 comments on commit d25af88

Please sign in to comment.