Skip to content

Instantly share code, notes, and snippets.

@exoego
Last active September 5, 2017 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exoego/b26cfc78ec7fa6848cee753ba3b990a2 to your computer and use it in GitHub Desktop.
Save exoego/b26cfc78ec7fa6848cee753ba3b990a2 to your computer and use it in GitHub Desktop.
ScalaJS で js.Object なクラスのインスタンスを生成して、そのLong型のフィールドを参照するとUndefinedBehaviorError
scala.scalajs.runtime.UndefinedBehaviorError:
An undefined behavior was detected: 123 is not an instance of scala.scalajs.runtime.RuntimeLong
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