Chromium Code Reviews| Index: test/mjsunit/comparison-ops-and-undefined.js |
| diff --git a/test/mjsunit/comparison-ops-and-undefined.js b/test/mjsunit/comparison-ops-and-undefined.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..29576ff35e82bd7eaf9f4b8c615db4096bf2aaf9 |
| --- /dev/null |
| +++ b/test/mjsunit/comparison-ops-and-undefined.js |
| @@ -0,0 +1,161 @@ |
| +// Copyright 2012 the V8 project authors. All rights reserved. |
| +// Redistribution and use in source and binary forms, with or without |
| +// modification, are permitted provided that the following conditions are |
| +// met: |
| +// |
| +// * Redistributions of source code must retain the above copyright |
| +// notice, this list of conditions and the following disclaimer. |
| +// * Redistributions in binary form must reproduce the above |
| +// copyright notice, this list of conditions and the following |
| +// disclaimer in the documentation and/or other materials provided |
| +// with the distribution. |
| +// * Neither the name of Google Inc. nor the names of its |
| +// contributors may be used to endorse or promote products derived |
| +// from this software without specific prior written permission. |
| +// |
| +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + |
| +// Flags: --allow-natives-syntax |
| + |
| +function less_1(a, b) { |
| + return a < b; |
| +} |
| + |
| +assertFalse(less_1(.5, .5)); |
| +assertFalse(less_1(.5, undefined)); |
| +assertFalse(less_1(undefined, .5)); |
| +assertFalse(less_1(undefined, undefined)); |
| + |
| +function less_2(a, b) { |
| + return a < b; |
| +} |
| +assertFalse(less_2(.5, .5)); |
| +%OptimizeFunctionOnNextCall(less_2); |
| +assertFalse(less_2(.5, .5)); |
|
fschneider
2012/03/02 12:39:15
You could compress this into a helper
function te
danno
2012/03/02 13:28:45
Done.
|
| +assertFalse(less_2(.5, undefined)); |
| +assertFalse(less_2(undefined, .5)); |
| +assertFalse(less_2(undefined, undefined)); |
| + |
| +function less_equal_1(a, b) { |
| + return a <= b; |
| +} |
| + |
| +assertTrue(less_equal_1(.5, .5)); |
| +assertFalse(less_equal_1(.5, undefined)); |
| +assertFalse(less_equal_1(undefined, .5)); |
| +assertFalse(less_equal_1(undefined, undefined)); |
| + |
| +function less_equal_2(a, b) { |
| + return a <= b; |
| +} |
| +assertTrue(less_equal_2(.5, .5)); |
| +%OptimizeFunctionOnNextCall(less_equal_2); |
| +assertTrue(less_equal_2(.5, .5)); |
| +assertFalse(less_equal_2(.5, undefined)); |
| +assertFalse(less_equal_2(undefined, .5)); |
| +assertFalse(less_equal_2(undefined, undefined)); |
| + |
| +function greater_1(a, b) { |
| + return a > b; |
| +} |
| + |
| +assertFalse(greater_1(.5, .5)); |
| +assertFalse(greater_1(.5, undefined)); |
| +assertFalse(greater_1(undefined, .5)); |
| +assertFalse(greater_1(undefined, undefined)); |
| + |
| +function greater_2(a, b) { |
| + return a > b; |
| +} |
| +assertFalse(greater_2(.5, .5)); |
| +%OptimizeFunctionOnNextCall(greater_2); |
| +assertFalse(greater_2(.5, .5)); |
| +assertFalse(greater_2(.5, undefined)); |
| +assertFalse(greater_2(undefined, .5)); |
| +assertFalse(greater_2(undefined, undefined)); |
| + |
| +function greater_equal_1(a, b) { |
| + return a >= b; |
| +} |
| + |
| +assertTrue(greater_equal_1(.5, .5)); |
| +assertFalse(greater_equal_1(.5, undefined)); |
| +assertFalse(greater_equal_1(undefined, .5)); |
| +assertFalse(greater_equal_1(undefined, undefined)); |
| + |
| +function greater_equal_2(a, b) { |
| + return a >= b; |
| +} |
| +assertTrue(greater_equal_2(.5, .5)); |
| +%OptimizeFunctionOnNextCall(greater_equal_2); |
| +assertTrue(greater_equal_2(.5, .5)); |
| +assertFalse(greater_equal_2(.5, undefined)); |
| +assertFalse(greater_equal_2(undefined, .5)); |
| +assertFalse(greater_equal_2(undefined, undefined)); |
| + |
| +function equal_1(a, b) { |
| + return a == b; |
| +} |
| + |
| +assertTrue(equal_1(.5, .5)); |
| +assertFalse(equal_1(.5, undefined)); |
| +assertFalse(equal_1(undefined, .5)); |
| +assertTrue(equal_1(undefined, undefined)); |
| + |
| +function equal_2(a, b) { |
| + return a == b; |
| +} |
| +assertTrue(equal_2(.5, .5)); |
| +%OptimizeFunctionOnNextCall(equal_2); |
| +assertTrue(equal_2(.5, .5)); |
| +assertFalse(equal_2(.5, undefined)); |
| +assertFalse(equal_2(undefined, .5)); |
| +assertTrue(equal_2(undefined, undefined)); |
| + |
| +function strict_equal_1(a, b) { |
| + return a === b; |
| +} |
| + |
| +assertTrue(strict_equal_1(.5, .5)); |
| +assertFalse(strict_equal_1(.5, undefined)); |
| +assertFalse(strict_equal_1(undefined, .5)); |
| +assertTrue(strict_equal_1(undefined, undefined)); |
| + |
| +function strict_equal_2(a, b) { |
| + return a === b; |
| +} |
| +assertTrue(strict_equal_2(.5, .5)); |
| +%OptimizeFunctionOnNextCall(strict_equal_2); |
| +assertTrue(strict_equal_2(.5, .5)); |
| +assertFalse(strict_equal_2(.5, undefined)); |
| +assertFalse(strict_equal_2(undefined, .5)); |
| +assertTrue(strict_equal_2(undefined, undefined)); |
| + |
| +function not_equal_1(a, b) { |
| + return a != b; |
| +} |
| + |
| +assertFalse(not_equal_1(.5, .5)); |
| +assertTrue(not_equal_1(.5, undefined)); |
| +assertTrue(not_equal_1(undefined, .5)); |
| +assertFalse(not_equal_1(undefined, undefined)); |
| + |
| +function not_equal_2(a, b) { |
| + return a != b; |
| +} |
| +assertFalse(not_equal_1(.5, .5)); |
| +%OptimizeFunctionOnNextCall(not_equal_2); |
| +assertFalse(not_equal_1(.5, .5)); |
| +assertTrue(not_equal_1(.5, undefined)); |
| +assertTrue(not_equal_1(undefined, .5)); |
| +assertFalse(not_equal_1(undefined, undefined)); |