Fix block-scoped var/function redeclarations (#4080)

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai daniel.batyai@h-lab.eu
This commit is contained in:
Dániel Bátyai 2020-07-31 17:43:15 +02:00 committed by GitHub
parent 84125275ea
commit 26a299adf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 31 deletions

View File

@ -1382,6 +1382,14 @@ scanner_detect_invalid_var (parser_context_t *context_p, /**< context */
}
scanner_literal_pool_t *literal_pool_p = scanner_context_p->active_literal_pool_p;
if (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_BLOCK
&& (var_literal_p->type & (SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_FUNC_DECLARATION))
== (SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_FUNC_DECLARATION))
{
scanner_raise_redeclaration_error (context_p);
}
const uint8_t *char_p = var_literal_p->char_p;
prop_length_t length = var_literal_p->length;
@ -1399,6 +1407,8 @@ scanner_detect_invalid_var (parser_context_t *context_p, /**< context */
{
if (literal_p->type & SCANNER_LITERAL_IS_LOCAL
&& !(literal_p->type & SCANNER_LITERAL_IS_ARG)
&& !((literal_p->type & SCANNER_LITERAL_IS_FUNC)
&& (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_BLOCK) == 0)
&& (literal_p->type & SCANNER_LITERAL_IS_LOCAL) != SCANNER_LITERAL_IS_LOCAL
&& literal_p->length == length)
{
@ -1424,6 +1434,8 @@ scanner_detect_invalid_var (parser_context_t *context_p, /**< context */
{
if (literal_p->type & SCANNER_LITERAL_IS_LOCAL
&& !(literal_p->type & SCANNER_LITERAL_IS_ARG)
&& !((literal_p->type & SCANNER_LITERAL_IS_FUNC)
&& (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_BLOCK) == 0)
&& (literal_p->type & SCANNER_LITERAL_IS_LOCAL) != SCANNER_LITERAL_IS_LOCAL
&& lexer_compare_identifiers (context_p, literal_p, var_literal_p))
{

View File

@ -1438,6 +1438,14 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
scanner_raise_redeclaration_error (context_p);
}
scanner_literal_pool_t *literal_pool_p = scanner_context_p->active_literal_pool_p;
if (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_BLOCK
&& (literal_p->type & (SCANNER_LITERAL_IS_VAR)))
{
scanner_raise_redeclaration_error (context_p);
}
literal_p->type |= SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_FUNC_DECLARATION;
scanner_context_p->status_flags &= (uint16_t) ~SCANNER_CONTEXT_THROW_ERR_ASYNC_FUNCTION;

View File

@ -0,0 +1,56 @@
// 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.
function check_syntax_error (script)
{
try
{
eval (script);
assert (false);
}
catch (e)
{
assert (e instanceof SyntaxError);
}
}
eval("function f(){}; var f;");
eval("var f; function f(){};");
eval("function f(){}; { var f; }")
eval("{ var f; } function f(){};")
eval("{ function f(){}; } var f;")
eval("var f; { function f(){}; }")
check_syntax_error ("{ function f(){}; var f; }");
check_syntax_error ("{ var f; function f(){}; }");
eval("{ { function f(){}; } var f; }")
eval("{ var f; { function f(){}; } }")
check_syntax_error ("{ function f(){}; { var f; } }")
check_syntax_error ("{ { var f; } function f(){}; }")
eval("{ { function f(){}; } { var f; } }")
eval("{ { var f; } { function f(){}; } }")
eval("function g(){ function f(){}; var f; }")
eval("function g(){ var f; function f(){}; }")
eval("function g(){ function f(){}; { var f; } }")
eval("function g(){ { var f; } function f(){}; }")
eval("function g(){ { function f(){}; } var f; }")
eval("function g(){ var f; { function f(){}; } }")

View File

@ -253,9 +253,7 @@
<test id="language/arguments-object/mapped/mapped-arguments-nonconfigurable-strict-delete-2.js"><reason></reason></test>
<test id="language/arguments-object/mapped/mapped-arguments-nonconfigurable-strict-delete-4.js"><reason></reason></test>
<test id="language/asi/S7.9_A5.7_T1.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration-in-block/attempt-to-redeclare-function-declaration-with-function-declaration.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration-in-block/attempt-to-redeclare-function-declaration-with-var.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration-in-block/attempt-to-redeclare-var-with-function-declaration.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration-in-block/attempt-to-redeclare-function-declaration-with-function-declaration.js"><reason>No longer a SyntaxError in ES11</reason></test>
<test id="language/default-parameters/function-length.js"><reason></reason></test>
<test id="language/expressions/arrow-function/lexical-super-call-from-within-constructor.js"><reason></reason></test>
<test id="language/expressions/assignment/destructuring/array-rest-init.js"><reason></reason></test>

View File

@ -4099,38 +4099,18 @@
<test id="language/block-scope/syntax/redeclaration/async-function-name-redeclaration-attempt-with-async-generator.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/async-function-name-redeclaration-attempt-with-function.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/async-function-name-redeclaration-attempt-with-generator.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/async-function-name-redeclaration-attempt-with-var.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/async-generator-name-redeclaration-attempt-with-async-function.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/async-generator-name-redeclaration-attempt-with-async-generator.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/async-generator-name-redeclaration-attempt-with-function.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/async-generator-name-redeclaration-attempt-with-generator.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/async-generator-name-redeclaration-attempt-with-var.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/fn-scope-var-name-redeclaration-attempt-with-async-function.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/fn-scope-var-name-redeclaration-attempt-with-async-generator.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/fn-scope-var-name-redeclaration-attempt-with-function.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/fn-scope-var-name-redeclaration-attempt-with-generator.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/function-name-redeclaration-attempt-with-async-function.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/function-name-redeclaration-attempt-with-async-generator.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/function-name-redeclaration-attempt-with-function.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/function-name-redeclaration-attempt-with-generator.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/function-name-redeclaration-attempt-with-var.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/generator-name-redeclaration-attempt-with-async-function.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/generator-name-redeclaration-attempt-with-async-generator.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/generator-name-redeclaration-attempt-with-function.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/generator-name-redeclaration-attempt-with-generator.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/generator-name-redeclaration-attempt-with-var.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-async-function.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-async-generator.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-function.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-generator.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/var-name-redeclaration-attempt-with-async-function.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/var-name-redeclaration-attempt-with-async-generator.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/var-name-redeclaration-attempt-with-function.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/var-name-redeclaration-attempt-with-generator.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/var-redeclaration-attempt-after-async-function.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/var-redeclaration-attempt-after-async-generator.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/var-redeclaration-attempt-after-function.js"><reason></reason></test>
<test id="language/block-scope/syntax/redeclaration/var-redeclaration-attempt-after-generator.js"><reason></reason></test>
<test id="language/comments/hashbang/eval-indirect.js"><reason></reason></test>
<test id="language/comments/hashbang/eval.js"><reason></reason></test>
<test id="language/comments/hashbang/line-terminator-carriage-return.js"><reason></reason></test>
@ -10417,26 +10397,18 @@
<test id="language/statements/switch/syntax/redeclaration/async-function-name-redeclaration-attempt-with-async-generator.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/async-function-name-redeclaration-attempt-with-function.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/async-function-name-redeclaration-attempt-with-generator.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/async-function-name-redeclaration-attempt-with-var.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/async-generator-name-redeclaration-attempt-with-async-function.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/async-generator-name-redeclaration-attempt-with-async-generator.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/async-generator-name-redeclaration-attempt-with-function.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/async-generator-name-redeclaration-attempt-with-generator.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/async-generator-name-redeclaration-attempt-with-var.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/function-name-redeclaration-attempt-with-async-function.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/function-name-redeclaration-attempt-with-async-generator.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/function-name-redeclaration-attempt-with-function.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/function-name-redeclaration-attempt-with-generator.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/function-name-redeclaration-attempt-with-var.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/generator-name-redeclaration-attempt-with-async-function.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/generator-name-redeclaration-attempt-with-async-generator.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/generator-name-redeclaration-attempt-with-function.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/generator-name-redeclaration-attempt-with-generator.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/generator-name-redeclaration-attempt-with-var.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/var-name-redeclaration-attempt-with-async-function.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/var-name-redeclaration-attempt-with-async-generator.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/var-name-redeclaration-attempt-with-function.js"><reason></reason></test>
<test id="language/statements/switch/syntax/redeclaration/var-name-redeclaration-attempt-with-generator.js"><reason></reason></test>
<test id="language/statements/switch/tco-case-body-dflt.js"><reason></reason></test>
<test id="language/statements/switch/tco-case-body.js"><reason></reason></test>
<test id="language/statements/switch/tco-dftl-body.js"><reason></reason></test>