blob: 1329bad2ca5df8a30589f7d86c4775e5c97ce186 [file] [log] [blame]
kasperl@chromium.org68ac0092009-07-09 06:00:35 +00001// 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
28var x = "";
29var v = new Object();
30var w = new Object();
31var vv = function() { x += "hest"; return 1; }
32var ww = function() { x += "fisk"; return 2; }
33v.valueOf = vv;
34w.valueOf = ww;
35assertEquals(1, Math.min(v,w));
36assertEquals("hestfisk", x, "min");
37
38x = "";
39assertEquals(2, Math.max(v,w));
40assertEquals("hestfisk", x, "max");
41
42x = "";
43assertEquals(Math.atan2(1, 2), Math.atan2(v, w));
44// JSC says fiskhest.
45assertEquals("hestfisk", x, "atan2");
46
47x = "";
48assertEquals(1, Math.pow(v, w));
49assertEquals("hestfisk", x, "pow");
50
51var year = { valueOf: function() { x += 1; return 2007; } };
52var month = { valueOf: function() { x += 2; return 2; } };
53var date = { valueOf: function() { x += 3; return 4; } };
54var hours = { valueOf: function() { x += 4; return 13; } };
55var minutes = { valueOf: function() { x += 5; return 50; } };
56var seconds = { valueOf: function() { x += 6; return 0; } };
57var ms = { valueOf: function() { x += 7; return 999; } };
58
59x = "";
60new Date(year, month, date, hours, minutes, seconds, ms);
61// JSC fails this one: Returns 12345671234567.
62assertEquals("1234567", x, "Date");
63
64x = "";
65Date(year, month, date, hours, minutes, seconds, ms);
66assertEquals("", x, "Date not constructor");
67
68x = "";
69Date.UTC(year, month, date, hours, minutes, seconds, ms);
70// JSC fails this one: Returns 12345671234567.
71assertEquals("1234567", x, "Date.UTC");
72
73x = "";
74new Date().setSeconds(seconds, ms);
75assertEquals("67", x, "Date.UTC");
76
77x = "";
78new Date().setSeconds(seconds, ms);
79assertEquals("67", x, "Date.setSeconds");
80
81x = "";
82new Date().setUTCSeconds(seconds, ms);
83assertEquals("67", x, "Date.setUTCSeconds");
84
85x = "";
86new Date().setMinutes(minutes, seconds, ms);
87assertEquals("567", x, "Date.setMinutes");
88
89x = "";
90new Date().setUTCMinutes(minutes, seconds, ms);
91assertEquals("567", x, "Date.setUTCMinutes");
92
93x = "";
94new Date().setHours(hours, minutes, seconds, ms);
95assertEquals("4567", x, "Date.setHours");
96
97x = "";
98new Date().setUTCHours(hours, minutes, seconds, ms);
99assertEquals("4567", x, "Date.setUTCHours");
100
101x = "";
102new Date().setDate(date, hours, minutes, seconds, ms);
103assertEquals("3", x, "Date.setDate");
104
105x = "";
106new Date().setUTCDate(date, hours, minutes, seconds, ms);
107assertEquals("3", x, "Date.setUTCDate");
108
109x = "";
110new Date().setMonth(month, date, hours, minutes, seconds, ms);
111assertEquals("23", x, "Date.setMonth");
112
113x = "";
114new Date().setUTCMonth(month, date, hours, minutes, seconds, ms);
115assertEquals("23", x, "Date.setUTCMonth");
116
117x = "";
118new Date().setFullYear(year, month, date, hours, minutes, seconds, ms);
119assertEquals("123", x, "Date.setFullYear");
120
121x = "";
122new Date().setUTCFullYear(year, month, date, hours, minutes, seconds, ms);
123assertEquals("123", x, "Date.setUTCFullYear");
124
125var a = { valueOf: function() { x += "hest"; return 97; } };
126var b = { valueOf: function() { x += "fisk"; return 98; } };
127assertEquals("ab", String.fromCharCode(a, b), "String.fromCharCode");
128
129print("ok");