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