michael@0: // Copyright 2009 the Sputnik authors. All rights reserved. michael@0: // This code is governed by the BSD license found in the LICENSE file. michael@0: michael@0: /** michael@0: * The with statement adds a computed object to the front of the michael@0: * scope chain of the current execution context michael@0: * michael@0: * @path ch12/12.10/S12.10_A1.2_T5.js michael@0: * @description Calling a function without "with" statement when the statement itself is declared within the function declaration, leading to completion by exception michael@0: * @noStrict michael@0: */ michael@0: michael@0: this.p1 = 1; michael@0: this.p2 = 2; michael@0: this.p3 = 3; michael@0: var result = "result"; michael@0: var myObj = {p1: 'a', michael@0: p2: 'b', michael@0: p3: 'c', michael@0: value: 'myObj_value', michael@0: valueOf : function(){return 'obj_valueOf';}, michael@0: parseInt : function(){return 'obj_parseInt';}, michael@0: NaN : 'obj_NaN', michael@0: Infinity : 'obj_Infinity', michael@0: eval : function(){return 'obj_eval';}, michael@0: parseFloat : function(){return 'obj_parseFloat';}, michael@0: isNaN : function(){return 'obj_isNaN';}, michael@0: isFinite : function(){return 'obj_isFinite';} michael@0: } michael@0: var del; michael@0: var st_p1 = "p1"; michael@0: var st_p2 = "p2"; michael@0: var st_p3 = "p3"; michael@0: var st_parseInt = "parseInt"; michael@0: var st_NaN = "NaN"; michael@0: var st_Infinity = "Infinity"; michael@0: var st_eval = "eval"; michael@0: var st_parseFloat = "parseFloat"; michael@0: var st_isNaN = "isNaN"; michael@0: var st_isFinite = "isFinite"; michael@0: michael@0: try { michael@0: var f = function(){ michael@0: with(myObj){ michael@0: throw value; michael@0: st_p1 = p1; michael@0: st_p2 = p2; michael@0: st_p3 = p3; michael@0: st_parseInt = parseInt; michael@0: st_NaN = NaN; michael@0: st_Infinity = Infinity; michael@0: st_eval = eval; michael@0: st_parseFloat = parseFloat; michael@0: st_isNaN = isNaN; michael@0: st_isFinite = isFinite; michael@0: p1 = 'x1'; michael@0: this.p2 = 'x2'; michael@0: del = delete p3; michael@0: var p4 = 'x4'; michael@0: p5 = 'x5'; michael@0: var value = 'value'; michael@0: } michael@0: } michael@0: f(); michael@0: } catch(e){ michael@0: result = e; michael@0: } michael@0: michael@0: if(!(result === "myObj_value")){ michael@0: $ERROR('#0: result === "myObj_value". Actual: result ==='+ result ); michael@0: } michael@0: michael@0: if(!(p2 === 2)){ michael@0: $ERROR('#2: p2 === 2. Actual: p2 ==='+ p2 ); michael@0: } michael@0: michael@0: if(!(p3 === 3)){ michael@0: $ERROR('#3: p3 === 3. Actual: p3 ==='+ p3 ); michael@0: } michael@0: michael@0: try { michael@0: p4; michael@0: $ERROR('#4: p4 is not defined'); michael@0: } catch(e) { michael@0: } michael@0: michael@0: try { michael@0: p5; michael@0: $ERROR('#5: p5 is not defined'); michael@0: } catch(e) { michael@0: } michael@0: michael@0: if(!(myObj.p1 === "a")){ michael@0: $ERROR('#6: myObj.p1 === "a". Actual: myObj.p1 ==='+ myObj.p1 ); michael@0: } michael@0: michael@0: if(!(myObj.p2 === "b")){ michael@0: $ERROR('#7: myObj.p2 === "b". Actual: myObj.p2 ==='+ myObj.p2 ); michael@0: } michael@0: michael@0: if(!(myObj.p3 === "c")){ michael@0: $ERROR('#8: myObj.p3 === "c". Actual: myObj.p3 ==='+ myObj.p3 ); michael@0: } michael@0: michael@0: if(!(myObj.p4 === undefined)){ michael@0: $ERROR('#9: myObj.p4 === undefined. Actual: myObj.p4 ==='+ myObj.p4 ); michael@0: } michael@0: michael@0: if(!(myObj.p5 === undefined)){ michael@0: $ERROR('#10: myObj.p5 === undefined. Actual: myObj.p5 ==='+ myObj.p5 ); michael@0: } michael@0: michael@0: if(!(st_parseInt === "parseInt")){ michael@0: $ERROR('#11: myObj.parseInt === "parseInt". Actual: myObj.parseInt ==='+ myObj.parseInt ); michael@0: } michael@0: michael@0: if(!(st_NaN === "NaN")){ michael@0: $ERROR('#12: st_NaN === "NaN". Actual: st_NaN ==='+ st_NaN ); michael@0: } michael@0: michael@0: if(!(st_Infinity === "Infinity")){ michael@0: $ERROR('#13: st_Infinity === "Infinity". Actual: st_Infinity ==='+ st_Infinity ); michael@0: } michael@0: michael@0: if(!(st_eval === "eval")){ michael@0: $ERROR('#14: st_eval === "eval". Actual: st_eval ==='+ st_eval ); michael@0: } michael@0: michael@0: if(!(st_parseFloat === "parseFloat")){ michael@0: $ERROR('#15: st_parseFloat === "parseFloat". Actual: st_parseFloat ==='+ st_parseFloat ); michael@0: } michael@0: michael@0: if(!(st_isNaN === "isNaN")){ michael@0: $ERROR('#16: st_isNaN === "isNaN". Actual: st_isNaN ==='+ st_isNaN ); michael@0: } michael@0: michael@0: if(!(st_isFinite === "isFinite")){ michael@0: $ERROR('#17: st_isFinite === "isFinite". Actual: st_isFinite ==='+ st_isFinite ); michael@0: } michael@0: michael@0: try{ michael@0: value; michael@0: $ERROR('#18: value is not defined'); michael@0: } michael@0: catch(e){ michael@0: } michael@0: michael@0: if(!(myObj.value === "myObj_value")){ michael@0: $ERROR('#19: myObj.value === "myObj_value". Actual: myObj.value ==='+ myObj.value ); michael@0: } michael@0: