Skip to content
Taritsyn edited this page Apr 1, 2023 · 15 revisions

JavaScriptEngineSwitcher.Yantra contains adapter YantraJsEngine (wrapper for the Yantra JavaScript Engine version 1.2.129).

Engine settings

You can specify a settings of JS engine during its registration:

engineSwitcher.EngineFactories
	.AddYantra(new YantraSettings
	{
		ConsoleCallback = (string type, object[] args) =>
		{
			TextWriter writer = type == "error" ? Console.Error : Console.Out;

			if (type != "log")
			{
				ConsoleColor typeColor;

				switch (type)
				{
					case "warn":
						typeColor = ConsoleColor.Yellow;
						break;
					case "error":
						typeColor = ConsoleColor.Red;
						break;
					default:
						typeColor = ConsoleColor.White;
						break;
				}

				Console.ForegroundColor = typeColor;
				writer.Write("{0}: ", type);
			}

			Console.ForegroundColor = ConsoleColor.White;

			for (int argIndex = 0; argIndex < args.Length; argIndex++)
			{
				if (argIndex > 0)
				{
					writer.Write(" ");
				}

				writer.Write(args[argIndex] ?? "null");
			}

			writer.WriteLine();
		}
	})
	;

If you manually create an instance of JS engine, then you can pass settings via the constructor:

IJsEngine engine = new YantraJsEngine(
	new YantraSettings
	{
		ConsoleCallback = (string type, object[] args) =>
		{}
	}
);

Consider in detail properties of the YantraSettings class:

Property name Data type Default value Description
ConsoleCallback YantraJsConsoleCallback delegate null JS debugging console callback.
Debugger YantraJS.Debugger.JSDebugger null Instance of JS debugger (for example, the YantraJS.Core.Debugger.V8Debugger)
Clone this wiki locally