Browse Source

Update README.md (#833)

* Update README.md

Updated to better reflect features and current state, readability improvements.

Co-authored-by: Sébastien Ros <[email protected]>
Marko Lahma 4 years ago
parent
commit
7e44891f18
1 changed files with 139 additions and 106 deletions
  1. 139 106
      README.md

+ 139 - 106
README.md

@@ -1,124 +1,192 @@
 [![Build status](https://ci.appveyor.com/api/projects/status/xh2lsliy6usk60o5?svg=true)](https://ci.appveyor.com/project/SebastienRos/jint)
 [![NuGet](https://img.shields.io/nuget/v/Jint.svg)](https://www.nuget.org/packages/Jint)
+[![NuGet](https://img.shields.io/nuget/vpre/Jint.svg)](https://www.nuget.org/packages/Jint)
 [![MyGet](https://img.shields.io/myget/jint/v/jint.svg)](https://www.myget.org/feed/Packages/jint)
 [![Join the chat at https://gitter.im/sebastienros/jint](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/sebastienros/jint)
 
 # Jint
 
-Jint is a __Javascript interpreter__ for .NET which provides full __ECMA 5.1__ compliance and can run on __any .NET platform__. Because it doesn't generate any .NET bytecode nor use the DLR it runs relatively small scripts faster. It's available as a PCL on Nuget at https://www.nuget.org/packages/Jint.
+Jint is a __Javascript interpreter__ for .NET which can run on __any modern .NET platform__ as it supports .NET Standard 2.0 and .NET 4.6.1 targets (and up). Because Jint neither generates any .NET bytecode nor uses the DLR it runs relatively small scripts really fast.
 
-# Features
+💡 You should prefer 3.x beta over the 2.x legacy version as all new features and improvements are targeted against version 3.x.
 
-- Full support for ECMAScript 5.1 - http://www.ecma-international.org/ecma-262/5.1/
-- .NET Portable Class Library - http://msdn.microsoft.com/en-us/library/gg597391(v=vs.110).aspx
+## ECMAScipt Features
+
+### Version 2.x
+
+-  ✔ Full support for [ECMAScript 5.1 (ES5)](http://www.ecma-international.org/ecma-262/5.1/)
 - .NET Interoperability 
 
-> ECMAScript 6.0 currently being implemeted, see https://github.com/sebastienros/jint/issues/343
+### Version 3.x
+
+The entire execution engine was rebuild with performance in mind, in many cases at least twice as fast as the old engine.  All the features of 2.x and more:
+
+#### ECMAScript 2015 (ES6)
+
+- ✔ Arrow function expression
+- ✔ Class support
+- ✔ Enhanced object literals
+- ✔ Template strings
+- ✔ Destructuring
+- ✔ Default, rest and spread
+- ✔ Lexical scoping of variables (let and const)
+- ✔ `for...of`
+- ✔ Map and Set
+- ✔ Proxies
+- ✔ Symbols
+- ✔ Reflect
+- ✔ Binary and octal literals
+- ❌ Generators
+- ❌ Unicode
+- ❌ Modules and module loaders
+- ❌ Weakmap and Weakset
+- ❌ Promises
+- ❌ Tail calls
+
+#### ECMAScript 2016
+
+- ✔ Block-scoping of variables and functions
+- ✔ Destructuring patterns (of variables)
+- ✔ Exponentiation operator `**`
+- ✔ `Array.prototype.includes`
+- ❌ `await`, `async`
+
+####  ECMAScript 2017
+
+- ✔ `Object.values`, `Object.entries` and `Object.getOwnPropertyDescriptors`
+
+#### ECMAScript 2018
+
+- ✔ Rest/spread operators for object literals (`...identifier`),
+- ❌ `Promise.prototype.finally`
+
+#### ECMAScript 2019
+
+- ❌ `Array.prototype.flat`, `Array.prototype.flatMap`
+
+#### ECMAScript 2020
+
+- ✔ Nullish coalescing operator (`??`)
+- ✔ `globalThis` object
+- ❌ BigInt
+
+#### Other
 
-# Discussion
+- Further refined .NET CLR interop capabilities
+- Constraints for execution (recursion, memory usage, duration)
+
+> Follow new features as they are being implemented, see https://github.com/sebastienros/jint/issues/343
+
+## Discussion
 
 Join the chat on [Gitter](https://gitter.im/sebastienros/jint) or post your questions with the `jint` tag on [stackoverflow](http://stackoverflow.com/questions/tagged/jint).
 
-# Examples
+## Examples
 
 This example defines a new value named `log` pointing to `Console.WriteLine`, then executes 
 a script calling `log('Hello World!')`. 
+
 ```c#
-    var engine = new Engine()
-        .SetValue("log", new Action<object>(Console.WriteLine))
-        ;
+var engine = new Engine()
+    .SetValue("log", new Action<object>(Console.WriteLine));
     
-    engine.Execute(@"
-      function hello() { 
+engine.Execute(@"
+    function hello() { 
         log('Hello World');
-      };
-      
-      hello();
-    ");
+    };
+ 
+    hello();
+");
 ```
+
 Here, the variable `x` is set to `3` and `x * x` is executed in JavaScript. The result is returned to .NET directly, in this case as a `double` value `9`. 
 ```c#
-    var square = new Engine()
-        .SetValue("x", 3) // define a new variable
-        .Execute("x * x") // execute a statement
-        .GetCompletionValue() // get the latest statement completion value
-        .ToObject() // converts the value to .NET
-        ;
+var square = new Engine()
+    .SetValue("x", 3) // define a new variable
+    .Execute("x * x") // execute a statement
+    .GetCompletionValue() // get the latest statement completion value
+    .ToObject(); // converts the value to .NET
 ```
+
 You can also directly pass POCOs or anonymous objects and use them from JavaScript. In this example for instance a new `Person` instance is manipulated from JavaScript. 
 ```c#
-    var p = new Person {
-        Name = "Mickey Mouse"
-    };
+var p = new Person {
+    Name = "Mickey Mouse"
+};
+
+var engine = new Engine()
+    .SetValue("p", p)
+    .Execute("p.Name = 'Minnie'");
 
-    var engine = new Engine()
-        .SetValue("p", p)
-        .Execute("p.Name = 'Minnie'")
-        ;
-    Assert.AreEqual("Minnie", p.Name);
+Assert.AreEqual("Minnie", p.Name);
 ```
+
 You can invoke JavaScript function reference
 ```c#
-    var add = new Engine()
-        .Execute("function add(a, b) { return a + b; }")
-        .GetValue("add")
-        ;
+var add = new Engine()
+    .Execute("function add(a, b) { return a + b; }")
+    .GetValue("add");
 
-    add.Invoke(1, 2); // -> 3
+add.Invoke(1, 2); // -> 3
 ```
 or directly by name 
 ```c#
-    var engine = new Engine()
-        .Execute("function add(a, b) { return a + b; }")
-        ;
+var engine = new Engine()
+   .Execute("function add(a, b) { return a + b; }");
 
-    engine.Invoke("add", 1, 2); // -> 3
+engine.Invoke("add", 1, 2); // -> 3
 ```
 ## Accessing .NET assemblies and classes
 
 You can allow an engine to access any .NET class by configuring the engine instance like this:
 ```c#
-    var engine = new Engine(cfg => cfg.AllowClr());
+var engine = new Engine(cfg => cfg.AllowClr());
 ```
+
 Then you have access to the `System` namespace as a global value. Here is how it's used in the context on the command line utility:
 ```javascript
-    jint> var file = new System.IO.StreamWriter('log.txt');
-    jint> file.WriteLine('Hello World !');
-    jint> file.Dispose();
+jint> var file = new System.IO.StreamWriter('log.txt');
+jint> file.WriteLine('Hello World !');
+jint> file.Dispose();
 ```
 And even create shortcuts to common .NET methods
 ```javascript
-    jint> var log = System.Console.WriteLine;
-    jint> log('Hello World !');
-    => "Hello World !"
+jint> var log = System.Console.WriteLine;
+jint> log('Hello World !');
+=> "Hello World !"
 ```
+
 When allowing the CLR, you can optionally pass custom assemblies to load types from. 
 ```c#
-    var engine = new Engine(cfg => cfg
-        .AllowClr(typeof(Bar).Assembly)
-    );
+var engine = new Engine(cfg => cfg
+    .AllowClr(typeof(Bar).Assembly)
+);
 ```
+
 and then to assign local namespaces the same way `System` does it for you, use `importNamespace`
 ```javascript
-    jint> var Foo = importNamespace('Foo');
-    jint> var bar = new Foo.Bar();
-    jint> log(bar.ToString());
+jint> var Foo = importNamespace('Foo');
+jint> var bar = new Foo.Bar();
+jint> log(bar.ToString());
 ```    
+
 adding a specific CLR type reference can be done like this
 ```csharp
 engine.SetValue("TheType", TypeReference.CreateTypeReference(engine, typeof(TheType)))
 ```
+
 and used this way
 ```javascript
-    jint> var o = new TheType();
+jint> var o = new TheType();
 ```
+
 Generic types are also supported. Here is how to declare, instantiate and use a `List<string>`:
 ```javascript
-    jint> var ListOfString = System.Collections.Generic.List(System.String);
-    jint> var list = new ListOfString();
-    jint> list.Add('foo');
-    jint> list.Add(1); // automatically converted to String
-    jint> list.Count; // 2
+jint> var ListOfString = System.Collections.Generic.List(System.String);
+jint> var list = new ListOfString();
+jint> list.Add('foo');
+jint> list.Add(1); // automatically converted to String
+jint> list.Count; // 2
 ```
 
 ## Internationalization
@@ -127,24 +195,24 @@ You can enforce what Time Zone or Culture the engine should use when locale Java
 
 This example forces the Time Zone to Pacific Standard Time.
 ```c#
-    var PST = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
-    var engine = new Engine(cfg => cfg.LocalTimeZone(PST));
+var PST = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
+var engine = new Engine(cfg => cfg.LocalTimeZone(PST));
     
-    engine.Execute("new Date().toString()"); // Wed Dec 31 1969 16:00:00 GMT-08:00
+engine.Execute("new Date().toString()"); // Wed Dec 31 1969 16:00:00 GMT-08:00
 ```
 
 This example is using French as the default culture.
 ```c#
-    var FR = CultureInfo.GetCultureInfo("fr-FR");
-    var engine = new Engine(cfg => cfg.Culture(FR));
+var FR = CultureInfo.GetCultureInfo("fr-FR");
+var engine = new Engine(cfg => cfg.Culture(FR));
     
-    engine.Execute("new Number(1.23).toString()"); // 1.23
-    engine.Execute("new Number(1.23).toLocaleString()"); // 1,23
+engine.Execute("new Number(1.23).toString()"); // 1.23
+engine.Execute("new Number(1.23).toLocaleString()"); // 1,23
 ```
 
-## Constraints 
+## Execution Constraints 
 
-Constraints are used during script execution to ensure that requirements around resource consumption are met, for example:
+Execution constraints are used during script execution to ensure that requirements around resource consumption are met, for example:
 
 * Scripts should not use more than X memory.
 * Scripts should only run for a maximum amount of time.
@@ -229,43 +297,7 @@ for (var i = 0; i < 10; i++)
 }
 ```
 
-## Implemented features:
-
-### ECMAScript 5.1
-
-- Complete implementation
-  - ECMAScript 5.1 test suite (http://test262.ecmascript.org/) 
-
-### ECMAScript 6.0
-
-ES6 features which are being implemented:
-- [x] [arrows](https://github.com/lukehoban/es6features/blob/master/README.md#arrows)
-- [x] [classes](https://github.com/lukehoban/es6features/blob/master/README.md#classes)
-- [x] [enhanced object literals](https://github.com/lukehoban/es6features/blob/master/README.md#enhanced-object-literals)
-- [x] [template strings](https://github.com/lukehoban/es6features/blob/master/README.md#template-strings)
-- [x] [destructuring](https://github.com/lukehoban/es6features/blob/master/README.md#destructuring)
-- [x] [default + rest + spread](https://github.com/lukehoban/es6features/blob/master/README.md#default--rest--spread)
-- [x] [let + const](https://github.com/lukehoban/es6features/blob/master/README.md#let--const)
-- [x] [iterators + for..of](https://github.com/lukehoban/es6features/blob/master/README.md#iterators--forof)
-- [ ] [generators](https://github.com/lukehoban/es6features/blob/master/README.md#generators)
-- [ ] [unicode](https://github.com/lukehoban/es6features/blob/master/README.md#unicode)
-- [ ] [modules](https://github.com/lukehoban/es6features/blob/master/README.md#modules)
-- [ ] [module loaders](https://github.com/lukehoban/es6features/blob/master/README.md#module-loaders)
-- [x] [map + set](https://github.com/lukehoban/es6features/blob/master/README.md#map--set--weakmap--weakset)
-- [ ] [weakmap + weakset](https://github.com/lukehoban/es6features/blob/master/README.md#map--set--weakmap--weakset)
-- [x] [proxies](https://github.com/lukehoban/es6features/blob/master/README.md#proxies)
-- [x] [symbols](https://github.com/lukehoban/es6features/blob/master/README.md#symbols)
-- [ ] [promises](https://github.com/lukehoban/es6features/blob/master/README.md#promises)
-- [x] [math APIs](https://github.com/lukehoban/es6features/blob/master/README.md#math--number--string--array--object-apis)
-- [x] [number APIs](https://github.com/lukehoban/es6features/blob/master/README.md#math--number--string--array--object-apis)
-- [x] [string APIs](https://github.com/lukehoban/es6features/blob/master/README.md#math--number--string--array--object-apis)
-- [x] [array APIs](https://github.com/lukehoban/es6features/blob/master/README.md#math--number--string--array--object-apis)
-- [x] [object APIs](https://github.com/lukehoban/es6features/blob/master/README.md#math--number--string--array--object-apis)
-- [x] [binary and octal literals](https://github.com/lukehoban/es6features/blob/master/README.md#binary-and-octal-literals)
-- [x] [reflect api](https://github.com/lukehoban/es6features/blob/master/README.md#reflect-api)
-- [ ] [tail calls](https://github.com/lukehoban/es6features/blob/master/README.md#tail-calls)
-
-### .NET Interoperability
+## .NET Interoperability
 
 - Manipulate CLR objects from JavaScript, including:
   - Single values
@@ -284,8 +316,9 @@ ES6 features which are being implemented:
   - boolean -> bool
   - Regex -> RegExp
   - Function -> Delegate
+- Extensions methods
 
-### Security
+## Security
 
 The following features provide you with a secure, sand-boxed environment to run user scripts.
 
@@ -297,7 +330,7 @@ The following features provide you with a secure, sand-boxed environment to run
 
 Continuous Integration kindly provided by  [AppVeyor](https://www.appveyor.com)
 
-### Branches and releases
+## Branches and releases
 
 - The recommended branch is __dev__, any PR should target this branch
 - The __dev__ branch is automatically built and published on [Myget](https://www.myget.org/feed/Packages/jint). Add this feed to your NuGet sources to use it: https://www.myget.org/F/jint/api/v3/index.json