| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (function(global, utils) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 %CheckIsBootstrapping(); | 7 %CheckIsBootstrapping(); |
| 8 | 8 |
| 9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
| 10 // Imports | 10 // Imports |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 var result = '/' + REGEXP_SOURCE(this) + '/'; | 289 var result = '/' + REGEXP_SOURCE(this) + '/'; |
| 290 if (REGEXP_GLOBAL(this)) result += 'g'; | 290 if (REGEXP_GLOBAL(this)) result += 'g'; |
| 291 if (REGEXP_IGNORE_CASE(this)) result += 'i'; | 291 if (REGEXP_IGNORE_CASE(this)) result += 'i'; |
| 292 if (REGEXP_MULTILINE(this)) result += 'm'; | 292 if (REGEXP_MULTILINE(this)) result += 'm'; |
| 293 if (REGEXP_UNICODE(this)) result += 'u'; | 293 if (REGEXP_UNICODE(this)) result += 'u'; |
| 294 if (REGEXP_STICKY(this)) result += 'y'; | 294 if (REGEXP_STICKY(this)) result += 'y'; |
| 295 return result; | 295 return result; |
| 296 } | 296 } |
| 297 | 297 |
| 298 | 298 |
| 299 function AtSurrogatePair(subject, index) { |
| 300 if (index + 1 >= subject.length) return false; |
| 301 var first = %_StringCharCodeAt(subject, index); |
| 302 if (first < 0xD800 || first > 0xDBFF) return false; |
| 303 var second = %_StringCharCodeAt(subject, index + 1); |
| 304 return second >= 0xDC00 || second <= 0xDFFF; |
| 305 } |
| 306 |
| 307 |
| 299 // ES6 21.2.5.11. | 308 // ES6 21.2.5.11. |
| 300 function RegExpSplit(string, limit) { | 309 function RegExpSplit(string, limit) { |
| 301 // TODO(yangguo): allow non-regexp receivers. | 310 // TODO(yangguo): allow non-regexp receivers. |
| 302 if (!IS_REGEXP(this)) { | 311 if (!IS_REGEXP(this)) { |
| 303 throw MakeTypeError(kIncompatibleMethodReceiver, | 312 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 304 "RegExp.prototype.@@split", this); | 313 "RegExp.prototype.@@split", this); |
| 305 } | 314 } |
| 306 var separator = this; | 315 var separator = this; |
| 307 var subject = TO_STRING(string); | 316 var subject = TO_STRING(string); |
| 308 | 317 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 330 | 339 |
| 331 var matchInfo = DoRegExpExec(separator, subject, startIndex); | 340 var matchInfo = DoRegExpExec(separator, subject, startIndex); |
| 332 if (matchInfo === null || length === (startMatch = matchInfo[CAPTURE0])) { | 341 if (matchInfo === null || length === (startMatch = matchInfo[CAPTURE0])) { |
| 333 result[result.length] = %_SubString(subject, currentIndex, length); | 342 result[result.length] = %_SubString(subject, currentIndex, length); |
| 334 break; | 343 break; |
| 335 } | 344 } |
| 336 var endIndex = matchInfo[CAPTURE1]; | 345 var endIndex = matchInfo[CAPTURE1]; |
| 337 | 346 |
| 338 // We ignore a zero-length match at the currentIndex. | 347 // We ignore a zero-length match at the currentIndex. |
| 339 if (startIndex === endIndex && endIndex === currentIndex) { | 348 if (startIndex === endIndex && endIndex === currentIndex) { |
| 340 startIndex++; | 349 if (REGEXP_UNICODE(this) && AtSurrogatePair(subject, startIndex)) { |
| 350 startIndex += 2; |
| 351 } else { |
| 352 startIndex++; |
| 353 } |
| 341 continue; | 354 continue; |
| 342 } | 355 } |
| 343 | 356 |
| 344 result[result.length] = %_SubString(subject, currentIndex, startMatch); | 357 result[result.length] = %_SubString(subject, currentIndex, startMatch); |
| 345 | 358 |
| 346 if (result.length === limit) break; | 359 if (result.length === limit) break; |
| 347 | 360 |
| 348 var matchinfo_len = NUMBER_OF_CAPTURES(matchInfo) + REGEXP_FIRST_CAPTURE; | 361 var matchinfo_len = NUMBER_OF_CAPTURES(matchInfo) + REGEXP_FIRST_CAPTURE; |
| 349 for (var i = REGEXP_FIRST_CAPTURE + 2; i < matchinfo_len; ) { | 362 for (var i = REGEXP_FIRST_CAPTURE + 2; i < matchinfo_len; ) { |
| 350 var start = matchInfo[i++]; | 363 var start = matchInfo[i++]; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 // Exports | 755 // Exports |
| 743 | 756 |
| 744 utils.Export(function(to) { | 757 utils.Export(function(to) { |
| 745 to.RegExpExec = DoRegExpExec; | 758 to.RegExpExec = DoRegExpExec; |
| 746 to.RegExpExecNoTests = RegExpExecNoTests; | 759 to.RegExpExecNoTests = RegExpExecNoTests; |
| 747 to.RegExpLastMatchInfo = RegExpLastMatchInfo; | 760 to.RegExpLastMatchInfo = RegExpLastMatchInfo; |
| 748 to.RegExpTest = RegExpTest; | 761 to.RegExpTest = RegExpTest; |
| 749 }); | 762 }); |
| 750 | 763 |
| 751 }) | 764 }) |
| OLD | NEW |