Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d5021d2
[no-master] Fix 4 erroneous comparisons of `RefinedType` with `Type`.
sjrd Jun 18, 2019
45cf1cf
[no-master] Remove `@deprecatedName`s that were introduced in 0.6.16.
sjrd Jun 17, 2019
c4d5070
[no-master] Upgrade to scopt 3.7.1.
sjrd Jun 18, 2019
fd2343e
[no-master] Enable Scala 2.13.0 in the tools and all the other artifa…
sjrd Jun 18, 2019
ab398e8
Merge pull request #3702 from sjrd/tools-on-scala-2.13.0
sjrd Jun 21, 2019
7e497d4
Recognize Metals as an IDE for the special treatment of the build.
sjrd Jun 21, 2019
9648cc8
Merge pull request #3707 from sjrd/better-metals-import
sjrd Jun 21, 2019
879d3c1
Fix #2870: Add warnings to duplicate export annotation.
Apr 29, 2019
845eff8
Merge pull request #3633 from exoego/warn-on-duplicate-export
gzm0 Jul 2, 2019
52ac12c
Throw UnsupportedEncodingException on bad charset.
Jun 5, 2019
48deae3
Remove obsolete scalalib overrides for 2.13.0-M5.
sjrd Jul 3, 2019
20bc7b2
Merge pull request #3713 from sjrd/remove-obsolete-2.13.0-M5-overrides
sjrd Jul 3, 2019
3f7b83b
Fix #3705: Correctly reimplement `ArrayBuilder.generic.addAll()`.
sjrd Jul 2, 2019
b643cc4
Widen the parameters of `ju.Objects.*` methods to `Any`.
sjrd Jul 3, 2019
137c11d
Implement `java.util.function.Predicate`.
sjrd Jul 3, 2019
3e0bebd
Further improve the default import of the build in Metals.
sjrd Jul 2, 2019
cb013d0
Fix #3709: Add TypedArray factory methods.
Jul 1, 2019
8061f61
Use `-Ystop-after` instead of `-Yskip` to disable the JVM back-end.
sjrd Jul 2, 2019
d15d2a1
Merge pull request #3687 from exoego/fix-osw-exception
sjrd Jul 4, 2019
f122aa5
Fix #3704: Implement java.util.Collection.removeIf.
sjrd Jul 3, 2019
567f5cd
Merge pull request #3710 from exoego/typedarray-methods
sjrd Jul 5, 2019
4e35b1b
Merge pull request #3712 from sjrd/fix-2.13-bugs
sjrd Jul 5, 2019
57ba2fe
Merge pull request #3711 from sjrd/even-better-metals-import
gzm0 Jul 6, 2019
d54cb2c
Skip the [no-master] commits until ab398e8d7.
sjrd Jul 8, 2019
829c2a3
Merge '0.6.x' into 'master'.
sjrd Jul 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ The JUnit tests from scala/scala can be run with

> scalaTestSuite/test

## Metals-based IDEs

We recommend [Metals](https://scalameta.org/metals/)-based IDEs such as VS Code
to develop Scala.js itself. It can import the Scala.js build out-of-the-box.

After importing the build in Metals, you will need to run `clean` in sbt before
normal sbt commands can correctly work. Metals will continue to provide all its
features after cleaning.

## Eclipse

If you want to develop in Eclipse, use
Expand Down
11 changes: 11 additions & 0 deletions compiler/src/main/scala/org/scalajs/nscplugin/PrepJSExports.scala
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,17 @@ trait PrepJSExports[G <: Global with Singleton] { this: PrepJSInterop[G] =>
ExportInfo(name, destination)(annot.pos)
}

allExportInfos.filter(_.destination == ExportDestination.Normal)
.groupBy(_.jsName)
.filter { case (jsName, group) =>
if (jsName == "apply" && group.size == 2)
// @JSExportAll and single @JSExport("apply") should not be warned.
!unitAnnots.exists(_.symbol == JSExportAllAnnotation)
else
group.size > 1
}
.foreach(_ => reporter.warning(sym.pos, s"Found duplicate @JSExport"))

/* Filter out static exports of accessors (as they are not actually
* exported, their fields are). The above is only used to uniformly perform
* checks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,88 @@ class JSExportTest extends DirectTest with TestHelpers {
"""import scala.scalajs.js, js.annotation._
"""

@Test
def warnOnDuplicateExport: Unit = {
"""
class A {
@JSExport
@JSExport
def a = 1
}
""" hasWarns
"""
|newSource1.scala:6: warning: Found duplicate @JSExport
| def a = 1
| ^
"""

"""
class A {
@JSExport
@JSExport("a")
def a = 1
}
""" hasWarns
"""
|newSource1.scala:6: warning: Found duplicate @JSExport
| def a = 1
| ^
"""

"""
class A {
@JSExport("a")
@JSExport("a")
def a = 1
}
""" hasWarns
"""
|newSource1.scala:6: warning: Found duplicate @JSExport
| def a = 1
| ^
"""

// special case for @JSExportAll and 2 or more @JSExport("apply")
// since @JSExportAll and single @JSExport("apply") should not be warned (see other tests)
"""
@JSExportAll
class A {
@JSExport("apply")
@JSExport("apply")
def apply(): Int = 1
}
""" hasWarns
"""
|newSource1.scala:7: warning: Found duplicate @JSExport
| def apply(): Int = 1
| ^
"""

"""
@JSExportAll
class A {
@JSExport
def a = 1
}
""" hasWarns
"""
|newSource1.scala:6: warning: Found duplicate @JSExport
| def a = 1
| ^
"""
}

@Test
def noWarnOnUniqueExplicitName: Unit = {
"""
class A {
@JSExport("a")
@JSExport("b")
def c = 1
}
""".hasNoWarns
}

@Test
def noJSExportClass: Unit = {
"""
Expand Down
10 changes: 8 additions & 2 deletions javalib/src/main/scala/java/io/OutputStreamWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ class OutputStreamWriter(private[this] var out: OutputStream,
def this(out: OutputStream) =
this(out, Charset.defaultCharset)

def this(out: OutputStream, charsetName: String) =
this(out, Charset.forName(charsetName))
def this(out: OutputStream, charsetName: String) = {
this(out, try {
Charset.forName(charsetName)
} catch {
case _: UnsupportedCharsetException =>
throw new UnsupportedEncodingException(charsetName)
})
}

def getEncoding(): String =
if (closed) null else enc.charset.name
Expand Down
18 changes: 18 additions & 0 deletions javalib/src/main/scala/java/util/Collection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

package java.util

import java.util.function.Predicate

import scala.scalajs.js.annotation.JavaDefaultMethod

trait Collection[E] extends java.lang.Iterable[E] {
def size(): Int
def isEmpty(): Boolean
Expand All @@ -24,6 +28,20 @@ trait Collection[E] extends java.lang.Iterable[E] {
def containsAll(c: Collection[_]): Boolean
def addAll(c: Collection[_ <: E]): Boolean
def removeAll(c: Collection[_]): Boolean

@JavaDefaultMethod
def removeIf(filter: Predicate[_ >: E]): Boolean = {
var result = false
val iter = iterator()
while (iter.hasNext()) {
if (filter.test(iter.next())) {
iter.remove()
result = true
}
}
result
}

def retainAll(c: Collection[_]): Boolean
def clear(): Unit
def equals(o: Any): Boolean
Expand Down
16 changes: 8 additions & 8 deletions javalib/src/main/scala/java/util/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import scala.reflect.ClassTag
object Objects {

@inline
def equals(a: AnyRef, b: AnyRef): Boolean =
def equals(a: Any, b: Any): Boolean =
if (a == null) b == null
else a.equals(b)

@inline
def deepEquals(a: AnyRef, b: AnyRef): Boolean = {
if (a eq b) true
def deepEquals(a: Any, b: Any): Boolean = {
if (a.asInstanceOf[AnyRef] eq b.asInstanceOf[AnyRef]) true
else if (a == null || b == null) false
else {
(a, b) match {
Expand All @@ -42,7 +42,7 @@ object Objects {
}

@inline
def hashCode(o: AnyRef): Int =
def hashCode(o: Any): Int =
if (o == null) 0
else o.hashCode()

Expand All @@ -51,11 +51,11 @@ object Objects {
Arrays.hashCode(values)

@inline
def toString(o: AnyRef): String =
def toString(o: Any): String =
String.valueOf(o)

@inline
def toString(o: AnyRef, nullDefault: String): String =
def toString(o: Any, nullDefault: String): String =
if (o == null) nullDefault
else o.toString

Expand All @@ -75,11 +75,11 @@ object Objects {
else obj

@inline
def isNull(obj: AnyRef): Boolean =
def isNull(obj: Any): Boolean =
obj == null

@inline
def nonNull(obj: AnyRef): Boolean =
def nonNull(obj: Any): Boolean =
obj != null

// Requires the implementation of java.util.function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package java.util.concurrent

import java.lang.{reflect => jlr}
import java.util._
import java.util.function.Predicate

import scala.annotation.tailrec

Expand Down Expand Up @@ -185,6 +186,39 @@ class CopyOnWriteArrayList[E <: AnyRef] private (private var inner: js.Array[E])
!c.isEmpty
}

/* Override Collection.removeIf() because our iterators do not support
* the `remove()` method.
*/
override def removeIf(filter: Predicate[_ >: E]): Boolean = {
// scalastyle:off return
/* The outer loop iterates as long as no element passes the filter (and
* hence no modification is required).
*/
val iter = iterator()
var index = 0
while (iter.hasNext()) {
if (filter.test(iter.next())) {
/* We found the first element that needs to be removed: copy and
* truncate at the current index.
*/
copyIfNeeded()
innerSplice(index, size() - index)
/* Now keep iterating, but push elements that do not pass the test.
* `index` is useless from now on, so do not keep updating it.
*/
while (iter.hasNext()) {
val elem = iter.next()
if (!filter.test(elem))
innerPush(elem)
}
return true
}
index += 1
}
false // the outer loop finished without entering the inner one
// scalastyle:on return
}

override def toString: String =
iterator().scalaOps.mkString("[", ",", "]")

Expand Down
55 changes: 55 additions & 0 deletions javalib/src/main/scala/java/util/function/Predicate.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 java.util.function

import java.{util => ju}

import scala.scalajs.js.annotation.JavaDefaultMethod

@FunctionalInterface
trait Predicate[T] { self =>
def test(t: T): Boolean

@JavaDefaultMethod
def and(other: Predicate[_ >: T]): Predicate[T] = {
new Predicate[T] {
def test(t: T): Boolean =
self.test(t) && other.test(t) // the order and short-circuit are by-spec
}
}

@JavaDefaultMethod
def negate(): Predicate[T] = {
new Predicate[T] {
def test(t: T): Boolean =
!self.test(t)
}
}

@JavaDefaultMethod
def or(other: Predicate[_ >: T]): Predicate[T] = {
new Predicate[T] {
def test(t: T): Boolean =
self.test(t) || other.test(t) // the order and short-circuit are by-spec
}
}
}

object Predicate {
def isEqual[T](targetRef: Any): Predicate[T] = {
new Predicate[T] {
def test(t: T): Boolean =
ju.Objects.equals(targetRef, t)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ class Float32Array private[this] () extends TypedArray[Float, Float32Array] {
*/
@js.native
@JSGlobal
object Float32Array extends TypedArrayStatic
object Float32Array extends TypedArrayStatic[Float, Float32Array]
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ class Float64Array private[this] () extends TypedArray[Double, Float64Array] {
*/
@js.native
@JSGlobal
object Float64Array extends TypedArrayStatic
object Float64Array extends TypedArrayStatic[Double, Float64Array]
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ class Int16Array private[this] () extends TypedArray[Short, Int16Array] {
*/
@js.native
@JSGlobal
object Int16Array extends TypedArrayStatic
object Int16Array extends TypedArrayStatic[Short, Int16Array]
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ class Int32Array private[this] () extends TypedArray[Int, Int32Array] {
*/
@js.native
@JSGlobal
object Int32Array extends TypedArrayStatic
object Int32Array extends TypedArrayStatic[Int, Int32Array]
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ class Int8Array private[this] () extends TypedArray[Byte, Int8Array] {
*/
@js.native
@JSGlobal
object Int8Array extends TypedArrayStatic
object Int8Array extends TypedArrayStatic[Byte, Int8Array]
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ trait TypedArray[T, Repr] extends ArrayBufferView with js.Iterable[T] {
* Static information that exists for any concrete TypedArray
*/
@js.native
trait TypedArrayStatic extends js.Object {
trait TypedArrayStatic[T, Repr] extends js.Object {
val BYTES_PER_ELEMENT: Int = js.native

/** Returns a new array from a set of elements. */
def of(items: T*): Repr = js.native

/** Creates an array from an `iterable` object. */
def from(iterable: js.Iterable[T]): Repr = js.native

/** Creates an array from an `iterable` object. */
def from[E](iterable: js.Iterable[E],
mapFn: js.Function1[E, T]): Repr = js.native

/** Creates an array from an `iterable` object. */
def from[D, E](iterable: js.Iterable[E], mapFn: js.ThisFunction1[D, E, T],
thisArg: D): Repr = js.native
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ class Uint16Array private[this] () extends TypedArray[Int, Uint16Array] {
*/
@js.native
@JSGlobal
object Uint16Array extends TypedArrayStatic
object Uint16Array extends TypedArrayStatic[Int, Uint16Array]
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ class Uint32Array private[this] () extends TypedArray[Double, Uint32Array] {
*/
@js.native
@JSGlobal
object Uint32Array extends TypedArrayStatic
object Uint32Array extends TypedArrayStatic[Double, Uint32Array]
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ class Uint8Array private[this] () extends TypedArray[Short, Uint8Array] {
*/
@js.native
@JSGlobal
object Uint8Array extends TypedArrayStatic
object Uint8Array extends TypedArrayStatic[Short, Uint8Array]
Loading