-
Notifications
You must be signed in to change notification settings - Fork 529
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
Fix JS feature detection so that it no longer crashes #2188
Conversation
An example of this crashing in practice can be seen in https://github.com/japgolly/scalajs-react/blob/v2.0.0-RC2/downstream-tests/js/src/test/resources/polyfill.js where I had to add a fake `importScripts` as a workaround.
Thanks for this! Our test suite currently passes on Firefox and Chrome, is there a way we can test for this in the future? |
No worries! Yeah it should be reproducible by running the tests with |
Hmm, isn't that an artificial environment? Does this actually occur in the browser? |
When you say the tests pass on Firefox and Chrome, I presume you're not testing using Cats Effect on the web worker side? If you have the capacity it would be good to test that too because it's a different env that normal JS world. |
Nah, it's a valid use-case to run Scala.JS from Node itself (eg. for AWS Lambdas). |
We are! I just added that #2165 actually. |
Yes, well we also test in the Node.js environment for this reason :) Node.js, Chrome, and Firefox. |
Oh you're already testing Node.js! Awesome! Hmmm, in that case maybe it's literally the jsdom interaction. But regardless, there are still two good reasons to adopt this (or a similar change):
|
Sounds like maybe this should be added to the test environments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're probably right that this should be added to the test environments. The matrix grows ever wider…
private[this] def isAvailable(a: => js.Dynamic): Boolean = | ||
try { | ||
a.asInstanceOf[js.UndefOr[Any]].isDefined | ||
} catch { | ||
case _: Throwable => false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about !js.isUndefined(a)
? Is that the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I tried this when I implemented the web worker polyfill and ran into problems, but maybe I did it wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No js.isUndefined
wouldn't work because it only tests whether a strict/eager value is undefined or not, but the problem is an exception is being thrown when attempting to resolve that value. Personally I think it's silly behaviour but sjrd is very, very adamant in these things. It is what it is now so when testing for optional JS features we need to always be ready to catch a (Fatal) exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, good to know. Thanks.
Ok, I fixed this in #2191, @japgolly would you mind giving it a try? You were right, we did need a |
@armanbilge Yeah no worries, I'll give it a try later today and get back to you |
Is this PR superseded by #2191? |
Closing in favor of #2191. |
An example of this crashing in practice can be seen in https://github.com/japgolly/scalajs-react/blob/v2.0.0-RC2/downstream-tests/js/src/test/resources/polyfill.js where I had to add a fake
importScripts
as a workaround. Atry
/catch
is necessary.