Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: test/mjsunit/undeletable-functions.js

Issue 8566009: Remove hidden prototype for builtin functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/regress/regress-91517.js ('k') | test/sputnik/sputnik.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Test that we match JSC in making some functions undeletable. 28 // Test that we match ECMAScript in making most builtin functions
29 // See http://code.google.com/p/chromium/issues/detail?id=1717 29 // deletable and only specific ones undeletable or read-only.
30 // The functions on these prototypes are not just undeletable. It is
31 // possible to override them with new definitions, then get the old
32 // version back by deleting the new definition.
33 30
34 var array; 31 var array;
35 32
36 array = [ 33 array = [
37 "toString", "toLocaleString", "join", "pop", "push", "concat", "reverse", 34 "toString", "toLocaleString", "join", "pop", "push", "concat", "reverse",
38 "shift", "unshift", "slice", "splice", "sort", "filter", "forEach", "some", 35 "shift", "unshift", "slice", "splice", "sort", "filter", "forEach", "some",
39 "every", "map", "indexOf", "lastIndexOf", "reduce", "reduceRight"]; 36 "every", "map", "indexOf", "lastIndexOf", "reduce", "reduceRight"];
40 CheckJSCSemantics(Array.prototype, array, "Array prototype"); 37 CheckEcmaSemantics(Array.prototype, array, "Array prototype");
41 38
42 var old_Array_prototype = Array.prototype; 39 var old_Array_prototype = Array.prototype;
43 var new_Array_prototype = {}; 40 var new_Array_prototype = {};
44 for (var i = 0; i < 7; i++) { 41 for (var i = 0; i < 7; i++) {
45 Array.prototype = new_Array_prototype; 42 Array.prototype = new_Array_prototype;
46 assertEquals(old_Array_prototype, Array.prototype); 43 assertEquals(old_Array_prototype, Array.prototype);
47 } 44 }
48 45
49 array = [ 46 array = [
50 "toString", "toDateString", "toTimeString", "toLocaleString", 47 "toString", "toDateString", "toTimeString", "toLocaleString",
51 "toLocaleDateString", "toLocaleTimeString", "valueOf", "getTime", 48 "toLocaleDateString", "toLocaleTimeString", "valueOf", "getTime",
52 "getFullYear", "getUTCFullYear", "getMonth", "getUTCMonth", "getDate", 49 "getFullYear", "getUTCFullYear", "getMonth", "getUTCMonth", "getDate",
53 "getUTCDate", "getDay", "getUTCDay", "getHours", "getUTCHours", "getMinutes", 50 "getUTCDate", "getDay", "getUTCDay", "getHours", "getUTCHours", "getMinutes",
54 "getUTCMinutes", "getSeconds", "getUTCSeconds", "getMilliseconds", 51 "getUTCMinutes", "getSeconds", "getUTCSeconds", "getMilliseconds",
55 "getUTCMilliseconds", "getTimezoneOffset", "setTime", "setMilliseconds", 52 "getUTCMilliseconds", "getTimezoneOffset", "setTime", "setMilliseconds",
56 "setUTCMilliseconds", "setSeconds", "setUTCSeconds", "setMinutes", 53 "setUTCMilliseconds", "setSeconds", "setUTCSeconds", "setMinutes",
57 "setUTCMinutes", "setHours", "setUTCHours", "setDate", "setUTCDate", 54 "setUTCMinutes", "setHours", "setUTCHours", "setDate", "setUTCDate",
58 "setMonth", "setUTCMonth", "setFullYear", "setUTCFullYear", "toGMTString", 55 "setMonth", "setUTCMonth", "setFullYear", "setUTCFullYear", "toGMTString",
59 "toUTCString", "getYear", "setYear", "toISOString", "toJSON"]; 56 "toUTCString", "getYear", "setYear", "toISOString", "toJSON"];
60 CheckJSCSemantics(Date.prototype, array, "Date prototype"); 57 CheckEcmaSemantics(Date.prototype, array, "Date prototype");
61 58
62 array = [ 59 array = [
63 "random", "abs", "acos", "asin", "atan", "ceil", "cos", "exp", "floor", "log", 60 "random", "abs", "acos", "asin", "atan", "ceil", "cos", "exp", "floor", "log",
64 "round", "sin", "sqrt", "tan", "atan2", "pow", "max", "min"]; 61 "round", "sin", "sqrt", "tan", "atan2", "pow", "max", "min"];
65 CheckJSCSemantics(Math, array, "Math1"); 62 CheckEcmaSemantics(Math, array, "Math1");
66 63
67 CheckEcmaSemantics(Date, ["UTC", "parse", "now"], "Date"); 64 CheckEcmaSemantics(Date, ["UTC", "parse", "now"], "Date");
68 65
69 array = [ 66 array = [
70 "E", "LN10", "LN2", "LOG2E", "LOG10E", "PI", "SQRT1_2", "SQRT2"]; 67 "E", "LN10", "LN2", "LOG2E", "LOG10E", "PI", "SQRT1_2", "SQRT2"];
71 CheckDontDelete(Math, array, "Math2"); 68 CheckDontDelete(Math, array, "Math2");
72 69
73 array = [ 70 array = [
74 "escape", "unescape", "decodeURI", "decodeURIComponent", "encodeURI", 71 "escape", "unescape", "decodeURI", "decodeURIComponent", "encodeURI",
75 "encodeURIComponent", "isNaN", "isFinite", "parseInt", "parseFloat", "eval", 72 "encodeURIComponent", "isNaN", "isFinite", "parseInt", "parseFloat", "eval",
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 CheckEcmaSemantics(Function.prototype, ["toString"], "Function prototype"); 104 CheckEcmaSemantics(Function.prototype, ["toString"], "Function prototype");
108 CheckEcmaSemantics(Date.prototype, ["constructor"], "Date prototype constructor" ); 105 CheckEcmaSemantics(Date.prototype, ["constructor"], "Date prototype constructor" );
109 106
110 array = [ 107 array = [
111 "charAt", "charCodeAt", "concat", "indexOf", 108 "charAt", "charCodeAt", "concat", "indexOf",
112 "lastIndexOf", "localeCompare", "match", "replace", "search", "slice", 109 "lastIndexOf", "localeCompare", "match", "replace", "search", "slice",
113 "split", "substring", "substr", "toLowerCase", "toLocaleLowerCase", 110 "split", "substring", "substr", "toLowerCase", "toLocaleLowerCase",
114 "toUpperCase", "toLocaleUpperCase", "link", "anchor", "fontcolor", "fontsize", 111 "toUpperCase", "toLocaleUpperCase", "link", "anchor", "fontcolor", "fontsize",
115 "big", "blink", "bold", "fixed", "italics", "small", "strike", "sub", "sup", 112 "big", "blink", "bold", "fixed", "italics", "small", "strike", "sub", "sup",
116 "toJSON", "toString", "valueOf"]; 113 "toJSON", "toString", "valueOf"];
117 CheckJSCSemantics(String.prototype, array, "String prototype"); 114 CheckEcmaSemantics(String.prototype, array, "String prototype");
118 CheckEcmaSemantics(String, ["fromCharCode"], "String"); 115 CheckEcmaSemantics(String, ["fromCharCode"], "String");
119 116
120 117
121 function CheckEcmaSemantics(type, props, name) { 118 function CheckEcmaSemantics(type, props, name) {
122 print(name); 119 print(name);
123 for (var i = 0; i < props.length; i++) { 120 for (var i = 0; i < props.length; i++) {
124 CheckDeletable(type, props[i]); 121 CheckDeletable(type, props[i]);
125 } 122 }
126 } 123 }
127 124
128 125
129 function CheckJSCSemantics(type, props, name) {
130 print(name);
131 for (var i = 0; i < props.length; i++) {
132 CheckNotDeletable(type, props[i]);
133 }
134 }
135
136
137 function CheckDontDelete(type, props, name) { 126 function CheckDontDelete(type, props, name) {
138 print(name); 127 print(name);
139 for (var i = 0; i < props.length; i++) { 128 for (var i = 0; i < props.length; i++) {
140 CheckDontDeleteAttr(type, props[i]); 129 CheckDontDeleteAttr(type, props[i]);
141 } 130 }
142 } 131 }
143 132
144 133
145 function CheckDeletable(type, prop) { 134 function CheckDeletable(type, prop) {
146 var old = type[prop]; 135 var old = type[prop];
147 var hasOwnProperty = Object.prototype.hasOwnProperty; 136 var hasOwnProperty = Object.prototype.hasOwnProperty;
148 if (!type[prop]) return; 137 if (!type[prop]) return;
149 assertTrue(type.hasOwnProperty(prop), "inherited: " + prop); 138 assertTrue(type.hasOwnProperty(prop), "inherited: " + prop);
150 var deleted = delete type[prop]; 139 var deleted = delete type[prop];
151 assertTrue(deleted, "delete operator returned false: " + prop); 140 assertTrue(deleted, "delete operator returned false: " + prop);
152 assertFalse(hasOwnProperty.call(type, prop), "still there after delete: " + pr op); 141 assertFalse(hasOwnProperty.call(type, prop), "still there after delete: " + pr op);
153 type[prop] = "foo"; 142 type[prop] = "foo";
154 assertEquals("foo", type[prop], "not overwritable: " + prop); 143 assertEquals("foo", type[prop], "not overwritable: " + prop);
155 type[prop] = old; 144 type[prop] = old;
156 } 145 }
157 146
158 147
159 function CheckNotDeletable(type, prop) {
160 var old = type[prop];
161 if (!type[prop]) return;
162 assertTrue(type.hasOwnProperty(prop), "inherited: " + prop);
163 var deleted = delete type[prop];
164 assertTrue(deleted, "delete operator returned false: " + prop);
165 assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop);
166 type[prop] = "foo";
167 assertEquals("foo", type[prop], "not overwritable: " + prop);
168 deleted = delete type[prop];
169 assertTrue(deleted, "delete operator returned false 2nd time: " + prop);
170 assertEquals(old.toString(), type[prop].toString(), "delete didn't restore the old value: " + prop);
171 }
172
173
174 function CheckDontDeleteAttr(type, prop) { 148 function CheckDontDeleteAttr(type, prop) {
175 var old = type[prop]; 149 var old = type[prop];
176 if (!type[prop]) return; 150 if (!type[prop]) return;
177 assertTrue(type.hasOwnProperty(prop), "inherited: " + prop); 151 assertTrue(type.hasOwnProperty(prop), "inherited: " + prop);
178 var deleted = delete type[prop]; 152 var deleted = delete type[prop];
179 assertFalse(deleted, "delete operator returned true: " + prop); 153 assertFalse(deleted, "delete operator returned true: " + prop);
180 assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop); 154 assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop);
181 type[prop] = "foo"; 155 type[prop] = "foo";
182 assertFalse("foo" == type[prop], "overwritable: " + prop); 156 assertFalse("foo" == type[prop], "overwritable: " + prop);
183 } 157 }
184 158
185 159
186 function CheckReadOnlyAttr(type, prop) { 160 function CheckReadOnlyAttr(type, prop) {
187 var old = type[prop]; 161 var old = type[prop];
188 if (!type[prop]) return; 162 if (!type[prop]) return;
189 assertTrue(type.hasOwnProperty(prop), "inherited: " + prop); 163 assertTrue(type.hasOwnProperty(prop), "inherited: " + prop);
190 var deleted = delete type[prop]; 164 var deleted = delete type[prop];
191 assertFalse(deleted, "delete operator returned true: " + prop); 165 assertFalse(deleted, "delete operator returned true: " + prop);
192 assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop); 166 assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop);
193 type[prop] = "foo"; 167 type[prop] = "foo";
194 assertEquals(old, type[prop], "overwritable: " + prop); 168 assertEquals(old, type[prop], "overwritable: " + prop);
195 } 169 }
196 170
197 print("OK"); 171 print("OK");
OLDNEW
« no previous file with comments | « test/mjsunit/regress/regress-91517.js ('k') | test/sputnik/sputnik.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698