Skip to content

Commit 1b84a17

Browse files
galpeterrerobika
authored andcommitted
Correctly propagate super prop ref when parsing expressions (#3077)
The "super prop ref" flag is incorrectly used at multiple expressions as it was only cleared if there was an assignment operation. JerryScript-DCO-1.0-Signed-off-by: Peter Gal [email protected]
1 parent 57f389d commit 1b84a17

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,6 +2245,16 @@ parser_parse_expression (parser_context_t *context_p, /**< context */
22452245

22462246
parser_stack_push_uint8 (context_p, LEXER_EXPRESSION_START);
22472247

2248+
#if ENABLED (JERRY_ES2015_CLASS)
2249+
/* Parsing a new expression:
2250+
* So save, remove, and at the end restore the super prop reference indicator.
2251+
*
2252+
* If this is not done, it is possible to carry the flag over to the next expression.
2253+
*/
2254+
bool has_super_ref = (context_p->status_flags & PARSER_CLASS_SUPER_PROP_REFERENCE);
2255+
context_p->status_flags &= (uint32_t) ~PARSER_CLASS_SUPER_PROP_REFERENCE;
2256+
#endif
2257+
22482258
while (true)
22492259
{
22502260
if (options & PARSE_EXPR_HAS_LITERAL)
@@ -2409,6 +2419,14 @@ parser_parse_expression (parser_context_t *context_p, /**< context */
24092419
{
24102420
parser_push_result (context_p);
24112421
}
2422+
2423+
#if ENABLED (JERRY_ES2015_CLASS)
2424+
/* Restore the super prop ref flag. */
2425+
if (has_super_ref)
2426+
{
2427+
context_p->status_flags |= (uint32_t) PARSER_CLASS_SUPER_PROP_REFERENCE;
2428+
}
2429+
#endif /* ENABLED (JERRY_ES2015_CLASS) */
24122430
} /* parser_parse_expression */
24132431

24142432
/**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
// Test case minimalized from issue #3067
16+
17+
function f () { }
18+
19+
class B extends f {
20+
constructor () {
21+
super (0)
22+
super.$
23+
this.$ = $
24+
}
25+
}
26+
27+
try {
28+
var b = new B;
29+
assert (false);
30+
} catch (ex) {
31+
assert (ex instanceof ReferenceError);
32+
}

0 commit comments

Comments
 (0)