Debian Codegraph @

rhino/testsrc/tests/js1_6/extensions/regress-312385-01.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 var gTestfile = 'regress-312385-01.js';
7 //-----------------------------------------------------------------------------
8 var BUGNUMBER = 312385;
9 var summary = 'Generic methods with null or undefined |this|';
10 var actual = '';
11 var expect = true;
12 var voids = [null, undefined];
13
14 var generics = {
15 String: [{ quote: [] },
16 { substring: [] },
17 { toLowerCase: [] },
18 { toUpperCase: [] },
19 { charAt: [] },
20 { charCodeAt: [] },
21 { indexOf: [] },
22 { lastIndexOf: [] },
23 { toLocaleLowerCase: [] },
24 { toLocaleUpperCase: [] },
25 { localeCompare: [] },
26 { match: [/(?:)/] }, // match(regexp)
27 { search: [] },
28 { replace: [] },
29 { split: [] },
30 { substr: [] },
31 { concat: [] },
32 { slice: [] }],
33
34 Array: [{ join: [] },
35 { reverse: [] },
36 { sort: [] },
37 // { push: [0] }, // push(item1, ...)
38 // { pop: [] },
39 // { shift: [] },
40 { unshift: [] },
41 // { splice: [0, 0, 1] }, // splice(start, deleteCount, item1, ...)
42 { concat: [] },
43 { indexOf: [] },
44 { lastIndexOf: [] },
45 // forEach is excluded since it does not return a value...
46 /* { forEach: [noop] }, // forEach(callback, thisObj) */
47 { map: [noop] }, // map(callback, thisObj)
48 { filter: [noop] }, // filter(callback, thisObj)
49 { some: [noop] }, // some(callback, thisObj)
50 { every: [noop] } // every(callback, thisObj)
51 ]
52 };
53
54 printBugNumber(BUGNUMBER);
55 printStatus (summary);
56
57 for (var c in generics)
58 {
59 var methods = generics[c];
60 for (var i = 0; i < methods.length; i++)
61 {
62 var method = methods[i];
63
64 for (var methodname in method)
65 {
66 for (var v = 0; v < voids.length; v++)
67 {
68 var lhs = c + '.' + methodname +
69 '(' + voids[v] + (method[methodname].length ?(', ' + method[methodname].toString()):'') + ')';
70
71 var rhs = c + '.prototype.' + methodname +
72 '.apply(' + voids[v] + ', ' + method[methodname].toSource() + ')';
73
74 var expr = lhs + ' == ' + rhs;
75 printStatus('Testing ' + expr);
76
77 try
78 {
79 printStatus('lhs ' + lhs + ': ' + eval(lhs));
80 }
81 catch(ex)
82 {
83 printStatus(ex + '');
84 }
85
86 try
87 {
88 printStatus('rhs ' + rhs + ': ' + eval(rhs));
89 }
90 catch(ex)
91 {
92 printStatus(ex + '');
93 }
94
95 try
96 {
97 actual = comparelr(eval(lhs), eval(rhs));
98 }
99 catch(ex)
100 {
101 actual = ex + '';
102 }
103 reportCompare(expect, actual, expr);
104 printStatus('');
105 }
106 }
107 }
108 }
109
110 function comparelr(lhs, rhs)
111 {
112
113 if (lhs.constructor.name != 'Array')
114 {
115 return (lhs == rhs);
116 }
117
118 return (lhs.toSource() == rhs.toSource());
119 }
120
121 function noop()
122 {
123 }