| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 // Copyright 2009 the V8 project authors. All rights reserved. |  | 
| 2 // Redistribution and use in source and binary forms, with or without |  | 
| 3 // modification, are permitted provided that the following conditions are |  | 
| 4 // met: |  | 
| 5 // |  | 
| 6 //     * Redistributions of source code must retain the above copyright |  | 
| 7 //       notice, this list of conditions and the following disclaimer. |  | 
| 8 //     * Redistributions in binary form must reproduce the above |  | 
| 9 //       copyright notice, this list of conditions and the following |  | 
| 10 //       disclaimer in the documentation and/or other materials provided |  | 
| 11 //       with the distribution. |  | 
| 12 //     * Neither the name of Google Inc. nor the names of its |  | 
| 13 //       contributors may be used to endorse or promote products derived |  | 
| 14 //       from this software without specific prior written permission. |  | 
| 15 // |  | 
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |  | 
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |  | 
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |  | 
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |  | 
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |  | 
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |  | 
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |  | 
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |  | 
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |  | 
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |  | 
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |  | 
| 27 |  | 
| 28 // Test that we match JSC in making some functions undeletable. |  | 
| 29 // See http://code.google.com/p/chromium/issues/detail?id=1717 |  | 
| 30 |  | 
| 31 var array; |  | 
| 32 |  | 
| 33 array = [ |  | 
| 34   "toString", "toLocaleString", "join", "pop", "push", "concat", "reverse", |  | 
| 35   "shift", "unshift", "slice", "splice", "sort", "filter", "forEach", "some", |  | 
| 36   "every", "map", "indexOf", "lastIndexOf", "reduce", "reduceRight"]; |  | 
| 37 CheckJSCSemantics(Array.prototype, array, "Array prototype"); |  | 
| 38 |  | 
| 39 array = [ |  | 
| 40   "toString", "toDateString", "toTimeString", "toLocaleString", |  | 
| 41   "toLocaleDateString", "toLocaleTimeString", "valueOf", "getTime", |  | 
| 42   "getFullYear", "getUTCFullYear", "getMonth", "getUTCMonth", "getDate", |  | 
| 43   "getUTCDate", "getDay", "getUTCDay", "getHours", "getUTCHours", "getMinutes", |  | 
| 44   "getUTCMinutes", "getSeconds", "getUTCSeconds", "getMilliseconds", |  | 
| 45   "getUTCMilliseconds", "getTimezoneOffset", "setTime", "setMilliseconds", |  | 
| 46   "setUTCMilliseconds", "setSeconds", "setUTCSeconds", "setMinutes", |  | 
| 47   "setUTCMinutes", "setHours", "setUTCHours", "setDate", "setUTCDate", |  | 
| 48   "setMonth", "setUTCMonth", "setFullYear", "setUTCFullYear", "toGMTString", |  | 
| 49   "toUTCString", "getYear", "setYear", "toISOString", "toJSON"]; |  | 
| 50 CheckJSCSemantics(Date.prototype, array, "Date prototype"); |  | 
| 51 |  | 
| 52 array = [ |  | 
| 53   "random", "abs", "acos", "asin", "atan", "ceil", "cos", "exp", "floor", "log", |  | 
| 54   "round", "sin", "sqrt", "tan", "atan2", "pow", "max", "min"]; |  | 
| 55 CheckJSCSemantics(Math, array, "Math1"); |  | 
| 56 |  | 
| 57 CheckEcmaSemantics(Date, ["UTC", "parse", "now"], "Date"); |  | 
| 58 |  | 
| 59 array = [ |  | 
| 60   "E", "LN10", "LN2", "LOG2E", "LOG10E", "PI", "SQRT1_2", "SQRT2"]; |  | 
| 61 CheckDontDelete(Math, array, "Math2"); |  | 
| 62 |  | 
| 63 array = [ |  | 
| 64   "escape", "unescape", "decodeURI", "decodeURIComponent", "encodeURI", |  | 
| 65   "encodeURIComponent", "isNaN", "isFinite", "parseInt", "parseFloat", "eval", |  | 
| 66   "execScript"]; |  | 
| 67 CheckEcmaSemantics(this, array, "Global"); |  | 
| 68 CheckReadOnlyAttr(this, "Infinity"); |  | 
| 69 |  | 
| 70 array = ["exec", "test", "toString", "compile"]; |  | 
| 71 CheckEcmaSemantics(RegExp.prototype, array, "RegExp prototype"); |  | 
| 72 |  | 
| 73 array = [ |  | 
| 74   "toString", "toLocaleString", "valueOf", |  | 
| 75   //"hasOwnProperty", |  | 
| 76   "isPrototypeOf", "propertyIsEnumerable", "__defineGetter__", |  | 
| 77   "__lookupGetter__", "__defineSetter__", "__lookupSetter__"]; |  | 
| 78 CheckEcmaSemantics(Object.prototype, array, "Object prototype"); |  | 
| 79 |  | 
| 80 array = [ |  | 
| 81   "toString", "valueOf", "toJSON"]; |  | 
| 82 CheckEcmaSemantics(Boolean.prototype, array, "Boolean prototype"); |  | 
| 83 |  | 
| 84 array = [ |  | 
| 85   "toString", "toLocaleString", "valueOf", "toFixed", "toExponential", |  | 
| 86   "toPrecision", "toJSON"]; |  | 
| 87 CheckEcmaSemantics(Number.prototype, array, "Number prototype"); |  | 
| 88 |  | 
| 89 CheckEcmaSemantics(Function.prototype, ["toString"], "Function prototype"); |  | 
| 90 |  | 
| 91 array = [ |  | 
| 92   "charAt", "charCodeAt", "concat", "indexOf", |  | 
| 93   "lastIndexOf", "localeCompare", "match", "replace", "search", "slice", |  | 
| 94   "split", "substring", "substr", "toLowerCase", "toLocaleLowerCase", |  | 
| 95   "toUpperCase", "toLocaleUpperCase", "link", "anchor", "fontcolor", "fontsize", |  | 
| 96   "big", "blink", "bold", "fixed", "italics", "small", "strike", "sub", "sup", |  | 
| 97   "toJSON", "toString", "valueOf"]; |  | 
| 98 CheckJSCSemantics(String.prototype, array, "String prototype"); |  | 
| 99 CheckEcmaSemantics(String, ["fromCharCode"], "String"); |  | 
| 100 |  | 
| 101 |  | 
| 102 function CheckEcmaSemantics(type, props, name) { |  | 
| 103   print(name); |  | 
| 104   for (var i = 0; i < props.length; i++) { |  | 
| 105     CheckDeletable(type, props[i]); |  | 
| 106   } |  | 
| 107 } |  | 
| 108 |  | 
| 109 |  | 
| 110 function CheckJSCSemantics(type, props, name) { |  | 
| 111   print(name); |  | 
| 112   for (var i = 0; i < props.length; i++) { |  | 
| 113     CheckNotDeletable(type, props[i]); |  | 
| 114   } |  | 
| 115 } |  | 
| 116 |  | 
| 117 |  | 
| 118 function CheckDontDelete(type, props, name) { |  | 
| 119   print(name); |  | 
| 120   for (var i = 0; i < props.length; i++) { |  | 
| 121     CheckDontDeleteAttr(type, props[i]); |  | 
| 122   } |  | 
| 123 } |  | 
| 124 |  | 
| 125 |  | 
| 126 function CheckDeletable(type, prop) { |  | 
| 127   var old = type[prop]; |  | 
| 128   if (!type[prop]) return; |  | 
| 129   assertTrue(type.hasOwnProperty(prop), "inherited: " + prop); |  | 
| 130   var deleted = delete type[prop]; |  | 
| 131   assertTrue(deleted, "delete operator returned false: " + prop); |  | 
| 132   assertFalse(type.hasOwnProperty(prop), "still there after delete: " + prop); |  | 
| 133   type[prop] = "foo"; |  | 
| 134   assertEquals("foo", type[prop], "not overwritable: " + prop); |  | 
| 135 } |  | 
| 136 |  | 
| 137 |  | 
| 138 function CheckNotDeletable(type, prop) { |  | 
| 139   var old = type[prop]; |  | 
| 140   if (!type[prop]) return; |  | 
| 141   assertTrue(type.hasOwnProperty(prop), "inherited: " + prop); |  | 
| 142   var deleted = delete type[prop]; |  | 
| 143   // Comment this next line to pass the test on JSC: |  | 
| 144   assertFalse(deleted, "delete operator returned true: " + prop); |  | 
| 145   assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop); |  | 
| 146   type[prop] = "foo"; |  | 
| 147   assertEquals("foo", type[prop], "not overwritable: " + prop); |  | 
| 148 } |  | 
| 149 |  | 
| 150 |  | 
| 151 function CheckDontDeleteAttr(type, prop) { |  | 
| 152   var old = type[prop]; |  | 
| 153   if (!type[prop]) return; |  | 
| 154   assertTrue(type.hasOwnProperty(prop), "inherited: " + prop); |  | 
| 155   var deleted = delete type[prop]; |  | 
| 156   assertFalse(deleted, "delete operator returned true: " + prop); |  | 
| 157   assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop); |  | 
| 158   type[prop] = "foo"; |  | 
| 159   assertFalse("foo" == type[prop], "overwritable: " + prop); |  | 
| 160 } |  | 
| 161 |  | 
| 162 |  | 
| 163 function CheckReadOnlyAttr(type, prop) { |  | 
| 164   var old = type[prop]; |  | 
| 165   if (!type[prop]) return; |  | 
| 166   assertTrue(type.hasOwnProperty(prop), "inherited: " + prop); |  | 
| 167   var deleted = delete type[prop]; |  | 
| 168   assertFalse(deleted, "delete operator returned true: " + prop); |  | 
| 169   assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop); |  | 
| 170   type[prop] = "foo"; |  | 
| 171   assertEquals("foo", type[prop], "overwritable: " + prop); |  | 
| 172 } |  | 
| 173 |  | 
| 174 print("OK"); |  | 
| OLD | NEW | 
|---|