从Java/Scala实例化Rhinoscript本机物件 [英] Instantiating Rhinoscript Native Objects from Java/Scala
问题描述
我正在尝试改善 javascript代码段评估程序的性能.这些脚本片段可以引用存在于类似json的对象图的字符串键映射中的任意数量的变量(IE:Json AST).我正在使用JDK 1.6和嵌入式Rhinoscript引擎(v1.6R2).
当前,处理采用以下形式:
- 分析摘录以发现引用变量的名称
- 从地图中检索变量并将其序列化为json字符串
- Json字符串在脚本开始时分配给了一个名称相似的变量
- 评估增强脚本
我试图弄清楚如何跳过json序列化阶段,并创建直接的Rhinoscript本机对象以放置在脚本的绑定"中.然后,所需的步骤将是:
- 分析摘录以发现引用变量的名称
- 从地图中检索变量,并转换为原生Rhinoscript等价物
- 本机对象置于绑定中
- 评估具有所述绑定的原始脚本
您知道吗,我在哪里可以找到文档或如何实例化本机犀牛对象的示例?
如果您想修改一下,我的scala学习项目可能会有所帮助.我想出的任何答案也应该出现在这里...
http://subversion.assembla. com/svn/freshcode_public/learn_scala/datastore/src/test/scala/pkg/script
谢谢.
因此,经过反复摆弄之后,我提出了一个适当的解决方案,尽管它并没有达到我希望的性能提升(仅提高了10%). /p>
该解决方案特定于Scala/Lift/Json,包含在
要创建NativeArray: 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 string-keyed map of json-like object graphs (IE: Json AST). I'm using JDK 1.6 and the embedded Rhinoscript engine (v1.6R2). Currently, processing takes the form: I'm trying to figure out how to skip the json serializing stage and create direct Rhinoscript native objects to place in the 'bindings' for the script. The desired steps would then be: Do you know where I could find documentation or examples of how to instantiate native rhinoscript objects? My scala learning project might be of some use if you want to tinker. And any answer I come up with should appear there too... http://subversion.assembla.com/svn/freshcode_public/learn_scala/datastore/src/test/scala/pkg/script Thanks in advance. 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: To create a NativeArray:
这篇关于从Java/Scala实例化Rhinoscript本机物件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!val na = new NativeArray(arr)
na.setPrototype(ScriptableObject.getClassPrototype(scope, "Array"))
java.lang.RuntimeException: No Context associated with current Thread
)Scriptable
is needed. The solution I came up with isn't pretty but it works.val na = new NativeArray(arr)
na.setPrototype(ScriptableObject.getClassPrototype(scope, "Array"))