mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
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:
parent
e2807c28fa
commit
daeee77d63
@ -2199,7 +2199,7 @@ parser_append_binary_single_assignment_token (parser_context_t *context_p, /**<
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL)
|
||||
switch (context_p->last_cbc_opcode)
|
||||
{
|
||||
literal_index = context_p->last_cbc.literal_index;
|
||||
context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE;
|
||||
}
|
||||
else if (context_p->last_cbc_opcode == CBC_PUSH_TWO_LITERALS)
|
||||
{
|
||||
literal_index = context_p->last_cbc.value;
|
||||
context_p->last_cbc_opcode = CBC_PUSH_LITERAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
case CBC_PUSH_LITERAL:
|
||||
{
|
||||
literal_index = context_p->last_cbc.literal_index;
|
||||
context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE;
|
||||
break;
|
||||
}
|
||||
case CBC_PUSH_TWO_LITERALS:
|
||||
{
|
||||
literal_index = context_p->last_cbc.value;
|
||||
context_p->last_cbc_opcode = CBC_PUSH_LITERAL;
|
||||
break;
|
||||
}
|
||||
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);
|
||||
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)
|
||||
{
|
||||
JERRY_ASSERT (CBC_SAME_ARGS (CBC_PUSH_PROP, CBC_ASSIGN));
|
||||
|
||||
@ -42,5 +42,19 @@ parse ("a =% b");
|
||||
parse ("c = a+");
|
||||
parse ("c = a-");
|
||||
|
||||
parse("a++\n()")
|
||||
parse("a--\n.b")
|
||||
parse("a++\n()");
|
||||
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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user