Browse Source

Changing the project type to a Portable Class Library

Sebastien Ros 12 năm trước cách đây
mục cha
commit
738abd2740

+ 1 - 1
Jint.Benchmark/Jint.Benchmark.csproj

@@ -73,7 +73,7 @@
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\Jint\Jint.csproj">
-      <Project>{a2707cfd-e37d-4b88-8fc2-238d4c1dfd01}</Project>
+      <Project>{678738da-f723-4920-b9e5-cad667104bda}</Project>
       <Name>Jint</Name>
     </ProjectReference>
   </ItemGroup>

+ 1 - 1
Jint.Benchmark/Program.cs

@@ -27,7 +27,7 @@ namespace Jint.Benchmark
 
         static void Main(string[] args)
         {
-            const int iterations = 100000;
+            const int iterations = 1000;
             const bool reuseEngine = false;
 
             var watch = new Stopwatch();

+ 4 - 5
Jint.Tests/Jint.Tests.csproj

@@ -58,16 +58,15 @@
   <ItemGroup>
     <None Include="packages.config" />
   </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Include="Runtime\Scripts\Scratch.js" />
+  </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\Jint\Jint.csproj">
-      <Project>{a2707cfd-e37d-4b88-8fc2-238d4c1dfd01}</Project>
+      <Project>{678738da-f723-4920-b9e5-cad667104bda}</Project>
       <Name>Jint</Name>
     </ProjectReference>
   </ItemGroup>
-  <ItemGroup>
-    <EmbeddedResource Include="Runtime\Scripts\Scratch.js" />
-  </ItemGroup>
-  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.

+ 6 - 6
Jint.sln

@@ -5,12 +5,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jint.Tests", "Jint.Tests\Ji
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jint.Benchmark", "Jint.Benchmark\Jint.Benchmark.csproj", "{8922A952-4F82-4A97-B41C-C0A9932BFFA8}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jint", "Jint\Jint.csproj", "{A2707CFD-E37D-4B88-8FC2-238D4C1DFD01}"
-EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jint.Tests.Scaffolding", "Jint.Tests.Scaffolding\Jint.Tests.Scaffolding.csproj", "{3F0178B0-6E36-4AE3-B791-25E3BBF04B03}"
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jint.Tests.Ecma", "Jint.Tests.Ecma\Jint.Tests.Ecma.csproj", "{201EB165-EE2D-45F1-AF0E-75F1CD1A20EE}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jint", "Jint\Jint.csproj", "{678738DA-F723-4920-B9E5-CAD667104BDA}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -25,10 +25,6 @@ Global
 		{8922A952-4F82-4A97-B41C-C0A9932BFFA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{8922A952-4F82-4A97-B41C-C0A9932BFFA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{8922A952-4F82-4A97-B41C-C0A9932BFFA8}.Release|Any CPU.Build.0 = Release|Any CPU
-		{A2707CFD-E37D-4B88-8FC2-238D4C1DFD01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{A2707CFD-E37D-4B88-8FC2-238D4C1DFD01}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{A2707CFD-E37D-4B88-8FC2-238D4C1DFD01}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{A2707CFD-E37D-4B88-8FC2-238D4C1DFD01}.Release|Any CPU.Build.0 = Release|Any CPU
 		{3F0178B0-6E36-4AE3-B791-25E3BBF04B03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{3F0178B0-6E36-4AE3-B791-25E3BBF04B03}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{3F0178B0-6E36-4AE3-B791-25E3BBF04B03}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -37,6 +33,10 @@ Global
 		{201EB165-EE2D-45F1-AF0E-75F1CD1A20EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{201EB165-EE2D-45F1-AF0E-75F1CD1A20EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{201EB165-EE2D-45F1-AF0E-75F1CD1A20EE}.Release|Any CPU.Build.0 = Release|Any CPU
+		{678738DA-F723-4920-B9E5-CAD667104BDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{678738DA-F723-4920-B9E5-CAD667104BDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{678738DA-F723-4920-B9E5-CAD667104BDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{678738DA-F723-4920-B9E5-CAD667104BDA}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 2 - 2
Jint/Engine.cs

@@ -190,7 +190,7 @@ namespace Jint
             return null;
         }
 
-        public dynamic EvaluateExpression(Expression expression)
+        public object EvaluateExpression(Expression expression)
         {
             switch (expression.Type)
             {
@@ -244,7 +244,7 @@ namespace Jint
             }
         }
 
-        public dynamic GetValue(object value)
+        public object GetValue(object value)
         {
             var reference = value as Reference;
             

+ 30 - 38
Jint/Jint.csproj

@@ -2,18 +2,20 @@
 <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
   <PropertyGroup>
+    <MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProjectGuid>{A2707CFD-E37D-4B88-8FC2-238D4C1DFD01}</ProjectGuid>
+    <ProjectGuid>{678738DA-F723-4920-B9E5-CAD667104BDA}</ProjectGuid>
     <OutputType>Library</OutputType>
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Jint</RootNamespace>
     <AssemblyName>Jint</AssemblyName>
-    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <TargetFrameworkProfile>Profile36</TargetFrameworkProfile>
     <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <PlatformTarget>AnyCPU</PlatformTarget>
     <DebugSymbols>true</DebugSymbols>
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
@@ -23,7 +25,6 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
-    <PlatformTarget>AnyCPU</PlatformTarget>
     <DebugType>pdbonly</DebugType>
     <Optimize>true</Optimize>
     <OutputPath>bin\Release\</OutputPath>
@@ -31,42 +32,34 @@
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
-  <PropertyGroup>
-    <StartupObject />
-  </PropertyGroup>
   <ItemGroup>
-    <Reference Include="System" />
-    <Reference Include="System.Core" />
-    <Reference Include="System.Xml.Linq" />
-    <Reference Include="System.Data.DataSetExtensions" />
-    <Reference Include="Microsoft.CSharp" />
-    <Reference Include="System.Data" />
-    <Reference Include="System.Xml" />
+    <!-- A reference to the entire .NET Framework is automatically included -->
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Engine.cs" />
     <Compile Include="Native\Array\ArrayConstructor.cs" />
     <Compile Include="Native\Array\ArrayInstance.cs" />
     <Compile Include="Native\Boolean\BooleanConstructor.cs" />
     <Compile Include="Native\Boolean\BooleanInstance.cs" />
-    <Compile Include="Native\String\StringConstructor.cs" />
-    <Compile Include="Native\String\StringInstance.cs" />
-    <Compile Include="Native\Errors\TypeError.cs" />
     <Compile Include="Native\Errors\ReferenceError.cs" />
+    <Compile Include="Native\Errors\TypeError.cs" />
+    <Compile Include="Native\Function\FunctionConstructor.cs" />
+    <Compile Include="Native\Function\FunctionInstance.cs" />
+    <Compile Include="Native\Function\FunctionShim.cs" />
     <Compile Include="Native\Function\ScriptFunctionInstance.cs" />
+    <Compile Include="Native\IConstructor.cs" />
     <Compile Include="Native\IPrimitiveType.cs" />
     <Compile Include="Native\Null.cs" />
-    <Compile Include="Native\Function\FunctionShim.cs" />
-    <Compile Include="Native\Function\FunctionInstance.cs" />
     <Compile Include="Native\Number\NumberConstructor.cs" />
     <Compile Include="Native\Number\NumberInstance.cs" />
     <Compile Include="Native\Object\ObjectConstructor.cs" />
     <Compile Include="Native\Object\ObjectInstance.cs" />
+    <Compile Include="Native\String\StringConstructor.cs" />
+    <Compile Include="Native\String\StringInstance.cs" />
     <Compile Include="Native\Undefined.cs" />
-    <Compile Include="Parser\Ast\IPropertyKeyExpression.cs" />
-    <Compile Include="Parser\ParserException.cs" />
+    <Compile Include="Options.cs" />
     <Compile Include="Parser\Ast\ArrayExpression.cs" />
     <Compile Include="Parser\Ast\AssignmentExpression.cs" />
-    <Compile Include="Parser\Ast\SyntaxNodes.cs" />
     <Compile Include="Parser\Ast\BinaryExpression.cs" />
     <Compile Include="Parser\Ast\BlockStatement.cs" />
     <Compile Include="Parser\Ast\BreakStatement.cs" />
@@ -85,18 +78,12 @@
     <Compile Include="Parser\Ast\FunctionExpression.cs" />
     <Compile Include="Parser\Ast\Identifier.cs" />
     <Compile Include="Parser\Ast\IfStatement.cs" />
+    <Compile Include="Parser\Ast\IPropertyKeyExpression.cs" />
     <Compile Include="Parser\Ast\LabeledStatement.cs" />
     <Compile Include="Parser\Ast\Literal.cs" />
     <Compile Include="Parser\Ast\MemberExpression.cs" />
     <Compile Include="Parser\Ast\NewExpression.cs" />
-    <Compile Include="Parser\Comment.cs" />
-    <Compile Include="Parser\JavascriptParser.cs" />
-    <Compile Include="Parser\Loc.cs" />
-    <Compile Include="Parser\Messages.cs" />
-    <Compile Include="Parser\ParserExtensions.cs" />
-    <Compile Include="Parser\Ast\SyntaxNode.cs" />
     <Compile Include="Parser\Ast\ObjectExpression.cs" />
-    <Compile Include="Parser\Ast\UpdateExpression.cs" />
     <Compile Include="Parser\Ast\Program.cs" />
     <Compile Include="Parser\Ast\Property.cs" />
     <Compile Include="Parser\Ast\ReturnStatement.cs" />
@@ -104,14 +91,23 @@
     <Compile Include="Parser\Ast\Statement.cs" />
     <Compile Include="Parser\Ast\SwitchCase.cs" />
     <Compile Include="Parser\Ast\SwitchStatement.cs" />
+    <Compile Include="Parser\Ast\SyntaxNode.cs" />
+    <Compile Include="Parser\Ast\SyntaxNodes.cs" />
     <Compile Include="Parser\Ast\ThisExpression.cs" />
     <Compile Include="Parser\Ast\ThrowStatement.cs" />
     <Compile Include="Parser\Ast\TryStatement.cs" />
     <Compile Include="Parser\Ast\UnaryExpression.cs" />
+    <Compile Include="Parser\Ast\UpdateExpression.cs" />
     <Compile Include="Parser\Ast\VariableDeclaration.cs" />
     <Compile Include="Parser\Ast\VariableDeclarator.cs" />
     <Compile Include="Parser\Ast\WhileStatement.cs" />
     <Compile Include="Parser\Ast\WithStatement.cs" />
+    <Compile Include="Parser\Comment.cs" />
+    <Compile Include="Parser\JavascriptParser.cs" />
+    <Compile Include="Parser\Loc.cs" />
+    <Compile Include="Parser\Messages.cs" />
+    <Compile Include="Parser\ParserException.cs" />
+    <Compile Include="Parser\ParserExtensions.cs" />
     <Compile Include="Parser\ParserOptions.cs" />
     <Compile Include="Parser\Position.cs" />
     <Compile Include="Parser\State.cs" />
@@ -119,25 +115,21 @@
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Runtime\Descriptors\AccessorDescriptor.cs" />
     <Compile Include="Runtime\Descriptors\DataDescriptor.cs" />
+    <Compile Include="Runtime\Descriptors\PropertyDescriptor.cs" />
+    <Compile Include="Runtime\Descriptors\Specialized\MethodProperty.cs" />
+    <Compile Include="Runtime\Environments\DeclarativeEnvironmentRecord.cs" />
+    <Compile Include="Runtime\Environments\EnvironmentRecord.cs" />
     <Compile Include="Runtime\Environments\ExecutionContext.cs" />
     <Compile Include="Runtime\Environments\LexicalEnvironment.cs" />
     <Compile Include="Runtime\Environments\ObjectEnvironmentRecord.cs" />
-    <Compile Include="Runtime\Environments\DeclarativeEnvironmentRecord.cs" />
-    <Compile Include="Runtime\Environments\EnvironmentRecord.cs" />
     <Compile Include="Runtime\ExpressionIntepreter.cs" />
-    <Compile Include="Native\Function\FunctionConstructor.cs" />
     <Compile Include="Runtime\Interop\BuiltInPropertyWrapper.cs" />
     <Compile Include="Runtime\Interop\DelegateWrapper.cs" />
-    <Compile Include="Options.cs" />
-    <Compile Include="Runtime\Descriptors\Specialized\MethodProperty.cs" />
-    <Compile Include="Engine.cs" />
-    <Compile Include="Runtime\Descriptors\PropertyDescriptor.cs" />
     <Compile Include="Runtime\References\Reference.cs" />
     <Compile Include="Runtime\StatementInterpreter.cs" />
     <Compile Include="Runtime\TypeConverter.cs" />
   </ItemGroup>
-  <ItemGroup />
-  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
   <Target Name="BeforeBuild">

+ 3 - 4
Jint/Native/Array/ArrayConstructor.cs

@@ -2,12 +2,11 @@
 using Jint.Native.Function;
 using Jint.Native.Object;
 using Jint.Runtime.Descriptors;
-using Jint.Runtime.Descriptors.Specialized;
 using Jint.Runtime.Interop;
 
 namespace Jint.Native.Array
 {
-    public class ArrayConstructor : FunctionInstance
+    public sealed class ArrayConstructor : FunctionInstance, IConstructor
     {
         private readonly Engine _engine;
 
@@ -24,12 +23,12 @@ namespace Jint.Native.Array
             this.Prototype.DefineOwnProperty("pop", new DataDescriptor(new BuiltInPropertyWrapper(engine, (Func<ArrayInstance, object>)Pop, engine.RootFunction)), false);
         }
 
-        public override dynamic Call(object thisObject, dynamic[] arguments)
+        public override object Call(object thisObject, object[] arguments)
         {
             return Construct(arguments);
         }
 
-        public virtual ObjectInstance Construct(dynamic[] arguments)
+        public ObjectInstance Construct(object[] arguments)
         {
             var instance = new ArrayInstance(Prototype);
 

+ 2 - 6
Jint/Native/Array/ArrayInstance.cs

@@ -1,13 +1,9 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Collections.Generic;
 using Jint.Native.Object;
 
 namespace Jint.Native.Array
 {
-    public class ArrayInstance : ObjectInstance
+    public sealed class ArrayInstance : ObjectInstance
     {
         private readonly Stack<object> _array = new Stack<object>();
  

+ 3 - 3
Jint/Native/Boolean/BooleanConstructor.cs

@@ -5,7 +5,7 @@ using Jint.Runtime.Descriptors;
 
 namespace Jint.Native.Boolean
 {
-    public class BooleanConstructor : FunctionInstance
+    public sealed class BooleanConstructor : FunctionInstance, IConstructor
     {
         private readonly Engine _engine;
 
@@ -20,7 +20,7 @@ namespace Jint.Native.Boolean
 
         }
 
-        public override dynamic Call(object thisObject, dynamic[] arguments)
+        public override object Call(object thisObject, object[] arguments)
         {
             return Construct(arguments);
         }
@@ -30,7 +30,7 @@ namespace Jint.Native.Boolean
         /// </summary>
         /// <param name="arguments"></param>
         /// <returns></returns>
-        public virtual ObjectInstance Construct(dynamic[] arguments)
+        public ObjectInstance Construct(object[] arguments)
         {
             return Construct(TypeConverter.ToBoolean(arguments[0]));
         }

+ 1 - 1
Jint/Native/Boolean/BooleanInstance.cs

@@ -3,7 +3,7 @@ using Jint.Native.Object;
 
 namespace Jint.Native.Boolean
 {
-    public class BooleanInstance : ObjectInstance, IPrimitiveType
+    public sealed class BooleanInstance : ObjectInstance, IPrimitiveType
     {
         public BooleanInstance(ObjectInstance prototype)
             : base(prototype)

+ 4 - 8
Jint/Native/Function/FunctionConstructor.cs

@@ -1,18 +1,14 @@
 using System.Collections.Generic;
-using System.Linq;
-using Jint.Native;
-using Jint.Native.Function;
 using Jint.Native.Object;
 using Jint.Parser.Ast;
 using Jint.Runtime.Descriptors;
-using Jint.Runtime.Environments;
 
-namespace Jint.Runtime
+namespace Jint.Native.Function
 {
     /// <summary>
     /// 
     /// </summary>
-    public class FunctionConstructor : FunctionInstance
+    public sealed class FunctionConstructor : FunctionInstance, IConstructor
     {
         private readonly Engine _engine;
         private readonly IEnumerable<Identifier> _parameters;
@@ -26,12 +22,12 @@ namespace Jint.Runtime
             Extensible = true;
         }
 
-        public override dynamic Call(object thisObject, dynamic[] arguments)
+        public override object Call(object thisObject, object[] arguments)
         {
             return Construct(arguments);
         }
 
-        public virtual ObjectInstance Construct(dynamic[] arguments)
+        public ObjectInstance Construct(object[] arguments)
         {
             var instance = new FunctionShim(_engine, Prototype, null, null);
             instance.DefineOwnProperty("constructor", new DataDescriptor(Prototype) { Writable = true, Enumerable = false, Configurable = false }, false);

+ 1 - 3
Jint/Native/Function/FunctionInstance.cs

@@ -1,8 +1,6 @@
 using Jint.Native.Object;
 using Jint.Parser.Ast;
-using Jint.Runtime.Descriptors;
 using Jint.Runtime.Environments;
-using System.Collections.Generic;
 
 namespace Jint.Native.Function
 {
@@ -24,7 +22,7 @@ namespace Jint.Native.Function
         /// <param name="state"></param>
         /// <param name="arguments"></param>
         /// <returns></returns>
-        public abstract dynamic Call(object thisObject, dynamic[] arguments);
+        public abstract object Call(object thisObject, object[] arguments);
 
         public LexicalEnvironment Scope { get; private set; }
         public Identifier[] Parameters { get; private set; }

+ 2 - 3
Jint/Native/Function/FunctionShim.cs

@@ -1,11 +1,10 @@
 using Jint.Native.Object;
 using Jint.Parser.Ast;
-using Jint.Runtime;
 using Jint.Runtime.Environments;
 
 namespace Jint.Native.Function
 {
-    public class FunctionShim : FunctionInstance
+    public sealed class FunctionShim : FunctionInstance
     {
         private readonly Engine _engine;
 
@@ -14,7 +13,7 @@ namespace Jint.Native.Function
             _engine = engine;
         }
 
-        public override dynamic Call(object thisObject, dynamic[] arguments)
+        public override object Call(object thisObject, object[] arguments)
         {
             return Undefined.Instance;
         }

+ 5 - 7
Jint/Native/Function/ScriptFunctionInstance.cs

@@ -1,18 +1,16 @@
 using System.Collections.Generic;
 using System.Linq;
-using Jint.Native;
-using Jint.Native.Function;
 using Jint.Native.Object;
 using Jint.Parser.Ast;
 using Jint.Runtime.Descriptors;
 using Jint.Runtime.Environments;
 
-namespace Jint.Runtime
+namespace Jint.Native.Function
 {
     /// <summary>
     /// 
     /// </summary>
-    public class ScriptFunctionInstance : FunctionInstance
+    public sealed class ScriptFunctionInstance : FunctionInstance, IConstructor
     {
         private readonly Engine _engine;
         private readonly Statement _body;
@@ -35,7 +33,7 @@ namespace Jint.Runtime
             DefineOwnProperty("prototype", new DataDescriptor(functionPrototype) { Writable = true, Enumerable = true, Configurable = true }, false);
         }
 
-        public override dynamic Call(object thisObject, dynamic[] arguments)
+        public override object Call(object thisObject, object[] arguments)
         {
             // todo: http://www.ecma-international.org/ecma-262/5.1/#sec-13.2.1
 
@@ -69,9 +67,9 @@ namespace Jint.Runtime
             return result;
         }
 
-        public virtual ObjectInstance Construct(dynamic[] arguments)
+        public ObjectInstance Construct(object[] arguments)
         {
-            /// todo: http://www.ecma-international.org/ecma-262/5.1/#sec-13.2.2
+            // todo: http://www.ecma-international.org/ecma-262/5.1/#sec-13.2.2
 
             var instance = new FunctionShim(_engine, this.Prototype, null, null);
             return instance;

+ 10 - 0
Jint/Native/IConstructor.cs

@@ -0,0 +1,10 @@
+using Jint.Native.Object;
+
+namespace Jint.Native
+{
+    public interface IConstructor
+    {
+        object Call(object thisObject, object[] arguments);
+        ObjectInstance Construct(object[] arguments);
+    }
+}

+ 2 - 2
Jint/Native/Null.cs

@@ -4,7 +4,7 @@ namespace Jint.Native
 {
     public sealed class Null : IPrimitiveType
     {
-        public static dynamic Instance = new Null();
+        public static object Instance = new Null();
 
         private Null()
         {   
@@ -17,7 +17,7 @@ namespace Jint.Native
 
         public TypeCode TypeCode
         {
-            get { return TypeCode.DBNull; }
+            get { return TypeCode.Empty; }
         }
 
         public object PrimitiveValue

+ 3 - 3
Jint/Native/Number/NumberConstructor.cs

@@ -5,7 +5,7 @@ using Jint.Runtime.Descriptors;
 
 namespace Jint.Native.Number
 {
-    public class NumberConstructor : FunctionInstance
+    public sealed class NumberConstructor : FunctionInstance, IConstructor
     {
         private readonly Engine _engine;
 
@@ -20,7 +20,7 @@ namespace Jint.Native.Number
 
         }
 
-        public override dynamic Call(object thisObject, dynamic[] arguments)
+        public override object Call(object thisObject, object[] arguments)
         {
             return Construct(arguments);
         }
@@ -30,7 +30,7 @@ namespace Jint.Native.Number
         /// </summary>
         /// <param name="arguments"></param>
         /// <returns></returns>
-        public virtual ObjectInstance Construct(dynamic[] arguments)
+        public ObjectInstance Construct(object[] arguments)
         {
             return Construct(arguments.Length > 0 ? TypeConverter.ToNumber(arguments[0]) : 0);
         }

+ 1 - 1
Jint/Native/Number/NumberInstance.cs

@@ -3,7 +3,7 @@ using Jint.Native.Object;
 
 namespace Jint.Native.Number
 {
-    public class NumberInstance : ObjectInstance, IPrimitiveType
+    public sealed class NumberInstance : ObjectInstance, IPrimitiveType
     {
         public NumberInstance(ObjectInstance prototype)
             : base(prototype)

+ 3 - 4
Jint/Native/Object/ObjectConstructor.cs

@@ -1,12 +1,11 @@
 using System;
 using Jint.Native.Function;
-using Jint.Runtime;
 using Jint.Runtime.Descriptors;
 using Jint.Runtime.Interop;
 
 namespace Jint.Native.Object
 {
-    public class ObjectConstructor : FunctionInstance
+    public sealed class ObjectConstructor : FunctionInstance, IConstructor
     {
         private readonly Engine _engine;
 
@@ -17,12 +16,12 @@ namespace Jint.Native.Object
             engine.RootFunction.DefineOwnProperty("toString", new DataDescriptor(new BuiltInPropertyWrapper(engine, (Func<ObjectInstance, string>)ToString, engine.RootFunction)), false);
         }
 
-        public override dynamic Call(object thisObject, dynamic[] arguments)
+        public override object Call(object thisObject, object[] arguments)
         {
             return Undefined.Instance;
         }
 
-        public ObjectInstance Construct(dynamic[] arguments)
+        public ObjectInstance Construct(object[] arguments)
         {
             var instance = new ObjectInstance(this.Prototype);
 

+ 16 - 16
Jint/Native/Object/ObjectInstance.cs

@@ -1,7 +1,5 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
 using Jint.Native.Errors;
-using Jint.Runtime;
 using Jint.Runtime.Descriptors;
 
 namespace Jint.Native.Object
@@ -10,7 +8,7 @@ namespace Jint.Native.Object
     {
         public ObjectInstance(ObjectInstance prototype)
         {
-            Properties = new SortedList<string, PropertyDescriptor>();
+            Properties = new Dictionary<string, PropertyDescriptor>();
             Extensible = true;
             Prototype = prototype;
             DefineOwnProperty("prototype", new DataDescriptor(prototype), false);
@@ -54,7 +52,7 @@ namespace Jint.Native.Object
                 return Undefined.Instance;
             }
 
-            return desc.Get();
+            return ((PropertyDescriptor)desc).Get();
         }
 
         public void Set(string name, object value)
@@ -77,7 +75,7 @@ namespace Jint.Native.Object
         /// </summary>
         /// <param name="propertyName"></param>
         /// <returns></returns>
-        public dynamic GetOwnProperty(string propertyName)
+        public object GetOwnProperty(string propertyName)
         {
             PropertyDescriptor value;
             if (Properties.TryGetValue(propertyName, out value))
@@ -93,7 +91,7 @@ namespace Jint.Native.Object
         /// </summary>
         /// <param name="propertyName"></param>
         /// <returns></returns>
-        public dynamic GetProperty(string propertyName)
+        public object GetProperty(string propertyName)
         {
             var prop = GetOwnProperty(propertyName);
 
@@ -130,7 +128,7 @@ namespace Jint.Native.Object
                 return;
             }
 
-            PropertyDescriptor ownDesc = GetOwnProperty(propertyName);
+            var ownDesc = (PropertyDescriptor)GetOwnProperty(propertyName);
 
             if (ownDesc.IsDataDescriptor())
             {
@@ -138,7 +136,7 @@ namespace Jint.Native.Object
                 return;
             }
 
-            var desc = GetProperty(propertyName);
+            var desc = (PropertyDescriptor)GetProperty(propertyName);
 
             if (desc.IsAccessorDescriptor())
             {
@@ -162,16 +160,17 @@ namespace Jint.Native.Object
         public bool CanPut(string propertyName)
         {
             var desc = GetOwnProperty(propertyName);
-
+            var pd = desc as PropertyDescriptor;
             if (desc != Undefined.Instance)
             {
-                if (desc.IsAccessorDescriptor())
+
+                if (pd.IsAccessorDescriptor())
                 {
                     return true;
                 }
                 else
                 {
-                    return desc.Writable;
+                    return pd.Writable;
                 }
             }
 
@@ -180,7 +179,7 @@ namespace Jint.Native.Object
                 return Extensible;
             }
 
-            var inherited = Prototype.GetProperty(propertyName);
+            var inherited = (PropertyDescriptor)Prototype.GetProperty(propertyName);
 
             if (inherited == Undefined.Instance)
             {
@@ -192,7 +191,7 @@ namespace Jint.Native.Object
                 return true;
             }
 
-            if (desc.IsAccessorDescriptor())
+            if (pd.IsAccessorDescriptor())
             {
                 return true;
             }
@@ -232,13 +231,14 @@ namespace Jint.Native.Object
         public bool Delete(string propertyName, bool throwOnError)
         {
             var desc = GetOwnProperty(propertyName);
+            var pd = desc as PropertyDescriptor;
 
             if (desc == Undefined.Instance)
             {
                 return true;
             }
 
-            if (desc.Configurable)
+            if (pd.Configurable)
             {
                 Properties.Remove(propertyName);
                 return true;
@@ -297,7 +297,7 @@ namespace Jint.Native.Object
                 return true;
             }
 
-            PropertyDescriptor current = property;
+            var current = (PropertyDescriptor)property;
 
             if (!current.Configurable)
             {

+ 3 - 3
Jint/Native/String/StringConstructor.cs

@@ -5,7 +5,7 @@ using Jint.Runtime.Descriptors;
 
 namespace Jint.Native.String
 {
-    public class StringConstructor : FunctionInstance
+    public sealed class StringConstructor : FunctionInstance, IConstructor
     {
         private readonly Engine _engine;
 
@@ -20,7 +20,7 @@ namespace Jint.Native.String
 
         }
 
-        public override dynamic Call(object thisObject, dynamic[] arguments)
+        public override object Call(object thisObject, object[] arguments)
         {
             return Construct(arguments);
         }
@@ -30,7 +30,7 @@ namespace Jint.Native.String
         /// </summary>
         /// <param name="arguments"></param>
         /// <returns></returns>
-        public virtual ObjectInstance Construct(dynamic[] arguments)
+        public ObjectInstance Construct(object[] arguments)
         {
             return Construct(arguments.Length > 0 ? TypeConverter.ToString(arguments[0]) : "");
         }

+ 1 - 1
Jint/Native/String/StringInstance.cs

@@ -3,7 +3,7 @@ using Jint.Native.Object;
 
 namespace Jint.Native.String
 {
-    public class StringInstance : ObjectInstance, IPrimitiveType
+    public sealed class StringInstance : ObjectInstance, IPrimitiveType
     {
         public StringInstance(ObjectInstance prototype)
             : base(prototype)

+ 1 - 1
Jint/Native/Undefined.cs

@@ -17,7 +17,7 @@ namespace Jint.Native
 
         public TypeCode TypeCode
         {
-            get { return TypeCode.DBNull; }
+            get { return TypeCode.Empty; }
         }
 
         public object PrimitiveValue

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 15 - 16
Jint/Parser/JavascriptParser.cs


+ 4 - 10
Jint/Properties/AssemblyInfo.cs

@@ -1,11 +1,12 @@
-using System.Reflection;
+using System.Resources;
+using System.Reflection;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 
 // General Information about an assembly is controlled through the following 
 // set of attributes. Change these attribute values to modify the information
 // associated with an assembly.
-[assembly: AssemblyTitle("Jint")]
+[assembly: AssemblyTitle("PortableClassLibrary1")]
 [assembly: AssemblyDescription("")]
 [assembly: AssemblyConfiguration("")]
 [assembly: AssemblyCompany("")]
@@ -13,14 +14,7 @@ using System.Runtime.InteropServices;
 [assembly: AssemblyCopyright("Copyright © Sébastien Ros 2013")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible 
-// to COM components.  If you need to access a type in this assembly from 
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("34891930-6ad9-4a32-a4fb-6cb094cac6ea")]
+[assembly: NeutralResourcesLanguage("en")]
 
 // Version information for an assembly consists of the following four values:
 //

+ 1 - 1
Jint/Runtime/Descriptors/Specialized/MethodProperty.cs

@@ -2,7 +2,7 @@
 
 namespace Jint.Runtime.Descriptors.Specialized
 {
-    public class MethodProperty : PropertyDescriptor
+    public sealed class MethodProperty : PropertyDescriptor
     {
         private readonly Engine _engine;
         private readonly Action<object> _setter;

+ 1 - 1
Jint/Runtime/Environments/DeclarativeEnvironmentRecord.cs

@@ -9,7 +9,7 @@ namespace Jint.Runtime.Environments
     /// </summary>
     public sealed class DeclarativeEnvironmentRecord : EnvironmentRecord
     {
-        private readonly IDictionary<string, object> _bindings = new SortedList<string, object>();
+        private readonly IDictionary<string, object> _bindings = new Dictionary<string, object>();
 
         public override bool HasBinding(string name)
         {

+ 117 - 49
Jint/Runtime/ExpressionIntepreter.cs

@@ -18,26 +18,27 @@ namespace Jint.Runtime
             _engine = engine;
         }
 
-        private dynamic EvaluateExpression(Expression expression)
+        private object EvaluateExpression(Expression expression)
         {
             return _engine.EvaluateExpression(expression);
         }
 
-        public dynamic EvaluateConditionalExpression(ConditionalExpression conditionalExpression)
+        public object EvaluateConditionalExpression(ConditionalExpression conditionalExpression)
         {
             var test = _engine.EvaluateExpression(conditionalExpression.Test);
-            var evaluate = test ? conditionalExpression.Consequent : conditionalExpression.Alternate;
+            var evaluate = TypeConverter.ToBoolean(test) ? conditionalExpression.Consequent : conditionalExpression.Alternate;
             
             return _engine.EvaluateExpression(evaluate);
         }
 
-        public dynamic EvaluateAssignmentExpression(AssignmentExpression assignmentExpression)
+        public object EvaluateAssignmentExpression(AssignmentExpression assignmentExpression)
         {
-            dynamic right = _engine.GetValue(EvaluateExpression(assignmentExpression.Right));
+            object right = _engine.GetValue(EvaluateExpression(assignmentExpression.Right));
 
-            Reference r = EvaluateExpression(assignmentExpression.Left);
+            var r = (Reference)EvaluateExpression(assignmentExpression.Left);
 
-            dynamic value = Undefined.Instance;
+            object value = _engine.GetValue(r);
+            var type = TypeConverter.GetType(value);
 
             switch (assignmentExpression.Operator)
             {
@@ -46,19 +47,44 @@ namespace Jint.Runtime
                     break;
 
                 case "+=":
-                    value = _engine.GetValue(r) + right;
+                    switch (type)
+                    {
+                        case TypeCode.String:
+                            value = TypeConverter.ToString(_engine.GetValue(r)) + right;
+                            break;
+
+                        case TypeCode.Double:
+                            value = TypeConverter.ToNumber(_engine.GetValue(r)) + TypeConverter.ToNumber(right);
+                            break;
+                    }
+                    
                     break;
 
                 case "-=":
-                    value = _engine.GetValue(r) - right;
+                    switch (type)
+                    {
+                        case TypeCode.Double:
+                            value = TypeConverter.ToNumber(_engine.GetValue(r)) + TypeConverter.ToNumber(right);
+                            break;
+                    }
                     break;
 
                 case "*=":
-                    value = _engine.GetValue(r) * right;
+                    switch (type)
+                    {
+                        case TypeCode.Double:
+                            value = TypeConverter.ToNumber(_engine.GetValue(r)) *TypeConverter.ToNumber(right);
+                            break;
+                    }
                     break;
 
                 case "/=":
-                    value = _engine.GetValue(r) / right;
+                    switch (type)
+                    {
+                        case TypeCode.Double:
+                            value = TypeConverter.ToNumber(_engine.GetValue(r)) / TypeConverter.ToNumber(right);
+                            break;
+                    }
                     break;
             }
 
@@ -67,30 +93,50 @@ namespace Jint.Runtime
             return value;
         }
 
-        private static dynamic add(dynamic left, dynamic right)
+        public object EvaluateBinaryExpression(BinaryExpression expression)
         {
-            return left + right;
-        }
-
-        public dynamic EvaluateBinaryExpression(BinaryExpression expression)
-        {
-            dynamic left = _engine.GetValue(EvaluateExpression(expression.Left));
-            dynamic right = _engine.GetValue(EvaluateExpression(expression.Right));
-            dynamic value;
+            object left = _engine.GetValue(EvaluateExpression(expression.Left));
+            object right = _engine.GetValue(EvaluateExpression(expression.Right));
+            object value = Undefined.Instance;
+            var type = TypeConverter.GetType(left);
 
             switch (expression.Operator)
             {
                 case "+":
-                    value = left + right;
+                    switch (type)
+                    {
+                        case TypeCode.String:
+                            value = TypeConverter.ToString(left) + right;
+                            break;
+
+                        case TypeCode.Double:
+                            value = TypeConverter.ToNumber(left) + TypeConverter.ToNumber(right);
+                            break;
+                    }
                     break;
                 case "-":
-                     value = left - right;
+                    switch (type)
+                    {
+                        case TypeCode.Double:
+                            value = TypeConverter.ToNumber(left) - TypeConverter.ToNumber(right);
+                            break;
+                    }
                     break;
                 case "*":
-                    value = left * right;
+                    switch (type)
+                    {
+                        case TypeCode.Double:
+                            value = TypeConverter.ToNumber(left) * TypeConverter.ToNumber(right);
+                            break;
+                    }
                     break;
                 case "/":
-                    value = left / right;
+                    switch (type)
+                    {
+                        case TypeCode.Double:
+                            value = TypeConverter.ToNumber(left) / TypeConverter.ToNumber(right);
+                            break;
+                    }
                     break;
                 case "==":
                     value = left.Equals(right);
@@ -99,23 +145,44 @@ namespace Jint.Runtime
                     value = !left.Equals(right);
                     break;
                 case ">":
-                    value = left > right;
+                    switch (type)
+                    {
+                        case TypeCode.Double:
+                            value = TypeConverter.ToNumber(left) > TypeConverter.ToNumber(right);
+                            break;
+                    }
                     break;
+
                 case ">=":
-                    value = left >= right;
+                    switch (type)
+                    {
+                        case TypeCode.Double:
+                            value = TypeConverter.ToNumber(left) >= TypeConverter.ToNumber(right);
+                            break;
+                    }
                     break;
                 case "<":
-                    value = left < right;
+                    switch (type)
+                    {
+                        case TypeCode.Double:
+                            value = TypeConverter.ToNumber(left) < TypeConverter.ToNumber(right);
+                            break;
+                    }
                     break;
                 case "<=":
-                    value = left <= right;
+                    switch (type)
+                    {
+                        case TypeCode.Double:
+                            value = TypeConverter.ToNumber(left) <= TypeConverter.ToNumber(right);
+                            break;
+                    }
                     break;
                 case "===":
                     value = left.GetType() == right.GetType() && left == right;
                     break;
                 case "instanceof":
-                    FunctionInstance f = right;
-                    value = right.HasInstance(left);
+                    var f = (FunctionInstance)right;
+                    value = f.HasInstance(left);
                     break;
                 default:
                     throw new NotImplementedException("");
@@ -124,7 +191,7 @@ namespace Jint.Runtime
             return value;
         }
 
-        public dynamic EvaluateIdentifier(Identifier identifier)
+        public object EvaluateIdentifier(Identifier identifier)
         {
             switch (identifier.Name)
             {
@@ -137,12 +204,12 @@ namespace Jint.Runtime
             return _engine.CurrentExecutionContext.LexicalEnvironment.GetIdentifierReference(identifier.Name, false);
         }
 
-        public dynamic EvaluateLiteral(Literal literal)
+        public object EvaluateLiteral(Literal literal)
         {
             return literal.Value;
         }
 
-        public dynamic EvaluateObjectExpression(ObjectExpression objectExpression)
+        public object EvaluateObjectExpression(ObjectExpression objectExpression)
         {
             var value = _engine.Object.Construct(new dynamic[0]);
 
@@ -167,7 +234,7 @@ namespace Jint.Runtime
             return value;
         }
 
-        public dynamic EvaluateMemberExpression(MemberExpression memberExpression)
+        public object EvaluateMemberExpression(MemberExpression memberExpression)
         {
             var baseValue = _engine.GetValue(EvaluateExpression(memberExpression.Object));
 
@@ -179,7 +246,7 @@ namespace Jint.Runtime
             return new Reference(baseValue, propertyName, false);
         }
 
-        public dynamic EvaluateFunctionExpression(FunctionExpression functionExpression)
+        public object EvaluateFunctionExpression(FunctionExpression functionExpression)
         {
             string identifier = functionExpression.Id != null ? functionExpression.Id.Name : null;
             return new ScriptFunctionInstance(
@@ -193,28 +260,29 @@ namespace Jint.Runtime
                 );
         }
 
-        public dynamic EvaluateCallExpression(CallExpression callExpression)
+        public object EvaluateCallExpression(CallExpression callExpression)
         {
             /// todo: read the spec as this is made up
             
             var arguments = callExpression.Arguments.Select(EvaluateExpression);
-            var r = EvaluateExpression(callExpression.Callee);
-            if (r is Reference)
+            var result = EvaluateExpression(callExpression.Callee);
+            var r = result as Reference;
+            if (r != null)
             {
                 // x.hasOwnProperty
-                FunctionInstance callee = _engine.GetValue(r);
+                var callee = (FunctionInstance)_engine.GetValue(r);
                 return callee.Call(r.GetBase(), arguments.ToArray());
             }
             else
             {
                 // assert(...)
-                FunctionInstance callee = _engine.GetValue(r);
+                var callee = (FunctionInstance)_engine.GetValue(result);
                 return callee.Call(_engine.CurrentExecutionContext.ThisBinding, arguments.ToArray());
             }
 
         }
 
-        public dynamic EvaluateSequenceExpression(SequenceExpression sequenceExpression)
+        public object EvaluateSequenceExpression(SequenceExpression sequenceExpression)
         {
             foreach (var expression in sequenceExpression.Expressions)
             {
@@ -224,9 +292,9 @@ namespace Jint.Runtime
             return Undefined.Instance;
         }
 
-        public dynamic EvaluateUpdateExpression(UpdateExpression updateExpression)
+        public object EvaluateUpdateExpression(UpdateExpression updateExpression)
         {
-            Reference r = EvaluateExpression(updateExpression.Argument);
+            var r = EvaluateExpression(updateExpression.Argument) as Reference;
 
             var value = _engine.GetValue(r);
             var old = value;
@@ -234,10 +302,10 @@ namespace Jint.Runtime
             switch (updateExpression.Operator)
             {
                 case "++" :
-                    value += 1;
+                    value = TypeConverter.ToNumber(value) + 1;
                     break;
                 case "--":
-                    value -= 1;
+                    value = TypeConverter.ToNumber(value) - 1;
                     break;
                 default:
                     throw new ArgumentException();
@@ -248,17 +316,17 @@ namespace Jint.Runtime
             return updateExpression.Prefix ? value : old;
         }
 
-        public dynamic EvaluateThisExpression(ThisExpression thisExpression)
+        public object EvaluateThisExpression(ThisExpression thisExpression)
         {
             return _engine.CurrentExecutionContext.ThisBinding;
         }
 
-        public dynamic EvaluateNewExpression(NewExpression newExpression)
+        public object EvaluateNewExpression(NewExpression newExpression)
         {
             var arguments = newExpression.Arguments.Select(EvaluateExpression).ToArray();
             
             // todo: optimize by defining a common abstract class or interface
-            dynamic callee = _engine.GetValue(EvaluateExpression(newExpression.Callee));
+            var callee = (IConstructor)_engine.GetValue(EvaluateExpression(newExpression.Callee));
 
             // construct the new instance using the Function's constructor method
             var instance = callee.Construct(arguments);
@@ -269,7 +337,7 @@ namespace Jint.Runtime
             return instance;
         }
 
-        public dynamic EvaluateArrayExpression(ArrayExpression arrayExpression)
+        public object EvaluateArrayExpression(ArrayExpression arrayExpression)
         {
             var arguments = arrayExpression.Elements.Select(EvaluateExpression).ToArray();
 

+ 2 - 3
Jint/Runtime/Interop/BuiltInPropertyWrapper.cs

@@ -5,11 +5,10 @@ using Jint.Native.Object;
 
 namespace Jint.Runtime.Interop
 {
-
     /// <summary>
     /// Reprensents a Property wrapper for static methods representing built-in properties.
     /// </summary>
-    public class BuiltInPropertyWrapper : FunctionInstance
+    public sealed class BuiltInPropertyWrapper : FunctionInstance
     {
         private readonly Engine _engine;
         private readonly Delegate _d;
@@ -21,7 +20,7 @@ namespace Jint.Runtime.Interop
             _d = d;
         }
 
-        public override dynamic Call(object thisObject, dynamic[] arguments)
+        public override object Call(object thisObject, object[] arguments)
         {
             // initialize Return flag
             _engine.CurrentExecutionContext.Return = Undefined.Instance;

+ 2 - 2
Jint/Runtime/Interop/DelegateWrapper.cs

@@ -9,7 +9,7 @@ namespace Jint.Runtime.Interop
     /// Represents a FunctionInstance wrapper around a CLR method. This is used by user to pass
     /// custom methods to the engine.
     /// </summary>
-    public class DelegateWrapper : FunctionInstance
+    public sealed class DelegateWrapper : FunctionInstance
     {
         private readonly Engine _engine;
         private readonly Delegate _d;
@@ -20,7 +20,7 @@ namespace Jint.Runtime.Interop
             _d = d;
         }
 
-        public override dynamic Call(object thisObject, dynamic[] arguments)
+        public override object Call(object thisObject, object[] arguments)
         {
             // initialize Return flag
             _engine.CurrentExecutionContext.Return = Undefined.Instance;

+ 7 - 6
Jint/Runtime/StatementInterpreter.cs

@@ -1,5 +1,6 @@
 using System.Linq;
 using Jint.Native;
+using Jint.Native.Function;
 using Jint.Parser.Ast;
 using Jint.Runtime.Environments;
 
@@ -38,7 +39,7 @@ namespace Jint.Runtime
 
             foreach (var declaration in statement.Declarations)
             {
-                dynamic value = Undefined.Instance;
+                object value = Undefined.Instance;
 
                 if (declaration.Init != null)
                 {
@@ -65,7 +66,7 @@ namespace Jint.Runtime
             do
             {
                 result = ExecuteStatement(doWhileStatement.Body);
-                test = _engine.EvaluateExpression(doWhileStatement.Test);
+                test = TypeConverter.ToBoolean(_engine.EvaluateExpression(doWhileStatement.Test));
             } while (test);
 
             return result;
@@ -144,7 +145,7 @@ namespace Jint.Runtime
         public object ExecuteIfStatement(IfStatement ifStatement)
         {
             object result = null;
-            var test = _engine.EvaluateExpression(ifStatement.Test);
+            var test = TypeConverter.ToBoolean(_engine.EvaluateExpression(ifStatement.Test));
 
             if (test)
             {
@@ -162,12 +163,12 @@ namespace Jint.Runtime
         {
             object result = null;
 
-            bool test = _engine.EvaluateExpression(whileStatement.Test);
+            bool test = TypeConverter.ToBoolean(_engine.EvaluateExpression(whileStatement.Test));
 
             while(test)
             {
                 result = ExecuteStatement(whileStatement.Body);
-                test = _engine.EvaluateExpression(whileStatement.Test);
+                test = TypeConverter.ToBoolean(_engine.EvaluateExpression(whileStatement.Test));
             }
 
             return result;
@@ -191,7 +192,7 @@ namespace Jint.Runtime
                 result = _engine.EvaluateExpression(forStatement.Init.As<Expression>());
             }
 
-            while (_engine.EvaluateExpression(forStatement.Test))
+            while (TypeConverter.ToBoolean(_engine.EvaluateExpression(forStatement.Test)))
             {
                 _engine.ExecuteStatement(forStatement.Body);
                 _engine.EvaluateExpression(forStatement.Update);

+ 31 - 6
Jint/Runtime/TypeConverter.cs

@@ -69,7 +69,7 @@ namespace Jint.Runtime
         /// </summary>
         /// <param name="o"></param>
         /// <returns></returns>
-        public int ToInteger(object o)
+        public static int ToInteger(object o)
         {
             return (int) o;
         }
@@ -79,7 +79,7 @@ namespace Jint.Runtime
         /// </summary>
         /// <param name="o"></param>
         /// <returns></returns>
-        public int ToInt32(object o)
+        public static int ToInt32(object o)
         {
             return (int)o;
         }
@@ -89,7 +89,7 @@ namespace Jint.Runtime
         /// </summary>
         /// <param name="o"></param>
         /// <returns></returns>
-        public uint ToUint32(object o)
+        public static uint ToUint32(object o)
         {
             return (uint)o;
         }
@@ -100,7 +100,7 @@ namespace Jint.Runtime
         /// </summary>
         /// <param name="o"></param>
         /// <returns></returns>
-        public ushort ToUint16(object o)
+        public static ushort ToUint16(object o)
         {
             return (ushort)o;
         }
@@ -110,12 +110,12 @@ namespace Jint.Runtime
         /// </summary>
         /// <param name="o"></param>
         /// <returns></returns>
-        public string ToString(object o)
+        public static string ToString(object o)
         {
             return (string)o;
         }
 
-        public ObjectInstance ToObject(Engine engine, object value)
+        public static ObjectInstance ToObject(Engine engine, object value)
         {
             var o = value as ObjectInstance;
             if (o != null)
@@ -159,5 +159,30 @@ namespace Jint.Runtime
 
             throw new TypeError();
         }
+
+        public static TypeCode GetType(object value)
+        {
+            if (value == null || value == Undefined.Instance || value == Null.Instance)
+            {
+                return TypeCode.Empty;
+            }
+
+            if (value is string)
+            {
+                return TypeCode.String;
+            }
+
+            if (value is double || value is int || value is uint || value is ushort)
+            {
+                return TypeCode.Double;
+            }
+
+            if (value is bool)
+            {
+                return TypeCode.Boolean;
+            }
+
+            return TypeCode.Object;
+        }
     }
 }

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác