Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fix-regexp-well-known-symbol-logic.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. // TODO: Remove from `core-js@4` since it's moved to entry points
  3. require('../modules/es.regexp.exec');
  4. var call = require('../internals/function-call');
  5. var defineBuiltIn = require('../internals/define-built-in');
  6. var regexpExec = require('../internals/regexp-exec');
  7. var fails = require('../internals/fails');
  8. var wellKnownSymbol = require('../internals/well-known-symbol');
  9. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  10. var SPECIES = wellKnownSymbol('species');
  11. var RegExpPrototype = RegExp.prototype;
  12. module.exports = function (KEY, exec, FORCED, SHAM) {
  13. var SYMBOL = wellKnownSymbol(KEY);
  14. var DELEGATES_TO_SYMBOL = !fails(function () {
  15. // String methods call symbol-named RegExp methods
  16. var O = {};
  17. O[SYMBOL] = function () { return 7; };
  18. return ''[KEY](O) !== 7;
  19. });
  20. var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL && !fails(function () {
  21. // Symbol-named RegExp methods call .exec
  22. var execCalled = false;
  23. var re = /a/;
  24. if (KEY === 'split') {
  25. // We can't use real regex here since it causes deoptimization
  26. // and serious performance degradation in V8
  27. // https://github.com/zloirock/core-js/issues/306
  28. re = {};
  29. // RegExp[@@split] doesn't call the regex's exec method, but first creates
  30. // a new one. We need to return the patched regex when creating the new one.
  31. re.constructor = {};
  32. re.constructor[SPECIES] = function () { return re; };
  33. re.flags = '';
  34. re[SYMBOL] = /./[SYMBOL];
  35. }
  36. re.exec = function () {
  37. execCalled = true;
  38. return null;
  39. };
  40. re[SYMBOL]('');
  41. return !execCalled;
  42. });
  43. if (
  44. !DELEGATES_TO_SYMBOL ||
  45. !DELEGATES_TO_EXEC ||
  46. FORCED
  47. ) {
  48. var nativeRegExpMethod = /./[SYMBOL];
  49. var methods = exec(SYMBOL, ''[KEY], function (nativeMethod, regexp, str, arg2, forceStringMethod) {
  50. var $exec = regexp.exec;
  51. if ($exec === regexpExec || $exec === RegExpPrototype.exec) {
  52. if (DELEGATES_TO_SYMBOL && !forceStringMethod) {
  53. // The native String method already delegates to @@method (this
  54. // polyfilled function), leasing to infinite recursion.
  55. // We avoid it by directly calling the native @@method method.
  56. return { done: true, value: call(nativeRegExpMethod, regexp, str, arg2) };
  57. }
  58. return { done: true, value: call(nativeMethod, str, regexp, arg2) };
  59. }
  60. return { done: false };
  61. });
  62. defineBuiltIn(String.prototype, KEY, methods[0]);
  63. defineBuiltIn(RegExpPrototype, SYMBOL, methods[1]);
  64. }
  65. if (SHAM) createNonEnumerableProperty(RegExpPrototype[SYMBOL], 'sham', true);
  66. };