js/src/tests/test262/ch09/9.8/S9.8_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.

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 String conversion from Object value is conversion
michael@0 6 * from primitive value
michael@0 7 *
michael@0 8 * @path ch09/9.8/S9.8_A5_T2.js
michael@0 9 * @description Some objects convert to String by implicit transformation
michael@0 10 */
michael@0 11
michael@0 12 // CHECK#1
michael@0 13 if (new Number() + "" !== "0") {
michael@0 14 $ERROR('#1: new Number() + "" === "0". Actual: ' + (new Number() + ""));
michael@0 15 }
michael@0 16
michael@0 17 // CHECK#2
michael@0 18 if (new Number(0) + "" !== "0") {
michael@0 19 $ERROR('#2: new Number(0) + "" === "0". Actual: ' + (new Number(0) + ""));
michael@0 20 }
michael@0 21
michael@0 22 // CHECK#3
michael@0 23 if (new Number(Number.NaN) + "" !== "NaN") {
michael@0 24 $ERROR('#3: new Number(Number.NaN) + "" === "NaN". Actual: ' + (new Number(Number.NaN) + ""));
michael@0 25 }
michael@0 26
michael@0 27 // CHECK#4
michael@0 28 if (new Number(null) + "" !== "0") {
michael@0 29 $ERROR('#4: new Number(null) + "" === "0". Actual: ' + (new Number(null) + ""));
michael@0 30 }
michael@0 31
michael@0 32 // CHECK#5
michael@0 33 if (new Number(void 0) + "" !== "NaN") {
michael@0 34 $ERROR('#5: new Number(void 0) + "" === "NaN. Actual: ' + (new Number(void 0) + ""));
michael@0 35 }
michael@0 36
michael@0 37 // CHECK#6
michael@0 38 if (new Number(true) + "" !== "1") {
michael@0 39 $ERROR('#6: new Number(true) + "" === "1". Actual: ' + (new Number(true) + ""));
michael@0 40 }
michael@0 41
michael@0 42 // CHECK#7
michael@0 43 if (new Number(false) + "" !== "0") {
michael@0 44 $ERROR('#7: new Number(false) + "" === "0". Actual: ' + (new Number(false) + ""));
michael@0 45 }
michael@0 46
michael@0 47 // CHECK#8
michael@0 48 if (new Boolean(true) + "" !== "true") {
michael@0 49 $ERROR('#8: new Boolean(true) + "" === "true". Actual: ' + (new Boolean(true) + ""));
michael@0 50 }
michael@0 51
michael@0 52 // CHECK#9
michael@0 53 if (new Boolean(false) + "" !== "false") {
michael@0 54 $ERROR('#9: Number(new Boolean(false)) === "false". Actual: ' + (Number(new Boolean(false))));
michael@0 55 }
michael@0 56
michael@0 57 // CHECK#10
michael@0 58 if (new Array(2,4,8,16,32) + "" !== "2,4,8,16,32") {
michael@0 59 $ERROR('#10: new Array(2,4,8,16,32) + "" === "2,4,8,16,32". Actual: ' + (new Array(2,4,8,16,32) + ""));
michael@0 60 }
michael@0 61
michael@0 62 // CHECK#11
michael@0 63 var myobj1 = {
michael@0 64 toNumber : function(){return 12345;},
michael@0 65 toString : function(){return 67890;},
michael@0 66 valueOf : function(){return "[object MyObj]";}
michael@0 67 };
michael@0 68
michael@0 69 if (myobj1 + "" !== "[object MyObj]"){
michael@0 70 $ERROR('#11: myobj1 + "" calls ToPrimitive with hint Number. Exptected: "[object MyObj]". Actual: ' + (myobj1 + ""));
michael@0 71 }
michael@0 72
michael@0 73 // CHECK#12
michael@0 74 var myobj2 = {
michael@0 75 toNumber : function(){return 12345;},
michael@0 76 toString : function(){return 67890},
michael@0 77 valueOf : function(){return {}}
michael@0 78 };
michael@0 79
michael@0 80 if (myobj2 + "" !== "67890"){
michael@0 81 $ERROR('#12: myobj2 + "" calls ToPrimitive with hint Number. Exptected: "67890". Actual: ' + (myobj2 + ""));
michael@0 82 }
michael@0 83
michael@0 84 // CHECK#13
michael@0 85 var myobj3 = {
michael@0 86 toNumber : function(){return 12345;}
michael@0 87 };
michael@0 88
michael@0 89 if (myobj3 + "" !== "[object Object]"){
michael@0 90 $ERROR('#13: myobj3 + "" calls ToPrimitive with hint Number. Exptected: "[object Object]". Actual: ' + (myobj3 + ""));
michael@0 91 }
michael@0 92

mercurial