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