-
Notifications
You must be signed in to change notification settings - Fork 684
Open
Description
Unhandled exception occurs when a private variable increments
When I do an increment operation on a private variable like "this.#cnt++", it will throw "Unhandled exception: SyntaxError: Invalid left-hand side expression in postfix operation"
JerryScript revision
jerryscript-3.0.0
Test case
class A {
#cnt;
constructor(init) {
this.#cnt = init;
}
incr() {
this.#cnt++;
}
get cnt() {
return this.#cnt;
}
}
a_inst = new A(10);
print(a_inst.cnt);
a_inst.incr();
print(a_inst.cnt);
Output
this.#cnt++;
~~~~~~~~~~~~~~~~~^
Unhandled exception: SyntaxError: Invalid left-hand side expression in postfix operation [test.js:7:18]
Expected behavior
10
11
Parser Output
--- Script parsing start ---
--- Scanning start ---
FUNCTION: flags: 0x4 declarations: 2 source:0
LET ** 'A'
CLASS: source:5
FUNCTION: flags: 0x0 declarations: 1 source:38
ARG 'init'
FUNCTION: flags: 0x0 declarations: 0 source:90
FUNCTION: flags: 0x0 declarations: 0 source:136
--- Scanning end ---
[ 0] CBC_CHECK_LET idx:0->ident(A)
[ 0] CBC_CREATE_LET IDX:0->ident(A)
[ 1] CBC_EXT_PUSH_NAMED_CLASS_ENV IDX:0->ident(A)
[ 2] CBC_PUSH_ELISION
[ 3] CBC_PUSH_LITERAL idx:1->unknown
[ 3] CBC_EXT_SET_CLASS_NAME IDX:0->ident(A)
[ 3] CBC_EXT_INIT_CLASS
[ 3] CBC_EXT_COLLECT_PRIVATE_FIELD idx:2->string(cnt)
--- Class constructor parsing start ---
[ 0] CBC_EXT_RUN_FIELD_INIT
[ 1] CBC_PUSH_THIS
[ 3] CBC_PUSH_TWO_LITERALS idx:1->string(cnt) REG:0->ident(init)
[ 0] CBC_EXT_ASSIGN_PRIVATE
Line info size: 4 bytes
New block: line: 4 StreamLength: [last]
ByteCodeEndOffset: [unterminated] Line: 4 Column: 9
Byte code dump:
Maximum stack depth: 4
Flags: [small_lit_enc,strict_mode,constructor]
Argument range end: 1
Register range end: 1
Identifier range end: 1
Const literal range end: 2
Literal range end: 2
0 : CBC_EXT_RUN_FIELD_INIT
2 : CBC_PUSH_THIS
3 : CBC_PUSH_TWO_LITERALS const:1->string(cnt) arg:0
6 : CBC_EXT_ASSIGN_PRIVATE
8 : CBC_RETURN_FUNCTION_END
Byte code size: 9 bytes
--- Class constructor parsing end ---
--- Function parsing start ---
[ 1] CBC_PUSH_THIS
--- Script parsing end ---
this.#cnt++;
~~~~~~~~~~~~~~~~~^
Unhandled exception: SyntaxError: Invalid left-hand side expression in postfix operation [test.js:7:18]
Metadata
Metadata
Assignees
Labels
No labels