Spread operator should not update the scanner context's binding type (#3613)

This patch fixes #3595.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik 2020-03-16 14:52:05 +01:00 committed by GitHub
parent bc7c39d893
commit 7f67795326
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 8 deletions

View File

@ -217,17 +217,19 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
}
#if ENABLED (JERRY_ES2015)
case LEXER_THREE_DOTS:
{
/* Elision or spread arguments */
if (stack_top != SCAN_STACK_PAREN_EXPRESSION && stack_top != SCAN_STACK_ARRAY_LITERAL)
{
scanner_raise_error (context_p);
}
scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION;
break;
}
#endif /* ENABLED (JERRY_ES2015) */
case LEXER_COMMA:
{
/* Elision or spread arguments */
#if ENABLED (JERRY_ES2015)
bool raise_error = (stack_top != SCAN_STACK_PAREN_EXPRESSION && stack_top != SCAN_STACK_ARRAY_LITERAL);
#else /* !ENABLED (JERRY_ES2015) */
bool raise_error = stack_top != SCAN_STACK_ARRAY_LITERAL;
#endif /* ENABLED (JERRY_ES2015) */
if (raise_error)
if (stack_top != SCAN_STACK_ARRAY_LITERAL)
{
scanner_raise_error (context_p);
}

View File

@ -0,0 +1,25 @@
// Copyright JS Foundation and other contributors, http://js.foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Test if the native function as constructor is correctly invoked
// when used as parent "class"
var src = "({ $($) { a(...args) }";
try {
eval (src);
assert (false);
} catch (e) {
assert (e instanceof SyntaxError);
}