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