kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1 | // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | var x = ""; |
| 29 | var v = new Object(); |
| 30 | var w = new Object(); |
| 31 | var vv = function() { x += "hest"; return 1; } |
| 32 | var ww = function() { x += "fisk"; return 2; } |
| 33 | v.valueOf = vv; |
| 34 | w.valueOf = ww; |
| 35 | assertEquals(1, Math.min(v,w)); |
| 36 | assertEquals("hestfisk", x, "min"); |
| 37 | |
| 38 | x = ""; |
| 39 | assertEquals(2, Math.max(v,w)); |
| 40 | assertEquals("hestfisk", x, "max"); |
| 41 | |
| 42 | x = ""; |
| 43 | assertEquals(Math.atan2(1, 2), Math.atan2(v, w)); |
| 44 | // JSC says fiskhest. |
| 45 | assertEquals("hestfisk", x, "atan2"); |
| 46 | |
| 47 | x = ""; |
| 48 | assertEquals(1, Math.pow(v, w)); |
| 49 | assertEquals("hestfisk", x, "pow"); |
| 50 | |
| 51 | var year = { valueOf: function() { x += 1; return 2007; } }; |
| 52 | var month = { valueOf: function() { x += 2; return 2; } }; |
| 53 | var date = { valueOf: function() { x += 3; return 4; } }; |
| 54 | var hours = { valueOf: function() { x += 4; return 13; } }; |
| 55 | var minutes = { valueOf: function() { x += 5; return 50; } }; |
| 56 | var seconds = { valueOf: function() { x += 6; return 0; } }; |
| 57 | var ms = { valueOf: function() { x += 7; return 999; } }; |
| 58 | |
| 59 | x = ""; |
| 60 | new Date(year, month, date, hours, minutes, seconds, ms); |
| 61 | // JSC fails this one: Returns 12345671234567. |
| 62 | assertEquals("1234567", x, "Date"); |
| 63 | |
| 64 | x = ""; |
| 65 | Date(year, month, date, hours, minutes, seconds, ms); |
| 66 | assertEquals("", x, "Date not constructor"); |
| 67 | |
| 68 | x = ""; |
| 69 | Date.UTC(year, month, date, hours, minutes, seconds, ms); |
| 70 | // JSC fails this one: Returns 12345671234567. |
| 71 | assertEquals("1234567", x, "Date.UTC"); |
| 72 | |
| 73 | x = ""; |
| 74 | new Date().setSeconds(seconds, ms); |
| 75 | assertEquals("67", x, "Date.UTC"); |
| 76 | |
| 77 | x = ""; |
| 78 | new Date().setSeconds(seconds, ms); |
| 79 | assertEquals("67", x, "Date.setSeconds"); |
| 80 | |
| 81 | x = ""; |
| 82 | new Date().setUTCSeconds(seconds, ms); |
| 83 | assertEquals("67", x, "Date.setUTCSeconds"); |
| 84 | |
| 85 | x = ""; |
| 86 | new Date().setMinutes(minutes, seconds, ms); |
| 87 | assertEquals("567", x, "Date.setMinutes"); |
| 88 | |
| 89 | x = ""; |
| 90 | new Date().setUTCMinutes(minutes, seconds, ms); |
| 91 | assertEquals("567", x, "Date.setUTCMinutes"); |
| 92 | |
| 93 | x = ""; |
| 94 | new Date().setHours(hours, minutes, seconds, ms); |
| 95 | assertEquals("4567", x, "Date.setHours"); |
| 96 | |
| 97 | x = ""; |
| 98 | new Date().setUTCHours(hours, minutes, seconds, ms); |
| 99 | assertEquals("4567", x, "Date.setUTCHours"); |
| 100 | |
| 101 | x = ""; |
| 102 | new Date().setDate(date, hours, minutes, seconds, ms); |
| 103 | assertEquals("3", x, "Date.setDate"); |
| 104 | |
| 105 | x = ""; |
| 106 | new Date().setUTCDate(date, hours, minutes, seconds, ms); |
| 107 | assertEquals("3", x, "Date.setUTCDate"); |
| 108 | |
| 109 | x = ""; |
| 110 | new Date().setMonth(month, date, hours, minutes, seconds, ms); |
| 111 | assertEquals("23", x, "Date.setMonth"); |
| 112 | |
| 113 | x = ""; |
| 114 | new Date().setUTCMonth(month, date, hours, minutes, seconds, ms); |
| 115 | assertEquals("23", x, "Date.setUTCMonth"); |
| 116 | |
| 117 | x = ""; |
| 118 | new Date().setFullYear(year, month, date, hours, minutes, seconds, ms); |
| 119 | assertEquals("123", x, "Date.setFullYear"); |
| 120 | |
| 121 | x = ""; |
| 122 | new Date().setUTCFullYear(year, month, date, hours, minutes, seconds, ms); |
| 123 | assertEquals("123", x, "Date.setUTCFullYear"); |
| 124 | |
| 125 | var a = { valueOf: function() { x += "hest"; return 97; } }; |
| 126 | var b = { valueOf: function() { x += "fisk"; return 98; } }; |
| 127 | assertEquals("ab", String.fromCharCode(a, b), "String.fromCharCode"); |
| 128 | |
| 129 | print("ok"); |