regexp-exec-abstract.js 732 B

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