| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- // ES6 block-scoping with closures, switches
- var x = 'global x';
- function write(x) { WScript.Echo(x); }
- (function() {
- try {
- inner();
- }
- catch(e) {
- write(e);
- }
- let x = 'local x';
- try {
- inner();
- }
- catch(e) {
- write(e);
- }
- function inner() {
- write(x);
- }
- })();
- (function() {
- while(1) {
- try {
- LABEL0:
- switch(x) {
- case 0:
- let x = 'local x';
- // fall through
- default:
- function inner() {
- write(x);
- }
- inner();
- // Should only get here after executing case 0.
- return;
- case 'seriously?':
- break LABEL0;
- }
- }
- catch(e) {
- write(e);
- // Should assign to global x.
- x = 0;
- }
- }
- })();
- try {
- (function() {
- if (typeof a === 'string') {
- write('a is a string');
- }
- let a = 'let a';
- })();
- } catch (e) {
- write(e);
- }
- try {
- (function() {
- let a = 'let a';
- if (typeof a === 'string') {
- write('a is a string');
- }
- })();
- } catch (e) {
- write(e);
- }
- try {
- (function () {
- if (delete a) {
- write("deleted a");
- } else {
- write("did not delete a");
- }
- let a = 'let a';
- })();
- } catch (e) {
- write(e);
- }
- try {
- (function () {
- let a = 'let a';
- if (delete a) {
- write("deleted a");
- } else {
- write("did not delete a");
- }
- })();
- } catch (e) {
- write(e);
- }
- try {
- try {
- write(eval('typeof t'));
- }
- catch(e) {
- write(e);
- }
- (function() {
- write(eval('typeof t'));
- })();
- }
- catch(e) {
- write(e);
- }
- let t;
- write(eval('typeof t'));
- (function () {
- try {
- let foo = eval('foo();');
- } catch (e) {
- write(e);
- }
- try {
- const foo = eval('foo();');
- } catch (e) {
- write(e);
- }
- try {
- eval('foo();');
- let foo = 123;
- } catch (e) {
- write(e);
- }
- try {
- eval('foo();');
- const foo = 123;
- } catch (e) {
- write(e);
- }
- })();
- (function () {
- try {
- eval('let a = a;');
- } catch (e) {
- write(e);
- }
- try {
- eval('const a = a;');
- } catch (e) {
- write(e);
- }
- try {
- // this works in a try/catch because Use Before Declaration is always a runtime error by the spec
- let a = a;
- } catch (e) {
- write(e);
- }
- try {
- // this works in a try/catch because Use Before Declaration is always a runtime error by the spec
- const a = a;
- } catch (e) {
- write(e);
- }
- })();
- (function () {
- try {
- eval('a() = 123; let a;');
- } catch (e) {
- write(e);
- }
- try {
- eval('a() = 123; const a = undefined;');
- } catch (e) {
- write(e);
- }
- })();
- try {
- write(delete glo_a);
- } catch (e) {
- write(e);
- }
- try {
- write(typeof glo_a);
- } catch (e) {
- write(e);
- }
- let glo_a = 'glo_a';
- try {
- write(delete glo_a);
- } catch (e) {
- write(e);
- }
- try {
- write(typeof glo_a);
- } catch (e) {
- write(e);
- }
- try {
- write(delete glo_b);
- } catch (e) {
- write(e);
- }
- try {
- write(typeof glo_b);
- } catch (e) {
- write(e);
- }
- const glo_b = 'glo_b';
- try {
- write(delete glo_b);
- } catch (e) {
- write(e);
- }
- try {
- write(typeof glo_b);
- } catch (e) {
- write(e);
- }
- //BLUE 404930
- try {
- switch (Math.round(.2)) {
- case 3:
- let x = eval("");
- default:
- x; // should emit a use-before-decl runtime error
- }
- } catch (e) {
- write(e);
- }
- // BLUE 404930 (bug reused, different from above)
- function testStSlotNoThrow() { let y = function () { write(y = 123); }; write(y); y(); write(y); }
- function testStSlotThrow() { let y = (function () { write(y = 123); })(); write(y); }
- function testStObjSlotNoThrow() { let y = function () { write(y = 123); }; write(y); y(); write(y); eval('y'); }
- function testStObjSlotThrow() { let y = (function () { write(y = 123); })(); write(y); eval('y'); }
- function testTypeOfNoThrow() { let y = function () { write(typeof y); }; y(); }
- function testTypeOfThrow() { let y = (function () { write(typeof y); })(); }
- function testTypeOfObjNoThrow() { let y = function () { write(typeof y); }; y(); eval('y'); }
- function testTypeOfObjThrow() { let y = (function () { write(typeof y); })(); eval('y'); }
- function testLdSlotNoThrow() { let y = function () { write(y); }; y(); }
- function testLdSlotThrow() { let y = (function () { write(y); })(); }
- function testLdObjSlotNoThrow() { let y = function () { write(y); }; y(); eval('y'); }
- function testLdObjSlotThrow() { let y = (function () { write(y); })(); eval('y'); }
- try { testStSlotNoThrow(); } catch (e) { write("shouldn't throw! " + e); }
- try { testStSlotThrow(); } catch (e) { write(e); }
- try { testStObjSlotNoThrow(); } catch (e) { write("shouldn't throw! " + e); }
- try { testStObjSlotThrow(); } catch (e) { write(e); }
- try { testTypeOfNoThrow(); } catch (e) { write("shouldn't throw! " + e); }
- try { testTypeOfThrow(); } catch (e) { write(e); }
- try { testTypeOfObjNoThrow(); } catch (e) { write("shouldn't throw! " + e); }
- try { testTypeOfObjThrow(); } catch (e) { write(e); }
- try { testLdSlotNoThrow(); } catch (e) { write("shouldn't throw! " + e); }
- try { testLdSlotThrow(); } catch (e) { write(e); }
- try { testLdObjSlotNoThrow(); } catch (e) { write("shouldn't throw! " + e); }
- try { testLdObjSlotThrow(); } catch (e) { write(e); }
- function testBugVsoOs849056() {
- let x; // this x should get a scope slot
- function inner() {
- y = x; // should throw use before declaration
- let y;
- }
- inner();
- }
- try { testBugVsoOs849056(); } catch (e) { write(e); }
- function testBugVsoOs1141661() {
- y = 5;
- let y;
- eval("write('This should be unreachable');");
- }
- try { testBugVsoOs1141661(); } catch (e) { write(e); }
|