|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * Verify correct handling of with statement with nested direct eval. |
| 10 | + */ |
| 11 | + |
| 12 | +load("assert.js"); |
| 13 | + |
| 14 | +var res; |
| 15 | +var expected = 42; |
| 16 | +var chk = function chk() { assertSame(expected, res); res = undefined; }; |
| 17 | + |
| 18 | +var b = [42]; |
| 19 | +with({}) { for(let w of eval("var a = b; a")) res = w; } chk(); |
| 20 | +with({}) { for(let w of eval("b;")) res = w; } chk(); |
| 21 | +b = 42; |
| 22 | +with({}) { let w = eval("var a = b"); res = a; } chk(); |
| 23 | +with([1]) { let w = eval("var a = b"); res = a; } chk(); |
| 24 | +var t={}; with(t) { let w = eval("var b = a"); res = b; } chk(); |
| 25 | +with("abc") { let w = eval("var b = a"); res = b; } chk(); |
| 26 | +with("") { let w = eval("b"); res = w; } chk(); |
| 27 | + |
| 28 | +expected = 43; |
| 29 | + |
| 30 | +var wee = {b: [43]}; |
| 31 | +with(wee) { with({}) { for(let w of eval("var a = b; a")) { res = w; } } } chk(); |
| 32 | +with(wee) { with({}) { for(let w of eval("b;")) { res = w; } } } chk(); |
| 33 | +wee.b = 43; |
| 34 | +with(wee) { with({}) { let w = eval("var a = b"); res = a; } } chk(); |
| 35 | +expected = 42; |
| 36 | +with([1]) { with({}) { let w = eval("var a = b"); res = a; } } chk(); |
| 37 | +var t={}; with(t) { with({}) { let w = eval("var b = a"); res = b; } } chk(); |
| 38 | +with("abc") { with({}) { let w = eval("var b = a"); res = b; } } chk(); |
| 39 | +with("") { with({}) { let w = eval("b"); res = w; } } chk(); |
| 40 | + |
| 41 | +expected = 43; |
| 42 | + |
| 43 | +var wee = {b: [43]}; |
| 44 | +with(wee) { with({}) { for(let w of eval("'use strict'; var a = b; a")) { res = w; } } } chk(); |
| 45 | +with(wee) { with({}) { for(let w of eval("'use strict'; b;")) { res = w; } } } chk(); |
| 46 | +wee.b = 43; |
| 47 | +with(wee) { with({}) { let w = eval("'use strict'; b"); res = w; } } chk(); |
0 commit comments