1 | 'use strict';
|
2 |
|
3 | require('../modules/es.regexp.exec');
|
4 | var $ = require('../internals/export');
|
5 | var isObject = require('../internals/is-object');
|
6 |
|
7 | var DELEGATES_TO_EXEC = function () {
|
8 | var execCalled = false;
|
9 | var re = /[ac]/;
|
10 | re.exec = function () {
|
11 | execCalled = true;
|
12 | return /./.exec.apply(this, arguments);
|
13 | };
|
14 | return re.test('abc') === true && execCalled;
|
15 | }();
|
16 |
|
17 | var nativeTest = /./.test;
|
18 |
|
19 |
|
20 |
|
21 | $({ target: 'RegExp', proto: true, forced: !DELEGATES_TO_EXEC }, {
|
22 | test: function (str) {
|
23 | if (typeof this.exec !== 'function') {
|
24 | return nativeTest.call(this, str);
|
25 | }
|
26 | var result = this.exec(str);
|
27 | if (result !== null && !isObject(result)) {
|
28 | throw new Error('RegExp exec method returned something other than an Object or null');
|
29 | }
|
30 | return !!result;
|
31 | }
|
32 | });
|