Browse Source

System.NullReferenceException caused by RegExp.prototype.toString() fixed (#593)

Fixes #592
Steffen Liersch 6 years ago
parent
commit
a3a8e06006
2 changed files with 15 additions and 4 deletions
  1. 6 0
      Jint.Tests/Runtime/EngineTests.cs
  2. 9 4
      Jint/Native/RegExp/RegExpPrototype.cs

+ 6 - 0
Jint.Tests/Runtime/EngineTests.cs

@@ -1968,6 +1968,12 @@ var prep = function (fn) { fn(); };
             ");
         }
 
+        [Fact]
+        public void RegExpPrototypeToString()
+        {
+            RunTest("assert(RegExp.prototype.toString() === '//');");
+        }
+
         [Fact]
         public void ShouldSetYearBefore1970()
         {

+ 9 - 4
Jint/Native/RegExp/RegExpPrototype.cs

@@ -40,11 +40,16 @@ namespace Jint.Native.RegExp
         {
             var regExp = thisObj.TryCast<RegExpInstance>();
 
-            return "/" + regExp.Source + "/"
-                + (regExp.Flags.Contains("g") ? "g" : "")
-                + (regExp.Flags.Contains("i") ? "i" : "")
-                + (regExp.Flags.Contains("m") ? "m" : "")
+            string res = "/" + regExp.Source + "/";
+            if (regExp.Flags != null)
+            {
+                res += (regExp.Flags.Contains("g") ? "g" : "")
+                    + (regExp.Flags.Contains("i") ? "i" : "")
+                    + (regExp.Flags.Contains("m") ? "m" : "")
                 ;
+            }
+
+            return res;
         }
 
         private JsValue Test(JsValue thisObj, JsValue[] arguments)