1 | 'use strict';
|
2 |
|
3 | require('../modules/es.regexp.exec');
|
4 | var $ = require('../internals/export');
|
5 | var call = require('../internals/function-call');
|
6 | var isCallable = require('../internals/is-callable');
|
7 | var anObject = require('../internals/an-object');
|
8 | var toString = require('../internals/to-string');
|
9 |
|
10 | var DELEGATES_TO_EXEC = function () {
|
11 | var execCalled = false;
|
12 | var re = /[ac]/;
|
13 | re.exec = function () {
|
14 | execCalled = true;
|
15 | return /./.exec.apply(this, arguments);
|
16 | };
|
17 | return re.test('abc') === true && execCalled;
|
18 | }();
|
19 |
|
20 | var nativeTest = /./.test;
|
21 |
|
22 |
|
23 |
|
24 | $({ target: 'RegExp', proto: true, forced: !DELEGATES_TO_EXEC }, {
|
25 | test: function (S) {
|
26 | var R = anObject(this);
|
27 | var string = toString(S);
|
28 | var exec = R.exec;
|
29 | if (!isCallable(exec)) return call(nativeTest, R, string);
|
30 | var result = call(exec, R, string);
|
31 | if (result === null) return false;
|
32 | anObject(result);
|
33 | return true;
|
34 | }
|
35 | });
|