8000 Merge pull request #1528 from sjrd/thread-name · commonlisp/scala-js@48e96cc · GitHub
[go: up one dir, main page]

Skip to content

Commit 48e96cc

Browse files
committed
Merge pull request scala-js#1528 from sjrd/thread-name
Fix scala-js#1526: Implement java.lang.Thread.{get,set}Name.
2 parents c8de0c2 + 8cf4a14 commit 48e96cc

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

javalanglib/src/main/scala/java/lang/Thread.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ package java.lang
66
* So we use a binary signature that no Java source file can ever produce.
77
*/
88
class Thread private (dummy: Unit) extends Runnable {
9+
private[this] var name: String = "main" // default name of the main thread
10+
911
def run(): Unit = ()
1012

13+
final def setName(name: String): Unit =
14+
this.name = name
15+
16+
final def getName(): String =
17+
this.name
18+
1119
def getStackTrace(): Array[StackTraceElement] =
1220
scala.scalajs.runtime.StackTrace.getCurrentStackTrace()
1321
}

test-suite/src/test/scala/org/scalajs/testsuite/javalib/ThreadTest.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ import org.scalajs.jasminetest.JasmineTest
1414
object ThreadTest extends JasmineTest {
1515

1616
describe("java.lang.Thread") {
17+
it("getName and setName") {
18+
val t = Thread.currentThread()
19+
expect(t.getName).toBe("main") // default name of the main thread
20+
t.setName("foo")
21+
try {
22+
expect(t.getName).toBe("foo")
23+
} finally {
24+
t.setName("main") // don't pollute the rest of the world with this test
25+
}
26+
expect(t.getName).toBe("main")
27+
}
28+
1729
it("Thread.currentThread().getStackTrace() should exist and not crash") {
1830
java.lang.Thread.currentThread().getStackTrace()
1931
}

0 commit comments

Comments
 (0)
0