Sebastien Ros 8 年之前
父節點
當前提交
94886e260e
共有 80 個文件被更改,包括 237 次插入6226 次删除
  1. 0 1
      Jint.Benchmark/project.json
  2. 18 40
      Jint.Tests/Parser/JavascriptParserTests.cs
  3. 3 5
      Jint.Tests/Runtime/EngineTests.cs
  4. 1 1
      Jint.Tests/project.json
  5. 6 0
      Jint.sln
  6. 52 53
      Jint/Engine.cs
  7. 8 6
      Jint/Native/Function/EvalFunctionInstance.cs
  8. 17 28
      Jint/Native/Function/FunctionConstructor.cs
  9. 8 8
      Jint/Native/Function/ScriptFunctionInstance.cs
  10. 7 5
      Jint/Native/Json/JsonInstance.cs
  11. 0 914
      Jint/Native/Json/JsonParser.cs
  12. 0 9
      Jint/Parser/Ast/ArrayExpression.cs
  13. 0 61
      Jint/Parser/Ast/AssignmentExpression.cs
  14. 0 88
      Jint/Parser/Ast/BinaryExpression.cs
  15. 0 9
      Jint/Parser/Ast/BlockStatement.cs
  16. 0 7
      Jint/Parser/Ast/BreakStatement.cs
  17. 0 15
      Jint/Parser/Ast/CallExpression.cs
  18. 0 8
      Jint/Parser/Ast/CatchClause.cs
  19. 0 9
      Jint/Parser/Ast/ConditionalExpression.cs
  20. 0 7
      Jint/Parser/Ast/ContinueStatement.cs
  21. 0 7
      Jint/Parser/Ast/DebuggerStatement.cs
  22. 0 9
      Jint/Parser/Ast/DoWhileStatement.cs
  23. 0 7
      Jint/Parser/Ast/EmptyStatement.cs
  24. 0 8
      Jint/Parser/Ast/Expression.cs
  25. 0 7
      Jint/Parser/Ast/ExpressionStatement.cs
  26. 0 10
      Jint/Parser/Ast/ForInStatement.cs
  27. 0 11
      Jint/Parser/Ast/ForStatement.cs
  28. 0 30
      Jint/Parser/Ast/FunctionDeclaration.cs
  29. 0 28
      Jint/Parser/Ast/FunctionExpression.cs
  30. 0 10
      Jint/Parser/Ast/IPropertyKeyExpression.cs
  31. 0 12
      Jint/Parser/Ast/Identifier.cs
  32. 0 9
      Jint/Parser/Ast/IfStatement.cs
  33. 0 8
      Jint/Parser/Ast/LabeledStatement.cs
  34. 0 19
      Jint/Parser/Ast/Literal.cs
  35. 0 31
      Jint/Parser/Ast/LogicalExpression.cs
  36. 0 11
      Jint/Parser/Ast/MemberExpression.cs
  37. 0 10
      Jint/Parser/Ast/NewExpression.cs
  38. 0 9
      Jint/Parser/Ast/ObjectExpression.cs
  39. 0 21
      Jint/Parser/Ast/Program.cs
  40. 0 20
      Jint/Parser/Ast/Property.cs
  41. 0 14
      Jint/Parser/Ast/RegExpLiteral.cs
  42. 0 7
      Jint/Parser/Ast/ReturnStatement.cs
  43. 0 9
      Jint/Parser/Ast/SequenceExpression.cs
  44. 0 7
      Jint/Parser/Ast/Statement.cs
  45. 0 10
      Jint/Parser/Ast/SwitchCase.cs
  46. 0 10
      Jint/Parser/Ast/SwitchStatement.cs
  47. 0 17
      Jint/Parser/Ast/SyntaxNode.cs
  48. 0 47
      Jint/Parser/Ast/SyntaxNodes.cs
  49. 0 7
      Jint/Parser/Ast/ThisExpression.cs
  50. 0 7
      Jint/Parser/Ast/ThrowStatement.cs
  51. 0 12
      Jint/Parser/Ast/TryStatement.cs
  52. 0 53
      Jint/Parser/Ast/UnaryExpression.cs
  53. 0 6
      Jint/Parser/Ast/UpdateExpression.cs
  54. 0 10
      Jint/Parser/Ast/VariableDeclaration.cs
  55. 0 8
      Jint/Parser/Ast/VariableDeclarator.cs
  56. 0 8
      Jint/Parser/Ast/WhileStatement.cs
  57. 0 8
      Jint/Parser/Ast/WithStatement.cs
  58. 0 10
      Jint/Parser/Comment.cs
  59. 0 13
      Jint/Parser/IFunctionDeclaration.cs
  60. 0 24
      Jint/Parser/IFunctionScope.cs
  61. 0 24
      Jint/Parser/IVariableScope.cs
  62. 0 4074
      Jint/Parser/JavascriptParser.cs
  63. 0 9
      Jint/Parser/Loc.cs
  64. 0 40
      Jint/Parser/Messages.cs
  65. 0 20
      Jint/Parser/ParserException.cs
  66. 0 37
      Jint/Parser/ParserExtensions.cs
  67. 0 10
      Jint/Parser/ParserOptions.cs
  68. 0 8
      Jint/Parser/Position.cs
  69. 0 15
      Jint/Parser/State.cs
  70. 0 30
      Jint/Parser/Token.cs
  71. 1 1
      Jint/Runtime/CallStack/CallStackElement.cs
  72. 3 2
      Jint/Runtime/Completion.cs
  73. 3 5
      Jint/Runtime/Debugger/DebugHandler.cs
  74. 1 2
      Jint/Runtime/Debugger/DebugInformation.cs
  75. 65 59
      Jint/Runtime/ExpressionIntepreter.cs
  76. 4 3
      Jint/Runtime/JavaScriptException.cs
  77. 0 6
      Jint/Runtime/RecursionDepthOverflowException.cs
  78. 31 31
      Jint/Runtime/StatementInterpreter.cs
  79. 3 12
      Jint/project.json
  80. 6 0
      global.json

+ 0 - 1
Jint.Benchmark/project.json

@@ -3,7 +3,6 @@
   "buildOptions": {
     "emitEntryPoint": true
   },
-
   "frameworks": {
     "net45": {
       "dependencies": {

+ 18 - 40
Jint.Tests/Parser/JavascriptParserTests.cs

@@ -3,17 +3,14 @@ using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Reflection;
-using Jint.Parser;
-using Jint.Parser.Ast;
+using Esprima;
+using Esprima.Ast;
 using Xunit;
-using Xunit.Extensions;
 
 namespace Jint.Tests.Parser
 {
     public class JavascriptParserTests
     {
-        private readonly JavaScriptParser _parser = new JavaScriptParser();
-
         private string GetEmbeddedFile(string filename)
         {
             const string prefix = "Jint.Tests.Parser.Scripts.";
@@ -30,45 +27,26 @@ namespace Jint.Tests.Parser
             }
         }
 
-        [Theory]
-        [InlineData("jQuery.js", "1.9.1")]
-        [InlineData("underscore.js", "1.5.2")]
-        [InlineData("backbone.js", "1.1.0")]
-        [InlineData("mootools.js", "1.4.5")]
-        [InlineData("angular.js", "1.2.5")]
-        [InlineData("JSXTransformer.js", "0.10.0")]
-        [InlineData("handlebars.js", "2.0.0")]
-        public void ShouldParseScriptFile(string file, string version)
-        {
-
-            var parser = new JavaScriptParser();
-            var source = GetEmbeddedFile(file);
-            var sw = new Stopwatch();
-            var program = parser.Parse(source);
-            Console.WriteLine("Parsed {0} {1} ({3} KB) in {2} ms", file, version, sw.ElapsedMilliseconds, (int)source.Length/1024);
-            Assert.NotNull(program);
-        }
-
         [Fact]
         public void ShouldParseThis()
         {
-            var program = _parser.Parse("this");
+            var program = new JavaScriptParser("this").ParseProgram();
             var body = program.Body;
 
             Assert.NotNull(body);
             Assert.Equal(1, body.Count());
-            Assert.Equal(SyntaxNodes.ThisExpression, body.First().As<ExpressionStatement>().Expression.Type);
+            Assert.Equal(Nodes.ThisExpression, body.First().As<ExpressionStatement>().Expression.Type);
         }
 
         [Fact]
         public void ShouldParseNull()
         {
-            var program = _parser.Parse("null");
+            var program = new JavaScriptParser("null").ParseProgram();
             var body = program.Body;
 
             Assert.NotNull(body);
             Assert.Equal(1, body.Count());
-            Assert.Equal(SyntaxNodes.Literal, body.First().As<ExpressionStatement>().Expression.Type);
+            Assert.Equal(Nodes.Literal, body.First().As<ExpressionStatement>().Expression.Type);
             Assert.Equal(null, body.First().As<ExpressionStatement>().Expression.As<Literal>().Value);
             Assert.Equal("null", body.First().As<ExpressionStatement>().Expression.As<Literal>().Raw);
         }
@@ -76,16 +54,16 @@ namespace Jint.Tests.Parser
         [Fact]
         public void ShouldParseNumeric()
         {
-            var program = _parser.Parse(
+            var program = new JavaScriptParser(
                 @"
                 42
-            ");
+            ").ParseProgram();
             var body = program.Body;
 
             Assert.NotNull(body);
             Assert.Equal(1, body.Count());
-            Assert.Equal(SyntaxNodes.Literal, body.First().As<ExpressionStatement>().Expression.Type);
-            Assert.Equal(42d, body.First().As<ExpressionStatement>().Expression.As<Literal>().Value);
+            Assert.Equal(Nodes.Literal, body.First().As<ExpressionStatement>().Expression.Type);
+            Assert.Equal(42L, body.First().As<ExpressionStatement>().Expression.As<Literal>().Value);
             Assert.Equal("42", body.First().As<ExpressionStatement>().Expression.As<Literal>().Raw);
         }
 
@@ -94,16 +72,16 @@ namespace Jint.Tests.Parser
         {
             BinaryExpression binary;
 
-            var program = _parser.Parse("(1 + 2 ) * 3");
+            var program = new JavaScriptParser("(1 + 2 ) * 3").ParseProgram();
             var body = program.Body;
 
             Assert.NotNull(body);
             Assert.Equal(1, body.Count());
             Assert.NotNull(binary = body.First().As<ExpressionStatement>().Expression.As<BinaryExpression>());
-            Assert.Equal(3d, binary.Right.As<Literal>().Value);
+            Assert.Equal(3L, binary.Right.As<Literal>().Value);
             Assert.Equal(BinaryOperator.Times, binary.Operator);
-            Assert.Equal(1d, binary.Left.As<BinaryExpression>().Left.As<Literal>().Value);
-            Assert.Equal(2d, binary.Left.As<BinaryExpression>().Right.As<Literal>().Value);
+            Assert.Equal(1L, binary.Left.As<BinaryExpression>().Left.As<Literal>().Value);
+            Assert.Equal(2L, binary.Left.As<BinaryExpression>().Right.As<Literal>().Value);
             Assert.Equal(BinaryOperator.Plus, binary.Left.As<BinaryExpression>().Operator);
         }
 
@@ -129,7 +107,7 @@ namespace Jint.Tests.Parser
         {
             Literal literal;
 
-            var program = _parser.Parse(source);
+            var program = new JavaScriptParser(source).ParseProgram();
             var body = program.Body;
 
             Assert.NotNull(body);
@@ -149,7 +127,7 @@ namespace Jint.Tests.Parser
         {
             Literal literal;
 
-            var program = _parser.Parse(source);
+            var program = new JavaScriptParser(source).ParseProgram();
             var body = program.Body;
 
             Assert.NotNull(body);
@@ -193,7 +171,7 @@ namespace Jint.Tests.Parser
 
         public void ShouldInsertSemicolons(string source)
         {
-            var program = _parser.Parse(source);
+            var program = new JavaScriptParser(source).ParseProgram();
             var body = program.Body;
 
             Assert.NotNull(body);
@@ -206,7 +184,7 @@ namespace Jint.Tests.Parser
 \
 '
 ";
-            var program = _parser.Parse(source);
+            var program = new JavaScriptParser(source, new ParserOptions { Loc = true }).ParseProgram();
             var expr = program.Body.First().As<ExpressionStatement>().Expression;
             Assert.Equal(1, expr.Location.Start.Line);
             Assert.Equal(0, expr.Location.Start.Column);

+ 3 - 5
Jint.Tests/Runtime/EngineTests.cs

@@ -2,14 +2,12 @@
 using System.Globalization;
 using System.IO;
 using System.Reflection;
-using System.Threading;
+using Esprima;
+using Esprima.Ast;
 using Jint.Native.Number;
-using Jint.Parser;
-using Jint.Parser.Ast;
 using Jint.Runtime;
 using Jint.Runtime.Debugger;
 using Xunit;
-using System.Net;
 
 namespace Jint.Tests.Runtime
 {
@@ -995,7 +993,7 @@ namespace Jint.Tests.Runtime
             engine.Execute("1.2");
 
             var result = engine.GetLastSyntaxNode();
-            Assert.Equal(SyntaxNodes.Literal, result.Type);
+            Assert.Equal(Nodes.Literal, result.Type);
         }
 
         [Fact]

+ 1 - 1
Jint.Tests/project.json

@@ -16,6 +16,6 @@
         }
       }
     },
-    "net451": {}
+    //"net451": {}
   }
 }

+ 6 - 0
Jint.sln

@@ -22,6 +22,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Jint.Tests.Ecma", "Jint.Tes
 EndProject
 Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Jint.Tests.CommonScripts", "Jint.Tests.CommonScripts\Jint.Tests.CommonScripts.xproj", "{B815F239-6409-4BA7-9461-18317AA2DBED}"
 EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Esprima", "..\Esprima.NET\src\Esprima\Esprima.xproj", "{C9C93BFD-D276-4537-8724-4268520BF3C6}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -52,6 +54,10 @@ Global
 		{B815F239-6409-4BA7-9461-18317AA2DBED}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{B815F239-6409-4BA7-9461-18317AA2DBED}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{B815F239-6409-4BA7-9461-18317AA2DBED}.Release|Any CPU.Build.0 = Release|Any CPU
+		{C9C93BFD-D276-4537-8724-4268520BF3C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{C9C93BFD-D276-4537-8724-4268520BF3C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{C9C93BFD-D276-4537-8724-4268520BF3C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{C9C93BFD-D276-4537-8724-4268520BF3C6}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 52 - 53
Jint/Engine.cs

@@ -15,8 +15,8 @@ using Jint.Native.Number;
 using Jint.Native.Object;
 using Jint.Native.RegExp;
 using Jint.Native.String;
-using Jint.Parser;
-using Jint.Parser.Ast;
+using Esprima;
+using Esprima.Ast;
 using Jint.Runtime;
 using Jint.Runtime.CallStack;
 using Jint.Runtime.Debugger;
@@ -35,7 +35,7 @@ namespace Jint
         private JsValue _completionValue = JsValue.Undefined;
         private int _statementsCount;
         private long _timeoutTicks;
-        private SyntaxNode _lastSyntaxNode = null;
+        private INode _lastSyntaxNode = null;
 
         public ITypeConverter ClrTypeConverter;
 
@@ -292,14 +292,13 @@ namespace Jint
 
         public Engine Execute(string source)
         {
-            var parser = new JavaScriptParser();
-            return Execute(parser.Parse(source));
+            return Execute(source, new ParserOptions());
         }
 
         public Engine Execute(string source, ParserOptions parserOptions)
         {
-            var parser = new JavaScriptParser();
-            return Execute(parser.Parse(source, parserOptions));
+            var parser = new JavaScriptParser(source, parserOptions);
+            return Execute(parser.ParseProgram());
         }
 
         public Engine Execute(Program program)
@@ -309,9 +308,9 @@ namespace Jint
             ResetLastStatement();
             ResetCallStack();
 
-            using (new StrictModeScope(Options._IsStrict || program.Strict))
+            using (new StrictModeScope(Options._IsStrict || program.IsStrict()))
             {
-                DeclarationBindingInstantiation(DeclarationBindingType.GlobalCode, program.FunctionDeclarations, program.VariableDeclarations, null, null);
+                DeclarationBindingInstantiation(DeclarationBindingType.GlobalCode, program.Body.OfType<FunctionDeclaration>(), program.Body.OfType<VariableDeclaration>(), null, null);
 
                 var result = _statements.ExecuteProgram(program);
                 if (result.Type == Completion.Throw)
@@ -363,64 +362,64 @@ namespace Jint
 
             switch (statement.Type)
             {
-                case SyntaxNodes.BlockStatement:
+                case Nodes.BlockStatement:
                     return _statements.ExecuteBlockStatement(statement.As<BlockStatement>());
 
-                case SyntaxNodes.BreakStatement:
+                case Nodes.BreakStatement:
                     return _statements.ExecuteBreakStatement(statement.As<BreakStatement>());
 
-                case SyntaxNodes.ContinueStatement:
+                case Nodes.ContinueStatement:
                     return _statements.ExecuteContinueStatement(statement.As<ContinueStatement>());
 
-                case SyntaxNodes.DoWhileStatement:
+                case Nodes.DoWhileStatement:
                     return _statements.ExecuteDoWhileStatement(statement.As<DoWhileStatement>());
 
-                case SyntaxNodes.DebuggerStatement:
+                case Nodes.DebuggerStatement:
                     return _statements.ExecuteDebuggerStatement(statement.As<DebuggerStatement>());
 
-                case SyntaxNodes.EmptyStatement:
+                case Nodes.EmptyStatement:
                     return _statements.ExecuteEmptyStatement(statement.As<EmptyStatement>());
 
-                case SyntaxNodes.ExpressionStatement:
+                case Nodes.ExpressionStatement:
                     return _statements.ExecuteExpressionStatement(statement.As<ExpressionStatement>());
 
-                case SyntaxNodes.ForStatement:
+                case Nodes.ForStatement:
                     return _statements.ExecuteForStatement(statement.As<ForStatement>());
 
-                case SyntaxNodes.ForInStatement:
+                case Nodes.ForInStatement:
                     return _statements.ExecuteForInStatement(statement.As<ForInStatement>());
 
-                case SyntaxNodes.FunctionDeclaration:
+                case Nodes.FunctionDeclaration:
                     return new Completion(Completion.Normal, null, null);
 
-                case SyntaxNodes.IfStatement:
+                case Nodes.IfStatement:
                     return _statements.ExecuteIfStatement(statement.As<IfStatement>());
 
-                case SyntaxNodes.LabeledStatement:
-                    return _statements.ExecuteLabelledStatement(statement.As<LabelledStatement>());
+                case Nodes.LabeledStatement:
+                    return _statements.ExecuteLabeledStatement(statement.As<LabeledStatement>());
 
-                case SyntaxNodes.ReturnStatement:
+                case Nodes.ReturnStatement:
                     return _statements.ExecuteReturnStatement(statement.As<ReturnStatement>());
 
-                case SyntaxNodes.SwitchStatement:
+                case Nodes.SwitchStatement:
                     return _statements.ExecuteSwitchStatement(statement.As<SwitchStatement>());
 
-                case SyntaxNodes.ThrowStatement:
+                case Nodes.ThrowStatement:
                     return _statements.ExecuteThrowStatement(statement.As<ThrowStatement>());
 
-                case SyntaxNodes.TryStatement:
+                case Nodes.TryStatement:
                     return _statements.ExecuteTryStatement(statement.As<TryStatement>());
 
-                case SyntaxNodes.VariableDeclaration:
+                case Nodes.VariableDeclaration:
                     return _statements.ExecuteVariableDeclaration(statement.As<VariableDeclaration>());
 
-                case SyntaxNodes.WhileStatement:
+                case Nodes.WhileStatement:
                     return _statements.ExecuteWhileStatement(statement.As<WhileStatement>());
 
-                case SyntaxNodes.WithStatement:
+                case Nodes.WithStatement:
                     return _statements.ExecuteWithStatement(statement.As<WithStatement>());
 
-                case SyntaxNodes.Program:
+                case Nodes.Program:
                     return _statements.ExecuteProgram(statement.As<Program>());
 
                 default:
@@ -434,55 +433,55 @@ namespace Jint
 
             switch (expression.Type)
             {
-                case SyntaxNodes.AssignmentExpression:
+                case Nodes.AssignmentExpression:
                     return _expressions.EvaluateAssignmentExpression(expression.As<AssignmentExpression>());
 
-                case SyntaxNodes.ArrayExpression:
+                case Nodes.ArrayExpression:
                     return _expressions.EvaluateArrayExpression(expression.As<ArrayExpression>());
 
-                case SyntaxNodes.BinaryExpression:
+                case Nodes.BinaryExpression:
                     return _expressions.EvaluateBinaryExpression(expression.As<BinaryExpression>());
 
-                case SyntaxNodes.CallExpression:
+                case Nodes.CallExpression:
                     return _expressions.EvaluateCallExpression(expression.As<CallExpression>());
 
-                case SyntaxNodes.ConditionalExpression:
+                case Nodes.ConditionalExpression:
                     return _expressions.EvaluateConditionalExpression(expression.As<ConditionalExpression>());
 
-                case SyntaxNodes.FunctionExpression:
-                    return _expressions.EvaluateFunctionExpression(expression.As<FunctionExpression>());
+                case Nodes.FunctionExpression:
+                    return _expressions.EvaluateFunctionExpression(expression.As<IFunction>());
 
-                case SyntaxNodes.Identifier:
+                case Nodes.Identifier:
                     return _expressions.EvaluateIdentifier(expression.As<Identifier>());
 
-                case SyntaxNodes.Literal:
+                case Nodes.Literal:
                     return _expressions.EvaluateLiteral(expression.As<Literal>());
 
-                case SyntaxNodes.RegularExpressionLiteral:
+                case Nodes.RegularExpressionLiteral:
                     return _expressions.EvaluateLiteral(expression.As<Literal>());
 
-                case SyntaxNodes.LogicalExpression:
-                    return _expressions.EvaluateLogicalExpression(expression.As<LogicalExpression>());
+                case Nodes.LogicalExpression:
+                    return _expressions.EvaluateLogicalExpression(expression.As<BinaryExpression>());
 
-                case SyntaxNodes.MemberExpression:
+                case Nodes.MemberExpression:
                     return _expressions.EvaluateMemberExpression(expression.As<MemberExpression>());
 
-                case SyntaxNodes.NewExpression:
+                case Nodes.NewExpression:
                     return _expressions.EvaluateNewExpression(expression.As<NewExpression>());
 
-                case SyntaxNodes.ObjectExpression:
+                case Nodes.ObjectExpression:
                     return _expressions.EvaluateObjectExpression(expression.As<ObjectExpression>());
 
-                case SyntaxNodes.SequenceExpression:
+                case Nodes.SequenceExpression:
                     return _expressions.EvaluateSequenceExpression(expression.As<SequenceExpression>());
 
-                case SyntaxNodes.ThisExpression:
+                case Nodes.ThisExpression:
                     return _expressions.EvaluateThisExpression(expression.As<ThisExpression>());
 
-                case SyntaxNodes.UpdateExpression:
+                case Nodes.UpdateExpression:
                     return _expressions.EvaluateUpdateExpression(expression.As<UpdateExpression>());
 
-                case SyntaxNodes.UnaryExpression:
+                case Nodes.UnaryExpression:
                     return _expressions.EvaluateUnaryExpression(expression.As<UnaryExpression>());
 
                 default:
@@ -716,9 +715,9 @@ namespace Jint
         }
 
         /// <summary>
-        /// Gets the last evaluated <see cref="SyntaxNode"/>.
+        /// Gets the last evaluated <see cref="INode"/>.
         /// </summary>
-        public SyntaxNode GetLastSyntaxNode()
+        public INode GetLastSyntaxNode()
         {
             return _lastSyntaxNode;
         }
@@ -741,7 +740,7 @@ namespace Jint
         }
 
         //  http://www.ecma-international.org/ecma-262/5.1/#sec-10.5
-        public void DeclarationBindingInstantiation(DeclarationBindingType declarationBindingType, IList<FunctionDeclaration> functionDeclarations, IList<VariableDeclaration> variableDeclarations, FunctionInstance functionInstance, JsValue[] arguments)
+        public void DeclarationBindingInstantiation(DeclarationBindingType declarationBindingType, IEnumerable<FunctionDeclaration> functionDeclarations, IEnumerable<VariableDeclaration> variableDeclarations, FunctionInstance functionInstance, JsValue[] arguments)
         {
             var env = ExecutionContext.VariableEnvironment.Record;
             bool configurableBindings = declarationBindingType == DeclarationBindingType.EvalCode;
@@ -831,7 +830,7 @@ namespace Jint
             // process all variable declarations in the current parser scope
             foreach (var d in variableDeclarations.SelectMany(x => x.Declarations))
             {
-                var dn = d.Id.Name;
+                var dn = d.Id.As<Identifier>().Name;
                 var varAlreadyDeclared = env.HasBinding(dn);
                 if (!varAlreadyDeclared)
                 {

+ 8 - 6
Jint/Native/Function/EvalFunctionInstance.cs

@@ -1,4 +1,6 @@
-using Jint.Parser;
+using System.Linq;
+using Esprima;
+using Esprima.Ast;
 using Jint.Runtime;
 using Jint.Runtime.Environments;
 
@@ -31,9 +33,9 @@ namespace Jint.Native.Function
 
             try
             {
-                var parser = new JavaScriptParser(StrictModeScope.IsStrictModeCode);
-                var program = parser.Parse(code);
-                using (new StrictModeScope(program.Strict))
+                var parser = new JavaScriptParser(code /* TODO: Esprima, StrictModeScope.IsStrictModeCode*/);
+                var program = parser.ParseProgram();
+                using (new StrictModeScope(program.IsStrict()))
                 {
                     using (new EvalCodeScope())
                     {
@@ -52,8 +54,8 @@ namespace Jint.Native.Function
                                 Engine.EnterExecutionContext(strictVarEnv, strictVarEnv, Engine.ExecutionContext.ThisBinding);
                             }
 
-                            Engine.DeclarationBindingInstantiation(DeclarationBindingType.EvalCode, program.FunctionDeclarations, program.VariableDeclarations, this, arguments);
-                            
+                            Engine.DeclarationBindingInstantiation(DeclarationBindingType.EvalCode, program.Body.OfType<FunctionDeclaration>(), program.Body.OfType<VariableDeclaration>(), this, arguments);
+
                             var result = _engine.ExecuteStatement(program);
 
                             if (result.Type == Completion.Throw)

+ 17 - 28
Jint/Native/Function/FunctionConstructor.cs

@@ -1,10 +1,10 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using Esprima;
+using Esprima.Ast;
 using Jint.Native.Object;
 using Jint.Native.String;
-using Jint.Parser;
-using Jint.Parser.Ast;
 using Jint.Runtime;
 using Jint.Runtime.Environments;
 
@@ -23,10 +23,10 @@ namespace Jint.Native.Function
 
             // The initial value of Function.prototype is the standard built-in Function prototype object
             obj.PrototypeObject = FunctionPrototype.CreatePrototypeObject(engine);
-            
-            // The value of the [[Prototype]] internal property of the Function constructor is the standard built-in Function prototype object 
+
+            // The value of the [[Prototype]] internal property of the Function constructor is the standard built-in Function prototype object
             obj.Prototype = obj.PrototypeObject;
-            
+
             obj.FastAddProperty("prototype", obj.PrototypeObject, false, false, false);
 
             obj.FastAddProperty("length", 1, false, false, false);
@@ -80,14 +80,14 @@ namespace Jint.Native.Function
 
                 body = TypeConverter.ToString(arguments[argCount-1]);
             }
-            
+
             var parameters = this.ParseArgumentNames(p);
-            var parser = new JavaScriptParser();
-            FunctionExpression function;
+            IFunction function;
             try
             {
                 var functionExpression = "function(" + p + ") { " + body + "}";
-                function = parser.ParseFunctionExpression(functionExpression); 
+                var parser = new JavaScriptParser(body);
+                function = parser.ParseProgram().Body.First().As<IFunction>();
             }
             catch (ParserException)
             {
@@ -97,28 +97,17 @@ namespace Jint.Native.Function
             // todo: check if there is not a way to use the FunctionExpression directly instead of creating a FunctionDeclaration
             var functionObject = new ScriptFunctionInstance(
                 Engine,
-                new FunctionDeclaration
-                    {
-                        Type = SyntaxNodes.FunctionDeclaration,
-                        Body = new BlockStatement
-                            {
-                                Type = SyntaxNodes.BlockStatement,
-                                Body = new [] { function.Body }
-                            },
-                        Parameters = parameters.Select(x => new Identifier
-                            {
-                                Type = SyntaxNodes.Identifier,
-                                Name = x
-                            }).ToArray(),
-                        FunctionDeclarations = function.FunctionDeclarations,
-                        VariableDeclarations = function.VariableDeclarations
-                    },  
+                new FunctionDeclaration(
+                    new Identifier(Guid.NewGuid().ToString("n")),
+                    parameters.Select(x => new Identifier(x)).ToArray(),
+                    function.Body,
+                    false),
                 LexicalEnvironment.NewDeclarativeEnvironment(Engine, Engine.ExecutionContext.LexicalEnvironment),
-                function.Strict
+                function.IsStrict()
                 ) { Extensible = true };
 
             return functionObject;
-            
+
         }
 
         /// <summary>
@@ -132,7 +121,7 @@ namespace Jint.Native.Function
                 Engine,
                 functionDeclaration,
                 LexicalEnvironment.NewDeclarativeEnvironment(Engine, Engine.ExecutionContext.LexicalEnvironment),
-                functionDeclaration.Strict
+                functionDeclaration.IsStrict()
                 ) { Extensible = true };
 
             return functionObject;

+ 8 - 8
Jint/Native/Function/ScriptFunctionInstance.cs

@@ -1,6 +1,6 @@
 using System.Linq;
+using Esprima.Ast;
 using Jint.Native.Object;
-using Jint.Parser;
 using Jint.Runtime;
 using Jint.Runtime.Descriptors;
 using Jint.Runtime.Environments;
@@ -8,11 +8,11 @@ using Jint.Runtime.Environments;
 namespace Jint.Native.Function
 {
     /// <summary>
-    /// 
+    ///
     /// </summary>
     public sealed class ScriptFunctionInstance : FunctionInstance, IConstructor
     {
-        private readonly IFunctionDeclaration _functionDeclaration;
+        private readonly IFunction _functionDeclaration;
 
         /// <summary>
         /// http://www.ecma-international.org/ecma-262/5.1/#sec-13.2
@@ -21,8 +21,8 @@ namespace Jint.Native.Function
         /// <param name="functionDeclaration"></param>
         /// <param name="scope"></param>
         /// <param name="strict"></param>
-        public ScriptFunctionInstance(Engine engine, IFunctionDeclaration functionDeclaration, LexicalEnvironment scope, bool strict)
-            : base(engine, functionDeclaration.Parameters.Select(x => x.Name).ToArray(), scope, strict)
+        public ScriptFunctionInstance(Engine engine, IFunction functionDeclaration, LexicalEnvironment scope, bool strict)
+            : base(engine, functionDeclaration.Params.Select(x => x.As<Identifier>().Name).ToArray(), scope, strict)
         {
             _functionDeclaration = functionDeclaration;
 
@@ -85,8 +85,8 @@ namespace Jint.Native.Function
                 {
                     Engine.DeclarationBindingInstantiation(
                         DeclarationBindingType.FunctionCode,
-                        _functionDeclaration.FunctionDeclarations, 
-                        _functionDeclaration.VariableDeclarations, 
+                        _functionDeclaration.Body.Body.OfType<FunctionDeclaration>(),
+                        _functionDeclaration.Body.Body.OfType<VariableDeclaration>(),
                         this,
                         arguments);
 
@@ -130,7 +130,7 @@ namespace Jint.Native.Function
             {
                 return result;
             }
-            
+
             return obj;
         }
 

+ 7 - 5
Jint/Native/Json/JsonInstance.cs

@@ -1,4 +1,5 @@
-using Jint.Native.Object;
+using Esprima;
+using Jint.Native.Object;
 using Jint.Runtime;
 using Jint.Runtime.Interop;
 
@@ -38,15 +39,16 @@ namespace Jint.Native.Json
 
         public JsValue Parse(JsValue thisObject, JsValue[] arguments)
         {
-            var parser = new JsonParser(_engine);
+            var parser = new JavaScriptParser(TypeConverter.ToString(arguments[0]));
+            // TODO: Esprima, convert object to JsonInstance
 
-            return parser.Parse(TypeConverter.ToString(arguments[0]));
+            return JsValue.Undefined;
         }
 
         public JsValue Stringify(JsValue thisObject, JsValue[] arguments)
         {
-            JsValue 
-                value = Undefined.Instance, 
+            JsValue
+                value = Undefined.Instance,
                 replacer = Undefined.Instance,
                 space = Undefined.Instance;
 

+ 0 - 914
Jint/Native/Json/JsonParser.cs

@@ -1,914 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using Jint.Native.Object;
-using Jint.Parser;
-using Jint.Parser.Ast;
-using Jint.Runtime;
-
-namespace Jint.Native.Json
-{
-    public class JsonParser
-    {
-        private readonly Engine _engine;
-
-        public JsonParser(Engine engine)
-        {
-            _engine = engine;
-        }
-
-        private Extra _extra;
-
-        private int _index; // position in the stream
-        private int _length; // length of the stream
-        private int _lineNumber;
-        private int _lineStart;
-        private Location _location;
-        private Token _lookahead;
-        private string _source;
-
-        private State _state;
-
-        private static bool IsDecimalDigit(char ch)
-        {
-            return (ch >= '0' && ch <= '9');
-        }
-
-        private static bool IsHexDigit(char ch)
-        {
-            return
-                ch >= '0' && ch <= '9' ||
-                ch >= 'a' && ch <= 'f' ||
-                ch >= 'A' && ch <= 'F'
-                ;
-        }
-
-        private static bool IsOctalDigit(char ch)
-        {
-            return ch >= '0' && ch <= '7';
-        }
-
-        private static bool IsWhiteSpace(char ch)
-        {
-            return (ch == ' ')  ||
-                   (ch == '\t') ||
-                   (ch == '\n') ||
-                   (ch == '\r');
-        }
-
-        private static bool IsLineTerminator(char ch)
-        {
-            return (ch == 10) || (ch == 13) || (ch == 0x2028) || (ch == 0x2029);
-        }
-
-        private static bool IsNullChar(char ch)
-        {
-            return ch == 'n'
-                || ch == 'u'
-                || ch == 'l'
-                || ch == 'l'
-                ;
-        }
-
-        private static bool IsTrueOrFalseChar(char ch)
-        {
-            return ch == 't'
-                || ch == 'r'
-                || ch == 'u'
-                || ch == 'e'
-                || ch == 'f'
-                || ch == 'a'
-                || ch == 'l'
-                || ch == 's'
-                ;
-        }
-
-        private char ScanHexEscape(char prefix)
-        {
-            int code = char.MinValue;
-
-            int len = (prefix == 'u') ? 4 : 2;
-            for (int i = 0; i < len; ++i)
-            {
-                if (_index < _length && IsHexDigit(_source.CharCodeAt(_index)))
-                {
-                    char ch = _source.CharCodeAt(_index++);
-                    code = code * 16 + "0123456789abcdef".IndexOf(ch.ToString(), StringComparison.OrdinalIgnoreCase);
-                }
-                else
-                {
-                    throw new JavaScriptException(_engine.SyntaxError, string.Format("Expected hexadecimal digit:{0}", _source));
-                }
-            }
-            return (char)code;
-        }
-
-        private void SkipWhiteSpace()
-        {
-            while (_index < _length)
-            {
-                char ch = _source.CharCodeAt(_index);
-
-                if (IsWhiteSpace(ch))
-                {
-                    ++_index;
-                }
-                else
-                {
-                    break;
-                }
-            }
-        }
-
-        private Token ScanPunctuator()
-        {
-            int start = _index;
-            char code = _source.CharCodeAt(_index);
-
-            switch ((int) code)
-            {
-                    // Check for most common single-character punctuators.
-                case 46: // . dot
-                case 40: // ( open bracket
-                case 41: // ) close bracket
-                case 59: // ; semicolon
-                case 44: // , comma
-                case 123: // { open curly brace
-                case 125: // } close curly brace
-                case 91: // [
-                case 93: // ]
-                case 58: // :
-                case 63: // ?
-                case 126: // ~
-                    ++_index;
-
-                    return new Token
-                        {
-                            Type = Tokens.Punctuator,
-                            Value = code.ToString(),
-                            LineNumber = _lineNumber,
-                            LineStart = _lineStart,
-                            Range = new[] {start, _index}
-                        };
-            }
-            throw new JavaScriptException(_engine.SyntaxError, string.Format(Messages.UnexpectedToken, code));
-        }
-
-        private Token ScanNumericLiteral()
-        {
-            char ch = _source.CharCodeAt(_index);
-
-            int start = _index;
-            string number = "";
-            
-            // Number start with a -
-            if (ch == '-')
-            {
-                number += _source.CharCodeAt(_index++).ToString();
-                ch = _source.CharCodeAt(_index);
-            }
-
-            if (ch != '.')
-            {
-                number += _source.CharCodeAt(_index++).ToString();
-                ch = _source.CharCodeAt(_index);
-
-                // Hex number starts with '0x'.
-                // Octal number starts with '0'.
-                if (number == "0")
-                {
-                    // decimal number starts with '0' such as '09' is illegal.
-                    if (ch > 0 && IsDecimalDigit(ch))
-                    {
-                        throw new Exception(Messages.UnexpectedToken);
-                    }
-                }
-
-                while (IsDecimalDigit(_source.CharCodeAt(_index)))
-                {
-                    number += _source.CharCodeAt(_index++).ToString();
-                }
-                ch = _source.CharCodeAt(_index);
-            }
-
-            if (ch == '.')
-            {
-                number += _source.CharCodeAt(_index++).ToString();
-                while (IsDecimalDigit(_source.CharCodeAt(_index)))
-                {
-                    number += _source.CharCodeAt(_index++).ToString();
-                }
-                ch = _source.CharCodeAt(_index);
-            }
-
-            if (ch == 'e' || ch == 'E')
-            {
-                number += _source.CharCodeAt(_index++).ToString();
-
-                ch = _source.CharCodeAt(_index);
-                if (ch == '+' || ch == '-')
-                {
-                    number += _source.CharCodeAt(_index++).ToString();
-                }
-                if (IsDecimalDigit(_source.CharCodeAt(_index)))
-                {
-                    while (IsDecimalDigit(_source.CharCodeAt(_index)))
-                    {
-                        number += _source.CharCodeAt(_index++).ToString();
-                    }
-                }
-                else
-                {
-                    throw new Exception(Messages.UnexpectedToken);
-                }
-            }
-
-            return new Token
-                {
-                    Type = Tokens.Number,
-                    Value = Double.Parse(number, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent, CultureInfo.InvariantCulture),
-                    LineNumber = _lineNumber,
-                    LineStart = _lineStart,
-                    Range = new[] {start, _index}
-                };
-        }
-
-        private Token ScanBooleanLiteral()
-        {
-            int start = _index;
-            string s = "";
-            
-            while (IsTrueOrFalseChar(_source.CharCodeAt(_index)))
-            {
-                s += _source.CharCodeAt(_index++).ToString();
-            }
-            
-            if (s == "true" || s == "false")
-            {
-                return new Token
-                {
-                    Type = Tokens.BooleanLiteral,
-                    Value = s == "true",
-                    LineNumber = _lineNumber,
-                    LineStart = _lineStart,
-                    Range = new[] { start, _index }
-                };
-            }
-            else 
-            {
-                throw new JavaScriptException(_engine.SyntaxError, string.Format(Messages.UnexpectedToken, s));
-            }
-        }
-
-        private Token ScanNullLiteral()
-        {
-            int start = _index;
-            string s = "";
-            
-            while (IsNullChar(_source.CharCodeAt(_index)))
-            {
-                s += _source.CharCodeAt(_index++).ToString();
-            }
-
-            if (s == Null.Text)
-            {
-                return new Token
-                {
-                    Type = Tokens.NullLiteral,
-                    Value = Null.Instance,
-                    LineNumber = _lineNumber,
-                    LineStart = _lineStart,
-                    Range = new[] { start, _index }
-                };
-            }
-            else
-            {
-                throw new JavaScriptException(_engine.SyntaxError, string.Format(Messages.UnexpectedToken, s));
-            }
-        }
-
-        private Token ScanStringLiteral()
-        {
-            string str = "";
-
-            char quote = _source.CharCodeAt(_index);
-
-            int start = _index;
-            ++_index;
-
-            while (_index < _length)
-            {
-                char ch = _source.CharCodeAt(_index++);
-
-                if (ch == quote)
-                {
-                    quote = char.MinValue;
-                    break;
-                }
-
-                if (ch <= 31)
-                {
-                    throw new JavaScriptException(_engine.SyntaxError, string.Format("Invalid character '{0}', position:{1}, string:{2}", ch, _index, _source));
-                }
-                
-                if (ch == '\\')
-                {
-                    ch = _source.CharCodeAt(_index++);
-
-                    if (ch > 0 || !IsLineTerminator(ch))
-                    {
-                        switch (ch)
-                        {
-                            case 'n':
-                                str += '\n';
-                                break;
-                            case 'r':
-                                str += '\r';
-                                break;
-                            case 't':
-                                str += '\t';
-                                break;
-                            case 'u':
-                            case 'x':
-                                int restore = _index;
-                                char unescaped = ScanHexEscape(ch);
-                                if (unescaped > 0)
-                                {
-                                    str += unescaped.ToString();
-                                }
-                                else
-                                {
-                                    _index = restore;
-                                    str += ch.ToString();
-                                }
-                                break;
-                            case 'b':
-                                str += "\b";
-                                break;
-                            case 'f':
-                                str += "\f";
-                                break;
-                            case 'v':
-                                str += "\x0B";
-                                break;
-
-                            default:
-                                if (IsOctalDigit(ch))
-                                {
-                                    int code = "01234567".IndexOf(ch);
-
-                                    if (_index < _length && IsOctalDigit(_source.CharCodeAt(_index)))
-                                    {
-                                        code = code * 8 + "01234567".IndexOf(_source.CharCodeAt(_index++));
-
-                                        // 3 digits are only allowed when string starts
-                                        // with 0, 1, 2, 3
-                                        if ("0123".IndexOf(ch) >= 0 &&
-                                            _index < _length &&
-                                            IsOctalDigit(_source.CharCodeAt(_index)))
-                                        {
-                                            code = code * 8 + "01234567".IndexOf(_source.CharCodeAt(_index++));
-                                        }
-                                    }
-                                    str += ((char)code).ToString();
-                                }
-                                else
-                                {
-                                    str += ch.ToString();
-                                }
-                                break;
-                        }
-                    }
-                    else
-                    {
-                        ++_lineNumber;
-                        if (ch == '\r' && _source.CharCodeAt(_index) == '\n')
-                        {
-                            ++_index;
-                        }
-                    }
-                }
-                else if (IsLineTerminator(ch))
-                {
-                    break;
-                }
-                else
-                {
-                    str += ch.ToString();
-                }
-            }
-
-            if (quote != 0)
-            {
-                throw new JavaScriptException(_engine.SyntaxError, string.Format(Messages.UnexpectedToken, _source));
-            }
-            
-            return new Token
-                {
-                    Type = Tokens.String,
-                    Value = str,
-                    LineNumber = _lineNumber,
-                    LineStart = _lineStart,
-                    Range = new[] {start, _index}
-                };
-        }
-
-        private Token Advance()
-        {
-            SkipWhiteSpace();
-
-            if (_index >= _length)
-            {
-                return new Token
-                    {
-                        Type = Tokens.EOF,
-                        LineNumber = _lineNumber,
-                        LineStart = _lineStart,
-                        Range = new[] {_index, _index}
-                    };
-            }
-
-            char ch = _source.CharCodeAt(_index);
-
-            // Very common: ( and ) and ;
-            if (ch == 40 || ch == 41 || ch == 58)
-            {
-                return ScanPunctuator();
-            }
-
-            // String literal starts with double quote (#34).
-            // Single quote (#39) are not allowed in JSON.
-            if (ch == 34) 
-            {
-                return ScanStringLiteral();
-            }
-            
-            // Dot (.) char #46 can also start a floating-point number, hence the need
-            // to check the next character.
-            if (ch == 46)
-            {
-                if (IsDecimalDigit(_source.CharCodeAt(_index + 1)))
-                {
-                    return ScanNumericLiteral();
-                }
-                return ScanPunctuator();
-            }
-
-            if (ch == '-') // Negative Number
-            {
-                if (IsDecimalDigit(_source.CharCodeAt(_index + 1)))
-                {
-                    return ScanNumericLiteral();
-                }
-                return ScanPunctuator();
-            }
-
-            if (IsDecimalDigit(ch))
-            {
-                return ScanNumericLiteral();
-            }
-
-            if (ch == 't' || ch == 'f')
-            {
-                return ScanBooleanLiteral();
-            }
-
-            if (ch == 'n')
-            {
-                return ScanNullLiteral();
-            }
-
-            return ScanPunctuator();
-        }
-
-        private Token CollectToken()
-        {
-            _location = new Location
-                {
-                    Start = new Position
-                        {
-                            Line = _lineNumber,
-                            Column = _index - _lineStart
-                        }
-                };
-
-            Token token = Advance();
-            _location.End = new Position
-                {
-                    Line = _lineNumber,
-                    Column = _index - _lineStart
-                };
-
-            if (token.Type != Tokens.EOF)
-            {
-                var range = new[] {token.Range[0], token.Range[1]};
-                string value = _source.Slice(token.Range[0], token.Range[1]);
-                _extra.Tokens.Add(new Token
-                    {
-                        Type = token.Type,
-                        Value = value,
-                        Range = range,
-                    });
-            }
-
-            return token;
-        }
-
-        private Token Lex()
-        {
-            Token token = _lookahead;
-            _index = token.Range[1];
-            _lineNumber = token.LineNumber.HasValue ? token.LineNumber.Value : 0;
-            _lineStart = token.LineStart;
-
-            _lookahead = (_extra.Tokens != null) ? CollectToken() : Advance();
-
-            _index = token.Range[1];
-            _lineNumber = token.LineNumber.HasValue ? token.LineNumber.Value : 0;
-            _lineStart = token.LineStart;
-
-            return token;
-        }
-
-        private void Peek()
-        {
-            int pos = _index;
-            int line = _lineNumber;
-            int start = _lineStart;
-            _lookahead = (_extra.Tokens != null) ? CollectToken() : Advance();
-            _index = pos;
-            _lineNumber = line;
-            _lineStart = start;
-        }
-
-        private void MarkStart()
-        {
-            if (_extra.Loc.HasValue)
-            {
-                _state.MarkerStack.Push(_index - _lineStart);
-                _state.MarkerStack.Push(_lineNumber);
-            }
-            if (_extra.Range != null)
-            {
-                _state.MarkerStack.Push(_index);
-            }
-        }
-
-        private T MarkEnd<T>(T node) where T : SyntaxNode
-        {
-            if (_extra.Range != null)
-            {
-                node.Range = new[] {_state.MarkerStack.Pop(), _index};
-            }
-            if (_extra.Loc.HasValue)
-            {
-                node.Location = new Location
-                    {
-                        Start = new Position
-                            {
-                                Line = _state.MarkerStack.Pop(),
-                                Column = _state.MarkerStack.Pop()
-                            },
-                        End = new Position
-                            {
-                                Line = _lineNumber,
-                                Column = _index - _lineStart
-                            }
-                    };
-                PostProcess(node);
-            }
-            return node;
-        }
-
-        public T MarkEndIf<T>(T node) where T : SyntaxNode
-        {
-            if (node.Range != null || node.Location != null)
-            {
-                if (_extra.Loc.HasValue)
-                {
-                    _state.MarkerStack.Pop();
-                    _state.MarkerStack.Pop();
-                }
-                if (_extra.Range != null)
-                {
-                    _state.MarkerStack.Pop();
-                }
-            }
-            else
-            {
-                MarkEnd(node);
-            }
-            return node;
-        }
-
-        public SyntaxNode PostProcess(SyntaxNode node)
-        {
-            if (_extra.Source != null)
-            {
-                node.Location.Source = _extra.Source;
-            }
-            return node;
-        }
-
-        public ObjectInstance CreateArrayInstance(IEnumerable<JsValue> values)
-        {
-            var jsArray = _engine.Array.Construct(Arguments.Empty);
-            _engine.Array.PrototypeObject.Push(jsArray, values.ToArray());
-            return jsArray;            
-        }
-
-        // Throw an exception
-
-        private void ThrowError(Token token, string messageFormat, params object[] arguments)
-        {
-            ParserException exception;
-            string msg = System.String.Format(messageFormat, arguments);
-
-            if (token.LineNumber.HasValue)
-            {
-                exception = new ParserException("Line " + token.LineNumber + ": " + msg)
-                    {
-                        Index = token.Range[0],
-                        LineNumber = token.LineNumber.Value,
-                        Column = token.Range[0] - _lineStart + 1
-                    };
-            }
-            else
-            {
-                exception = new ParserException("Line " + _lineNumber + ": " + msg)
-                    {
-                        Index = _index,
-                        LineNumber = _lineNumber,
-                        Column = _index - _lineStart + 1
-                    };
-            }
-
-            exception.Description = msg;
-            throw exception;
-        }
-
-        // Throw an exception because of the token.
-
-        private void ThrowUnexpected(Token token)
-        {
-            if (token.Type == Tokens.EOF)
-            {
-                ThrowError(token, Messages.UnexpectedEOS);
-            }
-
-            if (token.Type == Tokens.Number)
-            {
-                ThrowError(token, Messages.UnexpectedNumber);
-            }
-
-            if (token.Type == Tokens.String)
-            {
-                ThrowError(token, Messages.UnexpectedString);
-            }
-
-            // BooleanLiteral, NullLiteral, or Punctuator.
-            ThrowError(token, Messages.UnexpectedToken, token.Value as string);
-        }
-
-        // Expect the next token to match the specified punctuator.
-        // If not, an exception will be thrown.
-
-        private void Expect(string value)
-        {
-            Token token = Lex();
-            if (token.Type != Tokens.Punctuator || !value.Equals(token.Value))
-            {
-                ThrowUnexpected(token);
-            }
-        }
-
-        // Return true if the next token matches the specified punctuator.
-
-        private bool Match(string value)
-        {
-            return _lookahead.Type == Tokens.Punctuator && value.Equals(_lookahead.Value);
-        }
-        
-        private ObjectInstance ParseJsonArray()
-        {
-            var elements = new List<JsValue>();
-
-            Expect("[");
-
-            while (!Match("]"))
-            {
-                if (Match(","))
-                {
-                    Lex();
-                    elements.Add(Null.Instance);
-                }
-                else
-                {
-                    elements.Add(ParseJsonValue());
-
-                    if (!Match("]"))
-                    {
-                        Expect(",");
-                    }
-                }
-            }
-
-            Expect("]");
-
-            return CreateArrayInstance(elements);
-        }
-
-        public ObjectInstance ParseJsonObject()
-        {
-            Expect("{");
-
-            var obj = _engine.Object.Construct(Arguments.Empty);
-
-            while (!Match("}"))
-            {
-                Tokens type = _lookahead.Type;
-                if (type != Tokens.String)
-                {
-                    ThrowUnexpected(Lex());
-                }
-
-                var name = Lex().Value.ToString();
-                if (PropertyNameContainsInvalidChar0To31(name))
-                {
-                    throw new JavaScriptException(_engine.SyntaxError, string.Format("Invalid character in property name '{0}'", name));
-                }
-
-                Expect(":");
-                var value = ParseJsonValue();
-
-                obj.FastAddProperty(name, value, true, true, true);
-                
-                if (!Match("}"))
-                {
-                    Expect(",");
-                }
-            }
-
-            Expect("}");
-
-            return obj;
-        }
-
-        private bool PropertyNameContainsInvalidChar0To31(string s)
-        {    
-            const int max = 31;
-
-            for (var i = 0; i < s.Length; i++)
-            {
-                var val = (int)s[i];
-                if (val <= max)
-                    return true;
-            }
-            return false;
-        }
-        
-        /// <summary>
-        /// Optimization.
-        /// By calling Lex().Value for each type, we parse the token twice.
-        /// It was already parsed by the peek() method.
-        /// _lookahead.Value already contain the value.
-        /// </summary>
-        /// <returns></returns>
-        private JsValue ParseJsonValue()
-        {
-            Tokens type = _lookahead.Type;
-            MarkStart();
-
-            switch (type)
-            {
-                case Tokens.NullLiteral:
-                    var v = Lex().Value;
-                    return Null.Instance;
-                case Tokens.BooleanLiteral:
-                    return new JsValue((bool)Lex().Value);
-                case Tokens.String:
-                    return new JsValue((string)Lex().Value);
-                case Tokens.Number:
-                    return new JsValue((double)Lex().Value);
-            }
-            
-            if (Match("["))
-            {
-                return ParseJsonArray();
-            }
-            
-            if (Match("{"))
-            {
-                return ParseJsonObject();
-            }
-
-            ThrowUnexpected(Lex());
-
-            // can't be reached
-            return Null.Instance; 
-        }
-
-        public JsValue Parse(string code)
-        {
-            return Parse(code, null);
-        }
-
-        public JsValue Parse(string code, ParserOptions options)
-        {
-            _source = code;
-            _index = 0;
-            _lineNumber = (_source.Length > 0) ? 1 : 0;
-            _lineStart = 0;
-            _length = _source.Length;
-            _lookahead = null;
-            _state = new State
-                {
-                    AllowIn = true,
-                    LabelSet = new HashSet<string>(),
-                    InFunctionBody = false,
-                    InIteration = false,
-                    InSwitch = false,
-                    LastCommentStart = -1,
-                    MarkerStack = new Stack<int>()
-                };
-
-            _extra = new Extra
-                {
-                    Range = new int[0], 
-                    Loc = 0,
-
-                };
-
-            if (options != null)
-            {
-                if (!System.String.IsNullOrEmpty(options.Source))
-                {
-                    _extra.Source = options.Source;
-                }
-
-                if (options.Tokens)
-                {
-                    _extra.Tokens = new List<Token>();
-                }
-
-            }
-
-            try
-            {
-                MarkStart();
-                Peek();
-                JsValue jsv = ParseJsonValue();
-
-                Peek();
-                Tokens type = _lookahead.Type;
-                object value = _lookahead.Value;                
-                if(_lookahead.Type != Tokens.EOF)
-                {
-                    throw new JavaScriptException(_engine.SyntaxError, string.Format("Unexpected {0} {1}", _lookahead.Type, _lookahead.Value));
-                }
-                return jsv;
-            }
-            finally
-            {
-                _extra = new Extra();
-            }
-        }
-
-        private class Extra
-        {
-            public int? Loc;
-            public int[] Range;
-            public string Source;
-
-            public List<Token> Tokens;
-        }
-
-        private enum Tokens
-        {
-            NullLiteral,
-            BooleanLiteral,
-            String,
-            Number,
-            Punctuator,
-            EOF,
-        };
-
-        class Token
-        {
-            public Tokens Type;
-            public object Value;
-            public int[] Range;
-            public int? LineNumber;
-            public int LineStart;
-        }
-
-        static class Messages
-        {
-            public const string UnexpectedToken = "Unexpected token {0}";
-            public const string UnexpectedNumber = "Unexpected number";
-            public const string UnexpectedString = "Unexpected string";
-            public const string UnexpectedEOS = "Unexpected end of input";
-        };
-    }
-}

+ 0 - 9
Jint/Parser/Ast/ArrayExpression.cs

@@ -1,9 +0,0 @@
-using System.Collections.Generic;
-
-namespace Jint.Parser.Ast
-{
-    public class ArrayExpression : Expression
-    {
-        public IEnumerable<Expression> Elements;
-    }
-}

+ 0 - 61
Jint/Parser/Ast/AssignmentExpression.cs

@@ -1,61 +0,0 @@
-using System;
-
-namespace Jint.Parser.Ast
-{
-    public enum AssignmentOperator
-    {
-        Assign,
-        PlusAssign,
-        MinusAssign,
-        TimesAssign,
-        DivideAssign,
-        ModuloAssign,
-        BitwiseAndAssign,
-        BitwiseOrAssign,
-        BitwiseXOrAssign,
-        LeftShiftAssign,
-        RightShiftAssign,
-        UnsignedRightShiftAssign,
-    }
-
-    public class AssignmentExpression : Expression
-    {
-        public AssignmentOperator Operator;
-        public Expression Left;
-        public Expression Right;
-
-        public static AssignmentOperator ParseAssignmentOperator(string op)
-        {
-            switch (op)
-            {
-                case "=":
-                    return AssignmentOperator.Assign;
-                case "+=":
-                    return AssignmentOperator.PlusAssign;
-                case "-=":
-                    return AssignmentOperator.MinusAssign;
-                case "*=":
-                    return AssignmentOperator.TimesAssign;
-                case "/=":
-                    return AssignmentOperator.DivideAssign;
-                case "%=":
-                    return AssignmentOperator.ModuloAssign;
-                case "&=":
-                    return AssignmentOperator.BitwiseAndAssign;
-                case "|=":
-                    return AssignmentOperator.BitwiseOrAssign;
-                case "^=":
-                    return AssignmentOperator.BitwiseXOrAssign;
-                case "<<=":
-                    return AssignmentOperator.LeftShiftAssign;
-                case ">>=":
-                    return AssignmentOperator.RightShiftAssign;
-                case ">>>=":
-                    return AssignmentOperator.UnsignedRightShiftAssign;
-
-                default:
-                    throw new ArgumentOutOfRangeException("Invalid assignment operator: " + op);
-            }
-        }
-    }
-}

+ 0 - 88
Jint/Parser/Ast/BinaryExpression.cs

@@ -1,88 +0,0 @@
-using System;
-
-namespace Jint.Parser.Ast
-{
-    public enum BinaryOperator
-    {
-        Plus,
-        Minus,
-        Times,
-        Divide,
-        Modulo,
-        Equal,
-        NotEqual,
-        Greater,
-        GreaterOrEqual,
-        Less,
-        LessOrEqual,
-        StrictlyEqual,
-        StricltyNotEqual,
-        BitwiseAnd,
-        BitwiseOr,
-        BitwiseXOr,
-        LeftShift,
-        RightShift,
-        UnsignedRightShift,
-        InstanceOf,
-        In,
-    }
-
-    public class BinaryExpression : Expression
-    {
-        public BinaryOperator Operator;
-        public Expression Left;
-        public Expression Right;
-
-        public static BinaryOperator ParseBinaryOperator(string op)
-        {
-            switch (op)
-            {
-                case "+":
-                    return BinaryOperator.Plus;
-                case "-":
-                    return BinaryOperator.Minus;
-                case "*":
-                    return BinaryOperator.Times;
-                case "/":
-                    return BinaryOperator.Divide;
-                case "%":
-                    return BinaryOperator.Modulo;
-                case "==":
-                    return BinaryOperator.Equal;
-                case "!=":
-                    return BinaryOperator.NotEqual;
-                case ">":
-                    return BinaryOperator.Greater;
-                case ">=":
-                    return BinaryOperator.GreaterOrEqual;
-                case "<":
-                    return BinaryOperator.Less;
-                case "<=":
-                    return BinaryOperator.LessOrEqual;
-                case "===":
-                    return BinaryOperator.StrictlyEqual;
-                case "!==":
-                    return BinaryOperator.StricltyNotEqual;
-                case "&":
-                    return BinaryOperator.BitwiseAnd;
-                case "|":
-                    return BinaryOperator.BitwiseOr;
-                case "^":
-                    return BinaryOperator.BitwiseXOr;
-                case "<<":
-                    return BinaryOperator.LeftShift;
-                case ">>":
-                    return BinaryOperator.RightShift;
-                case ">>>":
-                    return BinaryOperator.UnsignedRightShift;
-                case "instanceof":
-                    return BinaryOperator.InstanceOf;
-                case "in":
-                    return BinaryOperator.In;
-
-                default: 
-                    throw new ArgumentOutOfRangeException("Invalid binary operator: " + op);
-            }
-        }
-    }
-}

+ 0 - 9
Jint/Parser/Ast/BlockStatement.cs

@@ -1,9 +0,0 @@
-using System.Collections.Generic;
-
-namespace Jint.Parser.Ast
-{
-    public class BlockStatement : Statement
-    {
-        public IEnumerable<Statement> Body;
-    }
-}

+ 0 - 7
Jint/Parser/Ast/BreakStatement.cs

@@ -1,7 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class BreakStatement : Statement
-    {
-        public Identifier Label;
-    }
-}

+ 0 - 15
Jint/Parser/Ast/CallExpression.cs

@@ -1,15 +0,0 @@
-using Jint.Native;
-using System.Collections.Generic;
-
-namespace Jint.Parser.Ast
-{
-    public class CallExpression : Expression
-    {
-        public Expression Callee;
-        public IList<Expression> Arguments;
-
-        public bool Cached;
-        public bool CanBeCached = true;
-        public JsValue[] CachedArguments;
-    }
-}

+ 0 - 8
Jint/Parser/Ast/CatchClause.cs

@@ -1,8 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class CatchClause : Statement
-    {
-        public Identifier Param;
-        public BlockStatement Body;
-    }
-}

+ 0 - 9
Jint/Parser/Ast/ConditionalExpression.cs

@@ -1,9 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class ConditionalExpression : Expression
-    {
-        public Expression Test;
-        public Expression Consequent;
-        public Expression Alternate;
-    }
-}

+ 0 - 7
Jint/Parser/Ast/ContinueStatement.cs

@@ -1,7 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class ContinueStatement : Statement
-    {
-        public Identifier Label;
-    }
-}

+ 0 - 7
Jint/Parser/Ast/DebuggerStatement.cs

@@ -1,7 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class DebuggerStatement: Statement
-    {
-        
-    }
-}

+ 0 - 9
Jint/Parser/Ast/DoWhileStatement.cs

@@ -1,9 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class DoWhileStatement  : Statement
-    {
-        public Statement Body;
-        public Expression Test;
-
-    }
-}

+ 0 - 7
Jint/Parser/Ast/EmptyStatement.cs

@@ -1,7 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class EmptyStatement : Statement
-    {
-        
-    }
-}

+ 0 - 8
Jint/Parser/Ast/Expression.cs

@@ -1,8 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class Expression : SyntaxNode
-    {
-        // an expression represents an actual value
-        // foo() is an expression, a switch/case is a statement
-    }
-}

+ 0 - 7
Jint/Parser/Ast/ExpressionStatement.cs

@@ -1,7 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class ExpressionStatement : Statement
-    {
-        public Expression Expression;
-    }
-}

+ 0 - 10
Jint/Parser/Ast/ForInStatement.cs

@@ -1,10 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class ForInStatement : Statement
-    {
-        public SyntaxNode Left;
-        public Expression Right;
-        public Statement Body;
-        public bool Each;
-    }
-}

+ 0 - 11
Jint/Parser/Ast/ForStatement.cs

@@ -1,11 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class ForStatement : Statement
-    {
-        // can be a Statement (var i) or an Expression (i=0)
-        public SyntaxNode Init;
-        public Expression Test;
-        public Expression Update;
-        public Statement Body;
-    }
-}

+ 0 - 30
Jint/Parser/Ast/FunctionDeclaration.cs

@@ -1,30 +0,0 @@
-using System.Collections.Generic;
-
-namespace Jint.Parser.Ast
-{
-    public class FunctionDeclaration : Statement, IFunctionDeclaration
-    {
-        public FunctionDeclaration()
-        {
-            VariableDeclarations = new List<VariableDeclaration>();
-        }
-
-        public Identifier Id { get; set; }
-        public IEnumerable<Identifier> Parameters { get; set; }
-        public Statement Body { get; set; }
-        public bool Strict { get; set; }
-
-        public IList<VariableDeclaration> VariableDeclarations { get; set; }
-
-        #region ECMA6
-        
-        public IEnumerable<Expression> Defaults;
-        public SyntaxNode Rest;
-        public bool Generator;
-        public bool Expression;
-        
-        #endregion
-
-        public IList<FunctionDeclaration> FunctionDeclarations { get; set; }
-    }
-}

+ 0 - 28
Jint/Parser/Ast/FunctionExpression.cs

@@ -1,28 +0,0 @@
-using System.Collections.Generic;
-
-namespace Jint.Parser.Ast
-{
-    public class FunctionExpression : Expression, IFunctionDeclaration
-    {
-        public FunctionExpression()
-        {
-            VariableDeclarations = new List<VariableDeclaration>();
-        }
-
-        public Identifier Id { get; set; }
-        public IEnumerable<Identifier> Parameters { get; set; }
-        public Statement Body { get; set; }
-        public bool Strict { get; set; }
-
-        public IList<VariableDeclaration> VariableDeclarations { get; set; }
-        public IList<FunctionDeclaration> FunctionDeclarations { get; set; }
-
-        #region ECMA6
-        public IEnumerable<Expression> Defaults;
-        public SyntaxNode Rest;
-        public bool Generator;
-        public bool Expression;
-        #endregion
-
-    }
-}

+ 0 - 10
Jint/Parser/Ast/IPropertyKeyExpression.cs

@@ -1,10 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    /// <summary>
-    /// Reprensents an expression which can be a key of a Property
-    /// </summary>
-    public interface IPropertyKeyExpression
-    {
-        string GetKey();
-    }
-}

+ 0 - 12
Jint/Parser/Ast/Identifier.cs

@@ -1,12 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class Identifier : Expression, IPropertyKeyExpression
-    {
-        public string Name;
-        
-        public string GetKey()
-        {
-            return Name;
-        }
-    }
-}

+ 0 - 9
Jint/Parser/Ast/IfStatement.cs

@@ -1,9 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class IfStatement : Statement
-    {
-        public Expression Test;
-        public Statement Consequent;
-        public Statement Alternate;
-    }
-}

+ 0 - 8
Jint/Parser/Ast/LabeledStatement.cs

@@ -1,8 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class LabelledStatement : Statement
-    {
-        public Identifier Label;
-        public Statement Body;
-    }
-}

+ 0 - 19
Jint/Parser/Ast/Literal.cs

@@ -1,19 +0,0 @@
-using Jint.Native;
-
-namespace Jint.Parser.Ast
-{
-    public class Literal : Expression, IPropertyKeyExpression
-    {
-        public object Value;
-        public string Raw;
-
-        public bool Cached;
-        public JsValue CachedValue; 
-
-        public string GetKey()
-        {
-            return Value.ToString();
-        }
-
-    }
-}

+ 0 - 31
Jint/Parser/Ast/LogicalExpression.cs

@@ -1,31 +0,0 @@
-using System;
-
-namespace Jint.Parser.Ast
-{
-    public enum LogicalOperator
-    {
-        LogicalAnd,
-        LogicalOr
-    }
-
-    public class LogicalExpression : Expression
-    {
-        public LogicalOperator Operator;
-        public Expression Left;
-        public Expression Right;
-        
-        public static LogicalOperator ParseLogicalOperator(string op)
-        {
-            switch (op)
-            {
-                case "&&":
-                    return LogicalOperator.LogicalAnd;
-                case "||":
-                    return LogicalOperator.LogicalOr;
-
-                default:
-                    throw new ArgumentOutOfRangeException("Invalid binary operator: " + op);
-            }
-        }
-    }
-}

+ 0 - 11
Jint/Parser/Ast/MemberExpression.cs

@@ -1,11 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class MemberExpression : Expression
-    {
-        public Expression Object;
-        public Expression Property;
-
-        // true if an indexer is used and the property to be evaluated
-        public bool Computed;
-    }
-}

+ 0 - 10
Jint/Parser/Ast/NewExpression.cs

@@ -1,10 +0,0 @@
-using System.Collections.Generic;
-
-namespace Jint.Parser.Ast
-{
-    public class NewExpression : Expression
-    {
-        public Expression Callee;
-        public IEnumerable<Expression> Arguments;
-    }
-}

+ 0 - 9
Jint/Parser/Ast/ObjectExpression.cs

@@ -1,9 +0,0 @@
-using System.Collections.Generic;
-
-namespace Jint.Parser.Ast
-{
-    public class ObjectExpression : Expression
-    {
-        public IEnumerable<Property> Properties;
-    }
-}

+ 0 - 21
Jint/Parser/Ast/Program.cs

@@ -1,21 +0,0 @@
-using System.Collections.Generic;
-
-namespace Jint.Parser.Ast
-{
-    public class Program : Statement, IVariableScope, IFunctionScope
-    {
-        public Program()
-        {
-            VariableDeclarations = new List<VariableDeclaration>();
-        }
-        public ICollection<Statement> Body;
-
-        public List<Comment> Comments;
-        public List<Token> Tokens;
-        public List<ParserException> Errors;
-        public bool Strict;
-
-        public IList<VariableDeclaration> VariableDeclarations { get; set; }
-        public IList<FunctionDeclaration> FunctionDeclarations { get; set; }
-    }
-}

+ 0 - 20
Jint/Parser/Ast/Property.cs

@@ -1,20 +0,0 @@
-using System;
-
-namespace Jint.Parser.Ast
-{
-    [Flags]
-    public enum PropertyKind
-    {
-        Data = 1,
-        Get = 2,
-        Set = 4
-    };
-
-
-    public class Property : Expression
-    {
-        public PropertyKind Kind;
-        public IPropertyKeyExpression Key;
-        public Expression Value;
-    }
-}

+ 0 - 14
Jint/Parser/Ast/RegExpLiteral.cs

@@ -1,14 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class RegExpLiteral : Expression, IPropertyKeyExpression
-    {
-        public object Value;
-        public string Raw;
-        public string Flags;
-        
-        public string GetKey()
-        {
-            return Value.ToString();
-        }
-    }
-}

+ 0 - 7
Jint/Parser/Ast/ReturnStatement.cs

@@ -1,7 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class ReturnStatement : Statement
-    {
-        public Expression Argument;
-    }
-}

+ 0 - 9
Jint/Parser/Ast/SequenceExpression.cs

@@ -1,9 +0,0 @@
-using System.Collections.Generic;
-
-namespace Jint.Parser.Ast
-{
-    public class SequenceExpression : Expression
-    {
-        public IList<Expression> Expressions;
-    }
-}

+ 0 - 7
Jint/Parser/Ast/Statement.cs

@@ -1,7 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class Statement : SyntaxNode
-    {
-        public string LabelSet;
-    }
-}

+ 0 - 10
Jint/Parser/Ast/SwitchCase.cs

@@ -1,10 +0,0 @@
-using System.Collections.Generic;
-
-namespace Jint.Parser.Ast
-{
-    public class SwitchCase : SyntaxNode
-    {
-        public Expression Test;
-        public IEnumerable<Statement> Consequent;
-    }
-}

+ 0 - 10
Jint/Parser/Ast/SwitchStatement.cs

@@ -1,10 +0,0 @@
-using System.Collections.Generic;
-
-namespace Jint.Parser.Ast
-{
-    public class SwitchStatement : Statement
-    {
-        public Expression Discriminant;
-        public IEnumerable<SwitchCase> Cases;
-    }
-}

+ 0 - 17
Jint/Parser/Ast/SyntaxNode.cs

@@ -1,17 +0,0 @@
-using System.Diagnostics;
-
-namespace Jint.Parser.Ast
-{
-    public class SyntaxNode
-    {
-        public SyntaxNodes Type;
-        public int[] Range;
-        public Location Location;
-
-        [DebuggerStepThrough]
-        public T As<T>() where T : SyntaxNode
-        {
-            return (T)this;
-        }
-    }
-}

+ 0 - 47
Jint/Parser/Ast/SyntaxNodes.cs

@@ -1,47 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public enum SyntaxNodes
-    {
-        AssignmentExpression,
-        ArrayExpression,
-        BlockStatement,
-        BinaryExpression,
-        BreakStatement,
-        CallExpression,
-        CatchClause,
-        ConditionalExpression,
-        ContinueStatement,
-        DoWhileStatement,
-        DebuggerStatement,
-        EmptyStatement,
-        ExpressionStatement,
-        ForStatement,
-        ForInStatement,
-        FunctionDeclaration,
-        FunctionExpression,
-        Identifier,
-        IfStatement,
-        Literal,
-        RegularExpressionLiteral,
-        LabeledStatement,
-        LogicalExpression,
-        MemberExpression,
-        NewExpression,
-        ObjectExpression,
-        Program,
-        Property,
-        ReturnStatement,
-        SequenceExpression,
-        SwitchStatement,
-        SwitchCase,
-        ThisExpression,
-        ThrowStatement,
-        TryStatement,
-        UnaryExpression,
-        UpdateExpression,
-        VariableDeclaration,
-        VariableDeclarator,
-        WhileStatement,
-        WithStatement
-    };
-}

+ 0 - 7
Jint/Parser/Ast/ThisExpression.cs

@@ -1,7 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class ThisExpression : Expression
-    {
-        
-    }
-}

+ 0 - 7
Jint/Parser/Ast/ThrowStatement.cs

@@ -1,7 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class ThrowStatement : Statement
-    {
-        public Expression Argument;
-    }
-}

+ 0 - 12
Jint/Parser/Ast/TryStatement.cs

@@ -1,12 +0,0 @@
-using System.Collections.Generic;
-
-namespace Jint.Parser.Ast
-{
-    public class TryStatement : Statement
-    {
-        public Statement Block;
-        public IEnumerable<Statement> GuardedHandlers;
-        public IEnumerable<CatchClause> Handlers;
-        public Statement Finalizer;
-    }
-}

+ 0 - 53
Jint/Parser/Ast/UnaryExpression.cs

@@ -1,53 +0,0 @@
-using System;
-
-namespace Jint.Parser.Ast
-{
-    public enum UnaryOperator
-    {
-        Plus,
-        Minus,
-        BitwiseNot,
-        LogicalNot,
-        Delete,
-        Void,
-        TypeOf,
-        Increment,
-        Decrement,
-    }
-
-    public class UnaryExpression : Expression
-    {
-        public UnaryOperator Operator;
-        public Expression Argument;
-        public bool Prefix;
-
-        public static UnaryOperator ParseUnaryOperator(string op)
-        {
-            switch (op)
-            {
-                case "+":
-                    return UnaryOperator.Plus;
-                case "-":
-                    return UnaryOperator.Minus;
-                case "++":
-                    return UnaryOperator.Increment;
-                case "--":
-                    return UnaryOperator.Decrement;
-                case "~":
-                    return UnaryOperator.BitwiseNot;
-                case "!":
-                    return UnaryOperator.LogicalNot;
-                case "delete":
-                    return UnaryOperator.Delete;
-                case "void":
-                    return UnaryOperator.Void;
-                case "typeof":
-                    return UnaryOperator.TypeOf;
-
-                default:
-                    throw new ArgumentOutOfRangeException("Invalid unary operator: " + op);
-
-            }
-        }
-    }
-}

+ 0 - 6
Jint/Parser/Ast/UpdateExpression.cs

@@ -1,6 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class UpdateExpression : UnaryExpression
-    {
-    }
-}

+ 0 - 10
Jint/Parser/Ast/VariableDeclaration.cs

@@ -1,10 +0,0 @@
-using System.Collections.Generic;
-
-namespace Jint.Parser.Ast
-{
-    public class VariableDeclaration : Statement
-    {
-        public IEnumerable<VariableDeclarator> Declarations;
-        public string Kind;
-    }
-}

+ 0 - 8
Jint/Parser/Ast/VariableDeclarator.cs

@@ -1,8 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class VariableDeclarator : Expression
-    {
-        public Identifier Id;
-        public Expression Init;
-    }
-}

+ 0 - 8
Jint/Parser/Ast/WhileStatement.cs

@@ -1,8 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class WhileStatement : Statement
-    {
-        public Expression Test;
-        public Statement Body;
-    }
-}

+ 0 - 8
Jint/Parser/Ast/WithStatement.cs

@@ -1,8 +0,0 @@
-namespace Jint.Parser.Ast
-{
-    public class WithStatement : Statement
-    {
-        public Expression Object;
-        public Statement Body;
-    }
-}

+ 0 - 10
Jint/Parser/Comment.cs

@@ -1,10 +0,0 @@
-namespace Jint.Parser
-{
-    public class Comment
-    {
-        public Location Location;
-        public int[] Range;
-        public string Type;
-        public string Value;
-    }
-}

+ 0 - 13
Jint/Parser/IFunctionDeclaration.cs

@@ -1,13 +0,0 @@
-using System.Collections.Generic;
-using Jint.Parser.Ast;
-
-namespace Jint.Parser
-{
-    public interface IFunctionDeclaration : IFunctionScope
-    {
-        Identifier Id { get; }
-        IEnumerable<Identifier> Parameters { get; }
-        Statement Body { get; }
-        bool Strict { get; }
-    }
-}

+ 0 - 24
Jint/Parser/IFunctionScope.cs

@@ -1,24 +0,0 @@
-using System.Collections.Generic;
-using Jint.Parser.Ast;
-
-namespace Jint.Parser
-{
-    /// <summary>
-    /// Used to safe references to all function delcarations in a specific scope.
-    /// </summary>
-    public interface IFunctionScope: IVariableScope
-    {
-        IList<FunctionDeclaration> FunctionDeclarations { get; set; }
-    }
-
-    public class FunctionScope : IFunctionScope
-    {
-        public FunctionScope()
-        {
-            FunctionDeclarations = new List<FunctionDeclaration>();
-        }
-
-        public IList<FunctionDeclaration> FunctionDeclarations { get; set; }
-        public IList<VariableDeclaration> VariableDeclarations { get; set; }
-    }
-}

+ 0 - 24
Jint/Parser/IVariableScope.cs

@@ -1,24 +0,0 @@
-using System.Collections.Generic;
-using Jint.Parser.Ast;
-
-namespace Jint.Parser
-{
-    /// <summary>
-    /// Used to safe references to all variable delcarations in a specific scope.
-    /// Hoisting.
-    /// </summary>
-    public interface IVariableScope
-    {
-        IList<VariableDeclaration> VariableDeclarations { get; set; }
-    }
-
-    public class VariableScope : IVariableScope
-    {
-        public VariableScope()
-        {
-            VariableDeclarations = new List<VariableDeclaration>();
-        }
-
-        public IList<VariableDeclaration> VariableDeclarations { get; set; }
-    }
-}

File diff suppressed because it is too large
+ 0 - 4074
Jint/Parser/JavascriptParser.cs


+ 0 - 9
Jint/Parser/Loc.cs

@@ -1,9 +0,0 @@
-namespace Jint.Parser
-{
-    public class Location
-    {
-        public Position Start;
-        public Position End;
-        public string Source;
-    }
-}

+ 0 - 40
Jint/Parser/Messages.cs

@@ -1,40 +0,0 @@
-namespace Jint.Parser
-{
-    // Error messages should be identical to V8.
-    public class Messages
-    {
-        public static string UnexpectedToken = "Unexpected token {0}";
-        public static string UnexpectedNumber = "Unexpected number";
-        public static string UnexpectedString = "Unexpected string";
-        public static string UnexpectedIdentifier = "Unexpected identifier";
-        public static string UnexpectedReserved = "Unexpected reserved word";
-        public static string UnexpectedEOS = "Unexpected end of input";
-        public static string NewlineAfterThrow = "Illegal newline after throw";
-        public static string InvalidRegExp = "Invalid regular expression";
-        public static string UnterminatedRegExp = "Invalid regular expression= missing /";
-        public static string InvalidLHSInAssignment = "Invalid left-hand side in assignment";
-        public static string InvalidLHSInForIn = "Invalid left-hand side in for-in";
-        public static string MultipleDefaultsInSwitch = "More than one default clause in switch statement";
-        public static string NoCatchOrFinally = "Missing catch or finally after try";
-        public static string UnknownLabel = "Undefined label \"{0}\"";
-        public static string Redeclaration = "{0} \"{1}\" has already been declared";
-        public static string IllegalContinue = "Illegal continue statement";
-        public static string IllegalBreak = "Illegal break statement";
-        public static string IllegalReturn = "Illegal return statement";
-        public static string StrictModeWith = "Strict mode code may not include a with statement";
-        public static string StrictCatchVariable = "Catch variable may not be eval or arguments in strict mode";
-        public static string StrictVarName = "Variable name may not be eval or arguments in strict mode";
-        public static string StrictParamName = "Parameter name eval or arguments is not allowed in strict mode";
-        public static string StrictParamDupe = "Strict mode function may not have duplicate parameter names";
-        public static string StrictFunctionName = "Function name may not be eval or arguments in strict mode";
-        public static string StrictOctalLiteral = "Octal literals are not allowed in strict mode.";
-        public static string StrictDelete = "Delete of an unqualified identifier in strict mode.";
-        public static string StrictDuplicateProperty = "Duplicate data property in object literal not allowed in strict mode";
-        public static string AccessorDataProperty = "Object literal may not have data and accessor property with the same name";
-        public static string AccessorGetSet = "Object literal may not have multiple get/set accessors with the same name";
-        public static string StrictLHSAssignment = "Assignment to eval or arguments is not allowed in strict mode";
-        public static string StrictLHSPostfix = "Postfix increment/decrement may not have eval or arguments operand in strict mode";
-        public static string StrictLHSPrefix = "Prefix increment/decrement may not have eval or arguments operand in strict mode";
-        public static string StrictReservedWord = "Use of future reserved word in strict mode";
-    };
-}

+ 0 - 20
Jint/Parser/ParserException.cs

@@ -1,20 +0,0 @@
-using System;
-
-namespace Jint.Parser
-{
-    public class ParserException : Exception
-    {
-        public int Column;
-        public string Description;
-        public int Index;
-        public int LineNumber;
-
-#if PORTABLE
-        public string Source;
-#endif
-
-        public ParserException(string message) : base(message)
-        {
-        }
-    }
-}

+ 0 - 37
Jint/Parser/ParserExtensions.cs

@@ -1,37 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Jint.Parser
-{
-    public static class ParserExtensions
-    {
-        public static string Slice(this string source, int start, int end)
-        {
-            return source.Substring(start, Math.Min(source.Length, end) - start);
-        }
-
-        public static char CharCodeAt(this string source, int index)
-        {
-            if (index < 0 || index > source.Length - 1)
-            {
-                // char.MinValue is used as the null value
-                return char.MinValue;
-            }
-
-            return source[index];
-        }
-
-        public static T Pop<T>(this List<T> list)
-        {
-            var lastIndex = list.Count - 1;
-            var last = list[lastIndex];
-            list.RemoveAt(lastIndex);
-            return last;
-        }
-
-        public static void Push<T>(this List<T> list, T item)
-        {
-            list.Add(item);
-        }
-    }
-}

+ 0 - 10
Jint/Parser/ParserOptions.cs

@@ -1,10 +0,0 @@
-namespace Jint.Parser
-{
-    public class ParserOptions
-    {
-        public string Source { get; set; }
-        public bool Tokens { get; set; }
-        public bool Comment { get; set; }
-        public bool Tolerant { get; set; }
-    }
-}

+ 0 - 8
Jint/Parser/Position.cs

@@ -1,8 +0,0 @@
-namespace Jint.Parser
-{
-    public struct Position
-    {
-        public int Line;
-        public int Column;
-    }
-}

+ 0 - 15
Jint/Parser/State.cs

@@ -1,15 +0,0 @@
-using System.Collections.Generic;
-
-namespace Jint.Parser
-{
-    public struct State
-    {
-        public int LastCommentStart;
-        public bool AllowIn;
-        public HashSet<string> LabelSet;
-        public bool InFunctionBody;
-        public bool InIteration;
-        public bool InSwitch;
-        public Stack<int> MarkerStack;
-    }
-}

+ 0 - 30
Jint/Parser/Token.cs

@@ -1,30 +0,0 @@
-namespace Jint.Parser
-{
-    public enum Tokens
-    {
-        BooleanLiteral = 1,
-        EOF = 2,
-        Identifier = 3,
-        Keyword = 4,
-        NullLiteral = 5,
-        NumericLiteral = 6,
-        Punctuator = 7,
-        StringLiteral = 8,
-        RegularExpression = 9
-    };
-
-    public class Token
-    {
-        public static Token Empty = new Token();
-
-        public Tokens Type;
-        public string Literal;
-        public object Value;
-        public int[] Range;
-        public int? LineNumber;
-        public int LineStart;
-        public bool Octal;
-        public Location Location;
-        public int Precedence;
-    }
-}

+ 1 - 1
Jint/Runtime/CallStack/CallStackElement.cs

@@ -1,7 +1,7 @@
 namespace Jint.Runtime
 {
+    using Esprima.Ast;
     using Jint.Native;
-    using Jint.Parser.Ast;
 
     public class CallStackElement
     {

+ 3 - 2
Jint/Runtime/Completion.cs

@@ -1,4 +1,5 @@
-using Jint.Native;
+using Esprima;
+using Jint.Native;
 
 namespace Jint.Runtime
 {
@@ -29,6 +30,6 @@ namespace Jint.Runtime
             return Value != null ? Value : Undefined.Instance;
         }
 
-        public Jint.Parser.Location Location { get; set; }
+        public Location Location { get; set; }
     }
 }

+ 3 - 5
Jint/Runtime/Debugger/DebugHandler.cs

@@ -1,10 +1,8 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
 using System.Linq;
+using Esprima.Ast;
 using Jint.Native;
-using Jint.Parser.Ast;
 using Jint.Runtime.Environments;
-using Jint.Runtime.References;
 
 namespace Jint.Runtime.Debugger
 {
@@ -74,7 +72,7 @@ namespace Jint.Runtime.Debugger
             {
                 return;
             }
-            
+
             BreakPoint breakpoint = _engine.BreakPoints.FirstOrDefault(breakPoint => BpTest(statement, breakPoint));
             bool breakpointFound = false;
 

+ 1 - 2
Jint/Runtime/Debugger/DebugInformation.cs

@@ -1,8 +1,7 @@
 using System;
 using System.Collections.Generic;
+using Esprima.Ast;
 using Jint.Native;
-using Jint.Parser.Ast;
-using Jint.Runtime.Environments;
 
 namespace Jint.Runtime.Debugger
 {

+ 65 - 59
Jint/Runtime/ExpressionIntepreter.cs

@@ -1,9 +1,9 @@
 using System;
 using System.Linq;
+using Esprima.Ast;
 using Jint.Native;
 using Jint.Native.Function;
 using Jint.Native.Number;
-using Jint.Parser.Ast;
 using Jint.Runtime.Descriptors;
 using Jint.Runtime.Environments;
 using Jint.Runtime.References;
@@ -41,7 +41,7 @@ namespace Jint.Runtime
 
         public JsValue EvaluateAssignmentExpression(AssignmentExpression assignmentExpression)
         {
-            var lref = EvaluateExpression(assignmentExpression.Left) as Reference;
+            var lref = EvaluateExpression(assignmentExpression.Left.As<Expression>()) as Reference;
             JsValue rval = _engine.GetValue(EvaluateExpression(assignmentExpression.Right));
 
             if (lref == null)
@@ -346,28 +346,28 @@ namespace Jint.Runtime
             return value;
         }
 
-        public JsValue EvaluateLogicalExpression(LogicalExpression logicalExpression)
+        public JsValue EvaluateLogicalExpression(BinaryExpression binaryExpression)
         {
-            var left = _engine.GetValue(EvaluateExpression(logicalExpression.Left));
+            var left = _engine.GetValue(EvaluateExpression(binaryExpression.Left));
 
-            switch (logicalExpression.Operator)
+            switch (binaryExpression.Operator)
             {
 
-                case LogicalOperator.LogicalAnd:
+                case BinaryOperator.LogicalAnd:
                     if (!TypeConverter.ToBoolean(left))
                     {
                         return left;
                     }
 
-                    return _engine.GetValue(EvaluateExpression(logicalExpression.Right));
+                    return _engine.GetValue(EvaluateExpression(binaryExpression.Right));
 
-                case LogicalOperator.LogicalOr:
+                case BinaryOperator.LogicalOr:
                     if (TypeConverter.ToBoolean(left))
                     {
                         return left;
                     }
 
-                    return _engine.GetValue(EvaluateExpression(logicalExpression.Right));
+                    return _engine.GetValue(EvaluateExpression(binaryExpression.Right));
 
                 default:
                     throw new NotImplementedException();
@@ -625,22 +625,26 @@ namespace Jint.Runtime
 
         public JsValue EvaluateLiteral(Literal literal)
         {
-            if(literal.Cached)
-            {
-                return literal.CachedValue;
-            }
-
-            if (literal.Type == SyntaxNodes.RegularExpressionLiteral)
-            {
-                literal.CachedValue = _engine.RegExp.Construct(literal.Raw);
-            }
-            else
-            {
-                literal.CachedValue = JsValue.FromObject(_engine, literal.Value);
-            }
-
-            literal.Cached = true;
-            return literal.CachedValue;
+            // TODO: Esprima
+
+            //if(literal.Cached)
+            //{
+            //    return literal.CachedValue;
+            //}
+
+            //if (literal.Type == Nodes.RegularExpressionLiteral)
+            //{
+            //    literal.CachedValue = _engine.RegExp.Construct(literal.Raw);
+            //}
+            //else
+            //{
+            //    literal.CachedValue = JsValue.FromObject(_engine, literal.Value);
+            //}
+
+            //literal.Cached = true;
+            // return literal.CachedValue;
+
+            return JsValue.FromObject(_engine, literal.Value);
         }
 
         public JsValue EvaluateObjectExpression(ObjectExpression objectExpression)
@@ -657,13 +661,13 @@ namespace Jint.Runtime
                 switch (property.Kind)
                 {
                     case PropertyKind.Data:
-                        var exprValue = _engine.EvaluateExpression(property.Value);
+                        var exprValue = _engine.EvaluateExpression(property.Value.As<Expression>());
                         var propValue = _engine.GetValue(exprValue);
                         propDesc = new PropertyDescriptor(propValue, true, true, true);
                         break;
 
                     case PropertyKind.Get:
-                        var getter = property.Value as FunctionExpression;
+                        var getter = property.Value as IFunction;
 
                         if (getter == null)
                         {
@@ -671,11 +675,11 @@ namespace Jint.Runtime
                         }
 
                         ScriptFunctionInstance get;
-                        using (new StrictModeScope(getter.Strict))
+                        using (new StrictModeScope(getter.IsStrict()))
                         {
                             get = new ScriptFunctionInstance(
                                 _engine,
-                                getter,
+                                getter.As<FunctionDeclaration>(),
                                 _engine.ExecutionContext.LexicalEnvironment,
                                 StrictModeScope.IsStrictModeCode
                             );
@@ -685,7 +689,7 @@ namespace Jint.Runtime
                         break;
 
                     case PropertyKind.Set:
-                        var setter = property.Value as FunctionExpression;
+                        var setter = property.Value as IFunction;
 
                         if (setter == null)
                         {
@@ -693,12 +697,12 @@ namespace Jint.Runtime
                         }
 
                         ScriptFunctionInstance set;
-                        using (new StrictModeScope(setter.Strict))
+                        using (new StrictModeScope(setter.IsStrict()))
                         {
 
                             set = new ScriptFunctionInstance(
                                 _engine,
-                                setter,
+                                setter.As<FunctionDeclaration>(),
                                 _engine.ExecutionContext.LexicalEnvironment,
                                 StrictModeScope.IsStrictModeCode
                                 );
@@ -761,7 +765,8 @@ namespace Jint.Runtime
 
             if (!memberExpression.Computed) // index accessor ?
             {
-                expression = new Literal { Type = SyntaxNodes.Literal, Value = memberExpression.Property.As<Identifier>().Name };
+                var name = memberExpression.Property.As<Identifier>().Name;
+                expression = new Literal(name, name);
             }
 
             var propertyNameReference = EvaluateExpression(expression);
@@ -772,7 +777,7 @@ namespace Jint.Runtime
             return new Reference(baseValue, propertyNameString, StrictModeScope.IsStrictModeCode);
         }
 
-        public JsValue EvaluateFunctionExpression(FunctionExpression functionExpression)
+        public JsValue EvaluateFunctionExpression(IFunction functionExpression)
         {
             var funcEnv = LexicalEnvironment.NewDeclarativeEnvironment(_engine, _engine.ExecutionContext.LexicalEnvironment);
             var envRec = (DeclarativeEnvironmentRecord)funcEnv.Record;
@@ -786,7 +791,7 @@ namespace Jint.Runtime
                 _engine,
                 functionExpression,
                 funcEnv,
-                functionExpression.Strict
+                functionExpression.IsStrict()
                 );
 
             if (functionExpression.Id != null && !String.IsNullOrEmpty(functionExpression.Id.Name))
@@ -813,28 +818,29 @@ namespace Jint.Runtime
 
             JsValue[] arguments;
 
-            if (callExpression.Cached)
-            {
-                arguments = callExpression.CachedArguments;
-            }
-            else
-            {
-                arguments = callExpression.Arguments.Select(EvaluateExpression).Select(_engine.GetValue).ToArray();
-
-                if (callExpression.CanBeCached)
-                {
-                    // The arguments array can be cached if they are all literals
-                    if (callExpression.Arguments.All(x => x is Literal))
-                    {
-                        callExpression.CachedArguments = arguments;
-                        callExpression.Cached = true;
-                    }
-                    else
-                    {
-                        callExpression.CanBeCached = false;
-                    }
-                }
-            }
+            // TODO: Esprima
+            //if (callExpression.Cached)
+            //{
+            //    arguments = callExpression.CachedArguments;
+            //}
+            //else
+            //{
+                arguments = callExpression.Arguments.Select(x => EvaluateExpression(x.As<Expression>())).Select(_engine.GetValue).ToArray();
+
+            //    if (callExpression.CanBeCached)
+            //    {
+            //        // The arguments array can be cached if they are all literals
+            //        if (callExpression.Arguments.All(x => x is Literal))
+            //        {
+            //            callExpression.CachedArguments = arguments;
+            //            callExpression.Cached = true;
+            //        }
+            //        else
+            //        {
+            //            callExpression.CanBeCached = false;
+            //        }
+            //    }
+            //}
 
             var func = _engine.GetValue(callee);
 
@@ -969,7 +975,7 @@ namespace Jint.Runtime
 
         public JsValue EvaluateNewExpression(NewExpression newExpression)
         {
-            var arguments = newExpression.Arguments.Select(EvaluateExpression).Select(_engine.GetValue).ToArray();
+            var arguments = newExpression.Arguments.Select(x => EvaluateExpression(x.As<Expression>())).Select(_engine.GetValue).ToArray();
 
             // todo: optimize by defining a common abstract class or interface
             var callee = _engine.GetValue(EvaluateExpression(newExpression.Callee)).TryCast<IConstructor>();
@@ -993,7 +999,7 @@ namespace Jint.Runtime
             {
                 if (expr != null)
                 {
-                    var value = _engine.GetValue(EvaluateExpression(expr));
+                    var value = _engine.GetValue(EvaluateExpression(expr.As<Expression>()));
                     a.DefineOwnProperty(n.ToString(),
                         new PropertyDescriptor(value, true, true, true), false);
                 }

+ 4 - 3
Jint/Runtime/JavaScriptException.cs

@@ -1,4 +1,5 @@
 using System;
+using Esprima;
 using Jint.Native;
 using Jint.Native.Error;
 
@@ -25,7 +26,7 @@ namespace Jint.Runtime
             _errorObject = error;
         }
 
-        private static string GetErrorMessage(JsValue error) 
+        private static string GetErrorMessage(JsValue error)
         {
             if (error.IsObject())
             {
@@ -34,7 +35,7 @@ namespace Jint.Runtime
                 return message;
             }
             else
-                return string.Empty;            
+                return string.Empty;
         }
 
         public JsValue Error { get { return _errorObject; } }
@@ -44,7 +45,7 @@ namespace Jint.Runtime
             return _errorObject.ToString();
         }
 
-        public Jint.Parser.Location Location { get; set; }
+        public Location Location { get; set; }
 
         public int LineNumber { get { return null == Location ? 0 : Location.Start.Line; } }
 

+ 0 - 6
Jint/Runtime/RecursionDepthOverflowException.cs

@@ -1,9 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-
-using Jint.Native;
-using Jint.Parser.Ast;
 
 namespace Jint.Runtime
 {
@@ -23,5 +18,4 @@ namespace Jint.Runtime
             CallChain = currentStack.ToString();
         }
     }
-    
 }

+ 31 - 31
Jint/Runtime/StatementInterpreter.cs

@@ -1,8 +1,8 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using Esprima.Ast;
 using Jint.Native;
-using Jint.Parser.Ast;
 using Jint.Runtime.Environments;
 using Jint.Runtime.References;
 
@@ -54,11 +54,13 @@ namespace Jint.Runtime
             return result;
         }
 
-        public Completion ExecuteLabelledStatement(LabelledStatement labelledStatement)
+        public Completion ExecuteLabeledStatement(LabeledStatement labeledStatement)
         {
-            labelledStatement.Body.LabelSet = labelledStatement.Label.Name;
-            var result = ExecuteStatement(labelledStatement.Body);
-            if (result.Type == Completion.Break && result.Identifier == labelledStatement.Label.Name)
+            // TODO: Esprima added Statement.Label, maybe not necessary as this line is finding the
+            // containing label and could keep a table per program with all the labels
+            // labeledStatement.Body.LabelSet = labeledStatement.Label;
+            var result = ExecuteStatement(labeledStatement.Body);
+            if (result.Type == Completion.Break && result.Identifier == labeledStatement.Label.Name)
             {
                 return new Completion(Completion.Normal, result.Value, null);
             }
@@ -83,9 +85,9 @@ namespace Jint.Runtime
                 {
                     v = stmt.Value;
                 }
-                if (stmt.Type != Completion.Continue || stmt.Identifier != doWhileStatement.LabelSet)
+                if (stmt.Type != Completion.Continue || stmt.Identifier != doWhileStatement.LabelSet.Name)
                 {
-                    if (stmt.Type == Completion.Break && (stmt.Identifier == null || stmt.Identifier == doWhileStatement.LabelSet))
+                    if (stmt.Type == Completion.Break && (stmt.Identifier == null || stmt.Identifier == doWhileStatement.LabelSet.Name))
                     {
                         return new Completion(Completion.Normal, v, null);
                     }
@@ -127,9 +129,9 @@ namespace Jint.Runtime
                     v = stmt.Value;
                 }
 
-                if (stmt.Type != Completion.Continue || stmt.Identifier != whileStatement.LabelSet)
+                if (stmt.Type != Completion.Continue || stmt.Identifier != whileStatement.LabelSet.Name)
                 {
-                    if (stmt.Type == Completion.Break && (stmt.Identifier == null || stmt.Identifier == whileStatement.LabelSet))
+                    if (stmt.Type == Completion.Break && (stmt.Identifier == null || stmt.Identifier == whileStatement.LabelSet.Name))
                     {
                         return new Completion(Completion.Normal, v, null);
                     }
@@ -152,7 +154,7 @@ namespace Jint.Runtime
 
             if (forStatement.Init != null)
             {
-                if (forStatement.Init.Type == SyntaxNodes.VariableDeclaration)
+                if (forStatement.Init.Type == Nodes.VariableDeclaration)
                 {
                     ExecuteStatement(forStatement.Init.As<Statement>());
                 }
@@ -179,11 +181,11 @@ namespace Jint.Runtime
                 {
                     v = stmt.Value;
                 }
-                if (stmt.Type == Completion.Break && (stmt.Identifier == null || stmt.Identifier == forStatement.LabelSet))
+                if (stmt.Type == Completion.Break && (stmt.Identifier == null || stmt.Identifier == forStatement.LabelSet.Name))
                 {
                     return new Completion(Completion.Normal, v, null);
                 }
-                if (stmt.Type != Completion.Continue || ((stmt.Identifier != null) && stmt.Identifier != forStatement.LabelSet))
+                if (stmt.Type != Completion.Continue || ((stmt.Identifier != null) && stmt.Identifier != forStatement.LabelSet.Name))
                 {
                     if (stmt.Type != Completion.Normal)
                     {
@@ -205,8 +207,8 @@ namespace Jint.Runtime
         /// <returns></returns>
         public Completion ExecuteForInStatement(ForInStatement forInStatement)
         {
-            Identifier identifier = forInStatement.Left.Type == SyntaxNodes.VariableDeclaration
-                                        ? forInStatement.Left.As<VariableDeclaration>().Declarations.First().Id
+            Identifier identifier = forInStatement.Left.Type == Nodes.VariableDeclaration
+                                        ? forInStatement.Left.As<VariableDeclaration>().Declarations.First().Id.As<Identifier>()
                                         : forInStatement.Left.As<Identifier>();
 
             var varRef = _engine.EvaluateExpression(identifier) as Reference;
@@ -351,7 +353,7 @@ namespace Jint.Runtime
         {
             var exprRef = _engine.EvaluateExpression(switchStatement.Discriminant);
             var r = ExecuteSwitchBlock(switchStatement.Cases, _engine.GetValue(exprRef));
-            if (r.Type == Completion.Break && r.Identifier == switchStatement.LabelSet)
+            if (r.Type == Completion.Break && r.Identifier == switchStatement.LabelSet.Name)
             {
                 return new Completion(Completion.Normal, r.Value, null);
             }
@@ -406,7 +408,7 @@ namespace Jint.Runtime
             return new Completion(Completion.Normal, v, null);
         }
 
-        public Completion ExecuteStatementList(IEnumerable<Statement> statementList)
+        public Completion ExecuteStatementList(IEnumerable<StatementListItem> statementList)
         {
             var c = new Completion(Completion.Normal, null, null);
             Completion sl = c;
@@ -416,8 +418,8 @@ namespace Jint.Runtime
             {
                 foreach (var statement in statementList)
                 {
-                    s = statement;
-                    c = ExecuteStatement(statement);
+                    s = statement.As<Statement>();
+                    c = ExecuteStatement(s);
                     if (c.Type != Completion.Normal)
                     {
                         return new Completion(c.Type, c.Value != null ? c.Value : sl.Value, c.Identifier)
@@ -463,19 +465,17 @@ namespace Jint.Runtime
             if (b.Type == Completion.Throw)
             {
                 // execute catch
-                if (tryStatement.Handlers.Any())
+                var catchClause = tryStatement.Handler;
+                if (catchClause != null)
                 {
-                    foreach (var catchClause in tryStatement.Handlers)
-                    {
-                        var c = _engine.GetValue(b);
-                        var oldEnv = _engine.ExecutionContext.LexicalEnvironment;
-                        var catchEnv = LexicalEnvironment.NewDeclarativeEnvironment(_engine, oldEnv);
-                        catchEnv.Record.CreateMutableBinding(catchClause.Param.Name);
-                        catchEnv.Record.SetMutableBinding(catchClause.Param.Name, c, false);
-                        _engine.ExecutionContext.LexicalEnvironment = catchEnv;
-                        b = ExecuteStatement(catchClause.Body);
-                        _engine.ExecutionContext.LexicalEnvironment = oldEnv;
-                    }
+                    var c = _engine.GetValue(b);
+                    var oldEnv = _engine.ExecutionContext.LexicalEnvironment;
+                    var catchEnv = LexicalEnvironment.NewDeclarativeEnvironment(_engine, oldEnv);
+                    catchEnv.Record.CreateMutableBinding(catchClause.Param.As<Identifier>().Name);
+                    catchEnv.Record.SetMutableBinding(catchClause.Param.As<Identifier>().Name, c, false);
+                    _engine.ExecutionContext.LexicalEnvironment = catchEnv;
+                    b = ExecuteStatement(catchClause.Body);
+                    _engine.ExecutionContext.LexicalEnvironment = oldEnv;
                 }
             }
 
@@ -504,7 +504,7 @@ namespace Jint.Runtime
             {
                 if (declaration.Init != null)
                 {
-                    var lhs = _engine.EvaluateExpression(declaration.Id) as Reference;
+                    var lhs = _engine.EvaluateExpression(declaration.Id.As<Identifier>()) as Reference;
 
                     if (lhs == null)
                     {

+ 3 - 12
Jint/project.json

@@ -24,18 +24,6 @@
         "System.Diagnostics.Contracts": "4.0.0.0"
       }
     },
-    ".NETPortable,Version=v4.0,Profile=Profile328": {
-      "buildOptions": {
-        "define": [
-          "PORTABLE"
-        ]
-      },
-      "frameworkAssemblies": {
-        "mscorlib": "",
-        "System": "",
-        "System.Core": ""
-      }
-    },
     "netstandard1.3": {
       "dependencies": {
         "NETStandard.Library": "1.6.0",
@@ -44,5 +32,8 @@
         "System.Reflection.TypeExtensions": "4.1.0"
       }
     }
+  },
+  "dependencies": {
+    "Esprima": "1.0.0-alpha-002"
   }
 }

+ 6 - 0
global.json

@@ -0,0 +1,6 @@
+{
+  "projects": [
+    "../Esprima.NET/src/Esprima",
+    "../Esprima.NET/src"
+  ]
+}

Some files were not shown because too many files changed in this diff