Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: test/mjsunit/regress/regress-2437.js

Issue 2339443002: [regexp] Avoid unneeded accesses to lastIndex (Closed)
Patch Set: Update test262 status Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/regexp.js ('k') | test/mjsunit/regress/regress-2438.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Summary of the spec: lastIndex is reset to 0 if 28 // Summary of the spec: lastIndex is reset to 0 if
29 // - a regexp fails to match, regardless of global or non-global. 29 // - a global or sticky regexp fails to match.
30 // - a global regexp is used in a function that returns multiple results, 30 // - a global regexp is used in a function that returns multiple results,
31 // such as String.prototype.replace or String.prototype.match, since it 31 // such as String.prototype.replace or String.prototype.match, since it
32 // repeats the regexp until it fails to match. 32 // repeats the regexp until it fails to match.
33 // Otherwise lastIndex is only set when a global regexp matches, to the index 33 // Otherwise lastIndex is only set when a global regexp matches, to the index
34 // after the match. 34 // after the match.
35 35
36 // Test Regexp.prototype.exec 36 // Test Regexp.prototype.exec
37 r = /a/; 37 r = /a/;
38 r.lastIndex = 1; 38 r.lastIndex = 1;
39 r.exec("zzzz"); 39 r.exec("zzzz");
40 assertEquals(0, r.lastIndex); 40 assertEquals(1, r.lastIndex);
41 41
42 // Test Regexp.prototype.test 42 // Test Regexp.prototype.test
43 r = /a/; 43 r = /a/;
44 r.lastIndex = 1; 44 r.lastIndex = 1;
45 r.test("zzzz"); 45 r.test("zzzz");
46 assertEquals(0, r.lastIndex); 46 assertEquals(1, r.lastIndex);
47 47
48 // Test String.prototype.match 48 // Test String.prototype.match
49 r = /a/; 49 r = /a/;
50 r.lastIndex = 1; 50 r.lastIndex = 1;
51 "zzzz".match(r); 51 "zzzz".match(r);
52 assertEquals(0, r.lastIndex); 52 assertEquals(1, r.lastIndex);
53 53
54 // Test String.prototype.replace with atomic regexp and empty string. 54 // Test String.prototype.replace with atomic regexp and empty string.
55 r = /a/; 55 r = /a/;
56 r.lastIndex = 1; 56 r.lastIndex = 1;
57 "zzzz".replace(r, ""); 57 "zzzz".replace(r, "");
58 assertEquals(0, r.lastIndex); 58 assertEquals(0, r.lastIndex);
59 59
60 // Test String.prototype.replace with non-atomic regexp and empty string. 60 // Test String.prototype.replace with non-atomic regexp and empty string.
61 r = /\d/; 61 r = /\d/;
62 r.lastIndex = 1; 62 r.lastIndex = 1;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 r.lastIndex = -1; 109 r.lastIndex = -1;
110 "01234567".replace(r, "x"); 110 "01234567".replace(r, "x");
111 assertEquals(0, r.lastIndex); 111 assertEquals(0, r.lastIndex);
112 112
113 r.lastIndex = -1; 113 r.lastIndex = -1;
114 "0123abcd".match(r); 114 "0123abcd".match(r);
115 assertEquals(-1, r.lastIndex); 115 assertEquals(-1, r.lastIndex);
116 116
117 r.lastIndex = -1; 117 r.lastIndex = -1;
118 "01234567".match(r); 118 "01234567".match(r);
119 assertEquals(0, r.lastIndex); 119 assertEquals(-1, r.lastIndex);
120 120
121 // Also test RegExp.prototype.exec and RegExp.prototype.test 121 // Also test RegExp.prototype.exec and RegExp.prototype.test
122 r = /a/g; 122 r = /a/g;
123 r.lastIndex = 1; 123 r.lastIndex = 1;
124 r.exec("01234567"); 124 r.exec("01234567");
125 assertEquals(0, r.lastIndex); 125 assertEquals(0, r.lastIndex);
126 126
127 r.lastIndex = 1; 127 r.lastIndex = 1;
128 r.exec("0123abcd"); 128 r.exec("0123abcd");
129 assertEquals(5, r.lastIndex); 129 assertEquals(5, r.lastIndex);
130 130
131 r = /a/; 131 r = /a/;
132 r.lastIndex = 1; 132 r.lastIndex = 1;
133 r.exec("01234567"); 133 r.exec("01234567");
134 assertEquals(0, r.lastIndex); 134 assertEquals(1, r.lastIndex);
135 135
136 r.lastIndex = 1; 136 r.lastIndex = 1;
137 r.exec("0123abcd"); 137 r.exec("0123abcd");
138 assertEquals(1, r.lastIndex); 138 assertEquals(1, r.lastIndex);
139 139
140 r = /a/g; 140 r = /a/g;
141 r.lastIndex = 1; 141 r.lastIndex = 1;
142 r.test("01234567"); 142 r.test("01234567");
143 assertEquals(0, r.lastIndex); 143 assertEquals(0, r.lastIndex);
144 144
145 r.lastIndex = 1; 145 r.lastIndex = 1;
146 r.test("0123abcd"); 146 r.test("0123abcd");
147 assertEquals(5, r.lastIndex); 147 assertEquals(5, r.lastIndex);
148 148
149 r = /a/; 149 r = /a/;
150 r.lastIndex = 1; 150 r.lastIndex = 1;
151 r.test("01234567"); 151 r.test("01234567");
152 assertEquals(0, r.lastIndex); 152 assertEquals(1, r.lastIndex);
153 153
154 r.lastIndex = 1; 154 r.lastIndex = 1;
155 r.test("0123abcd"); 155 r.test("0123abcd");
156 assertEquals(1, r.lastIndex); 156 assertEquals(1, r.lastIndex);
OLDNEW
« no previous file with comments | « test/mjsunit/regexp.js ('k') | test/mjsunit/regress/regress-2438.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698