UNPKG

598 BJavaScriptView Raw
1var classof = require('./classof-raw');
2var regexpExec = require('./regexp-exec');
3
4// `RegExpExec` abstract operation
5// https://tc39.github.io/ecma262/#sec-regexpexec
6module.exports = function (R, S) {
7 var exec = R.exec;
8 if (typeof exec === 'function') {
9 var result = exec.call(R, S);
10 if (typeof result !== 'object') {
11 throw TypeError('RegExp exec method returned something other than an Object or null');
12 }
13 return result;
14 }
15
16 if (classof(R) !== 'RegExp') {
17 throw TypeError('RegExp#exec called on incompatible receiver');
18 }
19
20 return regexpExec.call(R, S);
21};
22