diff --git a/compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala b/compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala index c571a08980a1..eba914f1aa98 100644 --- a/compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala +++ b/compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala @@ -1083,14 +1083,14 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) { js.VarRef(js.LocalIdent(restParamName))(jstpe.AnyType) } - def genAllArgsRefsForForwarder()(implicit pos: Position): List[js.Tree] = { + def genAllArgsRefsForForwarder()(implicit pos: Position): List[js.TreeOrJSSpread] = { val fixedArgRefs = fixedParamNames.toList.map { paramName => js.VarRef(js.LocalIdent(paramName))(jstpe.AnyType) } if (needsRestParam) { val restArgRef = js.VarRef(js.LocalIdent(restParamName))(jstpe.AnyType) - fixedArgRefs :+ restArgRef + fixedArgRefs :+ js.JSSpread(restArgRef) } else { fixedArgRefs } diff --git a/project/Build.scala b/project/Build.scala index 20cde25461cf..f443a7c20d0a 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -104,8 +104,8 @@ object Build { * scala-library. */ def stdlibVersion(implicit mode: Mode): String = mode match { - case NonBootstrapped => "2.13.5" - case Bootstrapped => "2.13.5" + case NonBootstrapped => "2.13.6" + case Bootstrapped => "2.13.6" } val dottyOrganization = "org.scala-lang" @@ -1173,12 +1173,10 @@ object Build { -- "ObjectTest.scala" // compile errors caused by #9588 -- "StackTraceTest.scala" // would require `npm install source-map-support` -- "UnionTypeTest.scala" // requires the Scala 2 macro defined in Typechecking*.scala - -- "PromiseMock.scala" // TODO: Enable once we use a Scala.js with https://github.com/scala-js/scala-js/pull/4451 in - // and remove copy in tests/sjs-junit )).get ++ (dir / "js/src/test/require-2.12" ** (("*.scala": FileFilter) - -- "JSOptionalTest212.scala" // TODO: Enable once we use a Scala.js with https://github.com/scala-js/scala-js/pull/4451 in + -- "JSOptionalTest212FunParamInference.scala" // TODO: #11694 )).get ++ (dir / "js/src/test/require-sam" ** "*.scala").get ++ (dir / "js/src/test/scala-new-collections" ** "*.scala").get @@ -1387,6 +1385,7 @@ object Build { scriptedLaunchOpts ++= Seq( "-Dplugin.version=" + version.value, "-Dplugin.scalaVersion=" + dottyVersion, + "-Dplugin.scala2Version=" + stdlibVersion(Bootstrapped), "-Dplugin.scalaJSVersion=" + scalaJSVersion, "-Dsbt.boot.directory=" + ((ThisBuild / baseDirectory).value / ".sbt-scripted").getAbsolutePath // Workaround sbt/sbt#3469 ), diff --git a/project/build.properties b/project/build.properties index e67343ae796c..19479ba46ff2 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.5.0 +sbt.version=1.5.2 diff --git a/project/plugins.sbt b/project/plugins.sbt index e0071ea63676..b1a292ec9624 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -2,7 +2,7 @@ // // e.g. addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.1.0") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.0") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.1") addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.6") diff --git a/sbt-test/scala2-compat/erasure-scalajs/build.sbt b/sbt-test/scala2-compat/erasure-scalajs/build.sbt index 6f30dbadc25b..342c32fc4cdc 100644 --- a/sbt-test/scala2-compat/erasure-scalajs/build.sbt +++ b/sbt-test/scala2-compat/erasure-scalajs/build.sbt @@ -1,7 +1,7 @@ lazy val scala2Lib = project.in(file("scala2Lib")) .enablePlugins(ScalaJSPlugin) .settings( - scalaVersion := "2.13.5" + scalaVersion := sys.props("plugin.scala2Version") ) lazy val dottyApp = project.in(file("dottyApp")) diff --git a/sbt-test/scala2-compat/erasure/build.sbt b/sbt-test/scala2-compat/erasure/build.sbt index 794d78b308c0..694101e79388 100644 --- a/sbt-test/scala2-compat/erasure/build.sbt +++ b/sbt-test/scala2-compat/erasure/build.sbt @@ -1,6 +1,6 @@ lazy val scala2Lib = project.in(file("scala2Lib")) .settings( - scalaVersion := "2.13.5" + scalaVersion := sys.props("plugin.scala2Version") ) lazy val dottyApp = project.in(file("dottyApp")) diff --git a/sbt-test/scala2-compat/i11173/build.sbt b/sbt-test/scala2-compat/i11173/build.sbt index 4cc8010e1d38..433a5e8baddf 100644 --- a/sbt-test/scala2-compat/i11173/build.sbt +++ b/sbt-test/scala2-compat/i11173/build.sbt @@ -1,5 +1,5 @@ val scala3Version = sys.props("plugin.scalaVersion") -val scala2Version = "2.13.5" +val scala2Version = sys.props("plugin.scala2Version") lazy val lib = project.in(file("lib")) .settings( diff --git a/sbt-test/scala2-compat/i12109/build.sbt b/sbt-test/scala2-compat/i12109/build.sbt index 4cc8010e1d38..433a5e8baddf 100644 --- a/sbt-test/scala2-compat/i12109/build.sbt +++ b/sbt-test/scala2-compat/i12109/build.sbt @@ -1,5 +1,5 @@ val scala3Version = sys.props("plugin.scalaVersion") -val scala2Version = "2.13.5" +val scala2Version = sys.props("plugin.scala2Version") lazy val lib = project.in(file("lib")) .settings( diff --git a/sbt-test/scala2-compat/i8001/build.sbt b/sbt-test/scala2-compat/i8001/build.sbt index 27c7d9ea9b3c..1dc85ed7cac0 100644 --- a/sbt-test/scala2-compat/i8001/build.sbt +++ b/sbt-test/scala2-compat/i8001/build.sbt @@ -1,5 +1,5 @@ val scala3Version = sys.props("plugin.scalaVersion") -val scala2Version = "2.13.5" +val scala2Version = sys.props("plugin.scala2Version") lazy val lib = (project in file ("lib")) .settings(scalaVersion := scala2Version) diff --git a/sbt-test/scala2-compat/i8847/build.sbt b/sbt-test/scala2-compat/i8847/build.sbt index 6a579f2be966..1e7c318b5880 100644 --- a/sbt-test/scala2-compat/i8847/build.sbt +++ b/sbt-test/scala2-compat/i8847/build.sbt @@ -1,5 +1,5 @@ val scala3Version = sys.props("plugin.scalaVersion") -val scala2Version = "2.13.5" +val scala2Version = sys.props("plugin.scala2Version") lazy val `i8847-lib` = (project in file ("lib")) .settings(scalaVersion := scala2Version) diff --git a/sbt-test/scala2-compat/i9916a/build.sbt b/sbt-test/scala2-compat/i9916a/build.sbt index 1f5c07900161..5da7a83d315f 100644 --- a/sbt-test/scala2-compat/i9916a/build.sbt +++ b/sbt-test/scala2-compat/i9916a/build.sbt @@ -1,5 +1,5 @@ val scala3Version = sys.props("plugin.scalaVersion") -val scala2Version = "2.13.5" +val scala2Version = sys.props("plugin.scala2Version") lazy val `i9916a-lib` = (project in file ("lib")) .settings(scalaVersion := scala2Version) diff --git a/sbt-test/scala2-compat/i9916b/build.sbt b/sbt-test/scala2-compat/i9916b/build.sbt index f597a8610607..14a979bb173c 100644 --- a/sbt-test/scala2-compat/i9916b/build.sbt +++ b/sbt-test/scala2-compat/i9916b/build.sbt @@ -1,5 +1,5 @@ val scala3Version = sys.props("plugin.scalaVersion") -val scala2Version = "2.13.5" +val scala2Version = sys.props("plugin.scala2Version") lazy val `i9916b-lib` = (project in file ("lib")) .settings(scalaVersion := scala2Version) diff --git a/sbt-test/scala2-compat/longnames/build.sbt b/sbt-test/scala2-compat/longnames/build.sbt index 61d8f34cd5f6..df60250f06f1 100644 --- a/sbt-test/scala2-compat/longnames/build.sbt +++ b/sbt-test/scala2-compat/longnames/build.sbt @@ -1,5 +1,5 @@ val scala3Version = sys.props("plugin.scalaVersion") -val scala2Version = "2.13.5" +val scala2Version = sys.props("plugin.scala2Version") lazy val lib = (project in file ("lib")) .settings(scalaVersion := scala2Version) diff --git a/sbt-test/scala2-compat/structural/build.sbt b/sbt-test/scala2-compat/structural/build.sbt index 61d8f34cd5f6..df60250f06f1 100644 --- a/sbt-test/scala2-compat/structural/build.sbt +++ b/sbt-test/scala2-compat/structural/build.sbt @@ -1,5 +1,5 @@ val scala3Version = sys.props("plugin.scalaVersion") -val scala2Version = "2.13.5" +val scala2Version = sys.props("plugin.scala2Version") lazy val lib = (project in file ("lib")) .settings(scalaVersion := scala2Version) diff --git a/tests/sjs-junit/test/org/scalajs/testsuite/jsinterop/PromiseMock.scala b/tests/sjs-junit/test/org/scalajs/testsuite/jsinterop/PromiseMock.scala deleted file mode 100644 index 6764cdc7ac83..000000000000 --- a/tests/sjs-junit/test/org/scalajs/testsuite/jsinterop/PromiseMock.scala +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Scala.js (https://www.scala-js.org/) - * - * Copyright EPFL. - * - * Licensed under Apache License 2.0 - * (https://www.apache.org/licenses/LICENSE-2.0). - * - * See the NOTICE file distributed with this work for - * additional information regarding copyright ownership. - */ - -package org.scalajs.testsuite.jsinterop - -import scala.scalajs.js -import scala.scalajs.js.annotation._ -import scala.scalajs.js.| - -import js.Thenable - -object PromiseMock { - - @noinline - def withMockedPromise[A](body: (() => Unit) => A): A = { - val global = org.scalajs.testsuite.utils.JSUtils.globalObject - - val oldPromise = - if (global.hasOwnProperty("Promise").asInstanceOf[Boolean]) Some(global.Promise) - else None - - global.Promise = js.constructorOf[MockPromise[_]] - try { - body(MockPromise.processQueue _) - } finally { - oldPromise.fold { - js.special.delete(global, "Promise") - } { old => - global.Promise = old - } - } - } - - @noinline - def withMockedPromiseIfExists[A](body: (Option[() => Unit]) => A): A = { - val global = org.scalajs.testsuite.utils.JSUtils.globalObject - - val oldPromise = global.Promise - - if (js.isUndefined(oldPromise)) { - body(None) - } else { - global.Promise = js.constructorOf[MockPromise[_]] - try { - body(Some(MockPromise.processQueue _)) - } finally { - global.Promise = oldPromise - } - } - } - - private object MockPromise { - private val queue = js.Array[js.Function0[Any]]() - - @JSExportStatic - def resolve[A](value: A | js.Thenable[A]): MockPromise[A] = { - new MockPromise[A]({ - (resolve: js.Function1[A | js.Thenable[A], _], - reject: js.Function1[Any, _]) => - resolve(value) - }) - } - - @JSExportStatic - def reject(reason: Any): MockPromise[Nothing] = { - new MockPromise[Nothing]({ - (resolve: js.Function1[Nothing | js.Thenable[Nothing], _], - reject: js.Function1[Any, _]) => - reject(reason) - }) - } - - def enqueue(f: js.Function0[Any]): Unit = - queue.push(f) - - def processQueue(): Unit = { - while (queue.nonEmpty) - queue.shift()() - } - - private sealed abstract class State[+A] - - private case object Pending extends State[Nothing] - private case class Fulfilled[+A](value: A) extends State[A] - private case class Rejected(reason: Any) extends State[Nothing] - - private def isNotAnObject(x: Any): Boolean = x match { - case null | () | _:Double | _:Boolean | _:String => true - case _ => false - } - - private def isCallable(x: Any): Boolean = - js.typeOf(x.asInstanceOf[js.Any]) == "function" - - private def throwAny(e: Any): Nothing = { - throw (e match { - case th: Throwable => th - case _ => js.JavaScriptException(e) - }) - } - - private def tryCatchAny[A](tryBody: => A)(catchBody: Any => A): A = { - try { - tryBody - } catch { - case th: Throwable => - catchBody(th match { - case js.JavaScriptException(e) => e - case _ => th - }) - } - } - } - - private class MockPromise[+A]( - executor: js.Function2[js.Function1[A | Thenable[A], _], js.Function1[scala.Any, _], _]) - extends js.Object with js.Thenable[A] { - - import MockPromise._ - - private[this] var state: State[A] = Pending - - private[this] var fulfillReactions = js.Array[js.Function1[A, Any]]() - private[this] var rejectReactions = js.Array[js.Function1[Any, Any]]() - - init(executor) - - // 25.4.3.1 Promise(executor) - private[this] def init( - executor: js.Function2[js.Function1[A | Thenable[A], _], js.Function1[scala.Any, _], _]) = { - tryCatchAny[Unit] { - executor(resolve _, reject _) - } { e => - reject(e) - } - } - - private[this] def fulfill(value: A): Unit = { - assert(state == Pending) - state = Fulfilled(value) - clearAndTriggerReactions(fulfillReactions, value) - } - - private[this] def clearAndTriggerReactions[A]( - reactions: js.Array[js.Function1[A, Any]], - argument: A): Unit = { - - assert(state != Pending) - - fulfillReactions = null - rejectReactions = null - - for (reaction <- reactions) - enqueue(() => reaction(argument)) - } - - // 25.4.1.3.2 Promise Resolve Functions - private[this] def resolve(resolution: A | Thenable[A]): Unit = { - if (state == Pending) { - if (resolution.asInstanceOf[AnyRef] eq this) { - reject(new js.TypeError("Self resolution")) - } else if (isNotAnObject(resolution)) { - fulfill(resolution.asInstanceOf[A]) - } else { - tryCatchAny { - val thenAction = resolution.asInstanceOf[js.Dynamic].`then` - if (!isCallable(thenAction)) { - fulfill(resolution.asInstanceOf[A]) - } else { - val thenable = resolution.asInstanceOf[Thenable[A]] - val thenActionFun = thenAction.asInstanceOf[js.Function] - enqueue(() => promiseResolveThenableJob(thenable, thenActionFun)) - } - } { e => - reject(e) - } - } - } - } - - // 25.4.2.2 PromiseResolveThenableJob - private[this] def promiseResolveThenableJob(thenable: Thenable[A], - thenAction: js.Function): Unit = { - thenAction.call(thenable, resolve _, reject _) - } - - // 25.4.1.3.1 Promise Reject Functions - private[this] def reject(reason: Any): Unit = { - if (state == Pending) { - state = Rejected(reason) - clearAndTriggerReactions(rejectReactions, reason) - } - } - - // 25.4.5.3 Promise.prototype.then - def `then`[B]( - onFulfilled: js.Function1[A, B | Thenable[B]], - onRejected: js.UndefOr[js.Function1[scala.Any, B | Thenable[B]]]): MockPromise[B] = { - - new MockPromise[B]( - { (innerResolve: js.Function1[B | Thenable[B], _], - innerReject: js.Function1[scala.Any, _]) => - - def doFulfilled(value: A): Unit = { - tryCatchAny[Unit] { - innerResolve(onFulfilled(value)) - } { e => - innerReject(e) - } - } - - def doRejected(reason: Any): Unit = { - tryCatchAny[Unit] { - onRejected.fold[Unit] { - innerReject(reason) - } { onRejectedFun => - innerResolve(onRejectedFun(reason)) - } - } { e => - innerReject(e) - } - } - - state match { - case Pending => - fulfillReactions += doFulfilled _ - rejectReactions += doRejected _ - - case Fulfilled(value) => - enqueue(() => doFulfilled(value)) - - case Rejected(reason) => - enqueue(() => doRejected(reason)) - } - } - ) - } - - def `then`[B >: A]( - onFulfilled: Unit, - onRejected: js.UndefOr[js.Function1[scala.Any, B | Thenable[B]]]): MockPromise[B] = { - `then`((x: A) => (x: B | Thenable[B]), onRejected) - } - - // 25.4.5.1 Promise.prototype.catch - def `catch`[B >: A]( - onRejected: js.UndefOr[js.Function1[scala.Any, B | Thenable[B]]]): MockPromise[B] = { - `then`((), onRejected) - } - } -}