Last active
September 5, 2017 01:21
-
-
Save exoego/b26cfc78ec7fa6848cee753ba3b990a2 to your computer and use it in GitHub Desktop.
ScalaJS で js.Object なクラスのインスタンスを生成して、そのLong型のフィールドを参照するとUndefinedBehaviorError
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala.scalajs.runtime.UndefinedBehaviorError: | |
An undefined behavior was detected: 123 is not an instance of scala.scalajs.runtime.RuntimeLong |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.scalatest.{ FunSpec, Matchers } | |
import scala.scalajs.js | |
@js.native | |
trait Foo extends js.Object { | |
val sizeBytes: Long = js.native | |
} | |
object Foo { | |
def apply(sizeByte: js.UndefOr[Long] = js.undefined): Foo = { | |
js.Dynamic.literal.applyDynamicNamed("apply")( | |
"sizeBytes" -> sizeByte.orElse(0L).map { x => x: js.Any } | |
).asInstanceOf[Foo] | |
} | |
} | |
class FooTest extends FunSpec with Matchers { | |
it("small") { | |
val h = Foo(sizeByte = 123L) | |
assert(h.sizeBytes == 123L) | |
} | |
it("max") { | |
val h = Foo(sizeByte = Long.MaxValue) | |
assert(h.sizeBytes == Long.MaxValue) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment