Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma_5 / extensions / nested-delete-name-in-evalcode.js
1 // Any copyright is dedicated to the Public Domain.
2 // http://creativecommons.org/licenses/publicdomain/
3
4 //-----------------------------------------------------------------------------
5 var BUGNUMBER = 616294;
6 var summary =
7   "|delete x| inside a function in eval code, where that eval code includes " +
8   "|var x| at top level, actually does delete the binding for x";
9
10 print(BUGNUMBER + ": " + summary);
11
12 /**************
13  * BEGIN TEST *
14  **************/
15
16 var f;
17
18 function testOuterLet()
19 {
20   return eval("let x; (function() { return delete x; })");
21 }
22
23 f = testOuterLet();
24
25 assertEq(f(), true); // configurable, so remove => true
26 assertEq(f(), true); // not there => true (only non-configurable => false)
27
28
29 function testOuterForLet()
30 {
31   return eval("for (let x; false; ); (function() { return delete x; })");
32 }
33
34 f = testOuterForLet();
35
36 assertEq(f(), true); // not there => true (only non-configurable => false)
37
38
39 function testOuterForInLet()
40 {
41   return eval("for (let x in {}); (function() { return delete x; })");
42 }
43
44 f = testOuterForInLet();
45
46 assertEq(f(), true); // configurable, so remove => true
47 assertEq(f(), true); // not there => true (only non-configurable => false)
48
49
50 function testOuterNestedVarInLetBlock()
51 {
52   return eval("let (x = 7) { var x = 9; } (function() { return delete x; })");
53 }
54
55 f = testOuterNestedVarInLetBlock();
56
57 assertEq(f(), true); // configurable var, so remove => true
58 assertEq(f(), true); // let still there, configurable => true
59 assertEq(f(), true); // nothing at all => true
60
61
62 function testOuterNestedVarInForLet()
63 {
64   return eval("for (let q = 0; q < 5; q++) { var x; } (function() { return delete x; })");
65 }
66
67 f = testOuterNestedVarInForLet();
68
69 assertEq(f(), true); // configurable, so remove => true
70 assertEq(f(), true); // there => true
71
72
73 function testArgumentShadowLet()
74 {
75   return eval("let x; (function(x) { return delete x; })");
76 }
77
78 f = testArgumentShadowLet();
79
80 assertEq(f(), false); // non-configurable argument => false
81
82
83 function testFunctionLocal()
84 {
85   return eval("(function() { let x; return delete x; })");
86 }
87
88 f = testFunctionLocal();
89
90 assertEq(f(), false); // defined by function code => not configurable => false
91
92
93 /******************************************************************************/
94
95 if (typeof reportCompare === "function")
96   reportCompare(true, true);
97
98 print("All tests passed!");