Переглянути джерело

Adding netstandard1.3 target

Sebastien Ros 8 роки тому
батько
коміт
cf4abb8204

+ 2 - 0
.gitignore

@@ -154,3 +154,5 @@ $RECYCLE.BIN/
 .DS_Store
 Jint.sln.ide/*
 /Jint.sln.GhostDoc.xml
+.vs
+project.lock.json

+ 2 - 3
Jint.Benchmark/Jint.Benchmark.csproj

@@ -75,12 +75,11 @@
     <None Include="packages.config" />
   </ItemGroup>
   <ItemGroup>
-    <ProjectReference Include="..\Jint\Jint.csproj">
-      <Project>{678738da-f723-4920-b9e5-cad667104bda}</Project>
+    <ProjectReference Include="..\Jint\Jint.xproj">
+      <Project>{4b6f353a-5d01-407d-9dc8-96d1fd4f7052}</Project>
       <Name>Jint</Name>
     </ProjectReference>
   </ItemGroup>
-  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

+ 4 - 4
Jint.Benchmark/Program.cs

@@ -14,11 +14,11 @@ namespace Jint.Benchmark
             if(o.Blah != 'bar42.0001') throw TypeError;
 
             function fib(n){
-                if(n<2) { 
-                    return n; 
+                if(n<2) {
+                    return n;
                 }
-    
-                return fib(n-1) + fib(n-2);  
+
+                return fib(n-1) + fib(n-2);
             }
 
             if(fib(3) != 2) throw TypeError;

+ 2 - 2
Jint.Repl/Jint.Repl.csproj

@@ -48,8 +48,8 @@
     <None Include="App.config" />
   </ItemGroup>
   <ItemGroup>
-    <ProjectReference Include="..\Jint\Jint.csproj">
-      <Project>{678738DA-F723-4920-B9E5-CAD667104BDA}</Project>
+    <ProjectReference Include="..\Jint\Jint.xproj">
+      <Project>{4b6f353a-5d01-407d-9dc8-96d1fd4f7052}</Project>
       <Name>Jint</Name>
     </ProjectReference>
   </ItemGroup>

+ 6 - 6
Jint.Tests.CommonScripts/Jint.Tests.CommonScripts.csproj

@@ -59,18 +59,18 @@
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="SunSpiderTests.cs" />
   </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\Jint\Jint.csproj">
-      <Project>{678738da-f723-4920-b9e5-cad667104bda}</Project>
-      <Name>Jint</Name>
-    </ProjectReference>
-  </ItemGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
   <ItemGroup>
     <None Include="packages.config" />
   </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\Jint\Jint.xproj">
+      <Project>{4b6f353a-5d01-407d-9dc8-96d1fd4f7052}</Project>
+      <Name>Jint</Name>
+    </ProjectReference>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

+ 6 - 6
Jint.Tests.Ecma/Jint.Tests.Ecma.csproj

@@ -467,12 +467,6 @@
     <Compile Include="Ecma\9.9.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\Jint\Jint.csproj">
-      <Project>{a2707cfd-e37d-4b88-8fc2-238d4c1dfd01}</Project>
-      <Name>Jint</Name>
-    </ProjectReference>
-  </ItemGroup>
   <ItemGroup>
     <Content Include="TestCases\ch06\6.1.js" />
     <Content Include="TestCases\ch07\7.2\S7.2_A1.1_T1.js" />
@@ -12048,6 +12042,12 @@
   <ItemGroup>
     <None Include="packages.config" />
   </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\Jint\Jint.xproj">
+      <Project>{4b6f353a-5d01-407d-9dc8-96d1fd4f7052}</Project>
+      <Name>Jint</Name>
+    </ProjectReference>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

+ 6 - 6
Jint.Tests/Jint.Tests.csproj

@@ -87,12 +87,6 @@
   <ItemGroup>
     <EmbeddedResource Include="Runtime\Scripts\Scratch.js" />
   </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\Jint\Jint.csproj">
-      <Project>{678738da-f723-4920-b9e5-cad667104bda}</Project>
-      <Name>Jint</Name>
-    </ProjectReference>
-  </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="Parser\Scripts\underscore.js" />
   </ItemGroup>
@@ -114,6 +108,12 @@
   <ItemGroup>
     <EmbeddedResource Include="Parser\Scripts\handlebars.js" />
   </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\Jint\Jint.xproj">
+      <Project>{4b6f353a-5d01-407d-9dc8-96d1fd4f7052}</Project>
+      <Name>Jint</Name>
+    </ProjectReference>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

+ 8 - 8
Jint.sln

@@ -1,7 +1,7 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.30723.0
+# Visual Studio 14
+VisualStudioVersion = 14.0.25420.1
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jint.Tests", "Jint.Tests\Jint.Tests.csproj", "{37C7D4E0-8770-4E2A-8B6D-E53087868354}"
 EndProject
@@ -9,8 +9,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jint.Benchmark", "Jint.Benc
 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
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jint.Repl", "Jint.Repl\Jint.Repl.csproj", "{A69FD3C5-F2B0-4055-A518-F4173EBA5E4D}"
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{90E4A7EF-8DB1-49D4-89F9-512999531AE8}"
@@ -22,6 +20,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{90E4A7
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jint.Tests.CommonScripts", "Jint.Tests.CommonScripts\Jint.Tests.CommonScripts.csproj", "{9A78C21A-8887-4B1B-9AFE-246B53EE23B4}"
 EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Jint", "Jint\Jint.xproj", "{4B6F353A-5D01-407D-9DC8-96D1FD4F7052}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -40,10 +40,6 @@ 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
 		{A69FD3C5-F2B0-4055-A518-F4173EBA5E4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{A69FD3C5-F2B0-4055-A518-F4173EBA5E4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{A69FD3C5-F2B0-4055-A518-F4173EBA5E4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -52,6 +48,10 @@ Global
 		{9A78C21A-8887-4B1B-9AFE-246B53EE23B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{9A78C21A-8887-4B1B-9AFE-246B53EE23B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{9A78C21A-8887-4B1B-9AFE-246B53EE23B4}.Release|Any CPU.Build.0 = Release|Any CPU
+		{4B6F353A-5D01-407D-9DC8-96D1FD4F7052}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{4B6F353A-5D01-407D-9DC8-96D1FD4F7052}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{4B6F353A-5D01-407D-9DC8-96D1FD4F7052}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{4B6F353A-5D01-407D-9DC8-96D1FD4F7052}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 21 - 0
Jint/Jint.xproj

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
+    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+  </PropertyGroup>
+
+  <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>4b6f353a-5d01-407d-9dc8-96d1fd4f7052</ProjectGuid>
+    <RootNamespace>Jint</RootNamespace>
+    <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
+    <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
+    <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
+  </PropertyGroup>
+
+  <PropertyGroup>
+    <SchemaVersion>2.0</SchemaVersion>
+  </PropertyGroup>
+  <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
+</Project>

+ 10 - 10
Jint/Native/Array/ArrayPrototype.cs

@@ -21,7 +21,7 @@ namespace Jint.Native.Array
         {
             var obj = new ArrayPrototype(engine)
                 {
-                    Extensible = true, 
+                    Extensible = true,
                     Prototype = engine.Object.PrototypeObject
                 };
 
@@ -387,11 +387,11 @@ namespace Jint.Native.Array
                 var fromPresent = o.HasProperty(from);
                 if (fromPresent)
                 {
-                    var fromValue = o.Get(from); 
+                    var fromValue = o.Get(from);
                     a.DefineOwnProperty(k.ToString(), new PropertyDescriptor(fromValue, true, true, true), false);
                 }
             }
-            
+
             var items = arguments.Skip(2).ToArray();
             if (items.Length < actualDeleteCount)
             {
@@ -477,7 +477,7 @@ namespace Jint.Native.Array
         {
             if (!thisObj.IsObject())
             {
-                throw new JavaScriptException(Engine.TypeError, "Array.prorotype.sort can only be applied on objects");  
+                throw new JavaScriptException(Engine.TypeError, "Array.prorotype.sort can only be applied on objects");
             }
 
             var obj = thisObj.AsObject();
@@ -538,7 +538,7 @@ namespace Jint.Native.Array
                 };
 
             var array = Enumerable.Range(0, lenVal).Select(i => obj.Get(i.ToString())).ToArray();
-            
+
             // don't eat inner exceptions
             try
             {
@@ -650,7 +650,7 @@ namespace Jint.Native.Array
             var o = TypeConverter.ToObject(Engine, thisObj);
             var lenVal = o.Get("length");
             var len = TypeConverter.ToUint32(lenVal);
-            var middle = (uint)System.Math.Floor(len/2);
+            var middle = (uint)System.Math.Floor(len/2.0);
             uint lower = 0;
             while (lower != middle)
             {
@@ -694,7 +694,7 @@ namespace Jint.Native.Array
                 separator = ",";
             }
             var sep = TypeConverter.ToString(separator);
-            
+
             // as per the spec, this has to be called after ToString(separator)
             if (len == 0)
             {
@@ -803,7 +803,7 @@ namespace Jint.Native.Array
             // this is not in the specs, but is necessary in case the last element of the last
             // array doesn't exist, and thus the length would not be incremented
             a.DefineOwnProperty("length", new PropertyDescriptor(n, null, null, null), false);
-            
+
             return a;
         }
 
@@ -884,7 +884,7 @@ namespace Jint.Native.Array
         {
             ObjectInstance o = TypeConverter.ToObject(Engine, thisObject);
             var lenVal = TypeConverter.ToNumber(o.Get("length"));
-            
+
             // cast to double as we need to prevent an overflow
             double n = TypeConverter.ToUint32(lenVal);
             foreach (JsValue e in arguments)
@@ -894,7 +894,7 @@ namespace Jint.Native.Array
             }
 
             o.Put("length", n, true);
-            
+
             return n;
         }
 

+ 2 - 1
Jint/Native/JsValue.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Diagnostics;
 using System.Diagnostics.Contracts;
 using System.Dynamic;
+using System.Reflection;
 using Jint.Native.Array;
 using Jint.Native.Boolean;
 using Jint.Native.Date;
@@ -348,7 +349,7 @@ namespace Jint.Native
                 return new DelegateWrapper(engine, d);
             }
 
-            if (value.GetType().IsEnum)
+            if (value.GetType().IsEnum())
             {
                 return new JsValue((Int32)value);
             }

+ 3 - 0
Jint/Parser/ParserException.cs

@@ -8,7 +8,10 @@ namespace Jint.Parser
         public string Description;
         public int Index;
         public int LineNumber;
+
+#if PORTABLE
         public string Source;
+#endif
 
         public ParserException(string message) : base(message)
         {

+ 65 - 0
Jint/ReflectionExtensions.cs

@@ -0,0 +1,65 @@
+#if NETSTANDARD1_3
+using System;
+using System.Linq;
+using System.Reflection;
+
+namespace Jint
+{
+    internal static class ReflectionExtensions
+    {
+        internal static bool IsEnum(this Type type)
+        {
+            return type.GetTypeInfo().IsEnum;
+        }
+
+        internal static bool IsGenericType(this Type type)
+        {
+            return type.GetTypeInfo().IsGenericType;
+        }
+
+        internal static bool IsValueType(this Type type)
+        {
+            return type.GetTypeInfo().IsValueType;
+        }
+
+        internal static bool HasAttribute<T>(this ParameterInfo member) where T : Attribute
+        {
+            return member.GetCustomAttributes<T>().Any();
+        }
+    }
+}
+#else
+using System;
+using System.Reflection;
+
+namespace Jint
+{
+    internal static class ReflectionExtensions
+    {
+        internal static bool IsEnum(this Type type)
+        {
+            return type.IsEnum;
+        }
+
+        internal static bool IsGenericType(this Type type)
+        {
+            return type.IsGenericType;
+        }
+
+        internal static bool IsValueType(this Type type)
+        {
+            return type.IsValueType;
+        }
+
+        internal static bool HasAttribute<T>(this ParameterInfo member) where T : Attribute
+        {
+            return Attribute.IsDefined(member, typeof(T));
+        }
+
+        internal static MethodInfo GetMethodInfo(this Delegate d)
+        {
+            return d.Method;
+        }
+    }
+}
+#endif

+ 1 - 3
Jint/Runtime/Descriptors/Specialized/IndexDescriptor.cs

@@ -1,6 +1,5 @@
 using System;
 using System.Globalization;
-using System.Linq;
 using System.Reflection;
 using Jint.Native;
 
@@ -20,8 +19,7 @@ namespace Jint.Runtime.Descriptors.Specialized
             _item = item;
 
             // get all instance indexers with exactly 1 argument
-            var indexers = targetType
-                .GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
+            var indexers = targetType.GetProperties();
 
             // try to find first indexer having either public getter or setter with matching argument type
             foreach (var indexer in indexers)

+ 16 - 13
Jint/Runtime/Interop/DefaultTypeConverter.cs

@@ -14,7 +14,7 @@ namespace Jint.Runtime.Interop
         private static readonly Dictionary<string, bool> _knownConversions = new Dictionary<string, bool>();
         private static readonly object _lockObject = new object();
 
-        private static MethodInfo convertChangeType = typeof(System.Convert).GetMethod("ChangeType", new Type[] { typeof(object), typeof(Type), typeof(IFormatProvider) } );
+        private static MethodInfo convertChangeType = typeof(System.Convert).GetMethod("ChangeType", new Type[] { typeof(object), typeof(Type), typeof(IFormatProvider) });
         private static MethodInfo jsValueFromObject = typeof(JsValue).GetMethod("FromObject");
         private static MethodInfo jsValueToObject = typeof(JsValue).GetMethod("ToObject");
 
@@ -41,7 +41,7 @@ namespace Jint.Runtime.Interop
                 return value;
             }
 
-            if (type.IsEnum)
+            if (type.IsEnum())
             {
                 var integer = System.Convert.ChangeType(value, typeof(int), formatProvider);
                 if (integer == null)
@@ -58,7 +58,7 @@ namespace Jint.Runtime.Interop
             {
                 var function = (Func<JsValue, JsValue[], JsValue>)value;
 
-                if (type.IsGenericType)
+                if (type.IsGenericType())
                 {
                     var genericType = type.GetGenericTypeDefinition();
 
@@ -76,7 +76,7 @@ namespace Jint.Runtime.Interop
                         for (var i = 0; i < @params.Count(); i++)
                         {
                             var param = @params[i];
-                            if (param.Type.IsValueType)
+                            if (param.Type.IsValueType())
                             {
                                 var boxing = Expression.Convert(param, typeof(object));
                                 tmpVars[i] = Expression.Call(null, jsValueFromObject, Expression.Constant(_engine, typeof(Engine)), boxing);
@@ -90,7 +90,7 @@ namespace Jint.Runtime.Interop
 
                         var callExpresion = Expression.Block(Expression.Call(
                                                 Expression.Call(Expression.Constant(function.Target),
-                                                    function.Method,
+                                                    function.GetMethodInfo(),
                                                     Expression.Constant(JsValue.Undefined, typeof(JsValue)),
                                                     @vars),
                                                 jsValueToObject), Expression.Empty());
@@ -108,9 +108,10 @@ namespace Jint.Runtime.Interop
                             @params[i] = Expression.Parameter(genericArguments[i], genericArguments[i].Name + i);
                         }
 
-                        var @vars = 
-                            Expression.NewArrayInit(typeof(JsValue), 
-                                @params.Select(p => {
+                        var @vars =
+                            Expression.NewArrayInit(typeof(JsValue),
+                                @params.Select(p =>
+                                {
                                     var boxingExpression = Expression.Convert(p, typeof(object));
                                     return Expression.Call(null, jsValueFromObject, Expression.Constant(_engine, typeof(Engine)), boxingExpression);
                                 })
@@ -124,13 +125,13 @@ namespace Jint.Runtime.Interop
                                                     convertChangeType,
                                                     Expression.Call(
                                                             Expression.Call(Expression.Constant(function.Target),
-                                                                    function.Method,
+                                                                    function.GetMethodInfo(),
                                                                     Expression.Constant(JsValue.Undefined, typeof(JsValue)),
                                                                     @vars),
                                                             jsValueToObject),
                                                         Expression.Constant(returnType, typeof(Type)),
                                                         Expression.Constant(System.Globalization.CultureInfo.InvariantCulture, typeof(IFormatProvider))
-                                                        ),                            
+                                                        ),
                                                     returnType);
 
                         return Expression.Lambda(callExpresion, new ReadOnlyCollection<ParameterExpression>(@params)).Compile();
@@ -142,7 +143,7 @@ namespace Jint.Runtime.Interop
                     {
                         return (Action)(() => function(JsValue.Undefined, new JsValue[0]));
                     }
-                    else if (type.IsSubclassOf(typeof(System.MulticastDelegate)))
+                    else if (typeof(MulticastDelegate).IsAssignableFrom(type))
                     {
                         var method = type.GetMethod("Invoke");
                         var arguments = method.GetParameters();
@@ -157,7 +158,7 @@ namespace Jint.Runtime.Interop
                         var callExpression = Expression.Block(
                                                 Expression.Call(
                                                     Expression.Call(Expression.Constant(function.Target),
-                                                        function.Method,
+                                                        function.GetMethodInfo(),
                                                         Expression.Constant(JsValue.Undefined, typeof(JsValue)),
                                                         @vars),
                                                     typeof(JsValue).GetMethod("ToObject")),
@@ -184,8 +185,10 @@ namespace Jint.Runtime.Interop
                 return result;
             }
 
-            if (type.IsGenericType && type.GetGenericTypeDefinition()==typeof(Nullable<>))
+            if (type.IsGenericType() && type.GetGenericTypeDefinition() == typeof(Nullable<>))
+            {
                 type = Nullable.GetUnderlyingType(type);
+            }
 
             return System.Convert.ChangeType(value, type, formatProvider);
         }

+ 5 - 4
Jint/Runtime/Interop/DelegateWrapper.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Globalization;
 using System.Linq;
+using System.Reflection;
 using Jint.Native;
 using Jint.Native.Function;
 
@@ -22,9 +23,9 @@ namespace Jint.Runtime.Interop
 
         public override JsValue Call(JsValue thisObject, JsValue[] jsArguments)
         {
-            var parameterInfos = _d.Method.GetParameters();
+            var parameterInfos = _d.GetMethodInfo().GetParameters();
 
-            bool delegateContainsParamsArgument = parameterInfos.Any(p => Attribute.IsDefined(p, typeof(ParamArrayAttribute)));
+            bool delegateContainsParamsArgument = parameterInfos.Any(p => p.HasAttribute<ParamArrayAttribute>());
             int delegateArgumentsCount = parameterInfos.Length;
             int delegateNonParamsArgumentsCount = delegateContainsParamsArgument ? delegateArgumentsCount - 1 : delegateArgumentsCount;
 
@@ -54,7 +55,7 @@ namespace Jint.Runtime.Interop
             // assign null to parameters not provided
             for (var i = jsArgumentsWithoutParamsCount; i < delegateNonParamsArgumentsCount; i++)
             {
-                if (parameterInfos[i].ParameterType.IsValueType)
+                if (parameterInfos[i].ParameterType.IsValueType())
                 {
                     parameters[i] = Activator.CreateInstance(parameterInfos[i].ParameterType);
                 }
@@ -87,7 +88,7 @@ namespace Jint.Runtime.Interop
                             jsArguments[i].ToObject(),
                             paramsParameterType,
                             CultureInfo.InvariantCulture);
-                    }                    
+                    }
                 }
                 parameters[paramsArgumentIndex] = paramsParameter;
             }

+ 1 - 1
Jint/Runtime/Interop/MethodInfoFunctionInstance.cs

@@ -98,7 +98,7 @@ namespace Jint.Runtime.Interop
             foreach (var methodInfo in methodInfos)
             {
                 var parameters = methodInfo.GetParameters();
-                if (!parameters.Any(p => Attribute.IsDefined(p, typeof(ParamArrayAttribute))))
+                if (!parameters.Any(p => p.HasAttribute<ParamArrayAttribute>()))
                     continue;
 
                 var nonParamsArgumentsCount = parameters.Length - 1;

+ 9 - 4
Jint/Runtime/Interop/NamespaceReference.cs

@@ -1,7 +1,6 @@
 using System;
 using System.Collections.Generic;
 using System.Globalization;
-using System.Linq;
 using System.Reflection;
 using Jint.Native;
 using Jint.Native.Object;
@@ -46,7 +45,7 @@ namespace Jint.Runtime.Interop
 
         public JsValue Call(JsValue thisObject, JsValue[] arguments)
         {
-            // direct calls on a NamespaceReference constructor object is creating a generic type 
+            // direct calls on a NamespaceReference constructor object is creating a generic type
             var genericTypes = new Type[arguments.Length];
             for (int i = 0; i < arguments.Length; i++)
             {
@@ -101,7 +100,13 @@ namespace Jint.Runtime.Interop
             }
 
             // search in loaded assemblies
-            foreach (var assembly in new[] { Assembly.GetCallingAssembly(), Assembly.GetExecutingAssembly() }.Distinct())
+#if NETSTANDARD1_3
+            var lookupAssemblies = new[] { typeof(NamespaceReference).GetTypeInfo().Assembly };
+#else
+            var lookupAssemblies = new[] { Assembly.GetCallingAssembly(), Assembly.GetExecutingAssembly() };
+#endif
+
+            foreach (var assembly in lookupAssemblies)
             {
                 type = assembly.GetType(path);
                 if (type != null)
@@ -132,7 +137,7 @@ namespace Jint.Runtime.Interop
                       Engine.TypeCache.Add(path.Replace("+", "."), nType);
                       return TypeReference.CreateTypeReference(Engine, nType);
                     }
-                  }            
+                  }
             }
 
             // the new path doesn't represent a known class, thus return a new namespace instance

+ 191 - 191
Jint/Runtime/Interop/TypeReference.cs

@@ -1,155 +1,155 @@
-using System;
-using System.Globalization;
-using System.Linq;
-using System.Reflection;
-using Jint.Native;
-using Jint.Native.Function;
-using Jint.Native.Object;
-using Jint.Runtime.Descriptors;
-using Jint.Runtime.Descriptors.Specialized;
-
-namespace Jint.Runtime.Interop
-{
-    public class TypeReference : FunctionInstance, IConstructor, IObjectWrapper
-    {
-        private TypeReference(Engine engine)
-            : base(engine, null, null, false)
-        {
-        }
-
-        public Type Type { get; set; }
-
-        public static TypeReference CreateTypeReference(Engine engine, Type type)
-        {
-            var obj = new TypeReference(engine);
-            obj.Extensible = false;
-            obj.Type = type;
-
-            // The value of the [[Prototype]] internal property of the TypeReference constructor is the Function prototype object 
-            obj.Prototype = engine.Function.PrototypeObject;
-
-            obj.FastAddProperty("length", 0, false, false, false);
-
-            // The initial value of Boolean.prototype is the Boolean prototype object
-            obj.FastAddProperty("prototype", engine.Object.PrototypeObject, false, false, false);
-
-            return obj;
-        }
-
-        public override JsValue Call(JsValue thisObject, JsValue[] arguments)
-        {
-            // direct calls on a TypeReference constructor object is equivalent to the new operator 
-            return Construct(arguments);
-        }
-
-        public ObjectInstance Construct(JsValue[] arguments)
-        {
-            if (arguments.Length == 0 && Type.IsValueType)
-            {
-                var instance = Activator.CreateInstance(Type);
-                var result = TypeConverter.ToObject(Engine, JsValue.FromObject(Engine, instance));
-
-                return result;
-            }
-
-            var constructors = Type.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
-            
-            var methods = TypeConverter.FindBestMatch(Engine, constructors, arguments).ToList();
-
-            foreach (var method in methods)
-            {
-                var parameters = new object[arguments.Length];
-                try
-                {
-                    for (var i = 0; i < arguments.Length; i++)
-                    {
-                        var parameterType =  method.GetParameters()[i].ParameterType;
-
-                        if (parameterType == typeof(JsValue))
-                        {
-                            parameters[i] = arguments[i];
-                        }
-                        else
-                        {
-                            parameters[i] = Engine.ClrTypeConverter.Convert(
-                                arguments[i].ToObject(),
-                                parameterType,
-                                CultureInfo.InvariantCulture);
-                        }
-                    }
-
-                    var constructor = (ConstructorInfo)method;
-                    var instance = constructor.Invoke(parameters.ToArray());
-                    var result = TypeConverter.ToObject(Engine, JsValue.FromObject(Engine, instance));
-
-                    // todo: cache method info
-
-                    return result;
-                }
-                catch
-                {
-                    // ignore method
-                }
-            }
-
-            throw new JavaScriptException(Engine.TypeError, "No public methods with the specified arguments were found.");
-            
-        }
-
-        public override bool DefineOwnProperty(string propertyName, PropertyDescriptor desc, bool throwOnError)
-        {
-            if (throwOnError)
-            {
-                throw new JavaScriptException(Engine.TypeError, "Can't define a property of a TypeReference");
-            }
-
-            return false;
-        }
-
-        public override bool Delete(string propertyName, bool throwOnError)
-        {
-            if (throwOnError)
-            {
-                throw new JavaScriptException(Engine.TypeError, "Can't delete a property of a TypeReference");
-            }
-
-            return false;
-        }
-
-        public override void Put(string propertyName, JsValue value, bool throwOnError)
-        {
-            if (!CanPut(propertyName))
-            {
-                if (throwOnError)
-                {
-                    throw new JavaScriptException(Engine.TypeError);
-                }
-
-                return;
-            }
-
-            var ownDesc = GetOwnProperty(propertyName);
-
-            if (ownDesc == null)
-            {
-                if (throwOnError)
-                {
-                    throw new JavaScriptException(Engine.TypeError, "Unknown member: " + propertyName);
-                }
-                else
-                {
-                    return;
-                }
-            }
-
-            ownDesc.Value = value;
-        }
-
-        public override PropertyDescriptor GetOwnProperty(string propertyName)
-        {
+using System;
+using System.Globalization;
+using System.Linq;
+using System.Reflection;
+using Jint.Native;
+using Jint.Native.Function;
+using Jint.Native.Object;
+using Jint.Runtime.Descriptors;
+using Jint.Runtime.Descriptors.Specialized;
+
+namespace Jint.Runtime.Interop
+{
+    public class TypeReference : FunctionInstance, IConstructor, IObjectWrapper
+    {
+        private TypeReference(Engine engine)
+            : base(engine, null, null, false)
+        {
+        }
+
+        public Type Type { get; set; }
+
+        public static TypeReference CreateTypeReference(Engine engine, Type type)
+        {
+            var obj = new TypeReference(engine);
+            obj.Extensible = false;
+            obj.Type = type;
+
+            // The value of the [[Prototype]] internal property of the TypeReference constructor is the Function prototype object
+            obj.Prototype = engine.Function.PrototypeObject;
+
+            obj.FastAddProperty("length", 0, false, false, false);
+
+            // The initial value of Boolean.prototype is the Boolean prototype object
+            obj.FastAddProperty("prototype", engine.Object.PrototypeObject, false, false, false);
+
+            return obj;
+        }
+
+        public override JsValue Call(JsValue thisObject, JsValue[] arguments)
+        {
+            // direct calls on a TypeReference constructor object is equivalent to the new operator
+            return Construct(arguments);
+        }
+
+        public ObjectInstance Construct(JsValue[] arguments)
+        {
+            if (arguments.Length == 0 && Type.IsValueType())
+            {
+                var instance = Activator.CreateInstance(Type);
+                var result = TypeConverter.ToObject(Engine, JsValue.FromObject(Engine, instance));
+
+                return result;
+            }
+
+            var constructors = Type.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
+
+            var methods = TypeConverter.FindBestMatch(Engine, constructors, arguments).ToList();
+
+            foreach (var method in methods)
+            {
+                var parameters = new object[arguments.Length];
+                try
+                {
+                    for (var i = 0; i < arguments.Length; i++)
+                    {
+                        var parameterType =  method.GetParameters()[i].ParameterType;
+
+                        if (parameterType == typeof(JsValue))
+                        {
+                            parameters[i] = arguments[i];
+                        }
+                        else
+                        {
+                            parameters[i] = Engine.ClrTypeConverter.Convert(
+                                arguments[i].ToObject(),
+                                parameterType,
+                                CultureInfo.InvariantCulture);
+                        }
+                    }
+
+                    var constructor = (ConstructorInfo)method;
+                    var instance = constructor.Invoke(parameters.ToArray());
+                    var result = TypeConverter.ToObject(Engine, JsValue.FromObject(Engine, instance));
+
+                    // todo: cache method info
+
+                    return result;
+                }
+                catch
+                {
+                    // ignore method
+                }
+            }
+
+            throw new JavaScriptException(Engine.TypeError, "No public methods with the specified arguments were found.");
+
+        }
+
+        public override bool DefineOwnProperty(string propertyName, PropertyDescriptor desc, bool throwOnError)
+        {
+            if (throwOnError)
+            {
+                throw new JavaScriptException(Engine.TypeError, "Can't define a property of a TypeReference");
+            }
+
+            return false;
+        }
+
+        public override bool Delete(string propertyName, bool throwOnError)
+        {
+            if (throwOnError)
+            {
+                throw new JavaScriptException(Engine.TypeError, "Can't delete a property of a TypeReference");
+            }
+
+            return false;
+        }
+
+        public override void Put(string propertyName, JsValue value, bool throwOnError)
+        {
+            if (!CanPut(propertyName))
+            {
+                if (throwOnError)
+                {
+                    throw new JavaScriptException(Engine.TypeError);
+                }
+
+                return;
+            }
+
+            var ownDesc = GetOwnProperty(propertyName);
+
+            if (ownDesc == null)
+            {
+                if (throwOnError)
+                {
+                    throw new JavaScriptException(Engine.TypeError, "Unknown member: " + propertyName);
+                }
+                else
+                {
+                    return;
+                }
+            }
+
+            ownDesc.Value = value;
+        }
+
+        public override PropertyDescriptor GetOwnProperty(string propertyName)
+        {
             // todo: cache members locally
 
-            if (Type.IsEnum)
+            if (Type.IsEnum())
             {
                 Array enumValues = Enum.GetValues(Type);
                 Array enumNames = Enum.GetNames(Type);
@@ -162,44 +162,44 @@ namespace Jint.Runtime.Interop
                     }
                 }
                 return PropertyDescriptor.Undefined;
-            }
-
-            var propertyInfo = Type.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Static);
-            if (propertyInfo != null)
-            {
-                return new PropertyInfoDescriptor(Engine, propertyInfo, Type);
-            }
-
-            var fieldInfo = Type.GetField(propertyName, BindingFlags.Public | BindingFlags.Static);
-            if (fieldInfo != null)
-            {
-                return new FieldInfoDescriptor(Engine, fieldInfo, Type);
-            }
-
-            var methodInfo = Type
-                .GetMethods(BindingFlags.Public | BindingFlags.Static)
-                .Where(mi => mi.Name == propertyName)
-                .ToArray();
-
-            if (methodInfo.Length == 0)
-            {
-                return PropertyDescriptor.Undefined;
-            }
-
-            return new PropertyDescriptor(new MethodInfoFunctionInstance(Engine, methodInfo), false, false, false);
-        }
-
-        public object Target
-        {
-            get
-            {
-                return Type;
-            } 
-        }
-
-        public override string Class
-        {
-            get { return "TypeReference"; }
-        }
-    }
-}
+            }
+
+            var propertyInfo = Type.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Static);
+            if (propertyInfo != null)
+            {
+                return new PropertyInfoDescriptor(Engine, propertyInfo, Type);
+            }
+
+            var fieldInfo = Type.GetField(propertyName, BindingFlags.Public | BindingFlags.Static);
+            if (fieldInfo != null)
+            {
+                return new FieldInfoDescriptor(Engine, fieldInfo, Type);
+            }
+
+            var methodInfo = Type
+                .GetMethods(BindingFlags.Public | BindingFlags.Static)
+                .Where(mi => mi.Name == propertyName)
+                .ToArray();
+
+            if (methodInfo.Length == 0)
+            {
+                return PropertyDescriptor.Undefined;
+            }
+
+            return new PropertyDescriptor(new MethodInfoFunctionInstance(Engine, methodInfo), false, false, false);
+        }
+
+        public object Target
+        {
+            get
+            {
+                return Type;
+            }
+        }
+
+        public override string Class
+        {
+            get { return "TypeReference"; }
+        }
+    }
+}

+ 1 - 1
Jint/Runtime/TypeConverter.cs

@@ -399,7 +399,7 @@ namespace Jint.Runtime
 
         public static bool TypeIsNullable(Type type)
         {
-            return !type.IsValueType || Nullable.GetUnderlyingType(type) != null;
+            return !type.IsValueType() || Nullable.GetUnderlyingType(type) != null;
         }
     }
 }

+ 70 - 0
Jint/project.json

@@ -0,0 +1,70 @@
+{
+  "version": "2.9.1",
+  "title": "Jint",
+  "description": "Javascript interpreter for .NET which provides full ECMA 5.1 compliance.",
+  "language": "en-US",
+  "authors": [ "Sebastien Ros" ],
+  "packOptions": {
+    "projectUrl": "https://github.com/sebastienros/jint",
+    "tags": [ "javascript, interpreter" ],
+    "licenseUrl": "https://raw.githubusercontent.com/sebastienros/jint/master/LICENSE.txt",
+    "repository": {
+      "type": "git",
+      "url": "git://github.com/sebastienros/jint"
+    }
+  },
+  "frameworks": {
+    "net45": {
+      "dependencies": {
+        "System.Diagnostics.Contracts": "4.0.0"
+      }
+    },
+    ".NETPortable,Version=v4.0,Profile=Profile328": {
+     "buildOptions": {
+       "define": [
+         "PORTABLE"
+       ]
+     },
+     "frameworkAssemblies": {
+       "mscorlib": "",
+       "System": "",
+       "System.Core": "",
+       "System.Runtime.Serialization": "",
+       "System.Xml": ""
+     }
+    },
+    "netstandard1.3": {
+      "buildOptions": {
+        "define": [
+          "NETSTANDARD1_3"
+        ]
+      },
+      "dependencies": {
+        "Microsoft.CSharp": "4.0.1",
+        "System.Collections": "4.0.11",
+        "System.Diagnostics.Contracts": "4.0.1",
+        "System.Diagnostics.Debug": "4.0.11",
+        "System.Dynamic.Runtime": "4.0.11",
+        "System.Globalization": "4.0.11",
+        "System.IO": "4.1.0",
+        "System.Linq": "4.1.0",
+        "System.Linq.Expressions": "4.1.0",
+        "System.ObjectModel": "4.0.12",
+        "System.Reflection": "4.1.0",
+        "System.Reflection.Extensions": "4.0.1",
+        "System.Reflection.TypeExtensions": "4.1.0",
+        "System.Resources.ResourceManager": "4.0.1",
+        "System.Runtime": "4.1.0",
+        "System.Runtime.Extensions": "4.1.0",
+        "System.Runtime.Serialization.Primitives": "4.1.1",
+        "System.Text.Encoding": "4.0.11",
+        "System.Text.Encoding.Extensions": "4.0.11",
+        "System.Text.RegularExpressions": "4.1.0",
+        "System.Threading": "4.0.11",
+        "System.Threading.Tasks": "4.0.11",
+        "System.Xml.ReaderWriter": "4.0.11",
+        "System.Xml.XDocument": "4.0.11"
+      }
+    }
+  }
+}