Skip to content

Instantly share code, notes, and snippets.

Avatar

Christian Wirth wirthi

View GitHub Profile
@wirthi
wirthi / testing_port
Created Dec 19, 2019
React.js blogpost
View testing_port
 s/d-cli
...
[talkyard-server] $ test
...
[info] ScalaTest
[info] Run completed in 1 minute, 41 seconds.
[info] Total number of tests run: 396
[info] Suites: completed 37, aborted 0
[info] Tests: succeeded 396, failed 0, canceled 0, ignored 0, pending 12
[info] All tests passed.
View script_object_mirror_diff
- dieIf(!result.isArray, "Not an array")
- dieIf(!result.hasSlot(0), "No slot 0")
- dieIf(!result.hasSlot(1), "No slot 1")
- dieIf(result.hasSlot(2), "Has slot 2")
+ dieIf(!result.hasArrayElements, "Not an array")
+ dieIf(result.getArraySize != 2, "Array of size != 2")
- val elem0 = result.getSlot(0)
- dieIf(!elem0.isInstanceOf[String], ...)
- val safeHtml = elem0.asInstanceOf[String]
View execute_functions_diff
- val htmlOrError = engine.invokeFunction(
- "renderReactServerSide", reactStoreJsonString, cdnOrigin.getOrElse("")).asInstanceOf[String]
+ val htmlOrError = engine.getBindings("js").getMember("renderReactServerSide")
+ .execute(reactStoreJsonString, cdnOrigin.getOrElse("")).asString
View source_create_diff
- newEngine.eval(script)
+ val scriptSource = graalvm.Source.newBuilder("js", script, "setup").buildLiteral
+ newEngine.eval(scriptSource)
View engine_create_diff
- val newEngine = new js.ScriptEngineManager(null).getEngineByName("nashorn")
+ val newEngine = graalvm.Context.newBuilder("js").allowAllAccess(true).build
@wirthi
wirthi / engine_diff
Created Dec 19, 2019
React.js blogpost
View engine_diff
- private def makeJavascriptEngine(): js.ScriptEngine = {
+ private def makeJavascriptEngine(): graalvm.Context = {
@wirthi
wirthi / import_diff
Last active Dec 19, 2019
React.js blog post: diff in imports
View import_diff
-import javax.{script => js}
+import org.graalvm.{polyglot => graalvm}