michael@0: // Copyright 2009 the Sputnik authors. All rights reserved. michael@0: // This code is governed by the BSD license found in the LICENSE file. michael@0: michael@0: /** michael@0: * Operator uses ToNumber michael@0: * michael@0: * @path ch09/9.7/S9.7_A3.1_T4.js michael@0: * @description Type(x) is Object michael@0: */ michael@0: michael@0: //CHECK#1 michael@0: var object = {valueOf: function() {return 1}}; michael@0: if (String.fromCharCode(object).charCodeAt(0) !== 1) { michael@0: $ERROR('#1: var object = {valueOf: function() {return 1}}; String.fromCharCode(object).charCodeAt(0) === 1. Actual: ' + (String.fromCharCode(object).charCodeAt(0))); michael@0: } michael@0: michael@0: //CHECK#2 michael@0: var object = {valueOf: function() {return 1}, toString: function() {return 0}}; michael@0: if (String.fromCharCode(object).charCodeAt(0) !== 1) { michael@0: $ERROR('#2: var object = {valueOf: function() {return 1}, toString: function() {return 0}}; String.fromCharCode(object).charCodeAt(0) === 1. Actual: ' + (String.fromCharCode(object).charCodeAt(0))); michael@0: } michael@0: michael@0: //CHECK#3 michael@0: var object = {valueOf: function() {return 1}, toString: function() {return {}}}; michael@0: if (String.fromCharCode(object).charCodeAt(0) !== 1) { michael@0: $ERROR('#3: var object = {valueOf: function() {return 1}, toString: function() {return {}}}; String.fromCharCode(object).charCodeAt(0) === 1. Actual: ' + (String.fromCharCode(object).charCodeAt(0))); michael@0: } michael@0: michael@0: //CHECK#4 michael@0: try { michael@0: var object = {valueOf: function() {return 1}, toString: function() {throw "error"}}; michael@0: if (String.fromCharCode(object).charCodeAt(0) !== 1) { michael@0: $ERROR('#4.1: var object = {valueOf: function() {return 1}, toString: function() {throw "error"}}; String.fromCharCode(object).charCodeAt(0) === 1. Actual: ' + (String.fromCharCode(object).charCodeAt(0))); michael@0: } michael@0: } michael@0: catch (e) { michael@0: if (e === "error") { michael@0: $ERROR('#4.2: var object = {valueOf: function() {return 1}, toString: function() {throw "error"}}; object not throw "error"'); michael@0: } else { michael@0: $ERROR('#4.3: var object = {valueOf: function() {return 1}, toString: function() {throw "error"}}; object not throw Error. Actual: ' + (e)); michael@0: } michael@0: } michael@0: michael@0: //CHECK#5 michael@0: var object = {toString: function() {return 1}}; michael@0: if (String.fromCharCode(object).charCodeAt(0) !== 1) { michael@0: $ERROR('#5: var object = {toString: function() {return 1}}; String.fromCharCode(object).charCodeAt(0) === 1. Actual: ' + (String.fromCharCode(object).charCodeAt(0))); michael@0: } michael@0: michael@0: //CHECK#6 michael@0: var object = {valueOf: function() {return {}}, toString: function() {return 1}} michael@0: if (String.fromCharCode(object).charCodeAt(0) !== 1) { michael@0: $ERROR('#6: var object = {valueOf: function() {return {}}, toString: function() {return 1}}; String.fromCharCode(object).charCodeAt(0) === 1. Actual: ' + (String.fromCharCode(object).charCodeAt(0))); michael@0: } michael@0: michael@0: //CHECK#7 michael@0: try { michael@0: var object = {valueOf: function() {throw "error"}, toString: function() {return 1}}; michael@0: object >>> 0; michael@0: $ERROR('#7.1: var object = {valueOf: function() {throw "error"}, toString: function() {return 1}}; object throw "error". Actual: ' + (object >>> 0)); michael@0: } michael@0: catch (e) { michael@0: if (e !== "error") { michael@0: $ERROR('#7.2: var object = {valueOf: function() {throw "error"}, toString: function() {return 1}}; object throw "error". Actual: ' + (e)); michael@0: } michael@0: } michael@0: michael@0: //CHECK#8 michael@0: try { michael@0: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; michael@0: object >>> 0; michael@0: $ERROR('#8.1: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; object throw TypeError. Actual: ' + (object >>> 0)); michael@0: } michael@0: catch (e) { michael@0: if ((e instanceof TypeError) !== true) { michael@0: $ERROR('#8.2: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; object throw TypeError. Actual: ' + (e)); michael@0: } michael@0: } michael@0: