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 -x uses [[Default Value]] michael@0: * michael@0: * @path ch11/11.4/11.4.7/S11.4.7_A2.2_T1.js michael@0: * @description If Type(value) is Object, evaluate ToPrimitive(value, Number) michael@0: */ michael@0: michael@0: //CHECK#1 michael@0: var object = {valueOf: function() {return -1}}; michael@0: if (-object !== 1) { michael@0: $ERROR('#1: var object = {valueOf: function() {return -1}}; -object === 1. Actual: ' + (-object)); michael@0: } michael@0: michael@0: //CHECK#2 michael@0: var object = {valueOf: function() {return -1}, toString: function() {return 0}}; michael@0: if (-object !== 1) { michael@0: $ERROR('#2: var object = {valueOf: function() {return -1}, toString: function() {return 0}}; -object === 1. Actual: ' + (-object)); michael@0: } michael@0: michael@0: //CHECK#3 michael@0: var object = {valueOf: function() {return -1}, toString: function() {return {}}}; michael@0: if (-object !== 1) { michael@0: $ERROR('#3: var object = {valueOf: function() {return -1}, toString: function() {return {}}}; -object === 1. Actual: ' + (-object)); 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 (-object !== 1) { michael@0: $ERROR('#4.1: var object = {valueOf: function() {return -1}, toString: function() {throw "error"}}; -object === 1. Actual: ' + (-object)); 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 (-object !== 1) { michael@0: $ERROR('#5.1: var object = {toString: function() {return -1}}; -object === 1. Actual: ' + (-object)); michael@0: } michael@0: michael@0: //CHECK#6 michael@0: var object = {valueOf: function() {return {}}, toString: function() {return -1}} michael@0: if (-object !== 1) { michael@0: $ERROR('#6: var object = {valueOf: function() {return {}}, toString: function() {return -1}}; -object === 1. Actual: ' + (-object)); 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; michael@0: $ERROR('#7.1: var object = {valueOf: function() {throw "error"}, toString: function() {return -1}}; -object throw "error". Actual: ' + (-object)); 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; michael@0: $ERROR('#8.1: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; -object throw TypeError. Actual: ' + (-object)); 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: