Fix local scoping for functions. (#3559)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2020-02-18 09:49:03 +01:00
committed by GitHub
parent 44e63e038d
commit fda02d4b2a
18 changed files with 366 additions and 288 deletions
+54
View File
@@ -0,0 +1,54 @@
// 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 f() { return 4 }
exit: {
assert(f() === 6);
break exit;
function f() { return 6; }
}
assert(f() === 4);
{
assert(f() === 6);
f = 1;
assert(f === 1);
function f() { return 6; }
f = 2;
assert(f === 2);
}
assert(f === 1);
function g() { return 3 }
exit: {
assert(g() === 5);
function g() { return 4; }
break exit;
function g() { return 5; }
}
assert(g() === 5);
function h() {
try {
x;
assert(false);
} catch (e) {
assert(e instanceof ReferenceError);
}
eval("exit: { assert(x() === 8); x = 4; break exit; function x() { return 8; } }");
assert(x === undefined);
}
h();
+25 -6
View File
@@ -16,21 +16,19 @@
var g = -1;
function f1() {
/* Function hoisted as var. */
/* Function copied to var. */
assert (g === undefined);
{
assert (g() === 1);
function g() { return 1 };
{
assert (g() === 2);
function g() { return 2 };
}
function g() { return 1 };
assert (g() === 2);
assert (g() === 1);
}
assert (g() === 2);
@@ -38,6 +36,27 @@ function f1() {
f1();
function f2() {
/* Function is not copied to var. */
'use strict'
assert (g === -1);
{
assert (g() === 1);
function g() { return 1 };
{
assert (g() === 2);
function g() { return 2 };
}
assert (g() === 1);
}
assert (g === -1);
}
f2();
function f3() {
/* Function hoisted as let. */
assert (g === -1);
@@ -65,4 +84,4 @@ function f2() {
assert (g === -1);
}
f2();
f3();
+25 -6
View File
@@ -16,21 +16,19 @@
var g = -1;
function f1() {
/* Function hoisted as var. */
/* Function copied to var. */
assert (g === undefined);
{
assert (g() === 1);
function g() { return 1 };
{
eval("assert (g() === 2)");
function g() { return 2 };
}
function g() { return 1 };
assert (g() === 2);
assert (g() === 1);
}
assert (g() === 2);
@@ -38,6 +36,27 @@ function f1() {
f1();
function f2() {
/* Function is not copied to var. */
'use strict'
assert (g === -1);
{
assert (g() === 1);
function g() { return 1 };
{
eval("assert (g() === 2)");
function g() { return 2 };
}
assert (g() === 1);
}
assert (g === -1);
}
f2();
function f3() {
/* Function hoisted as let. */
assert (g === -1);
@@ -65,4 +84,4 @@ function f2() {
assert (g === -1);
}
f2();
f3();
+18 -2
View File
@@ -51,12 +51,28 @@ default:
assert (f() === 8);
switch (g()) {
case g() * 2:
case g() + 5:
{
let g = 4;
assert (g == 4);
}
break;
default:
/* If the declaration is not "executed", it has no effect */
function g() { return 1; }
assert (false);
}
assert (g() === 6);
switch (g()) {
case g() * 2:
{
let g = 4;
assert (g == 4);
eval();
}
function g() { return 3; }
break;
+2 -2
View File
@@ -223,12 +223,12 @@ main (void)
/* Check the snapshot data. Unused bytes should be filled with zeroes */
const uint8_t expected_data[] =
{
0x4A, 0x52, 0x52, 0x59, 0x25, 0x00, 0x00, 0x00,
0x4A, 0x52, 0x52, 0x59, 0x26, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
0x03, 0x00, 0x01, 0x00, 0x41, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x01, 0x18, 0x00, 0x00, 0x00,
0x2C, 0x00, 0xC0, 0x4E, 0x00, 0x00, 0x00, 0x00,
0x2C, 0x00, 0xC1, 0x4E, 0x00, 0x00, 0x00, 0x00,
0x03, 0x00, 0x01, 0x00, 0x41, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x01, 0x07, 0x00, 0x00, 0x00,
0x4F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,