Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9343212
fix-regexp-well-known-symbol-logic.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
fix-regexp-well-known-symbol-logic.js
View Options
'use strict'
;
// TODO: Remove from `core-js@4` since it's moved to entry points
require
(
'../modules/es.regexp.exec'
);
var
uncurryThis
=
require
(
'../internals/function-uncurry-this'
);
var
defineBuiltIn
=
require
(
'../internals/define-built-in'
);
var
regexpExec
=
require
(
'../internals/regexp-exec'
);
var
fails
=
require
(
'../internals/fails'
);
var
wellKnownSymbol
=
require
(
'../internals/well-known-symbol'
);
var
createNonEnumerableProperty
=
require
(
'../internals/create-non-enumerable-property'
);
var
SPECIES
=
wellKnownSymbol
(
'species'
);
var
RegExpPrototype
=
RegExp
.
prototype
;
module
.
exports
=
function
(
KEY
,
exec
,
FORCED
,
SHAM
)
{
var
SYMBOL
=
wellKnownSymbol
(
KEY
);
var
DELEGATES_TO_SYMBOL
=
!
fails
(
function
()
{
// String methods call symbol-named RegEp methods
var
O
=
{};
O
[
SYMBOL
]
=
function
()
{
return
7
;
};
return
''
[
KEY
](
O
)
!=
7
;
});
var
DELEGATES_TO_EXEC
=
DELEGATES_TO_SYMBOL
&&
!
fails
(
function
()
{
// Symbol-named RegExp methods call .exec
var
execCalled
=
false
;
var
re
=
/a/
;
if
(
KEY
===
'split'
)
{
// We can't use real regex here since it causes deoptimization
// and serious performance degradation in V8
// https://github.com/zloirock/core-js/issues/306
re
=
{};
// RegExp[@@split] doesn't call the regex's exec method, but first creates
// a new one. We need to return the patched regex when creating the new one.
re
.
constructor
=
{};
re
.
constructor
[
SPECIES
]
=
function
()
{
return
re
;
};
re
.
flags
=
''
;
re
[
SYMBOL
]
=
/./
[
SYMBOL
];
}
re
.
exec
=
function
()
{
execCalled
=
true
;
return
null
;
};
re
[
SYMBOL
](
''
);
return
!
execCalled
;
});
if
(
!
DELEGATES_TO_SYMBOL
||
!
DELEGATES_TO_EXEC
||
FORCED
)
{
var
uncurriedNativeRegExpMethod
=
uncurryThis
(
/./
[
SYMBOL
]);
var
methods
=
exec
(
SYMBOL
,
''
[
KEY
],
function
(
nativeMethod
,
regexp
,
str
,
arg2
,
forceStringMethod
)
{
var
uncurriedNativeMethod
=
uncurryThis
(
nativeMethod
);
var
$exec
=
regexp
.
exec
;
if
(
$exec
===
regexpExec
||
$exec
===
RegExpPrototype
.
exec
)
{
if
(
DELEGATES_TO_SYMBOL
&&
!
forceStringMethod
)
{
// The native String method already delegates to @@method (this
// polyfilled function), leasing to infinite recursion.
// We avoid it by directly calling the native @@method method.
return
{
done
:
true
,
value
:
uncurriedNativeRegExpMethod
(
regexp
,
str
,
arg2
)
};
}
return
{
done
:
true
,
value
:
uncurriedNativeMethod
(
str
,
regexp
,
arg2
)
};
}
return
{
done
:
false
};
});
defineBuiltIn
(
String
.
prototype
,
KEY
,
methods
[
0
]);
defineBuiltIn
(
RegExpPrototype
,
SYMBOL
,
methods
[
1
]);
}
if
(
SHAM
)
createNonEnumerableProperty
(
RegExpPrototype
[
SYMBOL
],
'sham'
,
true
);
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jul 4, 1:21 PM (6 d, 8 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3357631
Attached To
rDWAPPS Web applications
Event Timeline
Log In to Comment