-
-
Notifications
You must be signed in to change notification settings - Fork 7
Home
YantraJS is a JavaScript runtime written in .NET Standard. Yantra has two components,
Since this is written in .NET Standard 2.0, it runs everywhere except iOS which enforces JIT restrictions. However, there may be a way to interpret IL with mono interpreter but we haven't explored it yet.
Running V8 in CLR is expensive, as both V8 and CLR contain same set of features such as garbage collection, threading, and moving objects from to and from V8 hurts performance. And native compilation requirement of V8 puts lot of pressure on maintaining and troubleshooting. So we wanted to create a JavaScript engine which will do everything inside CLR and will try to match performance of other engines. Matching V8 performance is out of scope as C# itself is an higher level language and IL will be JIT compiled at runtime. But we look at Yantra is simple way to integrate with other larger .NET projects. Simplicity in integration overcomes performance drawbacks. Currently Yantra is twice slower compared to V8. However, as time goes, we will certainly try to improve the speed. This is also the primary reason we are trying write lengthy code and avoid runtime inlining as currently there is no macro support in C#.
Expression compiler is similar to .NET's Linq Expression LambdaCompiler and supports compiling expression to method builder. It is not drop in replacement but the API is quite familiar to Linq Expressions.
YantraJS.Core is a JavaScript engine, which contains Scanner, Parser and Compiler which compiles JavaScript AST to ExpressionCompiler Expressions. That in turn are converted to IL and it can be saved.
Currently we are seeing more than 70% conformance to ECMAScript, reaching 100% is little out of scope as it is very huge and Yantra is only one year old. We are focusing on supporting most used JavaScript patterns instead of targeting 100% compliance due to limited development bandwidth.
- Compiles JavaScript to .Net Assembly
- Strict Mode Only JavaScript*
- Arrow functions
- Classes
- Enhanced object literals
- Template strings and tagged templates
- Destructuring
-
let
const
- Map, Set, WeakMap, WeakSet
- Symbols
- Subclassable built-ins
- Binary and Octal literals
- Module support
- Null coalesce
- Optional property chain
identifier?.[]
,identifier?.(
,identifier?.identifier
- Rest, Default and Spread Parameters
- Generators, iterators, for..of
- Async/Await
- Optional parameters
- Many ES5 + ES6 features
- CommonJS Module Support
- Easily marshal CLR Object to JavaScript and other way around
- CSX Module support
*
Most JavaScript today is available in strict mode, we do not feel any need to support non strict mode as modules are strict by default.