You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.0 KiB
36 lines
1.0 KiB
2 weeks ago
|
'use strict';
|
||
|
// TODO: Remove from `core-js@4` since it's moved to entry points
|
||
|
require('../modules/es.regexp.exec');
|
||
|
var $ = require('../internals/export');
|
||
|
var call = require('../internals/function-call');
|
||
|
var isCallable = require('../internals/is-callable');
|
||
|
var anObject = require('../internals/an-object');
|
||
|
var toString = require('../internals/to-string');
|
||
|
|
||
|
var DELEGATES_TO_EXEC = function () {
|
||
|
var execCalled = false;
|
||
|
var re = /[ac]/;
|
||
|
re.exec = function () {
|
||
|
execCalled = true;
|
||
|
return /./.exec.apply(this, arguments);
|
||
|
};
|
||
|
return re.test('abc') === true && execCalled;
|
||
|
}();
|
||
|
|
||
|
var nativeTest = /./.test;
|
||
|
|
||
|
// `RegExp.prototype.test` method
|
||
|
// https://tc39.es/ecma262/#sec-regexp.prototype.test
|
||
|
$({ target: 'RegExp', proto: true, forced: !DELEGATES_TO_EXEC }, {
|
||
|
test: function (S) {
|
||
|
var R = anObject(this);
|
||
|
var string = toString(S);
|
||
|
var exec = R.exec;
|
||
|
if (!isCallable(exec)) return call(nativeTest, R, string);
|
||
|
var result = call(exec, R, string);
|
||
|
if (result === null) return false;
|
||
|
anObject(result);
|
||
|
return true;
|
||
|
}
|
||
|
});
|