@@ -8,17 +8,39 @@ var regexpExec = require('../internals/regexp-exec');
8
8
9
9
var SPECIES = wellKnownSymbol ( 'species' ) ;
10
10
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
+
11
33
module . exports = function ( KEY , length , exec , sham ) {
12
34
var SYMBOL = wellKnownSymbol ( KEY ) ;
13
35
14
- var delegatesToSymbol = ! fails ( function ( ) {
36
+ var DELEGATES_TO_SYMBOL = ! fails ( function ( ) {
15
37
// String methods call symbol-named RegEp methods
16
38
var O = { } ;
17
39
O [ SYMBOL ] = function ( ) { return 7 ; } ;
18
40
return '' [ KEY ] ( O ) != 7 ;
19
41
} ) ;
20
42
21
- var delegatesToExec = delegatesToSymbol ? ! fails ( function ( ) {
43
+ var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL ? ! fails ( function ( ) {
22
44
// Symbol-named RegExp methods call .exec
23
45
var execCalled = false ;
24
46
var re = / a / ;
@@ -35,42 +57,20 @@ module.exports = function (KEY, length, exec, sham) {
35
57
return ! execCalled ;
36
58
} ) : undefined ;
37
59
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
-
60
60
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 )
65
65
) {
66
66
var nativeRegExpMethod = / ./ [ SYMBOL ] ;
67
67
var methods = exec (
68
68
requireObjectCoercible ,
69
69
SYMBOL ,
70
70
'' [ 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 ) {
74
74
// The native String method already delegates to @@method (this
75
75
// polyfilled function), leasing to infinite recursion.
76
76
// We avoid it by directly calling the native @@method method.
0 commit comments