|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Announcing Scala.js 1.12.0 |
| 4 | +category: news |
| 5 | +tags: [releases] |
| 6 | +permalink: /news/2022/09/15/announcing-scalajs-1.12.0/ |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +We are excited to announce the release of Scala.js 1.12.0! |
| 11 | + |
| 12 | +This release brings a number of bug fixes and enhancements. |
| 13 | +The highlights are: |
| 14 | + |
| 15 | +* Support for the JavaScript operator `**`, introduced in ECMAScript 2016. |
| 16 | +* Checked exceptions for `ArrayStoreExceptions`s and `NegativeArraySizeException`s |
| 17 | + |
| 18 | +The Scala standard library was upgraded to version 2.12.17 and 2.13.10. |
| 19 | + |
| 20 | +Read on for more details. |
| 21 | + |
| 22 | +<!--more--> |
| 23 | + |
| 24 | +## Getting started |
| 25 | + |
| 26 | +If you are new to Scala.js, head over to [the tutorial]({{ BASE_PATH }}/tutorial/). |
| 27 | + |
| 28 | +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). |
| 29 | + |
| 30 | +Bug reports can be filed [on GitHub](https://github.com/scala-js/scala-js/issues). |
| 31 | + |
| 32 | +## Release notes |
| 33 | + |
| 34 | +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. |
| 35 | + |
| 36 | +This is a **minor** release: |
| 37 | + |
| 38 | +* It is backward binary compatible with all earlier versions in the 1.x series: libraries compiled with 1.0.x through 1.11.x can be used with 1.12.0 without change. |
| 39 | +* It is *not* forward binary compatible with 1.11.x: libraries compiled with 1.12.0 cannot be used with 1.11.x or earlier. |
| 40 | +* It is *not* entirely backward source compatible: it is not guaranteed that a codebase will compile *as is* when upgrading from 1.11.x (in particular in the presence of `-Xfatal-warnings`). |
| 41 | + |
| 42 | +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. |
| 43 | + |
| 44 | +## Enhancements with compatibility concerns |
| 45 | + |
| 46 | +### Checked exceptions for `ArrayStoreException` and `NegativeArraySizeException` |
| 47 | + |
| 48 | +As documented in [the semantics of Scala.js]({{ BASE_PATH }}/doc/semantics.html#undefined-behaviors), `ArrayStoreException`s and `NegativeArraySizeException`s are Undefined Behavior in Scala.js, similarly to `ClassCastException`s and `ArrayIndexOutOfBoundsException`s. |
| 49 | +Prior to Scala.js 1.12.0, we made no effort internally to provide decent error messages, or any other kind of checks. |
| 50 | + |
| 51 | +Starting with this release, erroneous conditions leading to one of these two exceptions are checked in development (fastLink) mode. |
| 52 | +They will be reported as `UndefinedBehaviorError`s in fastLink mode, and unchecked in fullLink mode. |
| 53 | + |
| 54 | +In some rare situations, this may turn code that appeared to work into actively throwing an exception. |
| 55 | + |
| 56 | +Like other checked behaviors, it is now possible to configure the linker so that these exceptions are *compliant*. |
| 57 | +In that case, they will be thrown as specified for the JVM, in both fastLink and fullLink. |
| 58 | +You may enable them with the following sbt settings: |
| 59 | + |
| 60 | +{% highlight scala %} |
| 61 | +scalaJSLinkerConfig ~= { |
| 62 | + import org.scalajs.linker.interface.CheckedBehavior |
| 63 | + _.withSemantics(_ |
| 64 | + .withArrayStores(CheckedBehavior.Compliant) |
| 65 | + .withNegativeArraySizes(CheckedBehavior.Compliant) |
| 66 | + ) |
| 67 | +} |
| 68 | +{% endhighlight %} |
| 69 | + |
| 70 | +This may have significant performance impact in fullLink, like other compliant behaviors. |
| 71 | + |
| 72 | +### `js.Dynamic.**` now refers to the JavaScript `**` operator |
| 73 | + |
| 74 | +Previously, `dynamic1 ** dynamic2` would be equivalent to the JavaScript expression `dynamic1["**"](dynamic2)`. |
| 75 | +When recompiled, `**` will now resolve the JavaScript `**` operator (see below for details). |
| 76 | + |
| 77 | +If calling a method named `"**"` was intended, the above should be rewritten to `dynamic1.applyDynamic("**")(dynamic2)`. |
| 78 | + |
| 79 | +## New deprecations |
| 80 | + |
| 81 | +### `@JSOperator` is expected on JavaScript operator methods |
| 82 | + |
| 83 | +When defining a facade type, we can model JavaScript operators using methods with specific names. |
| 84 | +For example, the facade for `js.BigInt` contains: |
| 85 | + |
| 86 | +{% highlight scala %} |
| 87 | +import scala.scalajs.js |
| 88 | +import scala.scalajs.js.annotation._ |
| 89 | + |
| 90 | +@js.native @JSGlobal |
| 91 | +final class BigInt extends js.Object { |
| 92 | + def +(other: BigInt): BigInt = js.native |
| 93 | + ... |
| 94 | +} |
| 95 | +{% endhighlight %} |
| 96 | + |
| 97 | +Starting from Scala.js 1.12.0, such operator methods should be annotated with `@JSOperator`, as follows: |
| 98 | + |
| 99 | +{% highlight scala %} |
| 100 | + @JSOperator def +(other: BigInt): BigInt = js.native |
| 101 | +{% endhighlight %} |
| 102 | + |
| 103 | +A compiler warning will be emitted if the annotation is missing. |
| 104 | + |
| 105 | +## Improvements |
| 106 | + |
| 107 | +### Support for the JavaScript operator `**` |
| 108 | + |
| 109 | +ECMAScript 2016 introduced the `**` operator in JavaScript. |
| 110 | +`a ** b` computes `a` raised to the power `b`, and is applicable to `number`s and `bigint`s. |
| 111 | + |
| 112 | +Before Scala.js 1.12.0, it was not possible to write Scala.js code calling that operator. |
| 113 | +Scala.js 1.12.0 now supports it, through the definition of an `@JSOperator def **`, as follows: |
| 114 | + |
| 115 | +{% highlight scala %} |
| 116 | +import scala.scalajs.js |
| 117 | +import scala.scalajs.js.annotation._ |
| 118 | + |
| 119 | +@js.native @JSGlobal |
| 120 | +final class BigInt extends js.Object { |
| 121 | + @JSOperator def **(other: BigInt): BigInt = js.native |
| 122 | + ... |
| 123 | +} |
| 124 | +{% endhighlight %} |
| 125 | + |
| 126 | +Without the annotation, a compiler warning will be emitted, and the definition will behave as a call to a method named `"**"` instead, for backward compatibility. |
| 127 | +If that is actually the intended semantics, the warning can be silenced with an explicit `@JSName("**")`. |
| 128 | + |
| 129 | +## Bug fixes |
| 130 | + |
| 131 | +The following bugs have been fixed in 1.12.0: |
| 132 | + |
| 133 | +* [#4739](https://github.com/scala-js/scala-js/issues/4739) Incorrect codegen for singleton case from Scala 3 enum in Scala 2.13 codebase |
| 134 | +* [#4734](https://github.com/scala-js/scala-js/issues/4734) `j.u.ArrayDeque#pollFirst` is O(n) |
| 135 | +* [#4731](https://github.com/scala-js/scala-js/issues/4731) `j.u.Arrays.equals(Array[AnyRef])` doe not handle `null` values. |
| 136 | +* [#4753](https://github.com/scala-js/scala-js/issues/4753) The optimizer thinks that `x.getClass()` is non-nullable. |
| 137 | +* [#4755](https://github.com/scala-js/scala-js/issues/4755) The optimizer does not respect eval order of generic array get/set with nulls |
| 138 | + |
| 139 | +You can find the full list [on GitHub](https://github.com/scala-js/scala-js/issues?q=is%3Aissue+milestone%3Av1.12.0+is%3Aclosed). |
0 commit comments