From 65db83561f3deeca66e4582321e9a5865a679829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20G=C3=A1l?= Date: Tue, 17 Nov 2020 10:35:27 +0100 Subject: [PATCH] Implement rest parameter support for destructuring object patterns in for (#4338) In case of `for (const {...rest} ...) ` there was an incorrectly handling of the destructuring pattern. JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.usz@partner.samsung.com --- jerry-core/parser/js/js-parser-statm.c | 19 +++++++++--- tests/jerry/es.next/object-pattern2.js | 22 ++++++++++++++ tests/test262-esnext-excludelist.xml | 41 -------------------------- 3 files changed, 37 insertions(+), 45 deletions(-) diff --git a/jerry-core/parser/js/js-parser-statm.c b/jerry-core/parser/js/js-parser-statm.c index d2c6c6669..c5ba6124f 100644 --- a/jerry-core/parser/js/js-parser-statm.c +++ b/jerry-core/parser/js/js-parser-statm.c @@ -1350,15 +1350,26 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */ parser_emit_cbc_ext (context_p, is_for_in ? CBC_EXT_FOR_IN_GET_NEXT : CBC_EXT_FOR_OF_GET_NEXT); + parser_pattern_flags_t flags = (PARSER_PATTERN_BINDING | PARSER_PATTERN_TARGET_ON_STACK); + if (context_p->next_scanner_info_p->source_p == (context_p->source_p + 1)) { - JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER); + if (context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER) + { + scanner_release_next (context_p, sizeof (scanner_location_info_t)); + } + else + { + JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_LITERAL_FLAGS); + if (context_p->next_scanner_info_p->u8_arg & SCANNER_LITERAL_OBJECT_HAS_REST) + { + flags |= PARSER_PATTERN_HAS_REST_ELEMENT; + } - scanner_release_next (context_p, sizeof (scanner_location_info_t)); + scanner_release_next (context_p, sizeof (scanner_info_t)); + } } - parser_pattern_flags_t flags = (PARSER_PATTERN_BINDING | PARSER_PATTERN_TARGET_ON_STACK); - if (token_type == LEXER_KEYW_LET) { flags |= PARSER_PATTERN_LET; diff --git a/tests/jerry/es.next/object-pattern2.js b/tests/jerry/es.next/object-pattern2.js index 6a667c116..b0c46ff20 100644 --- a/tests/jerry/es.next/object-pattern2.js +++ b/tests/jerry/es.next/object-pattern2.js @@ -135,3 +135,25 @@ function f8() { rest_compare(b, ["0", "C", "1", "D"]) } f8() + +function f9() { + var counter = 0; + + for (const { ...rest} in { B: "AA", C: 6.25 }) { + switch (counter) { + case 0: { + /* rest === { '0': 'B' } */ + assert(rest['0'] === 'B'); + break; + } + case 1: { + /* rest === { '0': 'C' } */ + assert(rest['0'] == 'C'); + break; + } + } + counter++; + } + assert(counter === 2); +} +f9() diff --git a/tests/test262-esnext-excludelist.xml b/tests/test262-esnext-excludelist.xml index 98810d77a..619e7b1c0 100644 --- a/tests/test262-esnext-excludelist.xml +++ b/tests/test262-esnext-excludelist.xml @@ -7489,31 +7489,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - -