Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG/CRQ | Harden Symbol polyfill detection and avoid out of stack space error in IE 11 with polyfilled symbols #5463

Open
rjgotten opened this issue Jan 27, 2020 · 1 comment

Comments

@rjgotten
Copy link

rjgotten commented Jan 27, 2020

CanJS seems to be adding symbols to global prototypes, which -- in a scenario with polyfills using Babel for backwards compatibility -- triggers zloirock/core-js#735 .

The latter cannot be reliably worked around by means other than not placing symbols on globals.

In scenarios where CanJS has to add symbols to global prototypes, it should probably harden whatever checks it has in place to verify that it's dealing with native Symbol and not the CoreJS polyfill. If it's dealing with the polyfill, it should always fall back on the not-a-symbol-but-a-string-key approach.

When an application hits a bad use of a symbol that triggers above CoreJS problem, it leads to a complete breakdown as a stack overflow basically means: end-of-story.

This was found with the can@5.33.2 package but is probably present in 6.x as well.
As this is a real showstopper I'd also really appreciate a coherent patch to the 5.x versions as well.


[EDIT]

Seems this could be worked around by modifying the supportsNativeSymbols function in the can-symbol package, like so:

var supportsNativeSymbols = (function() {
  var symbolExists =
       typeof Symbol !== "undefined"
    && typeof Symbol.for === "function"
    // The following are additions introduced by the CoreJS polyfill
    // that breaks certain cases in CanJS.
    && !( "useSetter" in Symbol || "useSimple" in Symbol );

  if (!symbolExists) {
    return false;
  }

  var symbol = Symbol("a symbol for testing symbols");
  return typeof symbol === "symbol";
}());

[EDIT 2]

This works, but the exact same check is duplicated in the can-reflect package under ./reflections/type/type where it also needs to be amended.
(Actually; as can-reflect already takes a dependency on can-symbol the latter should probably export the result of the native symbol test so that the former can use it...)

[EDIT 3]
Doesn't actually work correctly.
Looks like CoreJS adds those two methods to the NATIVE Symbol as well. >_<

@rjgotten rjgotten changed the title BUG | Out of stack space error in IE 11 with polyfilled symbols BUG/CRQ | Harden Symbol polyfill detection and avoid out of stack space error in IE 11 with polyfilled symbols Jan 27, 2020
@rjgotten
Copy link
Author

Found a working solution:

var supportsNativeSymbols = (function() {
  var symbolExists =
       typeof Symbol !== "undefined"
    && typeof Symbol.for === "function"
    && !Symbol.sham;

  if (!symbolExists) {
    return false;
  }

  var symbol = Symbol("a symbol for testing symbols");
  return typeof symbol === "symbol";
}());

CoreJS only adds sham: true to its own fake symbol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant