| OLD | NEW |
| 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 // ...... function replace | 236 // ...... function replace |
| 237 // ...... string replace (with $-expansion) | 237 // ...... string replace (with $-expansion) |
| 238 | 238 |
| 239 if (IS_REGEXP(search)) { | 239 if (IS_REGEXP(search)) { |
| 240 // Emulate RegExp.prototype.exec's side effect in step 5, even if | 240 // Emulate RegExp.prototype.exec's side effect in step 5, even if |
| 241 // value is discarded. | 241 // value is discarded. |
| 242 ToInteger(search.lastIndex); | 242 ToInteger(search.lastIndex); |
| 243 %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]); | 243 %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]); |
| 244 | 244 |
| 245 if (!IS_SPEC_FUNCTION(replace)) { | 245 if (!IS_SPEC_FUNCTION(replace)) { |
| 246 replace = TO_STRING_INLINE(replace); |
| 247 |
| 246 if (!search.global) { | 248 if (!search.global) { |
| 247 // Non-global regexp search, string replace. | 249 // Non-global regexp search, string replace. |
| 248 var match = DoRegExpExec(search, subject, 0); | 250 var match = DoRegExpExec(search, subject, 0); |
| 249 if (match == null) { | 251 if (match == null) { |
| 250 search.lastIndex = 0 | 252 search.lastIndex = 0 |
| 251 return subject; | 253 return subject; |
| 252 } | 254 } |
| 253 replace = TO_STRING_INLINE(replace); | |
| 254 if (replace.length == 0) { | 255 if (replace.length == 0) { |
| 255 return %_SubString(subject, 0, match[CAPTURE0]) + | 256 return %_SubString(subject, 0, match[CAPTURE0]) + |
| 256 %_SubString(subject, match[CAPTURE1], subject.length) | 257 %_SubString(subject, match[CAPTURE1], subject.length) |
| 257 } | 258 } |
| 258 return ExpandReplacement(replace, subject, lastMatchInfo, | 259 return ExpandReplacement(replace, subject, lastMatchInfo, |
| 259 %_SubString(subject, 0, match[CAPTURE0])) + | 260 %_SubString(subject, 0, match[CAPTURE0])) + |
| 260 %_SubString(subject, match[CAPTURE1], subject.length); | 261 %_SubString(subject, match[CAPTURE1], subject.length); |
| 261 } | 262 } |
| 262 | 263 |
| 263 // Global regexp search, string replace. | 264 // Global regexp search, string replace. |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 "fixed", StringFixed, | 1038 "fixed", StringFixed, |
| 1038 "italics", StringItalics, | 1039 "italics", StringItalics, |
| 1039 "small", StringSmall, | 1040 "small", StringSmall, |
| 1040 "strike", StringStrike, | 1041 "strike", StringStrike, |
| 1041 "sub", StringSub, | 1042 "sub", StringSub, |
| 1042 "sup", StringSup | 1043 "sup", StringSup |
| 1043 )); | 1044 )); |
| 1044 } | 1045 } |
| 1045 | 1046 |
| 1046 SetUpString(); | 1047 SetUpString(); |
| OLD | NEW |