2

I'm trying to get the following code from scala-js/test/src/test/scala/scala/scalajs/test/jsinterop/DictionaryTest.scala to run in the Browser in a Scala.js project.

import scala.scalajs.js

val obj = js.eval("var dictionaryTest13 = 
     { a: 'Scala.js', b: 7357 }; dictionaryTest13;")
val dict = obj.asInstanceOf[js.Dictionary[js.Any]]
var propCount = 0
var propString = ""

for (prop <- js.Dictionary.propertiesOf(dict)) {
  propCount += 1
  propString += dict(prop)
}
// g.console.log(...)

It gives me: java.lang.RuntimeException: stub

How can I get this to work and make use of bracket access, e.g. to run through a json Object given from js to scala.js, in analogy to the js pattern: for(i in obj) {obj[i]} ?

That serves the trivial purpose to iterate in a over json datastructure in a way that is not bound to specific attributes.

7
  • What Scala.js version are you using to compile the code? Commented Mar 26, 2014 at 15:10
  • I'm using 0.4-SNAPSHOT to build a fork of scala-js-example-app, which itself uses 0.1-SNAPSHOT in build.sbt. Commented Mar 26, 2014 at 15:19
  • You might want to bump that to 0.4.1. I can't reproduce any of your issues. But the RTE saying "stub" suggests that your compiler isn't in sync with your library. (js.Dictionary.propertiesOf is a compiler primitive, if it fails like this, the compiler didn't replace it). Commented Mar 26, 2014 at 15:38
  • Could you try with a stable version, e.g., 0.4.0 or 0.4.1 (which are more recent than 0.4-SNAPSHOT). Also, could you provide a stack trace? Your browser should be able to give you that with the dev tools, or you can catch the exception and use printStackTrace() to display it on the console. Commented Mar 26, 2014 at 15:39
  • 1
    Ah great! It is not supposed to work in the sbt-scala-console, since this one uses a JVM, which cannot execute Scala.js code. (Put differently: there is no working REPL for Scala.js.) Commented Mar 28, 2014 at 14:06

1 Answer 1

1

To sum up the discussion:

The OP's code works with Scala.js 0.4.0 in the browser. However, it does not work in the REPL (through sbt), since Scala.js does not support the REPL.

The sbt plugin will issue a warning in the future if the REPL is used.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.