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.3.2-1.js
9 ECMA Section: 15.5.3.2 String.fromCharCode( char0, char1, ... )
10 Description: Return a string value containing as many characters
11 as the number of arguments. Each argument specifies
12 one character of the resulting string, with the first
13 argument specifying the first character, and so on,
14 from left to right. An argument is converted to a
15 character by applying the operation ToUint16_t and
16 regarding the resulting 16bit integeras the Unicode
17 encoding of a character. If no arguments are supplied,
18 the result is the empty string.
20 This test covers Basic Latin (range U+0020 - U+007F)
22 Author: christine@netscape.com
23 Date: 2 october 1997
24 */
26 var SECTION = "15.5.3.2-3";
27 var VERSION = "ECMA_1";
28 startTest();
29 var TITLE = "String.fromCharCode()";
31 writeHeaderToLog( SECTION + " "+ TITLE);
33 for ( CHARCODE = 0; CHARCODE < 256; CHARCODE++ ) {
34 new TestCase( SECTION,
35 "(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)",
36 ToUint16(CHARCODE),
37 (String.fromCharCode(CHARCODE)).charCodeAt(0)
38 );
39 }
40 for ( CHARCODE = 256; CHARCODE < 65536; CHARCODE+=333 ) {
41 new TestCase( SECTION,
42 "(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)",
43 ToUint16(CHARCODE),
44 (String.fromCharCode(CHARCODE)).charCodeAt(0)
45 );
46 }
47 for ( CHARCODE = 65535; CHARCODE < 65538; CHARCODE++ ) {
48 new TestCase( SECTION,
49 "(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)",
50 ToUint16(CHARCODE),
51 (String.fromCharCode(CHARCODE)).charCodeAt(0)
52 );
53 }
54 for ( CHARCODE = Math.pow(2,32)-1; CHARCODE < Math.pow(2,32)+1; CHARCODE++ ) {
55 new TestCase( SECTION,
56 "(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)",
57 ToUint16(CHARCODE),
58 (String.fromCharCode(CHARCODE)).charCodeAt(0)
59 );
60 }
61 for ( CHARCODE = 0; CHARCODE > -65536; CHARCODE-=3333 ) {
62 new TestCase( SECTION,
63 "(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)",
64 ToUint16(CHARCODE),
65 (String.fromCharCode(CHARCODE)).charCodeAt(0)
66 );
67 }
68 new TestCase( SECTION, "(String.fromCharCode(65535)).charCodeAt(0)", 65535, (String.fromCharCode(65535)).charCodeAt(0) );
69 new TestCase( SECTION, "(String.fromCharCode(65536)).charCodeAt(0)", 0, (String.fromCharCode(65536)).charCodeAt(0) );
70 new TestCase( SECTION, "(String.fromCharCode(65537)).charCodeAt(0)", 1, (String.fromCharCode(65537)).charCodeAt(0) );
72 test();
74 function ToUint16( num ) {
75 num = Number( num );
76 if ( isNaN( num ) || num == 0 || num == Number.POSITIVE_INFINITY || num == Number.NEGATIVE_INFINITY ) {
77 return 0;
78 }
80 var sign = ( num < 0 ) ? -1 : 1;
82 num = sign * Math.floor( Math.abs( num ) );
83 num = num % Math.pow(2,16);
84 num = ( num > -65536 && num < 0) ? 65536 + num : num;
85 return num;
86 }