js/src/tests/test262/ch09/9.3/S9.3_A5_T2.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

     1 // Copyright 2009 the Sputnik authors.  All rights reserved.
     2 // This code is governed by the BSD license found in the LICENSE file.
     4 /**
     5  * Result of number conversion from object value is the result
     6  * of conversion from primitive value
     7  *
     8  * @path ch09/9.3/S9.3_A5_T2.js
     9  * @description new Number(), new Number(0), new Number(Number.NaN), new Number(null),
    10  * new Number(void 0) and others convert to Number by implicit transformation
    11  */
    13 // CHECK#1
    14 if (+(new Number()) !== 0) {
    15   $ERROR('#1: +(new Number()) === 0. Actual: ' + (+(new Number())));
    16 }
    18 // CHECK#2
    19 if (+(new Number(0)) !== 0) {
    20   $ERROR('#2: +(new Number(0)) === 0. Actual: ' + (+(new Number(0))));
    21 }
    23 // CHECK#3
    24 if (isNaN(+(new Number(Number.NaN)) !== true)) {
    25   $ERROR('#3: +(new Number(Number.NaN)) === Not-a-Number. Actual: ' + (+(new Number(Number.NaN))));
    26 }
    28 // CHECK#4
    29 if (+(new Number(null)) !== 0) {
    30   $ERROR('#4.1: +(new Number(null)) === 0. Actual: ' + (+(new Number(null)))); 
    31 } else {
    32   if (1/+(new Number(null)) !== Number.POSITIVE_INFINITY) {
    33     $ERROR('#4.2: +(new Number(null)) === +0. Actual: -0');
    34   }	
    35 }
    37 // CHECK#5
    38 if (isNaN(+(new Number(void 0)) !== true)) {
    39   $ERROR('#5: +(new Number(void 0)) === Not-a-Number. Actual: ' + (+(new Number(void 0))));
    40 }
    42 // CHECK#6
    43 if (+(new Number(true)) !== 1) {
    44   $ERROR('#6: +(new Number(true)) === 1. Actual: ' + (+(new Number(true))));
    45 }
    47 // CHECK#7
    48 if (+(new Number(false)) !== +0) {
    49   $ERROR('#7.1: +(new Number(false)) === 0. Actual: ' + (+(new Number(false))));
    50 } else {
    51   if (1/+(new Number(false)) !== Number.POSITIVE_INFINITY) {
    52     $ERROR('#7.2: +(new Number(false)) === +0. Actual: -0');
    53   }
    54 }
    56 // CHECK#8
    57 if (+(new Boolean(true)) !== 1) {
    58   $ERROR('#8: +(new Boolean(true)) === 1. Actual: ' + (+(new Boolean(true))));
    59 }
    61 // CHECK#9
    62 if (+(new Boolean(false)) !== +0) {
    63   $ERROR('#9.1: +(new Boolean(false)) === 0. Actual: ' + (+(new Boolean(false))));
    64 } else {
    65   if (1/+(new Boolean(false)) !== Number.POSITIVE_INFINITY) {
    66     $ERROR('#9.2: +(new Boolean(false)) === +0. Actual: -0');
    67   }
    68 }
    70 // CHECK#10
    71 if (isNaN(+(new Array(2,4,8,16,32))) !== true) {
    72   $ERROR('#10: +(new Array(2,4,8,16,32)) === Not-a-Number. Actual: ' + (+(new Array(2,4,8,16,32))));
    73 }
    75 // CHECK#11
    76 var myobj1 = {
    77                 ToNumber : function(){return 12345;}, 
    78                 toString : function(){return "67890";},
    79                 valueOf  : function(){return "[object MyObj]";} 
    80             };
    82 if (isNaN(+(myobj1)) !== true){
    83   $ERROR("#11: +(myobj1) calls ToPrimitive with hint +. Exptected: Not-a-Number. Actual: " + (+(myobj1)));
    84 }
    86 // CHECK#12
    87 var myobj2 = {
    88                 ToNumber : function(){return 12345;}, 
    89                 toString : function(){return "67890";},
    90                 valueOf  : function(){return "9876543210";} 
    91             };
    93 if (+(myobj2) !== 9876543210){
    94   $ERROR("#12: +(myobj2) calls ToPrimitive with hint +. Exptected: 9876543210. Actual: " + (+(myobj2)));
    95 }
    98 // CHECK#13
    99 var myobj3 = {
   100                 ToNumber : function(){return 12345;}, 
   101                 toString : function(){return "[object MyObj]";} 
   102             };
   104 if (isNaN(+(myobj3)) !== true){
   105   $ERROR("#13: +(myobj3) calls ToPrimitive with hint +. Exptected: Not-a-Number. Actual: " + (+(myobj3)));
   106 }
   108 // CHECK#14
   109 var myobj4 = {
   110                 ToNumber : function(){return 12345;}, 
   111                 toString : function(){return "67890";} 
   112             };
   114 if (+(myobj4) !== 67890){
   115   $ERROR("#14: +(myobj4) calls ToPrimitive with hint +. Exptected: 67890. Actual: " + (+(myobj4)));
   116 }
   118 // CHECK#15
   119 var myobj5 = {
   120                 ToNumber : function(){return 12345;} 
   121             };
   123 if (isNaN(+(myobj5)) !== true){
   124   $ERROR("#15: +(myobj5) calls ToPrimitive with hint +. Exptected: 12345. Actual: " + (+(myobj5)));
   125 }

mercurial