UNPKG

700 BJavaScriptView Raw
1'use strict';
2var call = require('../internals/function-call');
3var anObject = require('../internals/an-object');
4var isCallable = require('../internals/is-callable');
5var classof = require('../internals/classof-raw');
6var regexpExec = require('../internals/regexp-exec');
7
8var $TypeError = TypeError;
9
10// `RegExpExec` abstract operation
11// https://tc39.es/ecma262/#sec-regexpexec
12module.exports = function (R, S) {
13 var exec = R.exec;
14 if (isCallable(exec)) {
15 var result = call(exec, R, S);
16 if (result !== null) anObject(result);
17 return result;
18 }
19 if (classof(R) === 'RegExp') return call(regexpExec, R, S);
20 throw new $TypeError('RegExp#exec called on incompatible receiver');
21};