blob: e393c83e8d4132259432faaedac5fcb317e76ee9 [file] [log] [blame]
Tim van der Lippefdbd42e2020-04-07 14:14:361'use strict';
2
Nikolay Vitkovd76576c2024-12-02 14:10:153var $TypeError = require('es-errors/type');
Tim van der Lippefdbd42e2020-04-07 14:14:364
Tim van der Lippe2c891972021-07-29 15:22:505var regexExec = require('call-bind/callBound')('RegExp.prototype.exec');
Tim van der Lippefdbd42e2020-04-07 14:14:366
7var Call = require('./Call');
8var Get = require('./Get');
9var IsCallable = require('./IsCallable');
10var Type = require('./Type');
11
Nikolay Vitkovd76576c2024-12-02 14:10:1512// https://262.ecma-international.org/6.0/#sec-regexpexec
Tim van der Lippefdbd42e2020-04-07 14:14:3613
14module.exports = function RegExpExec(R, S) {
15 if (Type(R) !== 'Object') {
16 throw new $TypeError('Assertion failed: `R` must be an Object');
17 }
Nikolay Vitkovd76576c2024-12-02 14:10:1518 if (typeof S !== 'string') {
Tim van der Lippefdbd42e2020-04-07 14:14:3619 throw new $TypeError('Assertion failed: `S` must be a String');
20 }
21 var exec = Get(R, 'exec');
22 if (IsCallable(exec)) {
23 var result = Call(exec, R, [S]);
Nikolay Vitkovd76576c2024-12-02 14:10:1524 if (typeof result === 'object') {
Tim van der Lippefdbd42e2020-04-07 14:14:3625 return result;
26 }
27 throw new $TypeError('"exec" method must return `null` or an Object');
28 }
29 return regexExec(R, S);
30};