8000 Fix #1526: Implement java.lang.Thread.{get,set}Name. by sjrd · Pull Request #1528 · scala-js/scala-js · GitHub
[go: up one dir, main page]

Skip to content

Fix #1526: Implement java.lang.Thread.{get,set}Name. #1528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Fix #1526: Implement java.lang.Thread.{get,set}Name.
  • Loading branch information
sjrd committed Mar 12, 2015
commit 8cf4a14ff4970a952bd91447cd8ddaf7385e4991
8 changes: 8 additions & 0 deletions javalanglib/src/main/scala/java/lang/Thread.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ package java.lang
* So we use a binary signature that no Java source file can ever produce.
*/
class Thread private (dummy: Unit) extends Runnable {
private[this] var name: String = "main" // default name of the main thread

def run(): Unit = ()

final def setName(name: String): Unit =
this.name = name

final def getName(): String =
this.name

def getStackTrace(): Array[StackTraceElement] =
scala.scalajs.runtime.StackTrace.getCurrentStackTrace()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ import org.scalajs.jasminetest.JasmineTest
object ThreadTest extends JasmineTest {

describe("java.lang.Thread") {
it("getName and setName") {
val t = Thread.currentThread()
expect(t.getName).toBe("main") // default name of the main thread
t.setName("foo")
try {
expect(t.getName).toBe("foo")
} finally {
t.setName("main") // don't pollute the rest of the world with this test
}
expect(t.getName).toBe("main")
}

it("Thread.currentThread().getStackTrace() should exist and not crash") {
java.lang.Thread.currentThread().getStackTrace()
}
Expand Down
0