1 /* The contents of this file are subject to the Netscape Public 2 * License Version 1.1 (the "License"); you may not use this file 3 * except in compliance with the License. You may obtain a copy of 4 * the License at http://www.mozilla.org/NPL/ 5 * 6 * Software distributed under the License is distributed on an "AS 7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 8 * implied. See the License for the specific language governing 9 * rights and limitations under the License. 10 * 11 * The Original Code is Mozilla Communicator client code, released March 12 * 31, 1998. 13 * 14 * The Initial Developer of the Original Code is Netscape Communications 15 * Corporation. Portions created by Netscape are 16 * Copyright (C) 1998 Netscape Communications Corporation. All 17 * Rights Reserved. 18 * 19 * Contributor(s): 20 * 21 */ 22 /** 23 File Name: 11.4.1.js 24 ECMA Section: 11.4.1 the Delete Operator 25 Description: returns true if the property could be deleted 26 returns false if it could not be deleted 27 Author: christine (at) netscape.com 28 Date: 7 july 1997 29 30 */ 31 32 33 var SECTION = "11.4.1"; 34 var VERSION = "ECMA_1"; 35 startTest(); 36 var TITLE = "The delete operator"; 37 38 writeHeaderToLog( SECTION + " "+ TITLE); 39 40 var testcases = getTestCases(); 41 42 test(); 43 44 function getTestCases() { 45 var array = new Array(); 46 var item = 0; 47 48 // array[item++] = new TestCase( SECTION, "x=[9,8,7];delete(x[2]);x.length", 2, eval("x=[9,8,7];delete(x[2]);x.length") ); 49 // array[item++] = new TestCase( SECTION, "x=[9,8,7];delete(x[2]);x.toString()", "9,8", eval("x=[9,8,7];delete(x[2]);x.toString()") ); 50 array[item++] = new TestCase( SECTION, "x=new Date();delete x;typeof(x)", "undefined", eval("x=new Date();delete x;typeof(x)") ); 51 52 // array[item++] = new TestCase( SECTION, "delete(x=new Date())", true, delete(x=new Date()) ); 53 // array[item++] = new TestCase( SECTION, "delete('string primitive')", true, delete("string primitive") ); 54 // array[item++] = new TestCase( SECTION, "delete(new String( 'string object' ) )", true, delete(new String("string object")) ); 55 // array[item++] = new TestCase( SECTION, "delete(new Number(12345) )", true, delete(new Number(12345)) ); 56 array[item++] = new TestCase( SECTION, "delete(Math.PI)", false, delete(Math.PI) ); 57 // array[item++] = new TestCase( SECTION, "delete(null)", true, delete(null) ); 58 // array[item++] = new TestCase( SECTION, "delete(void(0))", true, delete(void(0)) ); 59 60 // variables declared with the var statement are not deletable. 61 62 var abc; 63 array[item++] = new TestCase( SECTION, "var abc; delete(abc)", false, delete abc ); 64 65 array[item++] = new TestCase( SECTION, 66 "var OB = new MyObject(); for ( p in OB ) { delete p }", 67 true, 68 eval("var OB = new MyObject(); for ( p in OB ) { delete p }") ); 69 return ( array ); 70 } 71 72 function test() { 73 for ( tc = 0; tc < testcases.length; tc++ ) { 74 testcases[tc].passed = writeTestCaseResult( 75 testcases[tc].expect, 76 testcases[tc].actual, 77 testcases[tc].description +" = "+ testcases[tc].actual ); 78 79 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value " 80 81 } 82 stopTest(); 83 return ( testcases ); 84 } 85 86 function MyObject() { 87 this.prop1 = true; 88 this.prop2 = false; 89 this.prop3 = null 90 this.prop4 = void 0; 91 this.prop5 = "hi"; 92 this.prop6 = 42; 93 this.prop7 = new Date(); 94 this.prop8 = Math.PI; 95 }