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

Side by Side Diff: src/regexp.js

Issue 844006: Merge changes up to V8 version 2.1.3 into the partial snapshots (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: Created 10 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/prettyprinter.cc ('k') | src/register-allocator.h » ('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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 135 }
136 136
137 137
138 function DoRegExpExec(regexp, string, index) { 138 function DoRegExpExec(regexp, string, index) {
139 return %_RegExpExec(regexp, string, index, lastMatchInfo); 139 return %_RegExpExec(regexp, string, index, lastMatchInfo);
140 } 140 }
141 141
142 142
143 function RegExpExec(string) { 143 function RegExpExec(string) {
144 if (!IS_REGEXP(this)) { 144 if (!IS_REGEXP(this)) {
145 throw MakeTypeError('method_called_on_incompatible', 145 throw MakeTypeError('incompatible_method_receiver',
146 ['RegExp.prototype.exec', this]); 146 ['RegExp.prototype.exec', this]);
147 } 147 }
148 if (%_ArgumentsLength() == 0) { 148 if (%_ArgumentsLength() == 0) {
149 var regExpInput = LAST_INPUT(lastMatchInfo); 149 var regExpInput = LAST_INPUT(lastMatchInfo);
150 if (IS_UNDEFINED(regExpInput)) { 150 if (IS_UNDEFINED(regExpInput)) {
151 throw MakeError('no_input_to_regexp', [this]); 151 throw MakeError('no_input_to_regexp', [this]);
152 } 152 }
153 string = regExpInput; 153 string = regExpInput;
154 } 154 }
155 var s = ToString(string); 155 var s;
156 var length = s.length; 156 if (IS_STRING(string)) {
157 s = string;
158 } else {
159 s = ToString(string);
160 }
157 var lastIndex = this.lastIndex; 161 var lastIndex = this.lastIndex;
158 var i = this.global ? TO_INTEGER(lastIndex) : 0; 162 var i = this.global ? TO_INTEGER(lastIndex) : 0;
159 163
160 if (i < 0 || i > s.length) { 164 if (i < 0 || i > s.length) {
161 this.lastIndex = 0; 165 this.lastIndex = 0;
162 return null; 166 return null;
163 } 167 }
164 168
165 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, s, lastIndex]); 169 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, s, lastIndex]);
166 // matchIndices is either null or the lastMatchInfo array. 170 // matchIndices is either null or the lastMatchInfo array.
167 var matchIndices = %_RegExpExec(this, s, i, lastMatchInfo); 171 var matchIndices = %_RegExpExec(this, s, i, lastMatchInfo);
168 172
169 if (matchIndices == null) { 173 if (matchIndices == null) {
170 if (this.global) this.lastIndex = 0; 174 if (this.global) this.lastIndex = 0;
171 return matchIndices; // no match 175 return matchIndices; // no match
172 } 176 }
173 177
174 var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1; 178 var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1;
175 var result = new $Array(numResults); 179 var result;
176 for (var i = 0; i < numResults; i++) { 180 if (numResults === 1) {
177 var matchStart = lastMatchInfo[CAPTURE(i << 1)]; 181 var matchStart = lastMatchInfo[CAPTURE(0)];
178 var matchEnd = lastMatchInfo[CAPTURE((i << 1) + 1)]; 182 var matchEnd = lastMatchInfo[CAPTURE(1)];
179 if (matchStart != -1 && matchEnd != -1) { 183 result = [SubString(s, matchStart, matchEnd)];
180 result[i] = SubString(s, matchStart, matchEnd); 184 } else {
181 } else { 185 result = new $Array(numResults);
182 // Make sure the element is present. Avoid reading the undefined 186 for (var i = 0; i < numResults; i++) {
183 // property from the global object since this may change. 187 var matchStart = lastMatchInfo[CAPTURE(i << 1)];
184 result[i] = void 0; 188 var matchEnd = lastMatchInfo[CAPTURE((i << 1) + 1)];
189 if (matchStart != -1 && matchEnd != -1) {
190 result[i] = SubString(s, matchStart, matchEnd);
191 } else {
192 // Make sure the element is present. Avoid reading the undefined
193 // property from the global object since this may change.
194 result[i] = void 0;
195 }
185 } 196 }
186 } 197 }
187 198
188 if (this.global) 199 if (this.global)
189 this.lastIndex = lastMatchInfo[CAPTURE1]; 200 this.lastIndex = lastMatchInfo[CAPTURE1];
190 result.index = lastMatchInfo[CAPTURE0]; 201 result.index = lastMatchInfo[CAPTURE0];
191 result.input = s; 202 result.input = s;
192 return result; 203 return result;
193 } 204 }
194 205
195 206
196 // Section 15.10.6.3 doesn't actually make sense, but the intention seems to be 207 // Section 15.10.6.3 doesn't actually make sense, but the intention seems to be
197 // that test is defined in terms of String.prototype.exec. However, it probably 208 // that test is defined in terms of String.prototype.exec. However, it probably
198 // means the original value of String.prototype.exec, which is what everybody 209 // means the original value of String.prototype.exec, which is what everybody
199 // else implements. 210 // else implements.
200 function RegExpTest(string) { 211 function RegExpTest(string) {
201 if (!IS_REGEXP(this)) { 212 if (!IS_REGEXP(this)) {
202 throw MakeTypeError('method_called_on_incompatible', 213 throw MakeTypeError('incompatible_method_receiver',
203 ['RegExp.prototype.test', this]); 214 ['RegExp.prototype.test', this]);
204 } 215 }
205 if (%_ArgumentsLength() == 0) { 216 if (%_ArgumentsLength() == 0) {
206 var regExpInput = LAST_INPUT(lastMatchInfo); 217 var regExpInput = LAST_INPUT(lastMatchInfo);
207 if (IS_UNDEFINED(regExpInput)) { 218 if (IS_UNDEFINED(regExpInput)) {
208 throw MakeError('no_input_to_regexp', [this]); 219 throw MakeError('no_input_to_regexp', [this]);
209 } 220 }
210 string = regExpInput; 221 string = regExpInput;
211 } 222 }
212 var s = ToString(string); 223 var s = ToString(string);
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); 408 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE);
398 409
399 for (var i = 1; i < 10; ++i) { 410 for (var i = 1; i < 10; ++i) {
400 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D ELETE); 411 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D ELETE);
401 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); 412 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE);
402 } 413 }
403 } 414 }
404 415
405 416
406 SetupRegExp(); 417 SetupRegExp();
OLDNEW
« no previous file with comments | « src/prettyprinter.cc ('k') | src/register-allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698