| 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 |
| 11 | 11 |
| 12 var FLAG_harmony_tolength; | 12 var FLAG_harmony_tolength; |
| 13 var GlobalObject = global.Object; | 13 var GlobalObject = global.Object; |
| 14 var GlobalRegExp = global.RegExp; | 14 var GlobalRegExp = global.RegExp; |
| 15 var InternalArray = utils.InternalArray; | 15 var InternalArray = utils.InternalArray; |
| 16 var InternalPackedArray = utils.InternalPackedArray; | 16 var InternalPackedArray = utils.InternalPackedArray; |
| 17 var MakeTypeError; | 17 var MakeTypeError; |
| 18 var matchSymbol = utils.ImportNow("match_symbol"); | 18 var matchSymbol = utils.ImportNow("match_symbol"); |
| 19 var searchSymbol = utils.ImportNow("search_symbol"); |
| 19 var splitSymbol = utils.ImportNow("split_symbol"); | 20 var splitSymbol = utils.ImportNow("split_symbol"); |
| 20 | 21 |
| 21 utils.ImportFromExperimental(function(from) { | 22 utils.ImportFromExperimental(function(from) { |
| 22 FLAG_harmony_tolength = from.FLAG_harmony_tolength; | 23 FLAG_harmony_tolength = from.FLAG_harmony_tolength; |
| 23 }); | 24 }); |
| 24 | 25 |
| 25 utils.Import(function(from) { | 26 utils.Import(function(from) { |
| 26 MakeTypeError = from.MakeTypeError; | 27 MakeTypeError = from.MakeTypeError; |
| 27 }); | 28 }); |
| 28 | 29 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 111 |
| 111 flags = PatternFlags(pattern); | 112 flags = PatternFlags(pattern); |
| 112 pattern = REGEXP_SOURCE(pattern); | 113 pattern = REGEXP_SOURCE(pattern); |
| 113 } | 114 } |
| 114 | 115 |
| 115 return RegExpInitialize(this, pattern, flags); | 116 return RegExpInitialize(this, pattern, flags); |
| 116 } | 117 } |
| 117 | 118 |
| 118 | 119 |
| 119 function DoRegExpExec(regexp, string, index) { | 120 function DoRegExpExec(regexp, string, index) { |
| 120 var result = %_RegExpExec(regexp, string, index, RegExpLastMatchInfo); | 121 return %_RegExpExec(regexp, string, index, RegExpLastMatchInfo); |
| 121 return result; | |
| 122 } | 122 } |
| 123 | 123 |
| 124 | 124 |
| 125 // This is kind of performance sensitive, so we want to avoid unnecessary | 125 // This is kind of performance sensitive, so we want to avoid unnecessary |
| 126 // type checks on inputs. But we also don't want to inline it several times | 126 // type checks on inputs. But we also don't want to inline it several times |
| 127 // manually, so we use a macro :-) | 127 // manually, so we use a macro :-) |
| 128 macro RETURN_NEW_RESULT_FROM_MATCH_INFO(MATCHINFO, STRING) | 128 macro RETURN_NEW_RESULT_FROM_MATCH_INFO(MATCHINFO, STRING) |
| 129 var numResults = NUMBER_OF_CAPTURES(MATCHINFO) >> 1; | 129 var numResults = NUMBER_OF_CAPTURES(MATCHINFO) >> 1; |
| 130 var start = MATCHINFO[CAPTURE0]; | 130 var start = MATCHINFO[CAPTURE0]; |
| 131 var end = MATCHINFO[CAPTURE1]; | 131 var end = MATCHINFO[CAPTURE1]; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 } | 350 } |
| 351 | 351 |
| 352 var array_result = []; | 352 var array_result = []; |
| 353 %MoveArrayContents(result, array_result); | 353 %MoveArrayContents(result, array_result); |
| 354 return array_result; | 354 return array_result; |
| 355 } | 355 } |
| 356 | 356 |
| 357 | 357 |
| 358 // ES6 21.2.5.6. | 358 // ES6 21.2.5.6. |
| 359 function RegExpMatch(string) { | 359 function RegExpMatch(string) { |
| 360 // TODO(yangguo): allow non-regexp receivers. |
| 360 if (!IS_REGEXP(this)) { | 361 if (!IS_REGEXP(this)) { |
| 361 throw MakeTypeError(kIncompatibleMethodReceiver, | 362 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 362 "RegExp.prototype.@@match", this); | 363 "RegExp.prototype.@@match", this); |
| 363 } | 364 } |
| 364 var subject = TO_STRING(string); | 365 var subject = TO_STRING(string); |
| 365 | 366 |
| 366 if (!REGEXP_GLOBAL(this)) return RegExpExecNoTests(this, subject, 0); | 367 if (!REGEXP_GLOBAL(this)) return RegExpExecNoTests(this, subject, 0); |
| 367 this.lastIndex = 0; | 368 this.lastIndex = 0; |
| 368 var result = %StringMatch(subject, this, RegExpLastMatchInfo); | 369 var result = %StringMatch(subject, this, RegExpLastMatchInfo); |
| 369 return result; | 370 return result; |
| 370 } | 371 } |
| 371 | 372 |
| 372 | 373 |
| 374 // ES6 21.2.5.9. |
| 375 function RegExpSearch(string) { |
| 376 // TODO(yangguo): allow non-regexp receivers. |
| 377 if (!IS_REGEXP(this)) { |
| 378 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 379 "RegExp.prototype.@@search", this); |
| 380 } |
| 381 var match = DoRegExpExec(this, TO_STRING(string), 0); |
| 382 if (match) return match[CAPTURE0]; |
| 383 return -1; |
| 384 } |
| 385 |
| 386 |
| 373 // Getters for the static properties lastMatch, lastParen, leftContext, and | 387 // Getters for the static properties lastMatch, lastParen, leftContext, and |
| 374 // rightContext of the RegExp constructor. The properties are computed based | 388 // rightContext of the RegExp constructor. The properties are computed based |
| 375 // on the captures array of the last successful match and the subject string | 389 // on the captures array of the last successful match and the subject string |
| 376 // of the last successful match. | 390 // of the last successful match. |
| 377 function RegExpGetLastMatch() { | 391 function RegExpGetLastMatch() { |
| 378 var regExpSubject = LAST_SUBJECT(RegExpLastMatchInfo); | 392 var regExpSubject = LAST_SUBJECT(RegExpLastMatchInfo); |
| 379 return %_SubString(regExpSubject, | 393 return %_SubString(regExpSubject, |
| 380 RegExpLastMatchInfo[CAPTURE0], | 394 RegExpLastMatchInfo[CAPTURE0], |
| 381 RegExpLastMatchInfo[CAPTURE1]); | 395 RegExpLastMatchInfo[CAPTURE1]); |
| 382 } | 396 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 %AddNamedProperty( | 495 %AddNamedProperty( |
| 482 GlobalRegExp.prototype, 'constructor', GlobalRegExp, DONT_ENUM); | 496 GlobalRegExp.prototype, 'constructor', GlobalRegExp, DONT_ENUM); |
| 483 %SetCode(GlobalRegExp, RegExpConstructor); | 497 %SetCode(GlobalRegExp, RegExpConstructor); |
| 484 | 498 |
| 485 utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [ | 499 utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [ |
| 486 "exec", RegExpExecJS, | 500 "exec", RegExpExecJS, |
| 487 "test", RegExpTest, | 501 "test", RegExpTest, |
| 488 "toString", RegExpToString, | 502 "toString", RegExpToString, |
| 489 "compile", RegExpCompileJS, | 503 "compile", RegExpCompileJS, |
| 490 matchSymbol, RegExpMatch, | 504 matchSymbol, RegExpMatch, |
| 505 searchSymbol, RegExpSearch, |
| 491 splitSymbol, RegExpSplit, | 506 splitSymbol, RegExpSplit, |
| 492 ]); | 507 ]); |
| 493 | 508 |
| 494 utils.InstallGetter(GlobalRegExp.prototype, 'global', RegExpGetGlobal); | 509 utils.InstallGetter(GlobalRegExp.prototype, 'global', RegExpGetGlobal); |
| 495 utils.InstallGetter(GlobalRegExp.prototype, 'ignoreCase', RegExpGetIgnoreCase); | 510 utils.InstallGetter(GlobalRegExp.prototype, 'ignoreCase', RegExpGetIgnoreCase); |
| 496 utils.InstallGetter(GlobalRegExp.prototype, 'multiline', RegExpGetMultiline); | 511 utils.InstallGetter(GlobalRegExp.prototype, 'multiline', RegExpGetMultiline); |
| 497 utils.InstallGetter(GlobalRegExp.prototype, 'source', RegExpGetSource); | 512 utils.InstallGetter(GlobalRegExp.prototype, 'source', RegExpGetSource); |
| 498 | 513 |
| 499 // The length of compile is 1 in SpiderMonkey. | 514 // The length of compile is 1 in SpiderMonkey. |
| 500 %FunctionSetLength(GlobalRegExp.prototype.compile, 1); | 515 %FunctionSetLength(GlobalRegExp.prototype.compile, 1); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 // Exports | 563 // Exports |
| 549 | 564 |
| 550 utils.Export(function(to) { | 565 utils.Export(function(to) { |
| 551 to.RegExpExec = DoRegExpExec; | 566 to.RegExpExec = DoRegExpExec; |
| 552 to.RegExpExecNoTests = RegExpExecNoTests; | 567 to.RegExpExecNoTests = RegExpExecNoTests; |
| 553 to.RegExpLastMatchInfo = RegExpLastMatchInfo; | 568 to.RegExpLastMatchInfo = RegExpLastMatchInfo; |
| 554 to.RegExpTest = RegExpTest; | 569 to.RegExpTest = RegExpTest; |
| 555 }); | 570 }); |
| 556 | 571 |
| 557 }) | 572 }) |
| OLD | NEW |