main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
827 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $TypeError = require('es-errors/type');
|
---|
| 4 |
|
---|
[79a0317] | 5 | var regexExec = require('call-bound')('RegExp.prototype.exec');
|
---|
[d565449] | 6 |
|
---|
| 7 | var Call = require('./Call');
|
---|
| 8 | var Get = require('./Get');
|
---|
| 9 | var IsCallable = require('./IsCallable');
|
---|
[79a0317] | 10 |
|
---|
| 11 | var isObject = require('../helpers/isObject');
|
---|
[d565449] | 12 |
|
---|
| 13 | // https://262.ecma-international.org/6.0/#sec-regexpexec
|
---|
| 14 |
|
---|
| 15 | module.exports = function RegExpExec(R, S) {
|
---|
[79a0317] | 16 | if (!isObject(R)) {
|
---|
[d565449] | 17 | throw new $TypeError('Assertion failed: `R` must be an Object');
|
---|
| 18 | }
|
---|
| 19 | if (typeof S !== 'string') {
|
---|
| 20 | throw new $TypeError('Assertion failed: `S` must be a String');
|
---|
| 21 | }
|
---|
| 22 | var exec = Get(R, 'exec');
|
---|
| 23 | if (IsCallable(exec)) {
|
---|
| 24 | var result = Call(exec, R, [S]);
|
---|
[79a0317] | 25 | if (result === null || isObject(result)) {
|
---|
[d565449] | 26 | return result;
|
---|
| 27 | }
|
---|
| 28 | throw new $TypeError('"exec" method must return `null` or an Object');
|
---|
| 29 | }
|
---|
| 30 | return regexExec(R, S);
|
---|
| 31 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.