Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
7 /**
8 File Name: 15.5.4.12-1.js
9 ECMA Section: 15.5.4.12 String.prototype.toUpperCase()
10 Description:
12 Returns a string equal in length to the length of the result of converting
13 this object to a string. The result is a string value, not a String object.
15 Every character of the result is equal to the corresponding character of the
16 string, unless that character has a Unicode 2.0 uppercase equivalent, in which
17 case the uppercase equivalent is used instead. (The canonical Unicode 2.0 case
18 mapping shall be used, which does not depend on implementation or locale.)
20 Note that the toUpperCase function is intentionally generic; it does not require
21 that its this value be a String object. Therefore it can be transferred to other
22 kinds of objects for use as a method.
24 Author: christine@netscape.com
25 Date: 12 november 1997
26 */
28 var SECTION = "15.5.4.12-1";
29 var VERSION = "ECMA_1";
30 startTest();
31 var TITLE = "String.prototype.toUpperCase()";
33 writeHeaderToLog( SECTION + " "+ TITLE);
35 // Armenian
36 // Range: U+0530 to U+058F
37 for ( var i = 0x0530; i <= 0x058F; i++ ) {
38 var U = new Unicode( i );
39 /*
40 new TestCase( SECTION,
41 "var s = new String( String.fromCharCode("+i+") ); s.toUpperCase()",
42 String.fromCharCode(U.upper),
43 eval("var s = new String( String.fromCharCode("+i+") ); s.toUpperCase()") );
44 */
45 new TestCase( SECTION,
46 "var s = new String( String.fromCharCode("+i+") ); s.toUpperCase().charCodeAt(0)",
47 U.upper,
48 eval("var s = new String( String.fromCharCode(i) ); s.toUpperCase().charCodeAt(0)") );
50 }
52 test();
54 function MyObject( value ) {
55 this.value = value;
56 this.substring = String.prototype.substring;
57 this.toString = new Function ( "return this.value+''" );
58 }
59 function Unicode( c ) {
60 u = GetUnicodeValues( c );
61 this.upper = u[0];
62 this.lower = u[1]
63 return this;
64 }
65 function GetUnicodeValues( c ) {
66 u = new Array();
68 u[0] = c;
69 u[1] = c;
71 // upper case Basic Latin
73 if ( c >= 0x0041 && c <= 0x005A) {
74 u[0] = c;
75 u[1] = c + 32;
76 return u;
77 }
79 // lower case Basic Latin
80 if ( c >= 0x0061 && c <= 0x007a ) {
81 u[0] = c - 32;
82 u[1] = c;
83 return u;
84 }
86 // upper case Latin-1 Supplement
87 if ( (c >= 0x00C0 && c <= 0x00D6) || (c >= 0x00D8 && c<=0x00DE) ) {
88 u[0] = c;
89 u[1] = c + 32;
90 return u;
91 }
93 // lower case Latin-1 Supplement
94 if ( (c >= 0x00E0 && c <= 0x00F6) || (c >= 0x00F8 && c <= 0x00FE) ) {
95 u[0] = c - 32;
96 u[1] = c;
97 return u;
98 }
99 if ( c == 0x00FF ) {
100 u[0] = 0x0178;
101 u[1] = c;
102 return u;
103 }
104 // Latin Extended A
105 if ( (c >= 0x0100 && c < 0x0138) || (c > 0x0149 && c < 0x0178) ) {
106 // special case for capital I
107 if ( c == 0x0130 ) {
108 u[0] = c;
109 u[1] = 0x0069;
110 return u;
111 }
112 if ( c == 0x0131 ) {
113 u[0] = 0x0049;
114 u[1] = c;
115 return u;
116 }
118 if ( c % 2 == 0 ) {
119 // if it's even, it's a capital and the lower case is c +1
120 u[0] = c;
121 u[1] = c+1;
122 } else {
123 // if it's odd, it's a lower case and upper case is c-1
124 u[0] = c-1;
125 u[1] = c;
126 }
127 return u;
128 }
129 if ( c == 0x0178 ) {
130 u[0] = c;
131 u[1] = 0x00FF;
132 return u;
133 }
135 if ( (c >= 0x0139 && c < 0x0149) || (c > 0x0178 && c < 0x017F) ) {
136 if ( c % 2 == 1 ) {
137 // if it's odd, it's a capital and the lower case is c +1
138 u[0] = c;
139 u[1] = c+1;
140 } else {
141 // if it's even, it's a lower case and upper case is c-1
142 u[0] = c-1;
143 u[1] = c;
144 }
145 return u;
146 }
147 if ( c == 0x017F ) {
148 u[0] = 0x0053;
149 u[1] = c;
150 }
152 // Latin Extended B
153 // need to improve this set
155 if ( c >= 0x0200 && c <= 0x0217 ) {
156 if ( c % 2 == 0 ) {
157 u[0] = c;
158 u[1] = c+1;
159 } else {
160 u[0] = c-1;
161 u[1] = c;
162 }
163 return u;
164 }
166 // Latin Extended Additional
167 // Range: U+1E00 to U+1EFF
168 // http://www.unicode.org/Unicode.charts/glyphless/U1E00.html
170 // Spacing Modifier Leters
171 // Range: U+02B0 to U+02FF
173 // Combining Diacritical Marks
174 // Range: U+0300 to U+036F
176 // skip Greek for now
177 // Greek
178 // Range: U+0370 to U+03FF
180 // Cyrillic
181 // Range: U+0400 to U+04FF
183 if ( (c >= 0x0401 && c <= 0x040C) || ( c>= 0x040E && c <= 0x040F ) ) {
184 u[0] = c;
185 u[1] = c + 80;
186 return u;
187 }
190 if ( c >= 0x0410 && c <= 0x042F ) {
191 u[0] = c;
192 u[1] = c + 32;
193 return u;
194 }
196 if ( c >= 0x0430 && c<= 0x044F ) {
197 u[0] = c - 32;
198 u[1] = c;
199 return u;
201 }
202 if ( (c >= 0x0451 && c <= 0x045C) || (c >=0x045E && c<= 0x045F) ) {
203 u[0] = c -80;
204 u[1] = c;
205 return u;
206 }
208 if ( c >= 0x0460 && c <= 0x047F ) {
209 if ( c % 2 == 0 ) {
210 u[0] = c;
211 u[1] = c +1;
212 } else {
213 u[0] = c - 1;
214 u[1] = c;
215 }
216 return u;
217 }
219 // Armenian
220 // Range: U+0530 to U+058F
221 if ( c >= 0x0531 && c <= 0x0556 ) {
222 u[0] = c;
223 u[1] = c + 48;
224 return u;
225 }
226 if ( c >= 0x0561 && c < 0x0587 ) {
227 u[0] = c - 48;
228 u[1] = c;
229 return u;
230 }
232 // Hebrew
233 // Range: U+0590 to U+05FF
236 // Arabic
237 // Range: U+0600 to U+06FF
239 // Devanagari
240 // Range: U+0900 to U+097F
243 // Bengali
244 // Range: U+0980 to U+09FF
247 // Gurmukhi
248 // Range: U+0A00 to U+0A7F
251 // Gujarati
252 // Range: U+0A80 to U+0AFF
255 // Oriya
256 // Range: U+0B00 to U+0B7F
257 // no capital / lower case
260 // Tamil
261 // Range: U+0B80 to U+0BFF
262 // no capital / lower case
265 // Telugu
266 // Range: U+0C00 to U+0C7F
267 // no capital / lower case
270 // Kannada
271 // Range: U+0C80 to U+0CFF
272 // no capital / lower case
275 // Malayalam
276 // Range: U+0D00 to U+0D7F
278 // Thai
279 // Range: U+0E00 to U+0E7F
282 // Lao
283 // Range: U+0E80 to U+0EFF
286 // Tibetan
287 // Range: U+0F00 to U+0FBF
289 // Georgian
290 // Range: U+10A0 to U+10F0
291 if ( c >= 0x10A0 && c <= 0x10C5 ) {
292 u[0] = c;
293 u[1] = c + 48;
294 return u;
295 }
296 if ( c >= 0x10D0 && c <= 0x10F5 ) {
297 u[0] = c;
298 u[1] = c;
299 return u;
300 }
302 // Hangul Jamo
303 // Range: U+1100 to U+11FF
305 // Greek Extended
306 // Range: U+1F00 to U+1FFF
307 // skip for now
310 // General Punctuation
311 // Range: U+2000 to U+206F
313 // Superscripts and Subscripts
314 // Range: U+2070 to U+209F
316 // Currency Symbols
317 // Range: U+20A0 to U+20CF
320 // Combining Diacritical Marks for Symbols
321 // Range: U+20D0 to U+20FF
322 // skip for now
325 // Number Forms
326 // Range: U+2150 to U+218F
327 // skip for now
330 // Arrows
331 // Range: U+2190 to U+21FF
333 // Mathematical Operators
334 // Range: U+2200 to U+22FF
336 // Miscellaneous Technical
337 // Range: U+2300 to U+23FF
339 // Control Pictures
340 // Range: U+2400 to U+243F
342 // Optical Character Recognition
343 // Range: U+2440 to U+245F
345 // Enclosed Alphanumerics
346 // Range: U+2460 to U+24FF
348 // Box Drawing
349 // Range: U+2500 to U+257F
351 // Block Elements
352 // Range: U+2580 to U+259F
354 // Geometric Shapes
355 // Range: U+25A0 to U+25FF
357 // Miscellaneous Symbols
358 // Range: U+2600 to U+26FF
360 // Dingbats
361 // Range: U+2700 to U+27BF
363 // CJK Symbols and Punctuation
364 // Range: U+3000 to U+303F
366 // Hiragana
367 // Range: U+3040 to U+309F
369 // Katakana
370 // Range: U+30A0 to U+30FF
372 // Bopomofo
373 // Range: U+3100 to U+312F
375 // Hangul Compatibility Jamo
376 // Range: U+3130 to U+318F
378 // Kanbun
379 // Range: U+3190 to U+319F
382 // Enclosed CJK Letters and Months
383 // Range: U+3200 to U+32FF
385 // CJK Compatibility
386 // Range: U+3300 to U+33FF
388 // Hangul Syllables
389 // Range: U+AC00 to U+D7A3
391 // High Surrogates
392 // Range: U+D800 to U+DB7F
394 // Private Use High Surrogates
395 // Range: U+DB80 to U+DBFF
397 // Low Surrogates
398 // Range: U+DC00 to U+DFFF
400 // Private Use Area
401 // Range: U+E000 to U+F8FF
403 // CJK Compatibility Ideographs
404 // Range: U+F900 to U+FAFF
406 // Alphabetic Presentation Forms
407 // Range: U+FB00 to U+FB4F
409 // Arabic Presentation Forms-A
410 // Range: U+FB50 to U+FDFF
412 // Combining Half Marks
413 // Range: U+FE20 to U+FE2F
415 // CJK Compatibility Forms
416 // Range: U+FE30 to U+FE4F
418 // Small Form Variants
419 // Range: U+FE50 to U+FE6F
421 // Arabic Presentation Forms-B
422 // Range: U+FE70 to U+FEFF
424 // Halfwidth and Fullwidth Forms
425 // Range: U+FF00 to U+FFEF
427 if ( c >= 0xFF21 && c <= 0xFF3A ) {
428 u[0] = c;
429 u[1] = c + 32;
430 return u;
431 }
433 if ( c >= 0xFF41 && c <= 0xFF5A ) {
434 u[0] = c - 32;
435 u[1] = c;
436 return u;
437 }
439 // Specials
440 // Range: U+FFF0 to U+FFFF
442 return u;
443 }
445 function DecimalToHexString( n ) {
446 n = Number( n );
447 var h = "0x";
449 for ( var i = 3; i >= 0; i-- ) {
450 if ( n >= Math.pow(16, i) ){
451 var t = Math.floor( n / Math.pow(16, i));
452 n -= t * Math.pow(16, i);
453 if ( t >= 10 ) {
454 if ( t == 10 ) {
455 h += "A";
456 }
457 if ( t == 11 ) {
458 h += "B";
459 }
460 if ( t == 12 ) {
461 h += "C";
462 }
463 if ( t == 13 ) {
464 h += "D";
465 }
466 if ( t == 14 ) {
467 h += "E";
468 }
469 if ( t == 15 ) {
470 h += "F";
471 }
472 } else {
473 h += String( t );
474 }
475 } else {
476 h += "0";
477 }
478 }
480 return h;
481 }