- Notifications
You must be signed in to change notification settings - Fork49
Creating instances of JS engines
It is recommended create instances of JS engines by using the following methods of theIJsEngineSwitcher
interface:CreateEngine
andCreateDefaultEngine
.In this case, instances of JS engines are created with the settings, that you specified during their registration.
CreateEngine
method takes only one parameter - name of JS engine:
IJsEngineengine=JsEngineSwitcher.Current.CreateEngine("ChakraCoreJsEngine");
You can also use constant:
IJsEngineengine=JsEngineSwitcher.Current.CreateEngine(ChakraCoreJsEngine.EngineName);
Since the name of JS engine is a string value, then you can get it from an external source (for example, configuration file).This feature allows you to quickly switch a whole project to usage of the different JS engine.
CreateDefaultEngine
method takes no parameters:
IJsEngineengine=JsEngineSwitcher.Current.CreateDefaultEngine();
Decision about which JS engine you need to create depends on the value of theDefaultEngineName
property of theIJsEngineSwitcher
interface.
You can also directly create instances of JS engines by using constructors:
IJsEngineengine=newChakraCoreJsEngine(newChakraCoreSettings{DisableEval=true,EnableExperimentalFeatures=true});
But choosing this approach, you lose all benefits of the JavaScript Engine Switcher infrastructure.