File indexing completed on 2024-04-28 15:28:37
0001 // constant definition 0002 const c = 11; 0003 shouldBe("c", "11"); 0004 0005 // attempt to redefine should have no effect 0006 c = 22; 0007 shouldBe("c", "11"); 0008 0009 const dummy = 0; 0010 for (var v = 0;;) { 0011 ++v; 0012 shouldBe("v", "1"); 0013 break; 0014 } 0015 0016 // local vars & consts 0017 function h () 0018 { 0019 function shouldBe(_a, _b) 0020 { 0021 if (typeof _a != "string" || typeof _b != "string") 0022 debug("WARN: shouldBe() expects string arguments"); 0023 var _av, _bv; 0024 try { 0025 _av = eval(_a); 0026 } catch (e) { 0027 _av = evalError(_a, e); 0028 } 0029 try { 0030 _bv = eval(_b); 0031 } catch (e) { 0032 _bv = evalError(_b, e); 0033 } 0034 0035 if (_av === _bv) 0036 testPassed(_a + " is " + _b); 0037 else 0038 testFailed(_a + " should be " + _bv + ". Was " + _av); 0039 } 0040 0041 var hvar = 1; 0042 const hconst = 1; 0043 shouldBe("hvar", "1"); 0044 shouldBe("hconst", "1"); 0045 0046 hvar = 2; 0047 hconst = 2; 0048 shouldBe("hvar", "2"); 0049 shouldBe("hconst", "1"); 0050 0051 ++hvar; 0052 ++hconst; 0053 shouldBe("hvar", "3"); 0054 shouldBe("hconst", "1"); 0055 0056 shouldBe("(hvar = 4)", "4"); 0057 shouldBe("(hconst = 4)", "4"); 0058 0059 shouldBe("hvar", "4"); 0060 shouldBe("hconst", "1"); 0061 } 0062 0063 h(); 0064 h(); 0065 0066 // ### check for forbidden redeclaration