1 |
3a515b92
|
cagy
|
'use strict';
|
2 |
|
|
|
3 |
|
|
var GetIntrinsic = require('../GetIntrinsic');
|
4 |
|
|
|
5 |
|
|
var $TypeError = GetIntrinsic('%TypeError%');
|
6 |
|
|
|
7 |
|
|
var regexExec = require('../helpers/callBound')('RegExp.prototype.exec');
|
8 |
|
|
|
9 |
|
|
var Call = require('./Call');
|
10 |
|
|
var Get = require('./Get');
|
11 |
|
|
var IsCallable = require('./IsCallable');
|
12 |
|
|
var Type = require('./Type');
|
13 |
|
|
|
14 |
|
|
// https://ecma-international.org/ecma-262/6.0/#sec-regexpexec
|
15 |
|
|
|
16 |
|
|
module.exports = function RegExpExec(R, S) {
|
17 |
|
|
if (Type(R) !== 'Object') {
|
18 |
|
|
throw new $TypeError('Assertion failed: `R` must be an Object');
|
19 |
|
|
}
|
20 |
|
|
if (Type(S) !== 'String') {
|
21 |
|
|
throw new $TypeError('Assertion failed: `S` must be a String');
|
22 |
|
|
}
|
23 |
|
|
var exec = Get(R, 'exec');
|
24 |
|
|
if (IsCallable(exec)) {
|
25 |
|
|
var result = Call(exec, R, [S]);
|
26 |
|
|
if (result === null || Type(result) === 'Object') {
|
27 |
|
|
return result;
|
28 |
|
|
}
|
29 |
|
|
throw new $TypeError('"exec" method must return `null` or an Object');
|
30 |
|
|
}
|
31 |
|
|
return regexExec(R, S);
|
32 |
|
|
};
|