Skip to content

Commit 8766bb3

Browse files
rerobikadbatyai
authored andcommitted
CBC_PUSH_THIS_LITERAL must be converted back to CBC_PUSH_THIS during emitting unary lvalue opcode (#2939)
This patch fixes #2937. Co-authored-by: Gabor Loki loki@inf.u-szeged.hu JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
1 parent d22f6b4 commit 8766bb3

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ parser_emit_unary_lvalue_opcode (parser_context_t *context_p, /**< context */
164164
JERRY_ASSERT (CBC_SAME_ARGS (CBC_PUSH_PROP, opcode));
165165
context_p->last_cbc_opcode = (uint16_t) opcode;
166166
}
167+
else if (context_p->last_cbc_opcode == CBC_PUSH_THIS_LITERAL
168+
&& context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL)
169+
{
170+
context_p->last_cbc_opcode = CBC_PUSH_THIS;
171+
parser_emit_cbc_literal (context_p,
172+
(uint16_t) (opcode + CBC_UNARY_LVALUE_WITH_IDENT),
173+
context_p->lit_object.index);
174+
}
167175
else
168176
{
169177
switch (context_p->last_cbc_opcode)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
var c = 0;
16+
var p1 = this[c++];
17+
assert (p1 === undefined);
18+
assert (c === 1);
19+
20+
var p2 = this[c--];
21+
assert (p2 === undefined);
22+
assert (c === 0);
23+
24+
var p3 = this[++c];
25+
assert (p3 === undefined);
26+
assert (c === 1);
27+
28+
var p4 = this[--c];
29+
assert (p4 === undefined);
30+
assert (c === 0);

0 commit comments

Comments
 (0)