• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2008 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// Ensure that operations on small integers handle -0.
29
30var zero = 0;
31var one = 1;
32var minus_one = -1;
33var two = 2;
34var four = 4;
35var minus_two = -2;
36var minus_four = -4;
37
38// variable op variable
39
40assertEquals(-Infinity, one / (-zero), "one / -0 I");
41
42assertEquals(-Infinity, one / (zero * minus_one), "one / -1");
43assertEquals(-Infinity, one / (minus_one * zero), "one / -0 II");
44assertEquals(Infinity, one / (zero * zero), "one / 0 I");
45assertEquals(1, one / (minus_one * minus_one), "one / 1");
46
47assertEquals(-Infinity, one / (zero / minus_one), "one / -0 III");
48assertEquals(Infinity, one / (zero / one), "one / 0 II");
49
50assertEquals(-Infinity, one / (minus_four % two), "foo1");
51assertEquals(-Infinity, one / (minus_four % minus_two), "foo2");
52assertEquals(Infinity, one / (four % two), "foo3");
53assertEquals(Infinity, one / (four % minus_two), "foo4");
54
55// literal op variable
56
57assertEquals(-Infinity, one / (0 * minus_one), "bar1");
58assertEquals(-Infinity, one / (-1 * zero), "bar2");
59assertEquals(Infinity, one / (0 * zero), "bar3");
60assertEquals(1, one / (-1 * minus_one), "bar4");
61
62assertEquals(-Infinity, one / (0 / minus_one), "baz1");
63assertEquals(Infinity, one / (0 / one), "baz2");
64
65assertEquals(-Infinity, one / (-4 % two), "baz3");
66assertEquals(-Infinity, one / (-4 % minus_two), "baz4");
67assertEquals(Infinity, one / (4 % two), "baz5");
68assertEquals(Infinity, one / (4 % minus_two), "baz6");
69
70// variable op literal
71
72assertEquals(-Infinity, one / (zero * -1), "fizz1");
73assertEquals(-Infinity, one / (minus_one * 0), "fizz2");
74assertEquals(Infinity, one / (zero * 0), "fizz3");
75assertEquals(1, one / (minus_one * -1), "fizz4");
76
77assertEquals(-Infinity, one / (zero / -1), "buzz1");
78assertEquals(Infinity, one / (zero / 1), "buzz2");
79
80assertEquals(-Infinity, one / (minus_four % 2), "buzz3");
81assertEquals(-Infinity, one / (minus_four % -2), "buzz4");
82assertEquals(Infinity, one / (four % 2), "buzz5");
83assertEquals(Infinity, one / (four % -2), "buzz6");
84
85// literal op literal
86
87assertEquals(-Infinity, one / (-0), "fisk1");
88
89assertEquals(-Infinity, one / (0 * -1), "fisk2");
90assertEquals(-Infinity, one / (-1 * 0), "fisk3");
91assertEquals(Infinity, one / (0 * 0), "fisk4");
92assertEquals(1, one / (-1 * -1), "fisk5");
93
94assertEquals(-Infinity, one / (0 / -1), "hest1");
95assertEquals(Infinity, one / (0 / 1), "hest2");
96
97assertEquals(-Infinity, one / (-4 % 2), "fiskhest1");
98assertEquals(-Infinity, one / (-4 % -2), "fiskhest2");
99assertEquals(Infinity, one / (4 % 2), "fiskhest3");
100assertEquals(Infinity, one / (4 % -2), "fiskhest4");
101
102
103// This tests against a singleton -0.0 object being overwritten.gc
104x = 0;
105z = 3044;
106
107function foo(x) {
108  var y = -x + z;
109  return -x;
110}
111
112assertEquals(-0, foo(x));
113assertEquals(-0, foo(x));
114