Fix invalid / unhandled this_literal cases. (#3696)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2020-04-27 14:54:21 +02:00
committed by GitHub
parent 4e8dac8ce1
commit f254b1a8b7
2 changed files with 32 additions and 11 deletions
+4 -10
View File
@@ -178,7 +178,7 @@ parser_emit_ident_reference (parser_context_t *context_p, /**< context */
else if (context_p->last_cbc_opcode == CBC_PUSH_THIS_LITERAL) else if (context_p->last_cbc_opcode == CBC_PUSH_THIS_LITERAL)
{ {
context_p->last_cbc_opcode = CBC_PUSH_THIS; context_p->last_cbc_opcode = CBC_PUSH_THIS;
literal_index = context_p->lit_object.index; literal_index = context_p->last_cbc.literal_index;
} }
else else
{ {
@@ -1946,7 +1946,7 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
} }
#endif /* ENABLED (JERRY_ES2015) */ #endif /* ENABLED (JERRY_ES2015) */
else if (JERRY_UNLIKELY (context_p->status_flags & PARSER_INSIDE_WITH) else if (JERRY_UNLIKELY (context_p->status_flags & PARSER_INSIDE_WITH)
&& PARSER_IS_PUSH_LITERAL (context_p->last_cbc_opcode) && 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)
{ {
opcode = CBC_CALL_PROP; opcode = CBC_CALL_PROP;
@@ -2193,7 +2193,7 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
if (token == CBC_TYPEOF) if (token == CBC_TYPEOF)
{ {
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)
{ {
parser_emit_ident_reference (context_p, CBC_TYPEOF_IDENT); parser_emit_ident_reference (context_p, CBC_TYPEOF_IDENT);
@@ -2365,7 +2365,7 @@ parser_append_binary_token (parser_context_t *context_p) /**< context */
if (LEXER_IS_BINARY_LVALUE_TOKEN (context_p->token.type)) if (LEXER_IS_BINARY_LVALUE_TOKEN (context_p->token.type))
{ {
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)
{ {
parser_check_invalid_assign (context_p); parser_check_invalid_assign (context_p);
@@ -2376,12 +2376,6 @@ parser_append_binary_token (parser_context_t *context_p) /**< context */
{ {
context_p->last_cbc_opcode = PARSER_PUSH_PROP_TO_PUSH_PROP_REFERENCE (context_p->last_cbc_opcode); context_p->last_cbc_opcode = PARSER_PUSH_PROP_TO_PUSH_PROP_REFERENCE (context_p->last_cbc_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);
context_p->last_cbc_opcode = CBC_PUSH_IDENT_REFERENCE;
}
else else
{ {
/* Invalid LeftHandSide expression. */ /* Invalid LeftHandSide expression. */
+28 -1
View File
@@ -56,10 +56,37 @@ function f() {
try { try {
eval ("g(this, 'a' = 1)"); eval ("g(this, 'a' = 1)");
assert (false) assert (false);
} catch (e) { } catch (e) {
assert (e instanceof ReferenceError); assert (e instanceof ReferenceError);
} }
try {
eval ("g(this, 'a' += 1)");
assert (false);
} catch (e) {
assert (e instanceof ReferenceError);
}
assert (a === 0); assert (a === 0);
} }
f(); f();
function g(a, b)
{
assert(b === "undefined");
}
g(this, typeof undeclared_var)
function h()
{
var done = false;
var o = { a: function () { done = (this === o) } }
function f() {}
with (o) {
f(this, a());
}
assert(done);
}
h();