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.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | |
michael@0 | 7 | /** |
michael@0 | 8 | File Name: 15.5.3.2-1.js |
michael@0 | 9 | ECMA Section: 15.5.3.2 String.fromCharCode( char0, char1, ... ) |
michael@0 | 10 | Description: Return a string value containing as many characters |
michael@0 | 11 | as the number of arguments. Each argument specifies |
michael@0 | 12 | one character of the resulting string, with the first |
michael@0 | 13 | argument specifying the first character, and so on, |
michael@0 | 14 | from left to right. An argument is converted to a |
michael@0 | 15 | character by applying the operation ToUint16_t and |
michael@0 | 16 | regarding the resulting 16bit integeras the Unicode |
michael@0 | 17 | encoding of a character. If no arguments are supplied, |
michael@0 | 18 | the result is the empty string. |
michael@0 | 19 | |
michael@0 | 20 | This test covers Basic Latin (range U+0020 - U+007F) |
michael@0 | 21 | |
michael@0 | 22 | Author: christine@netscape.com |
michael@0 | 23 | Date: 2 october 1997 |
michael@0 | 24 | */ |
michael@0 | 25 | |
michael@0 | 26 | var SECTION = "15.5.3.2-3"; |
michael@0 | 27 | var VERSION = "ECMA_1"; |
michael@0 | 28 | startTest(); |
michael@0 | 29 | var TITLE = "String.fromCharCode()"; |
michael@0 | 30 | |
michael@0 | 31 | writeHeaderToLog( SECTION + " "+ TITLE); |
michael@0 | 32 | |
michael@0 | 33 | for ( CHARCODE = 0; CHARCODE < 256; CHARCODE++ ) { |
michael@0 | 34 | new TestCase( SECTION, |
michael@0 | 35 | "(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)", |
michael@0 | 36 | ToUint16(CHARCODE), |
michael@0 | 37 | (String.fromCharCode(CHARCODE)).charCodeAt(0) |
michael@0 | 38 | ); |
michael@0 | 39 | } |
michael@0 | 40 | for ( CHARCODE = 256; CHARCODE < 65536; CHARCODE+=333 ) { |
michael@0 | 41 | new TestCase( SECTION, |
michael@0 | 42 | "(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)", |
michael@0 | 43 | ToUint16(CHARCODE), |
michael@0 | 44 | (String.fromCharCode(CHARCODE)).charCodeAt(0) |
michael@0 | 45 | ); |
michael@0 | 46 | } |
michael@0 | 47 | for ( CHARCODE = 65535; CHARCODE < 65538; CHARCODE++ ) { |
michael@0 | 48 | new TestCase( SECTION, |
michael@0 | 49 | "(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)", |
michael@0 | 50 | ToUint16(CHARCODE), |
michael@0 | 51 | (String.fromCharCode(CHARCODE)).charCodeAt(0) |
michael@0 | 52 | ); |
michael@0 | 53 | } |
michael@0 | 54 | for ( CHARCODE = Math.pow(2,32)-1; CHARCODE < Math.pow(2,32)+1; CHARCODE++ ) { |
michael@0 | 55 | new TestCase( SECTION, |
michael@0 | 56 | "(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)", |
michael@0 | 57 | ToUint16(CHARCODE), |
michael@0 | 58 | (String.fromCharCode(CHARCODE)).charCodeAt(0) |
michael@0 | 59 | ); |
michael@0 | 60 | } |
michael@0 | 61 | for ( CHARCODE = 0; CHARCODE > -65536; CHARCODE-=3333 ) { |
michael@0 | 62 | new TestCase( SECTION, |
michael@0 | 63 | "(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)", |
michael@0 | 64 | ToUint16(CHARCODE), |
michael@0 | 65 | (String.fromCharCode(CHARCODE)).charCodeAt(0) |
michael@0 | 66 | ); |
michael@0 | 67 | } |
michael@0 | 68 | new TestCase( SECTION, "(String.fromCharCode(65535)).charCodeAt(0)", 65535, (String.fromCharCode(65535)).charCodeAt(0) ); |
michael@0 | 69 | new TestCase( SECTION, "(String.fromCharCode(65536)).charCodeAt(0)", 0, (String.fromCharCode(65536)).charCodeAt(0) ); |
michael@0 | 70 | new TestCase( SECTION, "(String.fromCharCode(65537)).charCodeAt(0)", 1, (String.fromCharCode(65537)).charCodeAt(0) ); |
michael@0 | 71 | |
michael@0 | 72 | test(); |
michael@0 | 73 | |
michael@0 | 74 | function ToUint16( num ) { |
michael@0 | 75 | num = Number( num ); |
michael@0 | 76 | if ( isNaN( num ) || num == 0 || num == Number.POSITIVE_INFINITY || num == Number.NEGATIVE_INFINITY ) { |
michael@0 | 77 | return 0; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | var sign = ( num < 0 ) ? -1 : 1; |
michael@0 | 81 | |
michael@0 | 82 | num = sign * Math.floor( Math.abs( num ) ); |
michael@0 | 83 | num = num % Math.pow(2,16); |
michael@0 | 84 | num = ( num > -65536 && num < 0) ? 65536 + num : num; |
michael@0 | 85 | return num; |
michael@0 | 86 | } |
michael@0 | 87 |