Implement correct construction of let/const declarations and function statements. (#3259)
Various cbc opcodes are added to support the different instantiations. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
committed by
Dániel Bátyai
parent
1c34539997
commit
1edfa81c76
@@ -29,6 +29,9 @@ check_syntax_error ("var a; let a;");
|
||||
check_syntax_error ("var a; const a = 3;");
|
||||
check_syntax_error ("let a; var a;");
|
||||
check_syntax_error ("const a = 3; var x, y, a;");
|
||||
check_syntax_error ("const a");
|
||||
check_syntax_error ("{ const a }");
|
||||
check_syntax_error ("const a, b");
|
||||
check_syntax_error ("let a; { let b; { var a; } }");
|
||||
check_syntax_error ("{ { var a = 4; } }; let a = 3");
|
||||
check_syntax_error ("function a() {}; let a;");
|
||||
@@ -41,4 +44,4 @@ check_syntax_error ("try {} catch (e) { const e = 1; }");
|
||||
check_syntax_error ("let A; class A {}");
|
||||
check_syntax_error ("const A; class A {}");
|
||||
check_syntax_error ("class A {}; let A");
|
||||
check_syntax_error ("class A {}; const A");
|
||||
check_syntax_error ("class A {}; const A = 1");
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/* 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() {
|
||||
try {
|
||||
a;
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof ReferenceError);
|
||||
}
|
||||
|
||||
eval ("assert (a === undefined); { function a() { return 5; } }");
|
||||
assert (a() === 5);
|
||||
|
||||
/* Variables created by eval can be deleted. */
|
||||
delete a;
|
||||
|
||||
try {
|
||||
a;
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof ReferenceError);
|
||||
}
|
||||
}
|
||||
f();
|
||||
|
||||
function g() {
|
||||
let a = 1;
|
||||
|
||||
eval ("assert (a === 1);"
|
||||
+ "{ function a() { return 2; } assert (a() === 2) }"
|
||||
+ "assert (a === 1);");
|
||||
|
||||
assert (a === 1);
|
||||
}
|
||||
g();
|
||||
@@ -0,0 +1,53 @@
|
||||
// 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() {
|
||||
try {
|
||||
a;
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof ReferenceError);
|
||||
}
|
||||
|
||||
var o = { a:1 };
|
||||
|
||||
with (o)
|
||||
{
|
||||
eval("var a = 2")
|
||||
}
|
||||
|
||||
assert (o.a === 2);
|
||||
assert (a === undefined);
|
||||
}
|
||||
f();
|
||||
|
||||
function g() {
|
||||
try {
|
||||
a;
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof ReferenceError);
|
||||
}
|
||||
|
||||
var o = { a:1 };
|
||||
|
||||
with (o)
|
||||
{
|
||||
eval("function a() { return 8; }")
|
||||
}
|
||||
|
||||
assert (o.a === 1);
|
||||
assert (a() === 8);
|
||||
}
|
||||
g();
|
||||
@@ -223,15 +223,15 @@ main (void)
|
||||
/* Check the snapshot data. Unused bytes should be filled with zeroes */
|
||||
const uint8_t expected_data[] =
|
||||
{
|
||||
0x4A, 0x52, 0x52, 0x59, 0x1A, 0x00, 0x00, 0x00,
|
||||
0x4A, 0x52, 0x52, 0x59, 0x1B, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
|
||||
0x03, 0x00, 0x01, 0x00, 0x21, 0x00, 0x01, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x18, 0x00, 0x00, 0x00,
|
||||
0x2C, 0x00, 0xBC, 0x4A, 0x00, 0x00, 0x00, 0x00,
|
||||
0x2C, 0x00, 0xBF, 0x4D, 0x00, 0x00, 0x00, 0x00,
|
||||
0x03, 0x00, 0x01, 0x00, 0x21, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x01, 0x07, 0x00, 0x00, 0x00,
|
||||
0x4B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x4E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x14, 0x00, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67,
|
||||
0x20, 0x66, 0x72, 0x6F, 0x6D, 0x20, 0x73, 0x6E,
|
||||
0x61, 0x70, 0x73, 0x68, 0x6F, 0x74,
|
||||
|
||||
Reference in New Issue
Block a user