zloirock / core-js

Standard Library
MIT License
24.61k stars 1.66k forks source link

handle missing scopes in strict mode when checking iteration #1286 #1287

Closed aleen42 closed 1 year ago

aleen42 commented 1 year ago

related issue: #1286

zloirock commented 1 year ago

I know about some specific behavior in PhantomJS's strict mode, but that looks strange since this variable is defined in the upper scope. Moreover, core-js is tested in PhantomJS and tests passed without any problems. As an option, it can be related, for example, to a minifier. Are you sure that it's a fix for your case?

aleen42 commented 1 year ago

@zloirock It cannot reproduce unless eval:

"use strict";
eval("\nvar wellKnownSymbol = __webpack_require__(/*! ../internals/well-known-symbol */ \"./node_modules/core-js/internals/well-known-symbol.js\");\n\nvar ITERATOR = wellKnownSymbol('iterator');\nvar SAFE_CLOSING = false;\n\ntry {\n  var called = 0;\n  var iteratorWithReturn = {\n    next: function () {\n      return { done: !!called++ };\n    },\n    'return': function () {\n      SAFE_CLOSING = true;\n    }\n  };\n  iteratorWithReturn[ITERATOR] = function () {\n    return this;\n  };\n  // eslint-disable-next-line es/no-array-from, no-throw-literal -- required for testing\n  Array.from(iteratorWithReturn, function () { throw 2; });\n} catch (error) { /* empty */ }\n\nmodule.exports = function (exec, SKIP_CLOSING) {\n  if (!SKIP_CLOSING && !SAFE_CLOSING) return false;\n  var ITERATION_SUPPORT = false;\n  try {\n    var object = {};\n    object[ITERATOR] = function () {\n      return {\n        next: function () {\n          return { done: ITERATION_SUPPORT = true };\n        }\n      };\n    };\n    exec(object);\n  } catch (error) { /* empty */ }\n  return ITERATION_SUPPORT;\n};\n\n\n//# sourceURL=webpack://./node_modules/core-js/internals/check-correctness-of-iteration.js?");

It seems like a bug in PhantomJS, but I can't find any workaround except modifying it under core-js.

zloirock commented 1 year ago

I'm not sure that it's the best workaround, but let it be.