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: * If Type(x) is primitive type and Type(y) is Object, michael@0: * return x == ToPrimitive(y) michael@0: * michael@0: * @path ch11/11.9/11.9.1/S11.9.1_A7.9.js michael@0: * @description y is object, x is primtitive michael@0: */ michael@0: michael@0: //CHECK#1 michael@0: if ((true == {valueOf: function() {return 1}}) !== true) { michael@0: $ERROR('#1: (true == {valueOf: function() {return 1}}) === true'); michael@0: } michael@0: michael@0: //CHECK#2 michael@0: if ((1 == {valueOf: function() {return 1}, toString: function() {return 0}}) !== true) { michael@0: $ERROR('#2: (1 == {valueOf: function() {return 1}, toString: function() {return 0}}) === true'); michael@0: } michael@0: michael@0: //CHECK#3 michael@0: if (("+1" == {valueOf: function() {return 1}, toString: function() {return {}}}) !== true) { michael@0: $ERROR('#3: ("+1" == {valueOf: function() {return 1}, toString: function() {return {}}}) === true'); michael@0: } michael@0: michael@0: //CHECK#4 michael@0: try { michael@0: if ((true == {valueOf: function() {return "+1"}, toString: function() {throw "error"}}) !== true) { michael@0: $ERROR('#4.1: (true == {valueOf: function() {return "+1"}, toString: function() {throw "error"}}) === true'); michael@0: } michael@0: } michael@0: catch (e) { michael@0: if (e === "error") { michael@0: $ERROR('#4.2: (true == {valueOf: function() {return "+1"}, toString: function() {throw "error"}}) not throw "error"'); michael@0: } else { michael@0: $ERROR('#4.3: (true == {valueOf: function() {return "+1"}, toString: function() {throw "error"}}) not throw Error. Actual: ' + (e)); michael@0: } michael@0: } michael@0: michael@0: //CHECK#5 michael@0: if ((1 == {toString: function() {return "+1"}}) !== true) { michael@0: $ERROR('#5: (1 == {toString: function() {return "+1"}}) === true'); michael@0: } michael@0: michael@0: //CHECK#6 michael@0: if (("1" == {valueOf: function() {return {}}, toString: function() {return "+1"}}) !== false) { michael@0: $ERROR('#6.1: ("1" == {valueOf: function() {return {}}, toString: function() {return "+1"}}) === false'); michael@0: } else { michael@0: if (("+1" == {valueOf: function() {return {}}, toString: function() {return "+1"}}) !== true) { michael@0: $ERROR('#6.2: ("+1" == {valueOf: function() {return {}}, toString: function() {return "+1"}}) === true'); michael@0: } michael@0: } michael@0: michael@0: //CHECK#7 michael@0: try { michael@0: (1 == {valueOf: function() {throw "error"}, toString: function() {return 1}}); michael@0: $ERROR('#7.1: (1 == {valueOf: function() {throw "error"}, toString: function() {return 1}}) throw "error". Actual: ' + ((1 == {valueOf: function() {throw "error"}, toString: function() {return 1}}))); michael@0: } michael@0: catch (e) { michael@0: if (e !== "error") { michael@0: $ERROR('#7.2: (1 == {valueOf: function() {throw "error"}, toString: function() {return 1}}) throw "error". Actual: ' + (e)); michael@0: } michael@0: } michael@0: michael@0: //CHECK#8 michael@0: try { michael@0: (1 == {valueOf: function() {return {}}, toString: function() {return {}}}); michael@0: $ERROR('#8.1: (1 == {valueOf: function() {return {}}, toString: function() {return {}}}) throw TypeError. Actual: ' + ((1 == {valueOf: function() {return {}}, toString: function() {return {}}}))); michael@0: } michael@0: catch (e) { michael@0: if ((e instanceof TypeError) !== true) { michael@0: $ERROR('#8.2: (1 == {valueOf: function() {return {}}, toString: function() {return {}}}) throw TypeError. Actual: ' + (e)); michael@0: } michael@0: } michael@0: