regexp-exec-abstract.js 682 B

1234567891011121314151617181920
  1. var call = require('../internals/function-call');
  2. var anObject = require('../internals/an-object');
  3. var isCallable = require('../internals/is-callable');
  4. var classof = require('../internals/classof-raw');
  5. var regexpExec = require('../internals/regexp-exec');
  6. var $TypeError = TypeError;
  7. // `RegExpExec` abstract operation
  8. // https://tc39.es/ecma262/#sec-regexpexec
  9. module.exports = function (R, S) {
  10. var exec = R.exec;
  11. if (isCallable(exec)) {
  12. var result = call(exec, R, S);
  13. if (result !== null) anObject(result);
  14. return result;
  15. }
  16. if (classof(R) === 'RegExp') return call(regexpExec, R, S);
  17. throw $TypeError('RegExp#exec called on incompatible receiver');
  18. };