Browse Source

Interop with ConcatenatedString can throw exception (#630)

Marko Lahma 6 years ago
parent
commit
408d7c7133
2 changed files with 11 additions and 4 deletions
  1. 10 0
      Jint.Tests/Runtime/InteropTests.cs
  2. 1 4
      Jint/Native/JsString.cs

+ 10 - 0
Jint.Tests/Runtime/InteropTests.cs

@@ -1814,5 +1814,15 @@ namespace Jint.Tests.Runtime
             ");
             ");
         }
         }
 
 
+        [Fact]
+        public void ShouldBeAbleToPlusAssignStringProperty()
+        {
+            var p = new Person();
+            var engine = new Engine();
+            engine.SetValue("P", p);
+            engine.Execute("P.Name = 'b';");
+            engine.Execute("P.Name += 'c';");
+            Assert.Equal("bc", p.Name);
+        } 
     }
     }
 }
 }

+ 1 - 4
Jint/Native/JsString.cs

@@ -200,10 +200,7 @@ namespace Jint.Native
 
 
             public override int Length => _stringBuilder?.Length ?? _value?.Length ?? 0;
             public override int Length => _stringBuilder?.Length ?? _value?.Length ?? 0;
 
 
-            public override object ToObject()
-            {
-                return _stringBuilder.ToString();
-            }
+            public override object ToObject() => ToString();
 
 
             public override bool Equals(JsValue other)
             public override bool Equals(JsValue other)
             {
             {