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

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

Issue 109004: Suggestion for 1717. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 7 months 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 | « src/string.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // 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
34 var array;
35
36 array = [
37 "toString", "toLocaleString", "join", "pop", "push", "concat", "reverse",
38 "shift", "unshift", "slice", "splice", "sort", "filter", "forEach", "some",
39 "every", "map", "indexOf", "lastIndexOf", "reduce", "reduceRight"];
40 CheckJSCSemantics(Array.prototype, array, "Array prototype");
41
42 array = [
43 "toString", "toDateString", "toTimeString", "toLocaleString",
44 "toLocaleDateString", "toLocaleTimeString", "valueOf", "getTime",
45 "getFullYear", "getUTCFullYear", "getMonth", "getUTCMonth", "getDate",
46 "getUTCDate", "getDay", "getUTCDay", "getHours", "getUTCHours", "getMinutes",
47 "getUTCMinutes", "getSeconds", "getUTCSeconds", "getMilliseconds",
48 "getUTCMilliseconds", "getTimezoneOffset", "setTime", "setMilliseconds",
49 "setUTCMilliseconds", "setSeconds", "setUTCSeconds", "setMinutes",
50 "setUTCMinutes", "setHours", "setUTCHours", "setDate", "setUTCDate",
51 "setMonth", "setUTCMonth", "setFullYear", "setUTCFullYear", "toGMTString",
52 "toUTCString", "getYear", "setYear", "toISOString", "toJSON"];
53 CheckJSCSemantics(Date.prototype, array, "Date prototype");
54
55 array = [
56 "random", "abs", "acos", "asin", "atan", "ceil", "cos", "exp", "floor", "log",
57 "round", "sin", "sqrt", "tan", "atan2", "pow", "max", "min"];
58 CheckJSCSemantics(Math, array, "Math1");
59
60 CheckEcmaSemantics(Date, ["UTC", "parse", "now"], "Date");
61
62 array = [
63 "E", "LN10", "LN2", "LOG2E", "LOG10E", "PI", "SQRT1_2", "SQRT2"];
64 CheckDontDelete(Math, array, "Math2");
65
66 array = [
67 "escape", "unescape", "decodeURI", "decodeURIComponent", "encodeURI",
68 "encodeURIComponent", "isNaN", "isFinite", "parseInt", "parseFloat", "eval",
69 "execScript"];
70 CheckEcmaSemantics(this, array, "Global");
71 CheckReadOnlyAttr(this, "Infinity");
72
73 array = ["exec", "test", "toString", "compile"];
74 CheckEcmaSemantics(RegExp.prototype, array, "RegExp prototype");
75
76 array = [
77 "toString", "toLocaleString", "valueOf", "hasOwnProperty",
78 "isPrototypeOf", "propertyIsEnumerable", "__defineGetter__",
79 "__lookupGetter__", "__defineSetter__", "__lookupSetter__"];
80 CheckEcmaSemantics(Object.prototype, array, "Object prototype");
81
82 array = [
83 "toString", "valueOf", "toJSON"];
84 CheckEcmaSemantics(Boolean.prototype, array, "Boolean prototype");
85
86 array = [
87 "toString", "toLocaleString", "valueOf", "toFixed", "toExponential",
88 "toPrecision", "toJSON"];
89 CheckEcmaSemantics(Number.prototype, array, "Number prototype");
90
91 CheckEcmaSemantics(Function.prototype, ["toString"], "Function prototype");
92 CheckEcmaSemantics(Date.prototype, ["constructor"], "Date prototype constructor" );
93
94 array = [
95 "charAt", "charCodeAt", "concat", "indexOf",
96 "lastIndexOf", "localeCompare", "match", "replace", "search", "slice",
97 "split", "substring", "substr", "toLowerCase", "toLocaleLowerCase",
98 "toUpperCase", "toLocaleUpperCase", "link", "anchor", "fontcolor", "fontsize",
99 "big", "blink", "bold", "fixed", "italics", "small", "strike", "sub", "sup",
100 "toJSON", "toString", "valueOf"];
101 CheckJSCSemantics(String.prototype, array, "String prototype");
102 CheckEcmaSemantics(String, ["fromCharCode"], "String");
103
104
105 function CheckEcmaSemantics(type, props, name) {
106 print(name);
107 for (var i = 0; i < props.length; i++) {
108 CheckDeletable(type, props[i]);
109 }
110 }
111
112
113 function CheckJSCSemantics(type, props, name) {
114 print(name);
115 for (var i = 0; i < props.length; i++) {
116 CheckNotDeletable(type, props[i]);
117 }
118 }
119
120
121 function CheckDontDelete(type, props, name) {
122 print(name);
123 for (var i = 0; i < props.length; i++) {
124 CheckDontDeleteAttr(type, props[i]);
125 }
126 }
127
128
129 function CheckDeletable(type, prop) {
130 var old = type[prop];
131 var hasOwnProperty = Object.prototype.hasOwnProperty;
132 if (!type[prop]) return;
133 assertTrue(type.hasOwnProperty(prop), "inherited: " + prop);
134 var deleted = delete type[prop];
135 assertTrue(deleted, "delete operator returned false: " + prop);
136 assertFalse(hasOwnProperty.call(type, prop), "still there after delete: " + pr op);
137 type[prop] = "foo";
138 assertEquals("foo", type[prop], "not overwritable: " + prop);
139 type[prop] = old;
140 }
141
142
143 function CheckNotDeletable(type, prop) {
144 var old = type[prop];
145 if (!type[prop]) return;
146 assertTrue(type.hasOwnProperty(prop), "inherited: " + prop);
147 var deleted = delete type[prop];
148 assertTrue(deleted, "delete operator returned false: " + prop);
149 assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop);
150 type[prop] = "foo";
151 assertEquals("foo", type[prop], "not overwritable: " + prop);
152 deleted = delete type[prop];
153 assertTrue(deleted, "delete operator returned false 2nd time: " + prop);
154 assertEquals(old.toString(), type[prop].toString(), "delete didn't restore the old value: " + prop);
155 }
156
157
158 function CheckDontDeleteAttr(type, prop) {
159 var old = type[prop];
160 if (!type[prop]) return;
161 assertTrue(type.hasOwnProperty(prop), "inherited: " + prop);
162 var deleted = delete type[prop];
163 assertFalse(deleted, "delete operator returned true: " + prop);
164 assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop);
165 type[prop] = "foo";
166 assertFalse("foo" == type[prop], "overwritable: " + prop);
167 }
168
169
170 function CheckReadOnlyAttr(type, prop) {
171 var old = type[prop];
172 if (!type[prop]) return;
173 assertTrue(type.hasOwnProperty(prop), "inherited: " + prop);
174 var deleted = delete type[prop];
175 assertFalse(deleted, "delete operator returned true: " + prop);
176 assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop);
177 type[prop] = "foo";
178 assertEquals("foo", type[prop], "overwritable: " + prop);
179 }
180
181 print("OK");
OLDNEW
« no previous file with comments | « src/string.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698