Skip to content
Craig Minihan edited this page Apr 20, 2015 · 3 revisions

SpiderMonkey scripts differ from Runtime::Evaluate and Context::Evaluate because they are compiled once and executed many times. Compilation offers the best performance from your JavaScript since only one pass of the script is required to produce optimized runnable output:

  rs::jsapi::Script script(rt, "(function(){return 42;})();");
  script.Compile();
    
  rs::jsapi::Value result(rt);
  script.Execute(result);

In the above example script.Execute() can be invoked multiple times without the need to compile or evaluate JavaScript code.

Clone this wiki locally