OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 3 // |
| 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions |
| 6 // are met: |
| 7 // 1. Redistributions of source code must retain the above copyright |
| 8 // notice, this list of conditions and the following disclaimer. |
| 9 // 2. Redistributions in binary form must reproduce the above copyright |
| 10 // notice, this list of conditions and the following disclaimer in the |
| 11 // documentation and/or other materials provided with the distribution. |
| 12 // |
| 13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 |
| 24 description( |
| 25 |
| 26 "This test checks for potential edge case bugs with certain math transforms invo
lving multiplication by 1 and unary plus." |
| 27 |
| 28 ); |
| 29 |
| 30 var values = { |
| 31 someInt: 42, |
| 32 someFloat: 42.42, |
| 33 one: 1, |
| 34 minusOne: -1, |
| 35 zero: 0, |
| 36 minusZero: -0, |
| 37 infinity: Infinity, |
| 38 minusInfinity: -Infinity, |
| 39 notANumber: NaN, |
| 40 nonNumberString: "x", |
| 41 someFloatString: "42.42" |
| 42 }; |
| 43 |
| 44 var numberForString = { |
| 45 nonNumberString: "notANumber", |
| 46 someFloatString: "someFloat" |
| 47 }; |
| 48 |
| 49 for (var name in values) { |
| 50 var numForStr = numberForString[name] ? numberForString[name] : name; |
| 51 |
| 52 shouldBe("values." + name + " * 1", "+values." + name); |
| 53 shouldBe("values." + name + " * 1", stringify(values[numForStr])); |
| 54 |
| 55 shouldBe("1 * values." + name, "+values." + name); |
| 56 shouldBe("1 * values." + name, stringify(values[numForStr])); |
| 57 } |
| 58 |
| 59 for (var name1 in values) { |
| 60 var numForStr1 = numberForString[name1] ? numberForString[name1] : name1; |
| 61 for (var name2 in values) { |
| 62 var numForStr2 = numberForString[name2] ? numberForString[name2] : name2
; |
| 63 |
| 64 shouldBe("+values." + name1 + " * values." + name2, "values." + name1 +
" * values." + name2); |
| 65 shouldBe("+values." + name1 + " * values." + name2, stringify(values[nam
e1] * values[name2])); |
| 66 shouldBe("values." + name1 + " * +values." + name2, "values." + name1 +
" * values." + name2); |
| 67 shouldBe("values." + name1 + " * +values." + name2, stringify(values[nam
e1] * values[name2])); |
| 68 shouldBe("+values." + name1 + " * +values." + name2, "values." + name1 +
" * values." + name2); |
| 69 shouldBe("+values." + name1 + " * +values." + name2, stringify(values[na
me1] * values[name2])); |
| 70 |
| 71 shouldBe("+values." + name1 + " / values." + name2, "values." + name1 +
" / values." + name2); |
| 72 shouldBe("+values." + name1 + " / values." + name2, stringify(values[nam
e1] / values[name2])); |
| 73 shouldBe("values." + name1 + " / +values." + name2, "values." + name1 +
" / values." + name2); |
| 74 shouldBe("values." + name1 + " / +values." + name2, stringify(values[nam
e1] / values[name2])); |
| 75 shouldBe("+values." + name1 + " / +values." + name2, "values." + name1 +
" / values." + name2); |
| 76 shouldBe("+values." + name1 + " / +values." + name2, stringify(values[na
me1] / values[name2])); |
| 77 |
| 78 shouldBe("+values." + name1 + " - values." + name2, "values." + name1 +
" - values." + name2); |
| 79 shouldBe("+values." + name1 + " - values." + name2, stringify(values[nam
e1] - values[name2])); |
| 80 shouldBe("values." + name1 + " - +values." + name2, "values." + name1 +
" - values." + name2); |
| 81 shouldBe("values." + name1 + " - +values." + name2, stringify(values[nam
e1] - values[name2])); |
| 82 shouldBe("+values." + name1 + " - +values." + name2, "values." + name1 +
" - values." + name2); |
| 83 shouldBe("+values." + name1 + " - +values." + name2, stringify(values[na
me1] - values[name2])); |
| 84 } |
| 85 } |
OLD | NEW |