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

Wed, 31 Dec 2014 07:53:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:53:36 +0100
branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
permissions
-rw-r--r--

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_T1.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 explicit transformation
michael@0 11 */
michael@0 12
michael@0 13 // CHECK#1
michael@0 14 if (Number(new Number()) !== 0) {
michael@0 15 $ERROR('#1: Number(new Number()) === 0. Actual: ' + (Number(new Number())));
michael@0 16 }
michael@0 17
michael@0 18 // CHECK#2
michael@0 19 if (Number(new Number(0)) !== 0) {
michael@0 20 $ERROR('#2: Number(new Number(0)) === 0. Actual: ' + (Number(new Number(0))));
michael@0 21 }
michael@0 22
michael@0 23 // CHECK#3
michael@0 24 if (isNaN(Number(new Number(Number.NaN)) !== true)) {
michael@0 25 $ERROR('#3: Number(new Number(Number.NaN)) === Not-a-Number. Actual: ' + (Number(new Number(Number.NaN))));
michael@0 26 }
michael@0 27
michael@0 28 // CHECK#4
michael@0 29 if (Number(new Number(null)) !== 0) {
michael@0 30 $ERROR('#4.1: Number(new Number(null)) === 0. Actual: ' + (Number(new Number(null))));
michael@0 31 } else {
michael@0 32 if (1/Number(new Number(null)) !== Number.POSITIVE_INFINITY) {
michael@0 33 $ERROR('#4.2: Number(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(Number(new Number(void 0)) !== true)) {
michael@0 39 $ERROR('#5: Number(new Number(void 0)) === Not-a-Number. Actual: ' + (Number(new Number(void 0))));
michael@0 40 }
michael@0 41
michael@0 42 // CHECK#6
michael@0 43 if (Number(new Number(true)) !== 1) {
michael@0 44 $ERROR('#6: Number(new Number(true)) === 1. Actual: ' + (Number(new Number(true))));
michael@0 45 }
michael@0 46
michael@0 47 // CHECK#7
michael@0 48 if (Number(new Number(false)) !== +0) {
michael@0 49 $ERROR('#7.1: Number(new Number(false)) === 0. Actual: ' + (Number(new Number(false))));
michael@0 50 } else {
michael@0 51 if (1/Number(new Number(false)) !== Number.POSITIVE_INFINITY) {
michael@0 52 $ERROR('#7.2: Number(new Number(false)) === +0. Actual: -0');
michael@0 53 }
michael@0 54 }
michael@0 55
michael@0 56 // CHECK#8
michael@0 57 if (Number(new Boolean(true)) !== 1) {
michael@0 58 $ERROR('#8: Number(new Boolean(true)) === 1. Actual: ' + (Number(new Boolean(true))));
michael@0 59 }
michael@0 60
michael@0 61 // CHECK#9
michael@0 62 if (Number(new Boolean(false)) !== +0) {
michael@0 63 $ERROR('#9.1: Number(new Boolean(false)) === 0. Actual: ' + (Number(new Boolean(false))));
michael@0 64 } else {
michael@0 65 if (1/Number(new Boolean(false)) !== Number.POSITIVE_INFINITY) {
michael@0 66 $ERROR('#9.2: Number(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(Number(new Array(2,4,8,16,32))) !== true) {
michael@0 72 $ERROR('#10: Number(new Array(2,4,8,16,32)) === Not-a-Number. Actual: ' + (Number(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(Number(myobj1)) !== true){
michael@0 83 $ERROR("#11: Number(myobj1) calls ToPrimitive with hint Number. Actual: " + (Number(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 (Number(myobj2) !== 9876543210){
michael@0 94 $ERROR("#12: Number(myobj2) calls ToPrimitive with hint Number. Exptected: 9876543210. Actual: " + (Number(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(Number(myobj3)) !== true){
michael@0 105 $ERROR("#13: Number(myobj3) calls ToPrimitive with hint Number. Exptected: Not-a-Number. Actual: " + (Number(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 (Number(myobj4) !== 67890){
michael@0 115 $ERROR("#14: Number(myobj4) calls ToPrimitive with hint Number. Exptected: 67890. Actual: " + (Number(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(Number(myobj5)) !== true){
michael@0 124 $ERROR("#15: Number(myobj5) calls ToPrimitive with hint Number. Exptected: Not-a-Number. Actual: " + (Number(myobj5)));
michael@0 125 }
michael@0 126

mercurial