Browse Source

JsString multiple concatination fails (#486)

pitMobile 7 years ago
parent
commit
9f532cabc3
2 changed files with 23 additions and 1 deletions
  1. 16 0
      Jint.Tests/Runtime/EngineTests.cs
  2. 7 1
      Jint/Native/JsString.cs

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

@@ -2384,5 +2384,21 @@ namespace Jint.Tests.Runtime
             var actualValue = engine.Execute(actual).GetCompletionValue().ToObject();
             Assert.Equal(expectedValue, actualValue);
         }
+	
+	[Fact]
+        public void ShouldReturnCorrectConcatenatedStrings()
+        {
+            RunTest(@"
+                function concat(x, a, b) { 
+                    x += a;
+                    x += b;
+                    return x; 
+                }");
+
+            var concat = _engine.GetValue("concat");
+            var result = concat.Invoke("concat", "well", "done").ToObject() as string;
+            Assert.Equal("concatwelldone", result);
+        }
+
     }
 }

+ 7 - 1
Jint/Native/JsString.cs

@@ -164,6 +164,12 @@ namespace Jint.Native
 
                 return _value;
             }
+            
+            [Pure]
+            public override object ToObject()
+            {
+                return AsString();
+            }
 
             public override JsString Append(JsValue jsValue)
             {
@@ -207,4 +213,4 @@ namespace Jint.Native
             }
         }
     }
-}
+}