S9.1_A1_T1.js (883B)
1 // Copyright 2009 the Sputnik authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 info: | 6 Result of primitive conversion from object is a default value for the 7 Object 8 es5id: 9.1_A1_T1 9 description: > 10 Using operator Number. The operator calls ToPrimitive with hint 11 Number 12 ---*/ 13 14 // CHECK#1 15 var object = { 16 valueOf: function() { 17 return "1" 18 }, 19 toString: function() { 20 return 0 21 } 22 }; 23 24 assert.sameValue( 25 Number(object), 26 1, 27 'Number({valueOf: function() {return "1"}, toString: function() {return 0}}) must return 1' 28 ); 29 30 // CHECK#2 31 var object = { 32 valueOf: function() { 33 return {} 34 }, 35 toString: function() { 36 return "0" 37 } 38 }; 39 40 assert.sameValue( 41 Number(object), 42 0, 43 'Number({valueOf: function() {return {}}, toString: function() {return "0"}}) must return 0' 44 ); 45 46 reportCompare(0, 0);