Browse Source

Merge remote-tracking branch 'upstream/master'

Brian Beard 11 years ago
parent
commit
c07d2194b1

+ 26 - 26
Jint.Tests.CommonScripts/SunSpiderTests.cs

@@ -30,7 +30,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("3d-cube", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/3d-cube.js")]
+        [InlineData("3d-cube", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/3d-cube.js")]
         public void ThreeDCube(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -38,7 +38,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("3d-morph", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/3d-morph.js")]
+        [InlineData("3d-morph", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/3d-morph.js")]
         public void ThreeDMorph(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -46,7 +46,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("3d-raytrace", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/3d-raytrace.js")]
+        [InlineData("3d-raytrace", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/3d-raytrace.js")]
         public void ThreeDRaytrace(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -54,7 +54,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("access-binary-trees", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/access-binary-trees.js")]
+        [InlineData("access-binary-trees", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/access-binary-trees.js")]
         public void AccessBinaryTrees(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -62,7 +62,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("access-fannkuch", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/access-fannkuch.js")]
+        [InlineData("access-fannkuch", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/access-fannkuch.js")]
         public void AccessFannkych(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -70,7 +70,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("access-nbody", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/access-nbody.js")]
+        [InlineData("access-nbody", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/access-nbody.js")]
         public void AccessNBody(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -78,14 +78,14 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("access-nsieve", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/access-nsieve.js")]
+        [InlineData("access-nsieve", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/access-nsieve.js")]
         public void AccessNSieve(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
             RunTest(content);
         }
 
-        [InlineData("bitops-3bit-bits-in-byte", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/bitops-3bit-bits-in-byte.js")]
+        [InlineData("bitops-3bit-bits-in-byte", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/bitops-3bit-bits-in-byte.js")]
         public void Bitops3BitBitsInByte(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -93,7 +93,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("bitops-bits-in-byte", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/bitops-bits-in-byte.js")]
+        [InlineData("bitops-bits-in-byte", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/bitops-bits-in-byte.js")]
         public void BitopsBitsInByte(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -101,7 +101,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("bitops-bitwise-and", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/bitops-bitwise-and.js")]
+        [InlineData("bitops-bitwise-and", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/bitops-bitwise-and.js")]
         public void BitopsBitwiseAnd(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -109,7 +109,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("bitops-nsieve-bits", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/bitops-nsieve-bits.js")]
+        [InlineData("bitops-nsieve-bits", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/bitops-nsieve-bits.js")]
         public void BitopsNSieveBits(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -117,7 +117,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("controlflow-recursive", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/controlflow-recursive.js")]
+        [InlineData("controlflow-recursive", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/controlflow-recursive.js")]
         public void ControlFlowRecursive(string name, string url)
         {
             var t = new Thread(() =>
@@ -131,7 +131,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("crypto-aes", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/crypto-aes.js")]
+        [InlineData("crypto-aes", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/crypto-aes.js")]
         public void CryptoAES(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -139,14 +139,14 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("crypto-md5", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/crypto-md5.js")]
+        [InlineData("crypto-md5", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/crypto-md5.js")]
         public void CryptoMD5(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
             RunTest(content);
         }
 
-        [InlineData("crypto-sha1", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/crypto-sha1.js")]
+        [InlineData("crypto-sha1", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/crypto-sha1.js")]
         public void CryptoSha1(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -154,7 +154,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("date-format-tofte", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/date-format-tofte.js")]
+        [InlineData("date-format-tofte", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/date-format-tofte.js")]
         public void DateFormatTofte(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -162,14 +162,14 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("date-format-xparb", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/date-format-xparb.js")]
+        [InlineData("date-format-xparb", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/date-format-xparb.js")]
         public void DateFormatXParb(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
             RunTest(content);
         }
 
-        [InlineData("math-cordic", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/math-cordic.js")]
+        [InlineData("math-cordic", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/math-cordic.js")]
         public void MathCordic(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -177,7 +177,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("math-partial-sums", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/math-partial-sums.js")]
+        [InlineData("math-partial-sums", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/math-partial-sums.js")]
         public void MathPartialSums(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -185,7 +185,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("math-spectral-norm", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/math-spectral-norm.js")]
+        [InlineData("math-spectral-norm", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/math-spectral-norm.js")]
         public void MathSpectralNorm(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -193,7 +193,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("regexp-dna", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/regexp-dna.js")]
+        [InlineData("regexp-dna", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/regexp-dna.js")]
         public void RegexpDna(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -201,14 +201,14 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("string-base64", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/string-base64.js")]
+        [InlineData("string-base64", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/string-base64.js")]
         public void StringBase64(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
             RunTest(content);
         }
 
-        [InlineData("string-fasta", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/string-fasta.js")]
+        [InlineData("string-fasta", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/string-fasta.js")]
         public void StringFasta(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -216,7 +216,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("string-tagcloud", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/string-tagcloud.js")]
+        [InlineData("string-tagcloud", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/string-tagcloud.js")]
         public void StringTagCloud(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -224,7 +224,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("string-unpack-code", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/string-unpack-code.js")]
+        [InlineData("string-unpack-code", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/string-unpack-code.js")]
         public void StringUnpackCode(string name, string url)
         {
             var content = new WebClient().DownloadString(url);
@@ -232,7 +232,7 @@ namespace Jint.Tests.CommonScripts
         }
 
         [Theory]
-        [InlineData("string-validate-input", "https://raw.github.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.1/string-validate-input.js")]
+        [InlineData("string-validate-input", "https://raw.githubusercontent.com/WebKit/webkit/master/PerformanceTests/SunSpider/tests/sunspider-1.0.2/string-validate-input.js")]
         public void StringValidateInput(string name, string url)
         {
             var content = new WebClient().DownloadString(url);

+ 3 - 0
Jint.Tests/Jint.Tests.csproj

@@ -99,6 +99,9 @@
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Include="Parser\Scripts\handlebars.js" />
+  </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. 

+ 1 - 0
Jint.Tests/Parser/JavascriptParserTests.cs

@@ -21,6 +21,7 @@ namespace Jint.Tests.Parser
         [InlineData("mootools.js", "1.4.5")]
         [InlineData("angular.js", "1.2.5")]
         [InlineData("JSXTransformer.js", "0.10.0")]
+        [InlineData("handlebars.js", "2.0.0")]
         public void ShouldParseScriptFile(string file, string version)
         {
             const string prefix = "Jint.Tests.Parser.Scripts.";

File diff suppressed because it is too large
+ 983 - 0
Jint.Tests/Parser/Scripts/handlebars.js


+ 35 - 1
Jint.Tests/Runtime/EngineTests.cs

@@ -9,6 +9,7 @@ using Jint.Parser.Ast;
 using Jint.Runtime;
 using Xunit;
 using Xunit.Extensions;
+using System.Net;
 
 namespace Jint.Tests.Runtime
 {
@@ -31,7 +32,6 @@ namespace Jint.Tests.Runtime
 
         private void RunTest(string source)
         {
-
             _engine.Execute(source);
         }
 
@@ -605,6 +605,14 @@ namespace Jint.Tests.Runtime
             );
         }
 
+        [Fact]
+        public void ShouldThrowTimeout()
+        {
+            Assert.Throws<TimeoutException>(
+                () => new Engine(cfg => cfg.TimeoutInterval(new TimeSpan(0,0,0,0,500))).Execute("while(true);")
+            );
+        }
+
         [Fact]
         public void ShouldConvertDoubleToStringWithoutLosingPrecision()
         {
@@ -839,5 +847,31 @@ namespace Jint.Tests.Runtime
             Assert.Equal(-11 * 60 * 1000, result);
         }
 
+        [Fact]
+        public void EmptyStringShouldMatchRegex()
+        {
+            RunTest(@"
+                var regex = /^(?:$)/g;
+                assert(''.match(regex) instanceof Array);
+            ");
+        }
+
+        [Fact]
+        public void ShouldExecuteHandlebars()
+        {
+            var url = "http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0/handlebars.js";
+            var content = new WebClient().DownloadString(url);
+            
+            RunTest(content);
+
+            RunTest(@"
+                var source = 'Hello {{name}}';
+                var template = Handlebars.compile(source);
+                var context = {name: 'Paul'};
+                var html = template(context);
+
+                assert('Hello Paul' == html);
+            ");
+        }
     }
 }

+ 13 - 0
Jint/Engine.cs

@@ -32,6 +32,7 @@ namespace Jint
         private readonly Stack<ExecutionContext> _executionContexts;
         private JsValue _completionValue = JsValue.Undefined;
         private int _statementsCount;
+        private long _timeoutTicks;
         private SyntaxNode _lastSyntaxNode = null;
 
         // cache of types used when resolving CLR type names
@@ -216,6 +217,12 @@ namespace Jint
             _statementsCount = 0;
         }
 
+        public void ResetTimeoutTicks()
+        {
+            var timeoutIntervalTicks = Options.GetTimeoutInterval().Ticks;
+            _timeoutTicks = timeoutIntervalTicks > 0 ? DateTime.UtcNow.Ticks + timeoutIntervalTicks : 0;
+        }
+
         public Engine Execute(string source)
         {
             var parser = new JavaScriptParser();
@@ -231,6 +238,7 @@ namespace Jint
         public Engine Execute(Program program)
         {
             ResetStatementsCount();
+            ResetTimeoutTicks();
             ResetLastStatement();
 
             using (new StrictModeScope(Options.IsStrict() || program.Strict))
@@ -270,6 +278,11 @@ namespace Jint
                 throw new StatementsCountOverflowException();
             }
 
+            if (_timeoutTicks > 0 && _timeoutTicks < DateTime.UtcNow.Ticks)
+            {
+                throw new TimeoutException();
+            }
+
             _lastSyntaxNode = statement;
 
             switch (statement.Type)

+ 1 - 1
Jint/Native/RegExp/RegExpPrototype.cs

@@ -86,7 +86,7 @@ namespace Jint.Native.RegExp
             }
 
             Match r = null;
-            if (i < 0 || i >= length)
+            if (i < 0 || i > length)
             {
                 R.Put("lastIndex", (double) 0, true);
                 return Null.Instance;

+ 12 - 0
Jint/Options.cs

@@ -17,6 +17,7 @@ namespace Jint
         private ITypeConverter _typeConverter = new DefaultTypeConverter();
         private readonly List<IObjectConverter> _objectConverters = new List<IObjectConverter>();
         private int _maxStatements;
+        private TimeSpan _timeoutInterval;
         private CultureInfo _culture = CultureInfo.CurrentCulture;
         private TimeZoneInfo _localTimeZone = TimeZoneInfo.Local;
         private List<Assembly> _lookupAssemblies = new List<Assembly>(); 
@@ -88,6 +89,12 @@ namespace Jint
             return this;
         }
 
+        public Options TimeoutInterval(TimeSpan timeoutInterval)
+        {
+            _timeoutInterval = timeoutInterval;
+            return this;
+        }
+
         public Options Culture(CultureInfo cultureInfo)
         {
             _culture = cultureInfo;
@@ -140,6 +147,11 @@ namespace Jint
             return _maxStatements;
         }
 
+        internal TimeSpan GetTimeoutInterval()
+        {
+            return _timeoutInterval;
+        }
+
         internal CultureInfo GetCulture()
         {
             return _culture;

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