Skip to content

Commit 94cb6ae

Browse files
committed
Fix prop_getters stack manipulation for assignment expression.
Related issue: jerryscript-project#614 JerryScript-DCO-1.0-Signed-off-by: Ilyong Cho ily.cho@samsung.com
1 parent eaca37c commit 94cb6ae

File tree

4 files changed

+78
-30
lines changed

4 files changed

+78
-30
lines changed

jerry-core/parser/js/opcodes-dumper.cpp

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -628,25 +628,23 @@ dump_prop_setter_or_triple_address_res (vm_op_t opcode,
628628
jsp_operand_t res,
629629
jsp_operand_t op)
630630
{
631-
const op_meta last = STACK_TOP (prop_getters);
632-
if (last.op.op_idx == VM_OP_PROP_GETTER)
631+
if (res.is_register_operand ())
633632
{
633+
/*
634+
* Left-hand-side must be a member expression and corresponding prop_getter
635+
* op is on top of the stack.
636+
*/
637+
const op_meta last = STACK_TOP (prop_getters);
638+
JERRY_ASSERT (last.op.op_idx == VM_OP_PROP_GETTER);
639+
634640
res = dump_triple_address_and_prop_setter_res (opcode, last, op);
641+
642+
STACK_DROP (prop_getters, 1);
635643
}
636644
else
637645
{
638-
if (res.is_register_operand ())
639-
{
640-
/*
641-
* FIXME:
642-
* Implement correct handling of references through parser operands
643-
*/
644-
PARSE_ERROR (JSP_EARLY_ERROR_REFERENCE, "Invalid left-hand-side expression", LIT_ITERATOR_POS_ZERO);
645-
}
646-
647646
dump_triple_address (opcode, res, res, op);
648647
}
649-
STACK_DROP (prop_getters, 1);
650648
return res;
651649
}
652650

@@ -1865,37 +1863,60 @@ rewrite_jump_to_end (void)
18651863
}
18661864

18671865
void
1868-
start_dumping_assignment_expression (void)
1866+
start_dumping_assignment_expression (jsp_operand_t lhs, locus loc __attr_unused___)
18691867
{
1870-
const op_meta last = last_dumped_op_meta ();
1871-
if (last.op.op_idx == VM_OP_PROP_GETTER)
1868+
if (lhs.is_register_operand ())
18721869
{
1873-
serializer_set_writing_position ((vm_instr_counter_t) (serializer_get_current_instr_counter () - 1));
1870+
/*
1871+
* Having left-handside of assignment expression as a temporary register
1872+
* means it's either a member expression or something else. Under the condition,
1873+
* only member expression could be a L-value for assignment expression, otherwise
1874+
* it's an invalid lhs expression.
1875+
*/
1876+
1877+
const op_meta last = last_dumped_op_meta ();
1878+
1879+
if (last.op.op_idx == VM_OP_PROP_GETTER)
1880+
{
1881+
/*
1882+
* If lhs is a member expression, last dumped op code should be
1883+
* prop_getter. For we are going to use the expression as L-value, it will
1884+
* be a prop_setter later, save the op to stack.
1885+
*/
1886+
serializer_set_writing_position ((vm_instr_counter_t) (serializer_get_current_instr_counter () - 1));
1887+
STACK_PUSH (prop_getters, last);
1888+
}
1889+
else
1890+
{
1891+
/*
1892+
* If lhs is a temporary register operand but not a member expression, It
1893+
* is an invalid left-hand-side expression.
1894+
*/
1895+
PARSE_ERROR (JSP_EARLY_ERROR_REFERENCE, "Invalid left-hand-side expression", loc);
1896+
}
18741897
}
1875-
STACK_PUSH (prop_getters, last);
18761898
}
18771899

18781900
jsp_operand_t
18791901
dump_prop_setter_or_variable_assignment_res (jsp_operand_t res, jsp_operand_t op)
18801902
{
1881-
const op_meta last = STACK_TOP (prop_getters);
1882-
if (last.op.op_idx == VM_OP_PROP_GETTER)
1903+
if (res.is_register_operand ())
18831904
{
1905+
/*
1906+
* Left-hand-side must be a member expression and corresponding prop_getter
1907+
* op is on top of the stack.
1908+
*/
1909+
const op_meta last = STACK_TOP (prop_getters);
1910+
JERRY_ASSERT (last.op.op_idx == VM_OP_PROP_GETTER);
1911+
18841912
dump_prop_setter_op_meta (last, op);
1913+
1914+
STACK_DROP (prop_getters, 1);
18851915
}
18861916
else
18871917
{
1888-
if (res.is_register_operand ())
1889-
{
1890-
/*
1891-
* FIXME:
1892-
* Implement correct handling of references through parser operands
1893-
*/
1894-
PARSE_ERROR (JSP_EARLY_ERROR_REFERENCE, "Invalid left-hand-side expression", LIT_ITERATOR_POS_ZERO);
1895-
}
18961918
dump_variable_assignment (res, op);
18971919
}
1898-
STACK_DROP (prop_getters, 1);
18991920
return op;
19001921
}
19011922

jerry-core/parser/js/opcodes-dumper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ void rewrite_conditional_check (void);
425425
void dump_jump_to_end_for_rewrite (void);
426426
void rewrite_jump_to_end (void);
427427

428-
void start_dumping_assignment_expression (void);
428+
void start_dumping_assignment_expression (jsp_operand_t, locus);
429429
jsp_operand_t dump_prop_setter_or_variable_assignment_res (jsp_operand_t, jsp_operand_t);
430430
jsp_operand_t dump_prop_setter_or_addition_res (jsp_operand_t, jsp_operand_t);
431431
jsp_operand_t dump_prop_setter_or_multiplication_res (jsp_operand_t, jsp_operand_t);

jerry-core/parser/js/parser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,7 @@ static jsp_operand_t
17301730
parse_assignment_expression (bool in_allowed)
17311731
{
17321732
bool is_conditional = false;
1733+
locus loc_expr = tok.loc;
17331734
jsp_operand_t expr = parse_conditional_expression (in_allowed, &is_conditional);
17341735
if (is_conditional)
17351736
{
@@ -1755,7 +1756,7 @@ parse_assignment_expression (bool in_allowed)
17551756
{
17561757
jsp_early_error_check_for_eval_and_arguments_in_strict_mode (expr, is_strict_mode (), tok.loc);
17571758
skip_newlines ();
1758-
start_dumping_assignment_expression ();
1759+
start_dumping_assignment_expression (expr, loc_expr);
17591760
const jsp_operand_t assign_expr = parse_assignment_expression (in_allowed);
17601761

17611762
if (tt == TOK_EQ)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2015 Samsung Electronics Co., Ltd.
2+
// Copyright 2015 University of Szeged.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
JSON.stringify & (Date = 1);
17+
18+
b = 1;
19+
this.a = 2;
20+
this.a
21+
b = 3;
22+
assert(b == 3);
23+
assert(a == 2);
24+
this.a & (b = 4);
25+
assert(b == 4);
26+
assert(a == 2);

0 commit comments

Comments
 (0)