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

Side by Side Diff: src/regexp.js

Issue 27491002: Cosmetic: Add macros for NaN, undefined and Infinity to native js code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 2 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/proxy.js ('k') | src/runtime.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
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 return null; 182 return null;
183 } 183 }
184 } else { 184 } else {
185 i = 0; 185 i = 0;
186 } 186 }
187 187
188 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, string, lastIndex]); 188 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, string, lastIndex]);
189 // matchIndices is either null or the lastMatchInfo array. 189 // matchIndices is either null or the lastMatchInfo array.
190 var matchIndices = %_RegExpExec(this, string, i, lastMatchInfo); 190 var matchIndices = %_RegExpExec(this, string, i, lastMatchInfo);
191 191
192 if (matchIndices === null) { 192 if (IS_NULL(matchIndices)) {
193 this.lastIndex = 0; 193 this.lastIndex = 0;
194 return null; 194 return null;
195 } 195 }
196 196
197 // Successful match. 197 // Successful match.
198 lastMatchInfoOverride = null; 198 lastMatchInfoOverride = null;
199 if (global) { 199 if (global) {
200 this.lastIndex = lastMatchInfo[CAPTURE1]; 200 this.lastIndex = lastMatchInfo[CAPTURE1];
201 } 201 }
202 return BuildResultFromMatchInfo(matchIndices, string); 202 return BuildResultFromMatchInfo(matchIndices, string);
(...skipping 22 matching lines...) Expand all
225 var i = TO_INTEGER(lastIndex); 225 var i = TO_INTEGER(lastIndex);
226 226
227 if (this.global) { 227 if (this.global) {
228 if (i < 0 || i > string.length) { 228 if (i < 0 || i > string.length) {
229 this.lastIndex = 0; 229 this.lastIndex = 0;
230 return false; 230 return false;
231 } 231 }
232 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, string, lastIndex]); 232 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, string, lastIndex]);
233 // matchIndices is either null or the lastMatchInfo array. 233 // matchIndices is either null or the lastMatchInfo array.
234 var matchIndices = %_RegExpExec(this, string, i, lastMatchInfo); 234 var matchIndices = %_RegExpExec(this, string, i, lastMatchInfo);
235 if (matchIndices === null) { 235 if (IS_NULL(matchIndices)) {
236 this.lastIndex = 0; 236 this.lastIndex = 0;
237 return false; 237 return false;
238 } 238 }
239 lastMatchInfoOverride = null; 239 lastMatchInfoOverride = null;
240 this.lastIndex = lastMatchInfo[CAPTURE1]; 240 this.lastIndex = lastMatchInfo[CAPTURE1];
241 return true; 241 return true;
242 } else { 242 } else {
243 // Non-global regexp. 243 // Non-global regexp.
244 // Remove irrelevant preceeding '.*' in a non-global test regexp. 244 // Remove irrelevant preceeding '.*' in a non-global test regexp.
245 // The expression checks whether this.source starts with '.*' and 245 // The expression checks whether this.source starts with '.*' and
246 // that the third char is not a '?'. 246 // that the third char is not a '?'.
247 var regexp = this; 247 var regexp = this;
248 if (%_StringCharCodeAt(regexp.source, 0) == 46 && // '.' 248 if (%_StringCharCodeAt(regexp.source, 0) == 46 && // '.'
249 %_StringCharCodeAt(regexp.source, 1) == 42 && // '*' 249 %_StringCharCodeAt(regexp.source, 1) == 42 && // '*'
250 %_StringCharCodeAt(regexp.source, 2) != 63) { // '?' 250 %_StringCharCodeAt(regexp.source, 2) != 63) { // '?'
251 regexp = TrimRegExp(regexp); 251 regexp = TrimRegExp(regexp);
252 } 252 }
253 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [regexp, string, lastIndex]); 253 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [regexp, string, lastIndex]);
254 // matchIndices is either null or the lastMatchInfo array. 254 // matchIndices is either null or the lastMatchInfo array.
255 var matchIndices = %_RegExpExec(regexp, string, 0, lastMatchInfo); 255 var matchIndices = %_RegExpExec(regexp, string, 0, lastMatchInfo);
256 if (matchIndices === null) { 256 if (IS_NULL(matchIndices)) {
257 this.lastIndex = 0; 257 this.lastIndex = 0;
258 return false; 258 return false;
259 } 259 }
260 lastMatchInfoOverride = null; 260 lastMatchInfoOverride = null;
261 return true; 261 return true;
262 } 262 }
263 } 263 }
264 264
265 function TrimRegExp(regexp) { 265 function TrimRegExp(regexp) {
266 if (!%_ObjectEquals(regexp_key, regexp)) { 266 if (!%_ObjectEquals(regexp_key, regexp)) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 377
378 // Property of the builtins object for recording the result of the last 378 // Property of the builtins object for recording the result of the last
379 // regexp match. The property lastMatchInfo includes the matchIndices 379 // regexp match. The property lastMatchInfo includes the matchIndices
380 // array of the last successful regexp match (an array of start/end index 380 // array of the last successful regexp match (an array of start/end index
381 // pairs for the match and all the captured substrings), the invariant is 381 // pairs for the match and all the captured substrings), the invariant is
382 // that there are at least two capture indeces. The array also contains 382 // that there are at least two capture indeces. The array also contains
383 // the subject string for the last successful match. 383 // the subject string for the last successful match.
384 var lastMatchInfo = new InternalPackedArray( 384 var lastMatchInfo = new InternalPackedArray(
385 2, // REGEXP_NUMBER_OF_CAPTURES 385 2, // REGEXP_NUMBER_OF_CAPTURES
386 "", // Last subject. 386 "", // Last subject.
387 void 0, // Last input - settable with RegExpSetInput. 387 UNDEFINED, // Last input - settable with RegExpSetInput.
388 0, // REGEXP_FIRST_CAPTURE + 0 388 0, // REGEXP_FIRST_CAPTURE + 0
389 0 // REGEXP_FIRST_CAPTURE + 1 389 0 // REGEXP_FIRST_CAPTURE + 1
390 ); 390 );
391 391
392 // Override last match info with an array of actual substrings. 392 // Override last match info with an array of actual substrings.
393 // Used internally by replace regexp with function. 393 // Used internally by replace regexp with function.
394 // The array has the format of an "apply" argument for a replacement 394 // The array has the format of an "apply" argument for a replacement
395 // function. 395 // function.
396 var lastMatchInfoOverride = null; 396 var lastMatchInfoOverride = null;
397 397
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 476
477 for (var i = 1; i < 10; ++i) { 477 for (var i = 1; i < 10; ++i) {
478 %DefineOrRedefineAccessorProperty($RegExp, '$' + i, 478 %DefineOrRedefineAccessorProperty($RegExp, '$' + i,
479 RegExpMakeCaptureGetter(i), NoOpSetter, 479 RegExpMakeCaptureGetter(i), NoOpSetter,
480 DONT_DELETE); 480 DONT_DELETE);
481 } 481 }
482 %ToFastProperties($RegExp); 482 %ToFastProperties($RegExp);
483 } 483 }
484 484
485 SetUpRegExp(); 485 SetUpRegExp();
OLDNEW
« no previous file with comments | « src/proxy.js ('k') | src/runtime.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698