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 splitSymbol = utils.ImportNow("split_symbol"); | 19 var splitSymbol = utils.ImportNow("split_symbol"); |
19 var matchSymbol = utils.ImportNow("match_symbol");; | |
20 | 20 |
21 utils.ImportFromExperimental(function(from) { | 21 utils.ImportFromExperimental(function(from) { |
22 FLAG_harmony_tolength = from.FLAG_harmony_tolength; | 22 FLAG_harmony_tolength = from.FLAG_harmony_tolength; |
23 }); | 23 }); |
24 | 24 |
25 utils.Import(function(from) { | 25 utils.Import(function(from) { |
26 MakeTypeError = from.MakeTypeError; | 26 MakeTypeError = from.MakeTypeError; |
27 }); | 27 }); |
28 | 28 |
29 // ------------------------------------------------------------------- | 29 // ------------------------------------------------------------------- |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 348 |
349 startIndex = currentIndex = endIndex; | 349 startIndex = currentIndex = endIndex; |
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. |
| 359 function RegExpMatch(string) { |
| 360 if (!IS_REGEXP(this)) { |
| 361 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 362 "RegExp.prototype.@@match", this); |
| 363 } |
| 364 var subject = TO_STRING(string); |
| 365 |
| 366 if (!REGEXP_GLOBAL(this)) return RegExpExecNoTests(this, subject, 0); |
| 367 this.lastIndex = 0; |
| 368 var result = %StringMatch(subject, this, RegExpLastMatchInfo); |
| 369 return result; |
| 370 } |
| 371 |
| 372 |
358 // Getters for the static properties lastMatch, lastParen, leftContext, and | 373 // Getters for the static properties lastMatch, lastParen, leftContext, and |
359 // rightContext of the RegExp constructor. The properties are computed based | 374 // rightContext of the RegExp constructor. The properties are computed based |
360 // on the captures array of the last successful match and the subject string | 375 // on the captures array of the last successful match and the subject string |
361 // of the last successful match. | 376 // of the last successful match. |
362 function RegExpGetLastMatch() { | 377 function RegExpGetLastMatch() { |
363 var regExpSubject = LAST_SUBJECT(RegExpLastMatchInfo); | 378 var regExpSubject = LAST_SUBJECT(RegExpLastMatchInfo); |
364 return %_SubString(regExpSubject, | 379 return %_SubString(regExpSubject, |
365 RegExpLastMatchInfo[CAPTURE0], | 380 RegExpLastMatchInfo[CAPTURE0], |
366 RegExpLastMatchInfo[CAPTURE1]); | 381 RegExpLastMatchInfo[CAPTURE1]); |
367 } | 382 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 %FunctionSetPrototype(GlobalRegExp, new GlobalObject()); | 480 %FunctionSetPrototype(GlobalRegExp, new GlobalObject()); |
466 %AddNamedProperty( | 481 %AddNamedProperty( |
467 GlobalRegExp.prototype, 'constructor', GlobalRegExp, DONT_ENUM); | 482 GlobalRegExp.prototype, 'constructor', GlobalRegExp, DONT_ENUM); |
468 %SetCode(GlobalRegExp, RegExpConstructor); | 483 %SetCode(GlobalRegExp, RegExpConstructor); |
469 | 484 |
470 utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [ | 485 utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [ |
471 "exec", RegExpExecJS, | 486 "exec", RegExpExecJS, |
472 "test", RegExpTest, | 487 "test", RegExpTest, |
473 "toString", RegExpToString, | 488 "toString", RegExpToString, |
474 "compile", RegExpCompileJS, | 489 "compile", RegExpCompileJS, |
| 490 matchSymbol, RegExpMatch, |
475 splitSymbol, RegExpSplit, | 491 splitSymbol, RegExpSplit, |
476 ]); | 492 ]); |
477 | 493 |
478 utils.InstallGetter(GlobalRegExp.prototype, 'global', RegExpGetGlobal); | 494 utils.InstallGetter(GlobalRegExp.prototype, 'global', RegExpGetGlobal); |
479 utils.InstallGetter(GlobalRegExp.prototype, 'ignoreCase', RegExpGetIgnoreCase); | 495 utils.InstallGetter(GlobalRegExp.prototype, 'ignoreCase', RegExpGetIgnoreCase); |
480 utils.InstallGetter(GlobalRegExp.prototype, 'multiline', RegExpGetMultiline); | 496 utils.InstallGetter(GlobalRegExp.prototype, 'multiline', RegExpGetMultiline); |
481 utils.InstallGetter(GlobalRegExp.prototype, 'source', RegExpGetSource); | 497 utils.InstallGetter(GlobalRegExp.prototype, 'source', RegExpGetSource); |
482 | 498 |
483 // The length of compile is 1 in SpiderMonkey. | 499 // The length of compile is 1 in SpiderMonkey. |
484 %FunctionSetLength(GlobalRegExp.prototype.compile, 1); | 500 %FunctionSetLength(GlobalRegExp.prototype.compile, 1); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 // Exports | 548 // Exports |
533 | 549 |
534 utils.Export(function(to) { | 550 utils.Export(function(to) { |
535 to.RegExpExec = DoRegExpExec; | 551 to.RegExpExec = DoRegExpExec; |
536 to.RegExpExecNoTests = RegExpExecNoTests; | 552 to.RegExpExecNoTests = RegExpExecNoTests; |
537 to.RegExpLastMatchInfo = RegExpLastMatchInfo; | 553 to.RegExpLastMatchInfo = RegExpLastMatchInfo; |
538 to.RegExpTest = RegExpTest; | 554 to.RegExpTest = RegExpTest; |
539 }); | 555 }); |
540 | 556 |
541 }) | 557 }) |
OLD | NEW |