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.

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

mercurial