~loic.molinari/+junk/qtdeclarative-shadereffectsource-changes

« back to all changes in this revision

Viewing changes to tests/auto/qml/parserstress/tests/ecma_3/Function/regress-58274.js

  • Committer: Loïc Molinari
  • Date: 2012-04-21 17:59:51 UTC
  • Revision ID: loic.molinari@canonical.com-20120421175951-bqx68caaf5zrp76l
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Mozilla Public License Version
 
6
 * 1.1 (the "License"); you may not use this file except in compliance with
 
7
 * the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/MPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is JavaScript Engine testing utilities.
 
16
 *
 
17
 * The Initial Developer of the Original Code is
 
18
 * Netscape Communications Corp.
 
19
 * Portions created by the Initial Developer are Copyright (C) 2002
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *   rogerl@netscape.com, pschwartau@netscape.com
 
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
 *
 
41
 * Date:    15 July 2002
 
42
 * SUMMARY: Testing functions with double-byte names
 
43
 * See http://bugzilla.mozilla.org/show_bug.cgi?id=58274
 
44
 *
 
45
 * Here is a sample of the problem:
 
46
 *
 
47
 *    js> function f\u02B1 () {}
 
48
 *
 
49
 *    js> f\u02B1.toSource();
 
50
 *    function f�() {}
 
51
 *
 
52
 *    js> f\u02B1.toSource().toSource();
 
53
 *    (new String("function f\xB1() {}"))
 
54
 *
 
55
 *
 
56
 * See how the high-byte information (the 02) has been lost?
 
57
 * The same thing was happening with the toString() method:
 
58
 *
 
59
 *    js> f\u02B1.toString();
 
60
 *
 
61
 *    function f�() {
 
62
 *    }
 
63
 *
 
64
 *    js> f\u02B1.toString().toSource();
 
65
 *    (new String("\nfunction f\xB1() {\n}\n"))
 
66
 *
 
67
 */
 
68
//-----------------------------------------------------------------------------
 
69
var gTestfile = 'regress-58274.js';
 
70
var UBound = 0;
 
71
var BUGNUMBER = 58274;
 
72
var summary = 'Testing functions with double-byte names';
 
73
var ERR = 'UNEXPECTED ERROR! \n';
 
74
var ERR_MALFORMED_NAME = ERR + 'Could not find function name in: \n\n';
 
75
var status = '';
 
76
var statusitems = [];
 
77
var actual = '';
 
78
var actualvalues = [];
 
79
var expect= '';
 
80
var expectedvalues = [];
 
81
var sEval;
 
82
var sName;
 
83
 
 
84
 
 
85
sEval = "function f\u02B2() {return 42;}";
 
86
eval(sEval);
 
87
sName = getFunctionName(f\u02B2);
 
88
 
 
89
// Test function call -
 
90
status = inSection(1);
 
91
actual = f\u02B2();
 
92
expect = 42;
 
93
addThis();
 
94
 
 
95
// Test both characters of function name -
 
96
status = inSection(2);
 
97
actual = sName[0];
 
98
expect = sEval[9];
 
99
addThis();
 
100
 
 
101
status = inSection(3);
 
102
actual = sName[1];
 
103
expect = sEval[10];
 
104
addThis();
 
105
 
 
106
 
 
107
 
 
108
sEval = "function f\u02B2\u0AAA () {return 84;}";
 
109
eval(sEval);
 
110
sName = getFunctionName(f\u02B2\u0AAA);
 
111
 
 
112
// Test function call -
 
113
status = inSection(4);
 
114
actual = f\u02B2\u0AAA();
 
115
expect = 84;
 
116
addThis();
 
117
 
 
118
// Test all three characters of function name -
 
119
status = inSection(5);
 
120
actual = sName[0];
 
121
expect = sEval[9];
 
122
addThis();
 
123
 
 
124
status = inSection(6);
 
125
actual = sName[1];
 
126
expect = sEval[10];
 
127
addThis();
 
128
 
 
129
status = inSection(7);
 
130
actual = sName[2];
 
131
expect = sEval[11];
 
132
addThis();
 
133
 
 
134
 
 
135
 
 
136
 
 
137
//-----------------------------------------------------------------------------
 
138
test();
 
139
//-----------------------------------------------------------------------------
 
140
 
 
141
 
 
142
 
 
143
/*
 
144
 * Goal: test that f.toString() contains the proper function name.
 
145
 *
 
146
 * Note, however, f.toString() is implementation-independent. For example,
 
147
 * it may begin with '\nfunction' instead of 'function'. Therefore we use
 
148
 * a regexp to make sure we extract the name properly.
 
149
 *
 
150
 * Here we assume that f has been defined by means of a function statement,
 
151
 * and not a function expression (where it wouldn't have to have a name).
 
152
 *
 
153
 * Rhino uses a Unicode representation for f.toString(); whereas
 
154
 * SpiderMonkey uses an ASCII representation, putting escape sequences
 
155
 * for non-ASCII characters. For example, if a function is called f\u02B1,
 
156
 * then in Rhino the toString() method will present a 2-character Unicode
 
157
 * string for its name, whereas SpiderMonkey will present a 7-character
 
158
 * ASCII string for its name: the string literal 'f\u02B1'.
 
159
 *
 
160
 * So we force the lexer to condense the string before using it.
 
161
 * This will give uniform results in Rhino and SpiderMonkey.
 
162
 */
 
163
function getFunctionName(f)
 
164
{
 
165
  var s = condenseStr(f.toString());
 
166
  var re = /\s*function\s+(\S+)\s*\(/;
 
167
    var arr = s.match(re);
 
168
 
 
169
  if (!(arr && arr[1]))
 
170
    return ERR_MALFORMED_NAME + s;
 
171
  return arr[1];
 
172
}
 
173
 
 
174
 
 
175
/*
 
176
 * This function is the opposite of functions like escape(), which take
 
177
 * Unicode characters and return escape sequences for them. Here, we force
 
178
 * the lexer to turn escape sequences back into single characters.
 
179
 *
 
180
 * Note we can't simply do |eval(str)|, since in practice |str| will be an
 
181
 * identifier somewhere in the program (e.g. a function name); thus |eval(str)|
 
182
 * would return the object that the identifier represents: not what we want.
 
183
 *
 
184
 * So we surround |str| lexicographically with quotes to force the lexer to
 
185
 * evaluate it as a string. Have to strip out any linefeeds first, however -
 
186
 */
 
187
function condenseStr(str)
 
188
{
 
189
  /*
 
190
   * You won't be able to do the next step if |str| has
 
191
   * any carriage returns or linefeeds in it. For example:
 
192
   *
 
193
   *  js> eval("'" + '\nHello' + "'");
 
194
   *  1: SyntaxError: unterminated string literal:
 
195
   *  1: '
 
196
   *  1: ^
 
197
   *
 
198
   * So replace them with the empty string -
 
199
   */
 
200
  str = str.replace(/[\r\n]/g, '')
 
201
    return eval("'" + str + "'");
 
202
}
 
203
 
 
204
 
 
205
function addThis()
 
206
{
 
207
  statusitems[UBound] = status;
 
208
  actualvalues[UBound] = actual;
 
209
  expectedvalues[UBound] = expect;
 
210
  UBound++;
 
211
}
 
212
 
 
213
 
 
214
function test()
 
215
{
 
216
  enterFunc('test');
 
217
  printBugNumber(BUGNUMBER);
 
218
  printStatus(summary);
 
219
 
 
220
  for (var i=0; i<UBound; i++)
 
221
  {
 
222
    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
 
223
  }
 
224
 
 
225
  exitFunc ('test');
 
226
}