Fix invalid assignment code generation. (#3695)
This patch prevents assigning a value to a string literal after a this token. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -2199,7 +2199,7 @@ parser_append_binary_single_assignment_token (parser_context_t *context_p, /**<
|
|||||||
|
|
||||||
uint8_t assign_opcode = CBC_ASSIGN;
|
uint8_t assign_opcode = CBC_ASSIGN;
|
||||||
|
|
||||||
if (PARSER_IS_PUSH_LITERAL (context_p->last_cbc_opcode)
|
if (PARSER_IS_PUSH_LITERALS_WITH_THIS (context_p->last_cbc_opcode)
|
||||||
&& context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL)
|
&& context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL)
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (CBC_SAME_ARGS (CBC_PUSH_LITERAL, assign_ident_opcode));
|
JERRY_ASSERT (CBC_SAME_ARGS (CBC_PUSH_LITERAL, assign_ident_opcode));
|
||||||
@@ -2208,33 +2208,39 @@ parser_append_binary_single_assignment_token (parser_context_t *context_p, /**<
|
|||||||
|
|
||||||
uint16_t literal_index;
|
uint16_t literal_index;
|
||||||
|
|
||||||
if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL)
|
switch (context_p->last_cbc_opcode)
|
||||||
{
|
{
|
||||||
literal_index = context_p->last_cbc.literal_index;
|
case CBC_PUSH_LITERAL:
|
||||||
context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE;
|
{
|
||||||
}
|
literal_index = context_p->last_cbc.literal_index;
|
||||||
else if (context_p->last_cbc_opcode == CBC_PUSH_TWO_LITERALS)
|
context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE;
|
||||||
{
|
break;
|
||||||
literal_index = context_p->last_cbc.value;
|
}
|
||||||
context_p->last_cbc_opcode = CBC_PUSH_LITERAL;
|
case CBC_PUSH_TWO_LITERALS:
|
||||||
}
|
{
|
||||||
else
|
literal_index = context_p->last_cbc.value;
|
||||||
{
|
context_p->last_cbc_opcode = CBC_PUSH_LITERAL;
|
||||||
JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_THREE_LITERALS);
|
break;
|
||||||
literal_index = context_p->last_cbc.third_literal_index;
|
}
|
||||||
context_p->last_cbc_opcode = CBC_PUSH_TWO_LITERALS;
|
case CBC_PUSH_THIS_LITERAL:
|
||||||
|
{
|
||||||
|
literal_index = context_p->last_cbc.literal_index;
|
||||||
|
context_p->last_cbc_opcode = CBC_PUSH_THIS;
|
||||||
|
parser_flush_cbc (context_p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_THREE_LITERALS);
|
||||||
|
literal_index = context_p->last_cbc.third_literal_index;
|
||||||
|
context_p->last_cbc_opcode = CBC_PUSH_TWO_LITERALS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parser_stack_push_uint16 (context_p, literal_index);
|
parser_stack_push_uint16 (context_p, literal_index);
|
||||||
assign_opcode = assign_ident_opcode;
|
assign_opcode = assign_ident_opcode;
|
||||||
}
|
}
|
||||||
else if (context_p->last_cbc_opcode == CBC_PUSH_THIS_LITERAL)
|
|
||||||
{
|
|
||||||
context_p->last_cbc_opcode = CBC_PUSH_THIS;
|
|
||||||
parser_flush_cbc (context_p);
|
|
||||||
parser_stack_push_uint16 (context_p, context_p->last_cbc.literal_index);
|
|
||||||
assign_opcode = assign_ident_opcode;
|
|
||||||
}
|
|
||||||
else if (context_p->last_cbc_opcode == CBC_PUSH_PROP)
|
else if (context_p->last_cbc_opcode == CBC_PUSH_PROP)
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (CBC_SAME_ARGS (CBC_PUSH_PROP, CBC_ASSIGN));
|
JERRY_ASSERT (CBC_SAME_ARGS (CBC_PUSH_PROP, CBC_ASSIGN));
|
||||||
|
|||||||
@@ -42,5 +42,19 @@ parse ("a =% b");
|
|||||||
parse ("c = a+");
|
parse ("c = a+");
|
||||||
parse ("c = a-");
|
parse ("c = a-");
|
||||||
|
|
||||||
parse("a++\n()")
|
parse("a++\n()");
|
||||||
parse("a--\n.b")
|
parse("a--\n.b");
|
||||||
|
|
||||||
|
function f() {
|
||||||
|
var a = 0;
|
||||||
|
function g() {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
eval ("g(this, 'a' = 1)");
|
||||||
|
assert (false)
|
||||||
|
} catch (e) {
|
||||||
|
assert (e instanceof ReferenceError);
|
||||||
|
}
|
||||||
|
assert (a === 0);
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
|||||||
Reference in New Issue
Block a user