@@ -8,17 +8,39 @@ var regexpExec = require('../internals/regexp-exec');
88
99var SPECIES = wellKnownSymbol ( 'species' ) ;
1010
11+ var REPLACE_SUPPORTS_NAMED_GROUPS = ! fails ( function ( ) {
12+ // #replace needs built-in support for named groups.
13+ // #match works fine because it just return the exec results, even if it has
14+ // a "grops" property.
15+ var re = / ./ ;
16+ re . exec = function ( ) {
17+ var result = [ ] ;
18+ result . groups = { a : '7' } ;
19+ return result ;
20+ } ;
21+ return '' . replace ( re , '$<a>' ) !== '7' ;
22+ } ) ;
23+
24+ var SPLIT_WORKS_WITH_OVERWRITTEN_EXEC = ( function ( ) {
25+ // Chrome 51 has a buggy "split" implementation when RegExp#exec !== nativeExec
26+ var re = / (?: ) / ;
27+ var originalExec = re . exec ;
28+ re . exec = function ( ) { return originalExec . apply ( this , arguments ) ; } ;
29+ var result = 'ab' . split ( re ) ;
30+ return result . length === 2 && result [ 0 ] === 'a' && result [ 1 ] === 'b' ;
31+ } ) ( ) ;
32+
1133module . exports = function ( KEY , length , exec , sham ) {
1234 var SYMBOL = wellKnownSymbol ( KEY ) ;
1335
14- var delegatesToSymbol = ! fails ( function ( ) {
36+ var DELEGATES_TO_SYMBOL = ! fails ( function ( ) {
1537 // String methods call symbol-named RegEp methods
1638 var O = { } ;
1739 O [ SYMBOL ] = function ( ) { return 7 ; } ;
1840 return '' [ KEY ] ( O ) != 7 ;
1941 } ) ;
2042
21- var delegatesToExec = delegatesToSymbol ? ! fails ( function ( ) {
43+ var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL ? ! fails ( function ( ) {
2244 // Symbol-named RegExp methods call .exec
2345 var execCalled = false ;
2446 var re = / a / ;
@@ -35,42 +57,20 @@ module.exports = function (KEY, length, exec, sham) {
3557 return ! execCalled ;
3658 } ) : undefined ;
3759
38- var replaceSupportsNamedGroups = KEY === 'replace' && ! fails ( function ( ) {
39- // #replace needs built-in support for named groups.
40- // #match works fine because it just return the exec results, even if it has
41- // a "grops" property.
42- var re = / ./ ;
43- re . exec = function ( ) {
44- var result = [ ] ;
45- result . groups = { a : '7' } ;
46- return result ;
47- } ;
48- return '' . replace ( re , '$<a>' ) !== '7' ;
49- } ) ;
50-
51- var splitWorksWithOverwrittenExec = KEY === 'split' && ( function ( ) {
52- // Chrome 51 has a buggy "split" implementation when RegExp#exec !== nativeExec
53- var re = / (?: ) / ;
54- var originalExec = re . exec ;
55- re . exec = function ( ) { return originalExec . apply ( this , arguments ) ; } ;
56- var result = 'ab' . split ( re ) ;
57- return result . length === 2 && result [ 0 ] === 'a' && result [ 1 ] === 'b' ;
58- } ) ( ) ;
59-
6060 if (
61- ! delegatesToSymbol ||
62- ! delegatesToExec ||
63- ( KEY === 'replace' && ! replaceSupportsNamedGroups ) ||
64- ( KEY === 'split' && ! splitWorksWithOverwrittenExec )
61+ ! DELEGATES_TO_SYMBOL ||
62+ ! DELEGATES_TO_EXEC ||
63+ ( KEY === 'replace' && ! REPLACE_SUPPORTS_NAMED_GROUPS ) ||
64+ ( KEY === 'split' && ! SPLIT_WORKS_WITH_OVERWRITTEN_EXEC )
6565 ) {
6666 var nativeRegExpMethod = / ./ [ SYMBOL ] ;
6767 var methods = exec (
6868 requireObjectCoercible ,
6969 SYMBOL ,
7070 '' [ KEY ] ,
71- function maybeCallNative ( nativeMethod , regexp , str , arg2 , forceStringMethod ) {
72- if ( regexp . exec === regexpExec . impl ) {
73- if ( delegatesToSymbol && ! forceStringMethod ) {
71+ function ( nativeMethod , regexp , str , arg2 , forceStringMethod ) {
72+ if ( regexp . exec === regexpExec ) {
73+ if ( DELEGATES_TO_SYMBOL && ! forceStringMethod ) {
7474 // The native String method already delegates to @@method (this
7575 // polyfilled function), leasing to infinite recursion.
7676 // We avoid it by directly calling the native @@method method.
0 commit comments