Debian Codegraph @

rhino/testsrc/tests/e4x/XML/regress-376773.js

raw symbols SCIP
1 /* -*- Mode: java; tab-width:8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 gTestfile = 'regress-376773.js';
8
9 var BUGNUMBER = 376773;
10 var summary = 'xmlsimple.stringmethod === xmlsimple.function::stringmethod';
11 var actual = '';
12 var expect = '';
13 var actualcall = '';
14 var expectcall = '';
15
16 printBugNumber(BUGNUMBER);
17 START(summary);
18
19 var nTest = 0;
20 var xml = <a>TEXT</a>;
21
22 // --------------------------------------------------------------
23
24 String.prototype.orig_toString = String.prototype.toString;
25 String.prototype.toString = function() {
26 actualcall = 'String.prototype.toString called';
27 return this.orig_toString();
28 };
29
30 expect = 'TEXT';
31 expectcall = 'String.prototype.toString not called';
32
33 actualcall = expectcall;
34 actual = xml.toString();
35 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
36
37 actualcall = expectcall;
38 actual = xml.function::toString();
39 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
40
41 actualcall = expectcall;
42 actual = xml.function::toString.call(xml);
43 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
44
45 String.prototype.toString = String.prototype.orig_toString;
46 delete String.prototype.orig_toString;
47
48 // --------------------------------------------------------------
49
50 String.prototype.orig_toSource = String.prototype.toSource;
51 String.prototype.toSource = function() {
52 actualcall = 'String.prototype.toSource called';
53 return this.orig_toSource();
54 };
55
56 expect = '<a>TEXT</a>';
57 expectcall = 'String.prototype.toSource not called';
58
59 actualcall = expectcall;
60 actual = xml.toSource();
61 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
62
63 actualcall = expectcall;
64 actual = xml.function::toSource();
65 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
66
67 actualcall = expectcall;
68 actual = xml.function::toSource.call(xml);
69 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
70
71 String.prototype.toSource = String.prototype.orig_toSource;
72 delete String.prototype.orig_toSource;
73
74 // --------------------------------------------------------------
75
76 String.prototype.orig_valueOf = String.prototype.valueOf;
77 String.prototype.valueOf = function() {
78 actualcall = 'String.prototype.valueOf called';
79 return this.orig_valueOf();
80 };
81
82 expect = 'TEXT';
83 expectcall = 'String.prototype.valueOf not called';
84
85 actualcall = expectcall;
86 actual = xml.valueOf();
87 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
88
89 actualcall = expectcall;
90 actual = xml.function::valueOf();
91 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
92
93 actualcall = expectcall;
94 actual = xml.function::valueOf.call(xml);
95 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
96
97 String.prototype.valueOf = String.prototype.orig_valueOf;
98 delete String.prototype.orig_valueOf;
99
100 // --------------------------------------------------------------
101
102 String.prototype.orig_charAt = String.prototype.charAt;
103 String.prototype.charAt = function(pos) {
104 actualcall = 'String.prototype.charAt called';
105 return this.orig_charAt(pos);
106 };
107
108 expect = 'T';
109 expectcall = 'String.prototype.charAt called';
110
111 actualcall = expectcall.replace(/called/, 'not called');
112 actual = xml.charAt(0);
113 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
114
115 actualcall = expectcall.replace(/called/, 'not called');
116 actual = xml.function::charAt(0);
117 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
118
119 actualcall = expectcall.replace(/called/, 'not called');
120 actual = xml.function::charAt.call(xml, 0);
121 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
122
123 String.prototype.charAt = String.prototype.orig_charAt;
124 delete String.prototype.orig_charAt;
125
126 // --------------------------------------------------------------
127
128 String.prototype.orig_charCodeAt = String.prototype.charCodeAt;
129 String.prototype.charCodeAt = function(pos) {
130 actualcall = 'String.prototype.charCodeAt called';
131 return this.orig_charCodeAt(pos);
132 };
133
134 expect = 84;
135 expectcall = 'String.prototype.charCodeAt called';
136
137 actualcall = expectcall.replace(/called/, 'not called');
138 actual = xml.charCodeAt(0);
139 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
140
141 actualcall = expectcall.replace(/called/, 'not called');
142 actual = xml.function::charCodeAt(0);
143 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
144
145 actualcall = expectcall.replace(/called/, 'not called');
146 actual = xml.function::charCodeAt.call(xml, 0);
147 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
148
149 String.prototype.charCodeAt = String.prototype.orig_charCodeAt;
150 delete String.prototype.orig_charCodeAt;
151
152 // --------------------------------------------------------------
153
154 String.prototype.orig_concat = String.prototype.concat;
155 String.prototype.concat = function(string1) {
156 actualcall = 'String.prototype.concat called';
157 return this.orig_concat(string1);
158 };
159
160 expect = 'TEXTtext';
161 expectcall = 'String.prototype.concat called';
162
163 actualcall = expectcall.replace(/called/, 'not called');
164 actual = xml.concat(<b>text</b>);
165 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
166
167 actualcall = expectcall.replace(/called/, 'not called');
168 actual = xml.function::concat(<b>text</b>);
169 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
170
171 actualcall = expectcall.replace(/called/, 'not called');
172 actual = xml.function::concat.call(xml, <b>text</b>);
173 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
174
175 String.prototype.concat = String.prototype.orig_concat;
176 delete String.prototype.orig_concat;
177
178 // --------------------------------------------------------------
179
180 String.prototype.orig_indexOf = String.prototype.indexOf;
181 String.prototype.indexOf = function(searchString, position) {
182 actualcall = 'String.prototype.indexOf called';
183 return this.orig_indexOf(searchString, position);
184 };
185
186 expect = 0;
187 expectcall = 'String.prototype.indexOf called';
188
189 actualcall = expectcall.replace(/called/, 'not called');
190 actual = xml.indexOf('T');
191 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
192
193 actualcall = expectcall.replace(/called/, 'not called');
194 actual = xml.function::indexOf('T');
195 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
196
197 actualcall = expectcall.replace(/called/, 'not called');
198 actual = xml.function::indexOf.call(xml, 'T');
199 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
200
201 String.prototype.indexOf = String.prototype.orig_indexOf;
202 delete String.prototype.orig_indexOf;
203
204 // --------------------------------------------------------------
205
206 String.prototype.orig_lastIndexOf = String.prototype.lastIndexOf;
207 String.prototype.lastIndexOf = function(searchString, position) {
208 actualcall = 'String.prototype.lastIndexOf called';
209 return this.orig_lastIndexOf(searchString, position);
210 };
211
212 expect = 3;
213 expectcall = 'String.prototype.lastIndexOf called';
214
215 actualcall = expectcall.replace(/called/, 'not called');
216 actual = xml.lastIndexOf('T');
217 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
218
219 actualcall = expectcall.replace(/called/, 'not called');
220 actual = xml.function::lastIndexOf('T');
221 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
222
223 actualcall = expectcall.replace(/called/, 'not called');
224 actual = xml.function::lastIndexOf.call(xml, 'T');
225 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
226
227 String.prototype.lastIndexOf = String.prototype.orig_lastIndexOf;
228 delete String.prototype.orig_lastIndexOf;
229
230 // --------------------------------------------------------------
231
232 String.prototype.orig_localeCompare = String.prototype.localeCompare;
233 String.prototype.localeCompare = function(that) {
234 actualcall = 'String.prototype.localeCompare called';
235 return this.orig_localeCompare(that);
236 };
237
238 expect = 0;
239 expectcall = 'String.prototype.localeCompare called';
240
241 actualcall = expectcall.replace(/called/, 'not called');
242 actual = xml.localeCompare(xml);
243 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
244
245 actualcall = expectcall.replace(/called/, 'not called');
246 actual = xml.function::localeCompare(xml);
247 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
248
249 actualcall = expectcall.replace(/called/, 'not called');
250 actual = xml.function::localeCompare.call(xml, xml);
251 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
252
253 String.prototype.localeCompare = String.prototype.orig_localeCompare;
254 delete String.prototype.orig_localeCompare;
255
256 // --------------------------------------------------------------
257
258 String.prototype.orig_match = String.prototype.match;
259 String.prototype.match = function(regexp) {
260 actualcall = 'String.prototype.match called';
261 return this.orig_match(regexp);
262 };
263
264 expect = ['TEXT'];
265 expectcall = 'String.prototype.match called';
266
267 actualcall = expectcall.replace(/called/, 'not called');
268 actual = xml.match(/TEXT/);
269 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
270
271 actualcall = expectcall.replace(/called/, 'not called');
272 actual = xml.function::match(/TEXT/);
273 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
274
275 actualcall = expectcall.replace(/called/, 'not called');
276 actual = xml.function::match.call(xml, /TEXT/);
277 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
278
279 String.prototype.match = String.prototype.orig_match;
280 delete String.prototype.orig_match;
281
282 // --------------------------------------------------------------
283
284 String.prototype.orig_replace = String.prototype.replace;
285 String.prototype.replace = function(searchValue, replaceValue) {
286 actualcall = 'String.prototype.replace called';
287 return this.orig_replace(searchValue, replaceValue);
288 };
289
290 expect = 'TEXT';
291 expectcall = 'String.prototype.replace not called';
292
293 actualcall = expectcall;
294 actual = xml.replace(/EXT/, 'ext');
295 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
296
297 actualcall = expectcall;
298 actual = xml.function::replace(/EXT/, 'ext');
299 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
300
301 actualcall = expectcall;
302 actual = xml.function::replace.call(xml, /EXT/, 'ext');
303 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
304
305 String.prototype.replace = String.prototype.orig_replace;
306 delete String.prototype.orig_replace;
307
308 // --------------------------------------------------------------
309
310 String.prototype.orig_search = String.prototype.search;
311 String.prototype.search = function(regexp) {
312 actualcall = 'String.prototype.search called';
313 return this.orig_search(regexp);
314 };
315
316 expect = 0;
317 expectcall = 'String.prototype.search called';
318
319 actualcall = expectcall.replace(/called/, 'not called');
320 actual = xml.search(/TEXT/);
321 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
322
323 actualcall = expectcall.search(/called/, 'not called');
324 actual = xml.function::search(/TEXT/);
325 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
326
327 actualcall = expectcall.search(/called/, 'not called');
328 actual = xml.function::search.call(xml, /TEXT/);
329 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
330
331 String.prototype.search = String.prototype.orig_search;
332 delete String.prototype.orig_search;
333
334 // --------------------------------------------------------------
335
336 String.prototype.orig_slice = String.prototype.slice;
337 String.prototype.slice = function(start, end) {
338 actualcall = 'String.prototype.slice called';
339 return this.orig_slice(start, end);
340 };
341
342 expect = '';
343 expectcall = 'String.prototype.slice called';
344
345 actualcall = expectcall.replace(/called/, 'not called');
346 actual = xml.slice(1,1);
347 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
348
349 actualcall = expectcall.slice(/called/, 'not called');
350 actual = xml.function::slice(1,1);
351 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
352
353 actualcall = expectcall.slice(/called/, 'not called');
354 actual = xml.function::slice.call(xml, 1,1);
355 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
356
357 String.prototype.slice = String.prototype.orig_slice;
358 delete String.prototype.orig_slice;
359
360 // --------------------------------------------------------------
361
362 String.prototype.orig_split = String.prototype.split;
363 String.prototype.split = function(separator, limit) {
364 actualcall = 'String.prototype.split called';
365 return this.orig_split(separator, limit);
366 };
367
368 expect = ['T', 'E', 'X', 'T'];
369 expectcall = 'String.prototype.split called';
370
371 actualcall = expectcall.replace(/called/, 'not called');
372 actual = xml.split('');
373 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
374
375 actualcall = expectcall.split(/called/, 'not called');
376 actual = xml.function::split('');
377 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
378
379 actualcall = expectcall.split(/called/, 'not called');
380 actual = xml.function::split.call(xml, '');
381 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
382
383 String.prototype.split = String.prototype.orig_split;
384 delete String.prototype.orig_split;
385
386 // --------------------------------------------------------------
387
388 String.prototype.orig_substr = String.prototype.substr;
389 String.prototype.substr = function(start, length) {
390 actualcall = 'String.prototype.substr called';
391 return this.orig_substr(start, length);
392 };
393
394 expect = 'E';
395 expectcall = 'String.prototype.substr called';
396
397 actualcall = expectcall.replace(/called/, 'not called');
398 actual = xml.substr(1,1);
399 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
400
401 actualcall = expectcall.substr(/called/, 'not called');
402 actual = xml.function::substr(1,1);
403 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
404
405 actualcall = expectcall.substr(/called/, 'not called');
406 actual = xml.function::substr.call(xml, 1,1);
407 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
408
409 String.prototype.substr = String.prototype.orig_substr;
410 delete String.prototype.orig_substr;
411
412 // --------------------------------------------------------------
413
414 String.prototype.orig_substring = String.prototype.substring;
415 String.prototype.substring = function(start, end) {
416 actualcall = 'String.prototype.substring called';
417 return this.orig_substring(start, end);
418 };
419
420 expect = '';
421 expectcall = 'String.prototype.substring called';
422
423 actualcall = expectcall.replace(/called/, 'not called');
424 actual = xml.substring(1,1);
425 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
426
427 actualcall = expectcall.substring(/called/, 'not called');
428 actual = xml.function::substring(1,1);
429 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
430
431 actualcall = expectcall.substring(/called/, 'not called');
432 actual = xml.function::substring.call(xml, 1,1);
433 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
434
435 String.prototype.substring = String.prototype.orig_substring;
436 delete String.prototype.orig_substring;
437
438 // --------------------------------------------------------------
439
440 String.prototype.orig_toLowerCase = String.prototype.toLowerCase;
441 String.prototype.toLowerCase = function() {
442 actualcall = 'String.prototype.toLowerCase called';
443 return this.orig_toLowerCase();
444 };
445
446 expect = 'text';
447 expectcall = 'String.prototype.toLowerCase called';
448
449 actualcall = expectcall.replace(/called/, 'not called');
450 actual = xml.toLowerCase();
451 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
452
453 actualcall = expectcall.toLowerCase(/called/, 'not called');
454 actual = xml.function::toLowerCase();
455 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
456
457 actualcall = expectcall.toLowerCase(/called/, 'not called');
458 actual = xml.function::toLowerCase.call(xml);
459 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
460
461 String.prototype.toLowerCase = String.prototype.orig_toLowerCase;
462 delete String.prototype.orig_toLowerCase;
463
464 // --------------------------------------------------------------
465
466 String.prototype.orig_toLocaleLowerCase = String.prototype.toLocaleLowerCase;
467 String.prototype.toLocaleLowerCase = function() {
468 actualcall = 'String.prototype.toLocaleLowerCase called';
469 return this.orig_toLocaleLowerCase();
470 };
471
472 expect = 'text';
473 expectcall = 'String.prototype.toLocaleLowerCase called';
474
475 actualcall = expectcall.replace(/called/, 'not called');
476 actual = xml.toLocaleLowerCase();
477 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
478
479 actualcall = expectcall.toLocaleLowerCase(/called/, 'not called');
480 actual = xml.function::toLocaleLowerCase();
481 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
482
483 actualcall = expectcall.toLocaleLowerCase(/called/, 'not called');
484 actual = xml.function::toLocaleLowerCase.call(xml);
485 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
486
487 String.prototype.toLocaleLowerCase = String.prototype.orig_toLocaleLowerCase;
488 delete String.prototype.orig_toLocaleLowerCase;
489
490 // --------------------------------------------------------------
491
492 String.prototype.orig_toUpperCase = String.prototype.toUpperCase;
493 String.prototype.toUpperCase = function() {
494 actualcall = 'String.prototype.toUpperCase called';
495 return this.orig_toUpperCase();
496 };
497
498 expect = 'TEXT';
499 expectcall = 'String.prototype.toUpperCase called';
500
501 actualcall = expectcall.replace(/called/, 'not called');
502 actual = xml.toUpperCase();
503 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
504
505 actualcall = expectcall.toUpperCase(/called/, 'not called');
506 actual = xml.function::toUpperCase();
507 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
508
509 actualcall = expectcall.toUpperCase(/called/, 'not called');
510 actual = xml.function::toUpperCase.call(xml);
511 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
512
513 String.prototype.toUpperCase = String.prototype.orig_toUpperCase;
514 delete String.prototype.orig_toUpperCase;
515
516 // --------------------------------------------------------------
517
518 String.prototype.orig_toLocaleUpperCase = String.prototype.toLocaleUpperCase;
519 String.prototype.toLocaleUpperCase = function() {
520 actualcall = 'String.prototype.toLocaleUpperCase called';
521 return this.orig_toLocaleUpperCase();
522 };
523
524 expect = 'TEXT';
525 expectcall = 'String.prototype.toLocaleUpperCase called';
526
527 actualcall = expectcall.replace(/called/, 'not called');
528 actual = xml.toLocaleUpperCase();
529 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
530
531 actualcall = expectcall.toLocaleUpperCase(/called/, 'not called');
532 actual = xml.function::toLocaleUpperCase();
533 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
534
535 actualcall = expectcall.toLocaleUpperCase(/called/, 'not called');
536 actual = xml.function::toLocaleUpperCase.call(xml);
537 TEST(++nTest, expectcall + ':' + expect, actualcall + ':' + actual);
538
539 String.prototype.toLocaleUpperCase = String.prototype.orig_toLocaleUpperCase;
540 delete String.prototype.orig_toLocaleUpperCase;
541
542 var l = <><a>text</a></>;
543 expect = 't';
544 actual = l.function::charAt.call(l, 0);
545 TEST(++nTest, expect, actual);
546
547 expect = 't';
548 with (l) actual = function::charAt(0);
549 TEST(++nTest, expect, actual);
550
551
552 END();