michael@0: // Any copyright is dedicated to the Public Domain. michael@0: // http://creativecommons.org/licenses/publicdomain/ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 616294; michael@0: var summary = michael@0: "|delete x| inside a function in eval code, where that eval code includes " + michael@0: "|var x| at top level, actually does delete the binding for x"; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: var f; michael@0: michael@0: function testOuterVar() michael@0: { michael@0: return eval("var x; (function() { return delete x; })"); michael@0: } michael@0: michael@0: f = testOuterVar(); michael@0: michael@0: assertEq(f(), true); // configurable, so remove => true michael@0: assertEq(f(), true); // not there => true (only non-configurable => false) michael@0: michael@0: michael@0: function testOuterFunction() michael@0: { michael@0: return eval("function x() { } (function() { return delete x; })"); michael@0: } michael@0: michael@0: f = testOuterFunction(); michael@0: michael@0: assertEq(f(), true); // configurable, so remove => true michael@0: assertEq(f(), true); // not there => true (only non-configurable => false) michael@0: michael@0: michael@0: function testOuterForVar() michael@0: { michael@0: return eval("for (var x; false; ); (function() { return delete x; })"); michael@0: } michael@0: michael@0: f = testOuterForVar(); michael@0: michael@0: assertEq(f(), true); // configurable, so remove => true michael@0: assertEq(f(), true); // not there => true (only non-configurable => false) michael@0: michael@0: michael@0: function testOuterForInVar() michael@0: { michael@0: return eval("for (var x in {}); (function() { return delete x; })"); michael@0: } michael@0: michael@0: f = testOuterForInVar(); michael@0: michael@0: assertEq(f(), true); // configurable, so remove => true michael@0: assertEq(f(), true); // not there => true (only non-configurable => false) michael@0: michael@0: michael@0: function testOuterNestedVar() michael@0: { michael@0: return eval("for (var q = 0; q < 5; q++) { var x; } (function() { return delete x; })"); michael@0: } michael@0: michael@0: f = testOuterNestedVar(); michael@0: michael@0: assertEq(f(), true); // configurable, so remove => true michael@0: assertEq(f(), true); // not there => true (only non-configurable => false) michael@0: michael@0: michael@0: function testOuterNestedConditionalVar() michael@0: { michael@0: return eval("for (var q = 0; q < 5; q++) { if (false) { var x; } } (function() { return delete x; })"); michael@0: } michael@0: michael@0: f = testOuterNestedConditionalVar(); michael@0: michael@0: assertEq(f(), true); // configurable, so remove => true michael@0: assertEq(f(), true); // not there => true (only non-configurable => false) michael@0: michael@0: michael@0: function testVarInWith() michael@0: { michael@0: return eval("with ({}) { var x; } (function() { return delete x; })"); michael@0: } michael@0: michael@0: f = testVarInWith(); michael@0: michael@0: assertEq(f(), true); // configurable, so remove => true michael@0: assertEq(f(), true); // not there => true (only non-configurable => false) michael@0: michael@0: michael@0: function testForVarInWith() michael@0: { michael@0: return eval("with ({}) { for (var x = 0; x < 5; x++); } (function() { return delete x; })"); michael@0: } michael@0: michael@0: f = testForVarInWith(); michael@0: michael@0: assertEq(f(), true); // configurable, so remove => true michael@0: assertEq(f(), true); // not there => true (only non-configurable => false) michael@0: michael@0: michael@0: function testForInVarInWith() michael@0: { michael@0: return eval("with ({}) { for (var x in {}); } (function() { return delete x; })"); michael@0: } michael@0: michael@0: f = testForInVarInWith(); michael@0: michael@0: assertEq(f(), true); // configurable, so remove => true michael@0: assertEq(f(), true); // not there => true (only non-configurable => false) michael@0: michael@0: michael@0: function testUnknown() michael@0: { michael@0: return eval("nameToDelete = 17; (function() { return delete nameToDelete; })"); michael@0: } michael@0: michael@0: f = testUnknown(); michael@0: michael@0: assertEq(f(), true); // configurable global property, so remove => true michael@0: assertEq(f(), true); // not there => true (only non-configurable => false) michael@0: michael@0: michael@0: function testArgumentShadow() michael@0: { michael@0: return eval("var x; (function(x) { return delete x; })"); michael@0: } michael@0: michael@0: f = testArgumentShadow(); michael@0: michael@0: assertEq(f(), false); // non-configurable argument => false michael@0: michael@0: michael@0: function testArgument() michael@0: { michael@0: return eval("(function(x) { return delete x; })"); michael@0: } michael@0: michael@0: f = testArgument(); michael@0: michael@0: assertEq(f(), false); // non-configurable argument => false michael@0: michael@0: michael@0: function testFunctionLocal() michael@0: { michael@0: return eval("(function() { var x; return delete x; })"); michael@0: } michael@0: michael@0: f = testFunctionLocal(); michael@0: michael@0: assertEq(f(), false); // defined by function code => not configurable => false michael@0: michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("All tests passed!");