-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Make Math.trunc
polyfill optional?
#16144
Comments
You would get much better JS output by making the JS codegen use Seems much more useful than optimizing 156 bytes. |
I mentioned that it was 156 bytes specifically to point out that it wouldn't be much of an optimization to remove it, I made this issue primarily for the code generation to not have to rely on eldritch maneuvers rather than for the code to be necessarily faster or smaller. I think the JS code should directly reflect the Nim code (hence I want polyfills to be user code in Nim), implementing move semantics would really help in that regard but there are many of these issues, for example the JS |
Surely we can do both -- just telling you where to get more juice. |
there's no need to single out rationale: each browser has their own limitations, for example EDITcheck whether something similar to |
Summary
There is a Math.trunc polyfill that goes in every Nim JS file (except if
-d:nodejs
is passed) for IE support. It should be made opt-in through another define, or if it's possible, emitted by users themselves possibly through an imported module.Description
Here is the polyfill:
Nim/lib/system/jssys.nim
Lines 781 to 792 in 3e7077a
It's not that big of a deal by itself since it's only 156 extra bytes per JS output, and a bigger polyfill has already been removed, the 481 byte typed array polyfill removed in #16077, but I'm not proposing removal here as much as I'm proposing other options because
Math.trunc
is used way more often in Nim JS output and it would definitely slightly be disabling people who want their JS to work on IE <11.My preferred solution would be some kind of
iefills
module (maybe another name), whereMath.trunc
and the typed number arrays would go. The user would import this, though you would have to make sure thatiefills
emits code before everything else, and I don't know the Nim constructs to do that (if there are any, #13376). This doesn't have to be in the standard library.Another solution is instead of doing
not defined(nodejs)
you could dodefined(ie)
or a define with a longer and clearer name that you only define if you want IE/really old browser support.Streamlining polyfills would make it easier for core Nim JS output to be more efficient. Bitsets currently work by setting fields in objects where the key is the value included in the set. 96.22% of users use browsers that support the
Set
type, there's no doubtSet
andMap
are faster compared to using object keys, but Nim can't use them. This might not be a perfect example because polyfillingSet
in this case would be a bit cumbersome but it would be possible. We also don't need to delegate everything to JS builtins, the Nim standard library shares a lot with the C++ standard library but we still use the Nim versions. Polyfills also can't solve every problem with JS compatibility, they could end up making the resulting code perform way worse than before for older versions. My point is there are things that polyfills would help with.Additional Information
-d:nodejs
in cases where you want to use new browser features but aren't using node.js doesn't work great let alone make sense. Thedom
module defines dummy routines when nodejs is defined and wraps the real routines when it's not.The text was updated successfully, but these errors were encountered: