Instantiating Rhinoscript Native Objects from Java/Scala

后端 未结 1 1969
日久生厌
日久生厌 2020-12-21 22:37

I\'m trying to improve the performance of a javascript snippet evaluator. These script snippets can reference any number of variables that exist in a strin

相关标签:
1条回答
  • 2020-12-21 22:57

    So after much fiddling I've come up with an adequate solution although it did not yield the performance increase I had hoped for (only 10% faster).

    The solution is specific to Scala / Lift / Json and is contained in the ScriptingUtil.scala file.

    To summarise:

    1. Context.javaToJs() does not seem to work in all cases. (java.lang.RuntimeException: No Context associated with current Thread)
    2. A 'scope' object of type Scriptable is needed. The solution I came up with isn't pretty but it works.
    3. To create a NativeArray:

      val na = new NativeArray(arr)
      na.setPrototype(ScriptableObject.getClassPrototype(scope, "Array"))
      
    0 讨论(0)
提交回复
热议问题