| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright (c) 2014, the Dart project authors. All rights reserved. |
| 2 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 3 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 4 // modification, are permitted provided that the following conditions are |
| 4 // met: | 5 // met: |
| 5 // | 6 // |
| 6 // * Redistributions of source code must retain the above copyright | 7 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 8 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 9 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 10 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 11 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. | 12 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 13 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 14 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 15 // from this software without specific prior written permission. |
| 15 // | 16 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 // (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 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 28 |
| 29 import 'v8_regexp_utils.dart'; |
| 30 import 'package:expect/expect.dart'; |
| 28 | 31 |
| 29 #include "diy-fp.h" | 32 void main() { |
| 30 #include "utils.h" | 33 // Tests from http://blog.stevenlevithan.com/archives/npcg-javascript |
| 31 | 34 |
| 32 namespace double_conversion { | 35 assertEquals(true, new RegExp(r"(x)?\1y").hasMatch("y")); |
| 36 shouldBe(new RegExp(r"(x)?\1y").firstMatch("y"), ["y", null]); |
| 37 shouldBe(new RegExp(r"(x)?y").firstMatch("y"), ["y", null]); |
| 38 shouldBe(firstMatch("y", new RegExp(r"(x)?\1y")), ["y", null]); |
| 39 shouldBe(firstMatch("y", new RegExp(r"(x)?y")), ["y", null]); |
| 40 shouldBe(firstMatch("y", new RegExp(r"(x)?\1y")), ["y", null]); |
| 41 Expect.listEquals(["", ""], "y".split(new RegExp(r"(x)?\1y"))); |
| 42 Expect.listEquals(["", ""], "y".split(new RegExp(r"(x)?y"))); |
| 43 assertEquals(0, "y".indexOf(new RegExp(r"(x)?\1y"))); |
| 44 assertEquals("z", "y".replaceAll(new RegExp(r"(x)?\1y"), "z")); |
| 33 | 45 |
| 34 void DiyFp::Multiply(const DiyFp& other) { | 46 // See https://bugzilla.mozilla.org/show_bug.cgi?id=476146 |
| 35 // Simply "emulates" a 128 bit multiplication. | 47 shouldBe(new RegExp(r"^(b+|a){1,2}?bc").firstMatch("bbc"), ["bbc", "b"]); |
| 36 // However: the resulting number only contains 64 bits. The least | 48 shouldBe(new RegExp(r"((\3|b)\2(a)){2,}").firstMatch("bbaababbabaaaaabbaaaabba
"), |
| 37 // significant 64 bits are only used for rounding the most significant 64 | 49 ["bbaa", "a", "", "a"]); |
| 38 // bits. | 50 |
| 39 const uint64_t kM32 = 0xFFFFFFFFU; | 51 // From crbug.com/128821 - don't hang: |
| 40 uint64_t a = f_ >> 32; | 52 firstMatch("", new RegExp(r"((a|i|A|I|u|o|U|O)(s|c|b|c|d|f|g|h|j|k|l|m|n|p|q|r
|s|t|v|w|x|y|z|B|C|D|F|G|H|J|K|L|M|N|P|Q|R|S|T|V|W|X|Y|Z)*) de\/da([.,!?\s]|$)")
); |
| 41 uint64_t b = f_ & kM32; | |
| 42 uint64_t c = other.f_ >> 32; | |
| 43 uint64_t d = other.f_ & kM32; | |
| 44 uint64_t ac = a * c; | |
| 45 uint64_t bc = b * c; | |
| 46 uint64_t ad = a * d; | |
| 47 uint64_t bd = b * d; | |
| 48 uint64_t tmp = (bd >> 32) + (ad & kM32) + (bc & kM32); | |
| 49 // By adding 1U << 31 to tmp we round the final result. | |
| 50 // Halfway cases will be round up. | |
| 51 tmp += 1U << 31; | |
| 52 uint64_t result_f = ac + (ad >> 32) + (bc >> 32) + (tmp >> 32); | |
| 53 e_ += other.e_ + 64; | |
| 54 f_ = result_f; | |
| 55 } | 53 } |
| 56 | |
| 57 } // namespace double_conversion | |
| OLD | NEW |