Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
951 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | // TODO: Remove from `core-js@4` since it's moved to entry points
|
---|
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 | // `RegExp.prototype.test` method
|
---|
20 | // https://tc39.es/ecma262/#sec-regexp.prototype.test
|
---|
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 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.