| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 parameters[j] = CaptureString(subject, captures, j); | 324 parameters[j] = CaptureString(subject, captures, j); |
| 325 } | 325 } |
| 326 parameters[j] = index; | 326 parameters[j] = index; |
| 327 parameters[j + 1] = subject; | 327 parameters[j + 1] = subject; |
| 328 return ToString(replace.apply(null, parameters)); | 328 return ToString(replace.apply(null, parameters)); |
| 329 } | 329 } |
| 330 | 330 |
| 331 | 331 |
| 332 // ECMA-262 section 15.5.4.7 | 332 // ECMA-262 section 15.5.4.7 |
| 333 %AddProperty($String.prototype, "indexOf", function(searchString /* position */)
{ // length == 1 | 333 %AddProperty($String.prototype, "indexOf", function(searchString /* position */)
{ // length == 1 |
| 334 var str = ToString(this); | 334 var subject_str = ToString(this); |
| 335 var str_len = str.length; | 335 var pattern_str = ToString(searchString); |
| 336 var searchStr = ToString(searchString); | 336 var subject_str_len = subject_str.length; |
| 337 var pattern_str_len = pattern_str.length; |
| 337 var index = 0; | 338 var index = 0; |
| 338 if (%_ArgumentsLength() > 1) { | 339 if (%_ArgumentsLength() > 1) { |
| 339 var arg1 = %_Arguments(1); // position | 340 var arg1 = %_Arguments(1); // position |
| 340 index = TO_INTEGER(arg1); | 341 index = TO_INTEGER(arg1); |
| 341 } | 342 } |
| 342 if (index < 0) index = 0; | 343 if (index < 0) index = 0; |
| 343 if (index > str_len) index = str_len; | 344 if (index > subject_str_len) index = subject_str_len; |
| 344 if (searchStr.length + index > str_len) return -1; | 345 if (pattern_str_len + index > subject_str_len) return -1; |
| 345 return %StringIndexOf(str, searchStr, index); | 346 return %StringIndexOf(subject_str, pattern_str, index); |
| 346 }, DONT_ENUM); | 347 }, DONT_ENUM); |
| 347 | 348 |
| 348 | 349 |
| 349 // ECMA-262 section 15.5.4.8 | 350 // ECMA-262 section 15.5.4.8 |
| 350 %AddProperty($String.prototype, "lastIndexOf", function(searchString /* position
*/) { // length == 1 | 351 %AddProperty($String.prototype, "lastIndexOf", function(searchString /* position
*/) { // length == 1 |
| 351 var sub = ToString(this); | 352 var sub = ToString(this); |
| 352 var pat = ToString(searchString); | 353 var pat = ToString(searchString); |
| 353 var index = (%_ArgumentsLength() > 1) | 354 var index = (%_ArgumentsLength() > 1) |
| 354 ? ToNumber(%_Arguments(1) /* position */) | 355 ? ToNumber(%_Arguments(1) /* position */) |
| 355 : $NaN; | 356 : $NaN; |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 | 764 |
| 764 | 765 |
| 765 StringBuilder.prototype.generate = function() { | 766 StringBuilder.prototype.generate = function() { |
| 766 return %StringBuilderConcat(this.elements, ""); | 767 return %StringBuilderConcat(this.elements, ""); |
| 767 } | 768 } |
| 768 | 769 |
| 769 | 770 |
| 770 ReplaceResultBuilder.prototype.generate = function() { | 771 ReplaceResultBuilder.prototype.generate = function() { |
| 771 return %StringBuilderConcat(this.elements, this.special_string); | 772 return %StringBuilderConcat(this.elements, this.special_string); |
| 772 } | 773 } |
| OLD | NEW |