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

Side by Side Diff: test/mjsunit/function-call.js

Issue 6904047: Test to ensure .call on native functions work correctly when passed (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 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 | « no previous file | 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 2011 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
29 var should_throw_on_null_and_undefined =
30 [Object.prototype.toLocaleString,
31 Object.prototype.valueOf,
32 Object.prototype.hasOwnProperty,
33 Object.prototype.isPrototypeOf,
34 Object.prototype.propertyIsEnumerable,
35 Array.prototype.toString,
36 Array.prototype.toLocaleString,
37 Array.prototype.concat,
38 Array.prototype.join,
39 Array.prototype.pop,
40 Array.prototype.push,
41 Array.prototype.reverse,
42 Array.prototype.shift,
43 Array.prototype.slice,
44 Array.prototype.sort,
45 Array.prototype.splice,
46 Array.prototype.unshift,
47 Array.prototype.indexOf,
48 Array.prototype.lastIndexOf,
49 Array.prototype.every,
50 Array.prototype.some,
51 Array.prototype.forEach,
52 Array.prototype.map,
53 Array.prototype.filter,
54 Array.prototype.reduce,
55 Array.prototype.reduceRight,
56 String.prototype.charAt,
57 String.prototype.charCodeAt,
58 String.prototype.concat,
59 String.prototype.indexOf,
60 String.prototype.lastIndexOf,
61 String.prototype.localeCompare,
62 String.prototype.match,
63 String.prototype.replace,
64 String.prototype.search,
65 String.prototype.slice,
66 String.prototype.split,
67 String.prototype.substring,
68 String.prototype.toLowerCase,
69 String.prototype.toLocaleLowerCase,
70 String.prototype.toUpperCase,
71 String.prototype.toLocaleUpperCase,
72 String.prototype.trim,
73 Number.prototype.toLocaleString,
74 Error.prototype.toString];
75
76 // Non generic natives does not work on any input other than the specific
77 // type, but since this change will allow call to be invoked with undefined
78 // or null as this we still explicitly test that we throw on these here.
79 var non_generic =
80 [Function.prototype.toString,
81 String.prototype.toString,
82 String.prototype.valueOf,
83 Boolean.prototype.toString,
84 Boolean.prototype.valueOf,
85 Number.prototype.toString,
86 Number.prototype.valueOf,
87 Number.prototype.toFixed,
88 Number.prototype.toExponential,
89 Number.prototype.toPrecision,
90 Date.prototype.toString,
91 Date.prototype.toDateString,
92 Date.prototype.toTimeString,
93 Date.prototype.toLocaleString,
94 Date.prototype.toLocaleDateString,
95 Date.prototype.toLocaleTimeString,
96 Date.prototype.valueOf,
97 Date.prototype.getTime,
98 Date.prototype.getFullYear,
99 Date.prototype.getUTCFullYear,
100 Date.prototype.getMonth,
101 Date.prototype.getUTCMonth,
102 Date.prototype.getDate,
103 Date.prototype.getUTCDate,
104 Date.prototype.getDay,
105 Date.prototype.getUTCDay,
106 Date.prototype.getHours,
107 Date.prototype.getUTCHours,
108 Date.prototype.getMinutes,
109 Date.prototype.getUTCMinutes,
110 Date.prototype.getSeconds,
111 Date.prototype.getUTCSeconds,
112 Date.prototype.getMilliseconds,
113 Date.prototype.getUTCMilliseconds,
114 Date.prototype.getTimezoneOffset,
115 Date.prototype.setTime,
116 Date.prototype.setMilliseconds,
117 Date.prototype.setUTCMilliseconds,
118 Date.prototype.setSeconds,
119 Date.prototype.setUTCSeconds,
120 Date.prototype.setMinutes,
121 Date.prototype.setUTCMinutes,
122 Date.prototype.setHours,
123 Date.prototype.setUTCHours,
124 Date.prototype.setDate,
125 Date.prototype.setUTCDate,
126 Date.prototype.setMonth,
127 Date.prototype.setUTCMonth,
128 Date.prototype.setFullYear,
129 Date.prototype.setUTCFullYear,
130 Date.prototype.toUTCString,
131 Date.prototype.toISOString,
132 Date.prototype.toJSON,
133 RegExp.prototype.exec,
134 RegExp.prototype.test,
135 RegExp.prototype.toString];
136
137
138 // Mapping functions.
139 var mapping_functions =
140 [Array.prototype.every,
141 Array.prototype.some,
142 Array.prototype.forEach,
143 Array.prototype.map,
144 Array.prototype.filter];
145
146 // Reduce functions.
147 var reducing_functions =
148 [Array.prototype.reduce,
149 Array.prototype.reduceRight];
150
151 // Test that all natives using the ToObject call throws the right exception.
152 for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) {
153 // Sanity check that all functions are correct
154 assertEquals(typeof(should_throw_on_null_and_undefined[i]), "function");
155
156 try {
157 should_throw_on_null_and_undefined[i].call(null);
158 assertUnreachable();
159 } catch (e) {
160 assertTrue(/called on non-object/.test(e));
161 }
162
163 try {
164 should_throw_on_null_and_undefined[i].call(undefined);
165 assertUnreachable();
166 } catch (e) {
167 assertTrue(/called on non-object/.test(e));
168 }
169
170 try {
171 should_throw_on_null_and_undefined[i].apply(null);
172 assertUnreachable();
173 } catch (e) {
174 assertTrue(/called on non-object/.test(e));
175 }
176
177 try {
178 should_throw_on_null_and_undefined[i].apply(undefined);
179 assertUnreachable();
180 } catch (e) {
181 assertTrue(/called on non-object/.test(e));
182 }
183 }
184
185 // Test that all natives that are non generic throws on null and undefined.
186 for (var i = 0; i < non_generic.length; i++) {
187 // Sanity check that all functions are correct
188 assertEquals(typeof(non_generic[i]), "function");
189
190 try {
191 non_generic[i].call(null);
192 assertUnreachable();
193 } catch (e) { }
194
195 try {
196 non_generic[i].call(null);
197 assertUnreachable();
198 } catch (e) { }
199
200 try {
201 non_generic[i].apply(null);
202 assertUnreachable();
203 } catch (e) { }
204
205 try {
206 non_generic[i].apply(null);
207 assertUnreachable();
208 } catch (e) { }
209 }
210
211
212 // Test that we still throw when calling with thisArg null or undefined
213 // through an array mapping function.
214 var array = [1,2,3,4,5];
215 for (var j = 0; j < mapping_functions.length; j++) {
216 for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) {
217 try {
218 mapping_functions[j].call(array,
219 should_throw_on_null_and_undefined[i],
220 null);
221 assertUnreachable();
222 } catch (e) {
223 assertTrue(/called on non-object/.test(e));
224 }
225
226 try {
227 mapping_functions[j].call(array,
228 should_throw_on_null_and_undefined[i],
229 undefined);
230 assertUnreachable();
231 } catch (e) {
232 assertTrue(/called on non-object/.test(e));
233 }
234 }
235 }
236
237 for (var j = 0; j < mapping_functions.length; j++) {
238 for (var i = 0; i < non_generic.length; i++) {
239 try {
240 mapping_functions[j].call(array,
241 non_generic[i],
242 null);
243 assertUnreachable();
244 } catch (e) { }
245
246 try {
247 mapping_functions[j].call(array,
248 non_generic[i],
249 null);
250 assertUnreachable();
251 } catch (e) { }
252 }
253 }
254
255
256 // Reduce functions do a call with null as this argument.
257 for (var j = 0; j < reduce_functions.length; j++) {
258 for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) {
259 try {
260 reduce_functions[j].call(array,
261 should_throw_on_null_and_undefined[i]);
262 assertUnreachable();
263 } catch (e) {
264 assertTrue(/called on non-object/.test(e));
265 }
266
267 try {
268 reduce_functions[j].call(array,
269 should_throw_on_null_and_undefined[i]);
270 assertUnreachable();
271 } catch (e) {
272 assertTrue(/called on non-object/.test(e));
273 }
274 }
275 }
276
277 for (var j = 0; j < reduce_functions.length; j++) {
278 for (var i = 0; i < non_generic.length; i++) {
279 try {
280 reduce_functions[j].call(array,
281 non_generic[i]);
282 assertUnreachable();
283 } catch (e) { }
284
285 try {
286 reduce_functions[j].call(array,
287 non_generic[i]);
288 assertUnreachable();
289 } catch (e) { }
290 }
291 }
292
293 // Object.prototype.toString()
294 assertEquals(Object.prototype.toString.call(null),
295 '[object Null]')
296
297 assertEquals(Object.prototype.toString.call(undefined),
298 '[object Undefined]')
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698