|
| 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 and `class`es 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 | +In some rare situations, this may turn code that appeared to work into actively throwing an exception. |
| 70 | + |
| 71 | +Further, these additional checks can and will slow down fastLink-generated code. |
| 72 | +Benchmarks show slowdowns of anywhere between 0% and 17%. |
| 73 | +As a reminder, we expect production code to be generated with `fullLinkJS`. |
| 74 | +fullLink-generated code is not affected by the checks and therefore not subject to this performance hit. |
| 75 | + |
| 76 | +If the performance hit in `fastLinkJS` is too much to bear in your particular case, you can disable the checks even in fastLink with the following sbt setting: |
| 77 | + |
| 78 | +{% highlight scala %} |
| 79 | +scalaJSLinkerConfig ~= { |
| 80 | + import org.scalajs.linker.interface.CheckedBehavior |
| 81 | + _.withSemantics(_ |
| 82 | + .withNullPointers(CheckedBehavior.Unchecked) |
| 83 | + ) |
| 84 | +} |
| 85 | +{% endhighlight %} |
| 86 | + |
| 87 | +Like other checked behaviors, it is now possible to configure the linker so that these exceptions are *compliant*. |
| 88 | +In that case, they will be thrown as specified for the JVM, in both fastLink and fullLink. |
| 89 | +You may enable them with the following sbt settings: |
| 90 | + |
| 91 | +{% highlight scala %} |
| 92 | +scalaJSLinkerConfig ~= { |
| 93 | + import org.scalajs.linker.interface.CheckedBehavior |
| 94 | + _.withSemantics(_ |
| 95 | + .withNullPointers(CheckedBehavior.Compliant) |
| 96 | + ) |
| 97 | +} |
| 98 | +{% endhighlight %} |
| 99 | + |
| 100 | +This may have significant performance impact in fullLink, like other compliant behaviors. |
| 101 | + |
| 102 | +### Changes to the IR and linker APIs |
| 103 | + |
| 104 | +For tooling authors who directly manipulate the IR and linker APIs, there have been some breaking changes in that area. |
| 105 | +This is in line with our version policy for the linker APIs. |
| 106 | + |
| 107 | +The most likely changes you may hit are: |
| 108 | + |
| 109 | +* `ClassDef` has several distinct lists of members instead of a single `memberDefs` field. |
| 110 | +* Member defs are versioned using a dedicated `version: org.scalajs.ir.Version` instead of a `hash: Option[Hash]`. |
| 111 | + |
| 112 | +## Improvements |
| 113 | + |
| 114 | +### Export inner `object`s and `class`es in Scala classes |
| 115 | + |
| 116 | +Scala.js 1.13.0 allows to use `@JSExport` on `object`s and `class`es that are members of Scala classes. |
| 117 | +For example: |
| 118 | + |
| 119 | +{% highlight scala %} |
| 120 | +class Container { |
| 121 | + @JSExport |
| 122 | + object MemberObject |
| 123 | + |
| 124 | + @JSExport |
| 125 | + class MemberClass |
| 126 | +} |
| 127 | +{% endhighlight %} |
| 128 | + |
| 129 | +`@JSExportAll` on the container class now exports its `object` members, like other term members, but does not automatically export `class` members. |
| 130 | +Class members must be individually exported with `@JSExport`. |
| 131 | + |
| 132 | +### New JDK APIs |
| 133 | + |
| 134 | +This release adds support for the following JDK classes and methods: |
| 135 | + |
| 136 | +* `java.util.TreeMap` |
| 137 | +* `java.nio.charset.Charset.availableCharsets()` |
| 138 | +* Default and static methods of `java.util.Comparator` |
| 139 | +* `java.util.concurrent.Flow` |
| 140 | +* `java.math.BigInteger.intValueExact()` and `longValueExact()` |
| 141 | +* Missing methods of `java.io.InputStream` and `java.io.OutputStream` |
| 142 | + |
| 143 | +### Optimizations for exported methods and methods of JavaScript classes |
| 144 | + |
| 145 | +Before Scala.js 1.13.0, `@JSExport`ed methods and methods within JavaScript classes (that extend `js.Any`) were not processed by our optimizer. |
| 146 | +This is now the case. |
| 147 | + |
| 148 | +## Bug fixes |
| 149 | + |
| 150 | +The following bugs have been fixed in 1.13.0: |
| 151 | + |
| 152 | +* [#4784](https://github.com/scala-js/scala-js/issues/4784) SyntaxError on regex with an optional negative lookahead (only on JS) |
| 153 | +* [#4794](https://github.com/scala-js/scala-js/issues/4794) The output of the compiler/linker is not stable |
| 154 | + |
| 155 | +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