S9.1_A1_T2.js (996B)
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_T2 9 description: > 10 Using operator Number. This operator calls ToPrimitive with hint 11 Number 12 ---*/ 13 14 // CHECK#1 15 var object = { 16 valueOf: function() { 17 return 0 18 }, 19 toString: function() { 20 return 1 21 } 22 }; 23 if (String(object) !== "1") { 24 throw new Test262Error('#1: var object = {valueOf: function() {return 0}, toString: function() {return 1}}; String(object) === "1". Actual: ' + (String(object))); 25 } 26 27 // CHECK#2 28 var object = { 29 valueOf: function() { 30 return 0 31 }, 32 toString: function() { 33 return {} 34 } 35 }; 36 if (String(object) !== "0") { 37 throw new Test262Error('#2: var object = {valueOf: function() {return 0}, toString: function() {return {}}}; String(object) === "0". Actual: ' + (String(object))); 38 } 39 40 reportCompare(0, 0);