_regexp-exec-abstract.js 615 B

123456789101112131415161718192021
  1. 'use strict';
  2. var classof = require('./_classof');
  3. var builtinExec = RegExp.prototype.exec;
  4. // `RegExpExec` abstract operation
  5. // https://tc39.github.io/ecma262/#sec-regexpexec
  6. module.exports = function (R, S) {
  7. var exec = R.exec;
  8. if (typeof exec === 'function') {
  9. var result = exec.call(R, S);
  10. if (typeof result !== 'object') {
  11. throw new TypeError('RegExp exec method returned something other than an Object or null');
  12. }
  13. return result;
  14. }
  15. if (classof(R) !== 'RegExp') {
  16. throw new TypeError('RegExp#exec called on incompatible receiver');
  17. }
  18. return builtinExec.call(R, S);
  19. };