|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Announcing Scala.js 1.13.0 |
| 4 | +category: news |
| 5 | +tags: [releases] |
| 6 | +permalink: /news/2023/01/26/announcing-scalajs-1.13.0/ |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +We are excited to announce the release of Scala.js 1.13.0! |
| 11 | + |
| 12 | +**This release drops support for Scala 2.11.** |
| 13 | +Finally, 5 years after Scala 2.11 was declared end-of-life, we decided to drop support for it in Scala.js. |
| 14 | +We also dropped support for Scala 2.12.1 (Scala 2.12.2+ is still supported, of course). |
| 15 | + |
| 16 | +Other than that, this release brings a number of bug fixes and enhancements. |
| 17 | +Notably: |
| 18 | + |
| 19 | +* Ability to export inner `object`s in Scala classes |
| 20 | +* Checked exceptions for `NullPointerExceptions`s |
| 21 | +* Better optimizations for exported methods and methods in JavaScript classes |
| 22 | + |
| 23 | +Read on for more details. |
| 24 | + |
| 25 | +<!--more--> |
| 26 | + |
| 27 | +## Getting started |
| 28 | + |
| 29 | +If you are new to Scala.js, head over to [the tutorial]({{ BASE_PATH }}/tutorial/). |
| 30 | + |
| 31 | +If you need help with anything related to Scala.js, you may find our community [in `#scala-js` on Discord](https://discord.com/invite/scala) and [on Stack Overflow](https://stackoverflow.com/questions/tagged/scala.js). |
| 32 | + |
| 33 | +Bug reports can be filed [on GitHub](https://github.com/scala-js/scala-js/issues). |
| 34 | + |
| 35 | +## Release notes |
| 36 | + |
| 37 | +If upgrading from Scala.js 0.6.x, make sure to read [the release notes of Scala.js 1.0.0]({{ BASE_PATH }}/news/2020/02/25/announcing-scalajs-1.0.0/) first, as they contain a host of important information, including breaking changes. |
| 38 | + |
| 39 | +This is a **minor** release: |
| 40 | + |
| 41 | +* It is backward binary compatible with all earlier versions in the 1.x series: libraries compiled with 1.0.x through 1.12.x can be used with 1.13.0 without change. |
| 42 | +* It is *not* forward binary compatible with 1.12.x: libraries compiled with 1.13.0 cannot be used with 1.12.x or earlier. |
| 43 | +* It is *not* entirely backward source compatible: it is not guaranteed that a codebase will compile *as is* when upgrading from 1.12.x (in particular in the presence of `-Xfatal-warnings`). |
| 44 | + |
| 45 | +As a reminder, libraries compiled with 0.6.x cannot be used with Scala.js 1.x; they must be republished with 1.x first. |
| 46 | + |
| 47 | +## Breaking changes |
| 48 | + |
| 49 | +### Drop support for Scala 2.11 and 2.12.1 |
| 50 | + |
| 51 | +5 years after the end-of-life of Scala 2.11, Scala.js 1.13.0 drops its support. |
| 52 | +Support for Scala 2.11 has slowly but steadily increased in cost over the year, and we arrived at the issue that broke the proverbial camel's back. |
| 53 | + |
| 54 | +We announced a [request for comments issue](https://github.com/scala-js/scala-js/issues/4759) through all our usual communication channels. |
| 55 | +It gathered by far the highest number of upvotes any Scala.js issue ever received. |
| 56 | + |
| 57 | +Along with it, we dropped support for Scala 2.12.1, as it then remained the only version that does not support trailing commas. |
| 58 | + |
| 59 | +## Enhancements with compatibility concerns |
| 60 | + |
| 61 | +### Checked exceptions for `NullPointerException` |
| 62 | + |
| 63 | +As documented in [the semantics of Scala.js]({{ BASE_PATH }}/doc/semantics.html#undefined-behaviors), `NullPointerExceptions`s are Undefined Behavior in Scala.js, similarly to `ClassCastException`s and `ArrayIndexOutOfBoundsException`s. |
| 64 | +Since Scala.js 1.12.0 added checks for `ArrayStoreException`s and `NegativeArraySizeException`s, the `NullPointerException`s were the only remaining language-mandated exceptions that did not receive checks. |
| 65 | + |
| 66 | +Scala.js 1.13.0 fills that gap, and now checks `NullPointerException`s in development (fastLink) mode. |
| 67 | +As other undefined behavior errors, they will be reported as `UndefinedBehaviorError`s in fastLink mode, and unchecked in fullLink mode. |
| 68 | + |
| 69 | +These additional checks can and will slow down fastLink-generated code. |
| 70 | +Benchmarks show slowdowns of anywhere between 0% and 17%. |
| 71 | +As a reminder, we expect production code to be generated with `fullLinkJS`. |
| 72 | +fullLink-generated code is not affected by the checks and therefore not subject to this performance hit. |
| 73 | + |
| 74 | +In some rare situations, this may turn code that appeared to work into actively throwing an exception. |
| 75 | + |
| 76 | +Like other checked behaviors, it is now possible to configure the linker so that these exceptions are *compliant*. |
| 77 | +In that case, they will be thrown as specified for the JVM, in both fastLink and fullLink. |
| 78 | +You may enable them with the following sbt settings: |
| 79 | + |
| 80 | +{% highlight scala %} |
| 81 | +scalaJSLinkerConfig ~= { |
| 82 | + import org.scalajs.linker.interface.CheckedBehavior |
| 83 | + _.withSemantics(_ |
| 84 | + .withNullPointers(CheckedBehavior.Compliant) |
| 85 | + ) |
| 86 | +} |
| 87 | +{% endhighlight %} |
| 88 | + |
| 89 | +This may have significant performance impact in fullLink, like other compliant behaviors. |
| 90 | + |
| 91 | +## Improvements |
| 92 | + |
| 93 | +### Export inner `object`s in Scala classes |
| 94 | + |
| 95 | +Scala.js 1.13.0 allows to use `@JSExport` on `object`s that are members of Scala classes. |
| 96 | +For example: |
| 97 | + |
| 98 | +{% highlight scala %} |
| 99 | +class Container { |
| 100 | + @JSExport |
| 101 | + object MemberObject |
| 102 | +} |
| 103 | +{% endhighlight %} |
| 104 | + |
| 105 | +For backward compatibility, adding `@JSExportAll` on the container class does *not* automatically export its `object` members. |
| 106 | +They must be individually exported with `@JSExport`. |
| 107 | + |
| 108 | +### New JDK APIs |
| 109 | + |
| 110 | +This release adds support for the following JDK classes and methods: |
| 111 | + |
| 112 | +* `java.util.TreeMap` |
| 113 | +* `java.nio.charset.Charset.availableCharsets()` |
| 114 | +* Default and static methods of `java.util.Comparator` |
| 115 | +* `java.util.concurrent.Flow` |
| 116 | +* `java.math.BigInteger.intValueExact()` and `longValueExact()` |
| 117 | +* Missing methods of `java.io.InputStream` and `java.io.OutputStream` |
| 118 | + |
| 119 | +### Optimizations for exported methods and methods of JavaScript classes |
| 120 | + |
| 121 | +Before Scala.js 1.13.0, `@JSExport`ed methods and methods within JavaScript classes (that extend `js.Any`) were not processed by our optimizer. |
| 122 | +This is now the case. |
| 123 | + |
| 124 | +## Bug fixes |
| 125 | + |
| 126 | +The following bugs have been fixed in 1.13.0: |
| 127 | + |
| 128 | +* [#4784](https://github.com/scala-js/scala-js/issues/4784) SyntaxError on regex with an optional negative lookahead (only on JS) |
| 129 | +* [#4794](https://github.com/scala-js/scala-js/issues/4794) The output of the compiler/linker is not stable |
| 130 | + |
| 131 | +You can find the full list [on GitHub](https://github.com/scala-js/scala-js/issues?q=is%3Aissue+milestone%3Av1.13.0+is%3Aclosed). |
0 commit comments