| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
gTestfile = '9.7.js'; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
var SECTION = "9.7"; |
| 27 |
var VERSION = "ECMA_1"; |
| 28 |
startTest(); |
| 29 |
|
| 30 |
writeHeaderToLog( SECTION + " Type Conversion: ToInt16"); |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
new TestCase( "9.7", "String.fromCharCode(0).charCodeAt(0)", ToInt16(0), String.fromCharCode(0).charCodeAt(0) ); |
| 49 |
new TestCase( "9.7", "String.fromCharCode(-0).charCodeAt(0)", ToInt16(0), String.fromCharCode(-0).charCodeAt(0) ); |
| 50 |
new TestCase( "9.7", "String.fromCharCode(1).charCodeAt(0)", ToInt16(1), String.fromCharCode(1).charCodeAt(0) ); |
| 51 |
new TestCase( "9.7", "String.fromCharCode(64).charCodeAt(0)", ToInt16(64), String.fromCharCode(64).charCodeAt(0) ); |
| 52 |
new TestCase( "9.7", "String.fromCharCode(126).charCodeAt(0)", ToInt16(126), String.fromCharCode(126).charCodeAt(0) ); |
| 53 |
new TestCase( "9.7", "String.fromCharCode(127).charCodeAt(0)", ToInt16(127), String.fromCharCode(127).charCodeAt(0) ); |
| 54 |
new TestCase( "9.7", "String.fromCharCode(128).charCodeAt(0)", ToInt16(128), String.fromCharCode(128).charCodeAt(0) ); |
| 55 |
new TestCase( "9.7", "String.fromCharCode(130).charCodeAt(0)", ToInt16(130), String.fromCharCode(130).charCodeAt(0) ); |
| 56 |
new TestCase( "9.7", "String.fromCharCode(255).charCodeAt(0)", ToInt16(255), String.fromCharCode(255).charCodeAt(0) ); |
| 57 |
new TestCase( "9.7", "String.fromCharCode(256).charCodeAt(0)", ToInt16(256), String.fromCharCode(256).charCodeAt(0) ); |
| 58 |
|
| 59 |
new TestCase( "9.7", "String.fromCharCode(Math.pow(2,16)-1).charCodeAt(0)", 65535, String.fromCharCode(Math.pow(2,16)-1).charCodeAt(0) ); |
| 60 |
new TestCase( "9.7", "String.fromCharCode(Math.pow(2,16)).charCodeAt(0)", 0, String.fromCharCode(Math.pow(2,16)).charCodeAt(0) ); |
| 61 |
|
| 62 |
new TestCase( "9.7", "String.fromCharCode(65535).charCodeAt(0)", ToInt16(65535), String.fromCharCode(65535).charCodeAt(0) ); |
| 63 |
new TestCase( "9.7", "String.fromCharCode(65536).charCodeAt(0)", ToInt16(65536), String.fromCharCode(65536).charCodeAt(0) ); |
| 64 |
new TestCase( "9.7", "String.fromCharCode(65537).charCodeAt(0)", ToInt16(65537), String.fromCharCode(65537).charCodeAt(0) ); |
| 65 |
|
| 66 |
new TestCase( "9.7", "String.fromCharCode(131071).charCodeAt(0)", ToInt16(131071), String.fromCharCode(131071).charCodeAt(0) ); |
| 67 |
new TestCase( "9.7", "String.fromCharCode(131072).charCodeAt(0)", ToInt16(131072), String.fromCharCode(131072).charCodeAt(0) ); |
| 68 |
new TestCase( "9.7", "String.fromCharCode(131073).charCodeAt(0)", ToInt16(131073), String.fromCharCode(131073).charCodeAt(0) ); |
| 69 |
|
| 70 |
new TestCase( "9.7", "String.fromCharCode('65535').charCodeAt(0)", 65535, String.fromCharCode("65535").charCodeAt(0) ); |
| 71 |
new TestCase( "9.7", "String.fromCharCode('65536').charCodeAt(0)", 0, String.fromCharCode("65536").charCodeAt(0) ); |
| 72 |
|
| 73 |
new TestCase( "9.7", "String.fromCharCode(-1).charCodeAt(0)", ToInt16(-1), String.fromCharCode(-1).charCodeAt(0) ); |
| 74 |
new TestCase( "9.7", "String.fromCharCode(-64).charCodeAt(0)", ToInt16(-64), String.fromCharCode(-64).charCodeAt(0) ); |
| 75 |
new TestCase( "9.7", "String.fromCharCode(-126).charCodeAt(0)", ToInt16(-126), String.fromCharCode(-126).charCodeAt(0) ); |
| 76 |
new TestCase( "9.7", "String.fromCharCode(-127).charCodeAt(0)", ToInt16(-127), String.fromCharCode(-127).charCodeAt(0) ); |
| 77 |
new TestCase( "9.7", "String.fromCharCode(-128).charCodeAt(0)", ToInt16(-128), String.fromCharCode(-128).charCodeAt(0) ); |
| 78 |
new TestCase( "9.7", "String.fromCharCode(-130).charCodeAt(0)", ToInt16(-130), String.fromCharCode(-130).charCodeAt(0) ); |
| 79 |
new TestCase( "9.7", "String.fromCharCode(-255).charCodeAt(0)", ToInt16(-255), String.fromCharCode(-255).charCodeAt(0) ); |
| 80 |
new TestCase( "9.7", "String.fromCharCode(-256).charCodeAt(0)", ToInt16(-256), String.fromCharCode(-256).charCodeAt(0) ); |
| 81 |
|
| 82 |
new TestCase( "9.7", "String.fromCharCode(-Math.pow(2,16)-1).charCodeAt(0)", 65535, String.fromCharCode(-Math.pow(2,16)-1).charCodeAt(0) ); |
| 83 |
new TestCase( "9.7", "String.fromCharCode(-Math.pow(2,16)).charCodeAt(0)", 0, String.fromCharCode(-Math.pow(2,16)).charCodeAt(0) ); |
| 84 |
|
| 85 |
new TestCase( "9.7", "String.fromCharCode(-65535).charCodeAt(0)", ToInt16(-65535), String.fromCharCode(-65535).charCodeAt(0) ); |
| 86 |
new TestCase( "9.7", "String.fromCharCode(-65536).charCodeAt(0)", ToInt16(-65536), String.fromCharCode(-65536).charCodeAt(0) ); |
| 87 |
new TestCase( "9.7", "String.fromCharCode(-65537).charCodeAt(0)", ToInt16(-65537), String.fromCharCode(-65537).charCodeAt(0) ); |
| 88 |
|
| 89 |
new TestCase( "9.7", "String.fromCharCode(-131071).charCodeAt(0)", ToInt16(-131071), String.fromCharCode(-131071).charCodeAt(0) ); |
| 90 |
new TestCase( "9.7", "String.fromCharCode(-131072).charCodeAt(0)", ToInt16(-131072), String.fromCharCode(-131072).charCodeAt(0) ); |
| 91 |
new TestCase( "9.7", "String.fromCharCode(-131073).charCodeAt(0)", ToInt16(-131073), String.fromCharCode(-131073).charCodeAt(0) ); |
| 92 |
|
| 93 |
new TestCase( "9.7", "String.fromCharCode('-65535').charCodeAt(0)", ToInt16(-65535), String.fromCharCode("-65535").charCodeAt(0) ); |
| 94 |
new TestCase( "9.7", "String.fromCharCode('-65536').charCodeAt(0)", ToInt16(-65536), String.fromCharCode("-65536").charCodeAt(0) ); |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
test(); |
| 110 |
|
| 111 |
function ToInt16( num ) { |
| 112 |
num = Number( num ); |
| 113 |
if ( isNaN( num ) || num == 0 || num == Number.POSITIVE_INFINITY || num == Number.NEGATIVE_INFINITY ) { |
| 114 |
return 0; |
| 115 |
} |
| 116 |
|
| 117 |
var sign = ( num < 0 ) ? -1 : 1; |
| 118 |
|
| 119 |
num = sign * Math.floor( Math.abs( num ) ); |
| 120 |
|
| 121 |
num = num % Math.pow(2,16); |
| 122 |
|
| 123 |
num = ( num > -65536 && num < 0) ? 65536 + num : num; |
| 124 |
|
| 125 |
return num; |
| 126 |
} |
| 127 |
|