| 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 'use strict'; | 7 'use strict'; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 'RegExp.prototype.exec', this); | 187 'RegExp.prototype.exec', this); |
| 188 } | 188 } |
| 189 | 189 |
| 190 string = TO_STRING(string); | 190 string = TO_STRING(string); |
| 191 var lastIndex = this.lastIndex; | 191 var lastIndex = this.lastIndex; |
| 192 | 192 |
| 193 // Conversion is required by the ES2015 specification (RegExpBuiltinExec | 193 // Conversion is required by the ES2015 specification (RegExpBuiltinExec |
| 194 // algorithm, step 4) even if the value is discarded for non-global RegExps. | 194 // algorithm, step 4) even if the value is discarded for non-global RegExps. |
| 195 var i = TO_LENGTH(lastIndex); | 195 var i = TO_LENGTH(lastIndex); |
| 196 | 196 |
| 197 var global = TO_BOOLEAN(this.global); | 197 var global = TO_BOOLEAN(REGEXP_GLOBAL(this)); |
| 198 var sticky = TO_BOOLEAN(this.sticky); | 198 var sticky = TO_BOOLEAN(REGEXP_STICKY(this)); |
| 199 var updateLastIndex = global || sticky; | 199 var updateLastIndex = global || sticky; |
| 200 if (updateLastIndex) { | 200 if (updateLastIndex) { |
| 201 if (i > string.length) { | 201 if (i > string.length) { |
| 202 this.lastIndex = 0; | 202 this.lastIndex = 0; |
| 203 return null; | 203 return null; |
| 204 } | 204 } |
| 205 } else { | 205 } else { |
| 206 i = 0; | 206 i = 0; |
| 207 } | 207 } |
| 208 | 208 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 new GlobalRegExp( | 363 new GlobalRegExp( |
| 364 %_SubString(REGEXP_SOURCE(regexp), 2, REGEXP_SOURCE(regexp).length), | 364 %_SubString(REGEXP_SOURCE(regexp), 2, REGEXP_SOURCE(regexp).length), |
| 365 (REGEXP_IGNORE_CASE(regexp) ? REGEXP_MULTILINE(regexp) ? "im" : "i" | 365 (REGEXP_IGNORE_CASE(regexp) ? REGEXP_MULTILINE(regexp) ? "im" : "i" |
| 366 : REGEXP_MULTILINE(regexp) ? "m" : "")); | 366 : REGEXP_MULTILINE(regexp) ? "m" : "")); |
| 367 } | 367 } |
| 368 return regexp_val; | 368 return regexp_val; |
| 369 } | 369 } |
| 370 | 370 |
| 371 | 371 |
| 372 function RegExpToString() { | 372 function RegExpToString() { |
| 373 if (!IS_REGEXP(this)) { | 373 if (!IS_RECEIVER(this)) { |
| 374 // RegExp.prototype.toString() returns '/(?:)/' as a compatibility fix; | 374 throw MakeTypeError( |
| 375 // a UseCounter is incremented to track it. | 375 kIncompatibleMethodReceiver, 'RegExp.prototype.toString', this); |
| 376 // TODO(littledan): Remove this workaround or standardize it | |
| 377 if (this === GlobalRegExpPrototype) { | |
| 378 %IncrementUseCounter(kRegExpPrototypeToString); | |
| 379 return '/(?:)/'; | |
| 380 } | |
| 381 if (!IS_RECEIVER(this)) { | |
| 382 throw MakeTypeError( | |
| 383 kIncompatibleMethodReceiver, 'RegExp.prototype.toString', this); | |
| 384 } | |
| 385 return '/' + TO_STRING(this.source) + '/' + TO_STRING(this.flags); | |
| 386 } | 376 } |
| 387 var result = '/' + REGEXP_SOURCE(this) + '/'; | 377 if (this === GlobalRegExpPrototype) { |
| 388 if (REGEXP_GLOBAL(this)) result += 'g'; | 378 %IncrementUseCounter(kRegExpPrototypeToString); |
| 389 if (REGEXP_IGNORE_CASE(this)) result += 'i'; | 379 } |
| 390 if (REGEXP_MULTILINE(this)) result += 'm'; | 380 return '/' + TO_STRING(this.source) + '/' + TO_STRING(this.flags); |
| 391 if (REGEXP_UNICODE(this)) result += 'u'; | |
| 392 if (REGEXP_STICKY(this)) result += 'y'; | |
| 393 return result; | |
| 394 } | 381 } |
| 395 | 382 |
| 396 | 383 |
| 397 function AtSurrogatePair(subject, index) { | 384 function AtSurrogatePair(subject, index) { |
| 398 if (index + 1 >= subject.length) return false; | 385 if (index + 1 >= subject.length) return false; |
| 399 var first = %_StringCharCodeAt(subject, index); | 386 var first = %_StringCharCodeAt(subject, index); |
| 400 if (first < 0xD800 || first > 0xDBFF) return false; | 387 if (first < 0xD800 || first > 0xDBFF) return false; |
| 401 var second = %_StringCharCodeAt(subject, index + 1); | 388 var second = %_StringCharCodeAt(subject, index + 1); |
| 402 return second >= 0xDC00 || second <= 0xDFFF; | 389 return second >= 0xDC00 || second <= 0xDFFF; |
| 403 } | 390 } |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 return TO_BOOLEAN(REGEXP_MULTILINE(this)); | 1106 return TO_BOOLEAN(REGEXP_MULTILINE(this)); |
| 1120 } | 1107 } |
| 1121 | 1108 |
| 1122 | 1109 |
| 1123 // ES6 21.2.5.10. | 1110 // ES6 21.2.5.10. |
| 1124 function RegExpGetSource() { | 1111 function RegExpGetSource() { |
| 1125 if (!IS_REGEXP(this)) { | 1112 if (!IS_REGEXP(this)) { |
| 1126 // TODO(littledan): Remove this RegExp compat workaround | 1113 // TODO(littledan): Remove this RegExp compat workaround |
| 1127 if (this === GlobalRegExpPrototype) { | 1114 if (this === GlobalRegExpPrototype) { |
| 1128 %IncrementUseCounter(kRegExpPrototypeSourceGetter); | 1115 %IncrementUseCounter(kRegExpPrototypeSourceGetter); |
| 1129 return UNDEFINED; | 1116 return "(?:)"; |
| 1130 } | 1117 } |
| 1131 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.source"); | 1118 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.source"); |
| 1132 } | 1119 } |
| 1133 return REGEXP_SOURCE(this); | 1120 return REGEXP_SOURCE(this); |
| 1134 } | 1121 } |
| 1135 | 1122 |
| 1136 | 1123 |
| 1137 // ES6 21.2.5.12. | 1124 // ES6 21.2.5.12. |
| 1138 function RegExpGetSticky() { | 1125 function RegExpGetSticky() { |
| 1139 if (!IS_REGEXP(this)) { | 1126 if (!IS_REGEXP(this)) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 to.RegExpSubclassExecJS = RegExpSubclassExecJS; | 1239 to.RegExpSubclassExecJS = RegExpSubclassExecJS; |
| 1253 to.RegExpSubclassMatch = RegExpSubclassMatch; | 1240 to.RegExpSubclassMatch = RegExpSubclassMatch; |
| 1254 to.RegExpSubclassReplace = RegExpSubclassReplace; | 1241 to.RegExpSubclassReplace = RegExpSubclassReplace; |
| 1255 to.RegExpSubclassSearch = RegExpSubclassSearch; | 1242 to.RegExpSubclassSearch = RegExpSubclassSearch; |
| 1256 to.RegExpSubclassSplit = RegExpSubclassSplit; | 1243 to.RegExpSubclassSplit = RegExpSubclassSplit; |
| 1257 to.RegExpSubclassTest = RegExpSubclassTest; | 1244 to.RegExpSubclassTest = RegExpSubclassTest; |
| 1258 to.RegExpTest = RegExpTest; | 1245 to.RegExpTest = RegExpTest; |
| 1259 }); | 1246 }); |
| 1260 | 1247 |
| 1261 }) | 1248 }) |
| OLD | NEW |