Skip to content

Commit 5aba57a

Browse files
committed
Added support of identifier names compliant with ECMAScript 5
1 parent b698702 commit 5aba57a

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

NuGet/MsieJavaScriptEngine.nuspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
<releaseNotes>1. In JsRT modes fixed a problems in calculation of error locations;
1616
2. An attempt was made to prevent occurrence of the access violation exception;
1717
3. Now the original exception is added to instance of the `JsRuntimeException` class as an inner exception;
18-
4. An attempt was made to prevent a blocking of finalizer's thread.</releaseNotes>
18+
4. An attempt was made to prevent a blocking of finalizer's thread;
19+
5. Added support of identifier names compliant with ECMAScript 5.</releaseNotes>
1920
<copyright>Copyright (c) 2012-2017 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
2021
<language>en-US</language>
2122
<tags>JavaScript ECMAScript MSIE IE Edge Chakra</tags>

NuGet/readme.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
2. An attempt was made to prevent occurrence of the access violation exception;
2626
3. Now the original exception is added to instance of the `JsRuntimeException`
2727
class as an inner exception;
28-
4. An attempt was made to prevent a blocking of finalizer's thread.
28+
4. An attempt was made to prevent a blocking of finalizer's thread;
29+
5. Added support of identifier names compliant with ECMAScript 5.
2930

3031
============
3132
PROJECT SITE

src/MsieJavaScriptEngine/Helpers/ValidationHelpers.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ public static class ValidationHelpers
2020
};
2121

2222
/// <summary>
23-
/// Regular expression for working with JS-names
23+
/// Regular expression for working with JS names
2424
/// </summary>
25-
private static readonly Regex _jsNameRegex = new Regex(@"^[A-Za-z_\$][0-9A-Za-z_\$]*$");
25+
private static readonly Regex _jsNameRegex = new Regex(@"^[$_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}]" +
26+
@"[$_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}\u200C\u200D\p{Mn}\p{Mc}\p{Nd}\p{Pc}]*$");
2627

2728

2829
/// <summary>

test/MsieJavaScriptEngine.Test.Common/CommonTestsBase.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,40 @@ public virtual void SettingAndGettingVariableWithUnicodeStringValueIsCorrect()
847847
Assert.AreEqual(input2, output2);
848848
}
849849

850+
[Test]
851+
public virtual void SettingAndGettingVariableWithNameContainingUnicodeCharactersIsCorrect()
852+
{
853+
// Arrange
854+
const string variableName = "слово";
855+
856+
const string input1 = "Hip-hip Hooray";
857+
const string targetOutput1 = "Hip-hip Hooray!";
858+
859+
const string input2 = "Hip-hip Hurrah";
860+
861+
// Act
862+
bool variableExists;
863+
string output1;
864+
string output2;
865+
866+
using (var jsEngine = CreateJsEngine())
867+
{
868+
jsEngine.SetVariableValue(variableName, input1);
869+
variableExists = jsEngine.HasVariable(variableName);
870+
jsEngine.Execute(string.Format("{0} += '!';", variableName));
871+
output1 = jsEngine.GetVariableValue<string>(variableName);
872+
873+
jsEngine.SetVariableValue(variableName, input2);
874+
output2 = jsEngine.GetVariableValue<string>(variableName);
875+
}
876+
877+
// Assert
878+
Assert.True(variableExists);
879+
Assert.AreEqual(targetOutput1, output1);
880+
881+
Assert.AreEqual(input2, output2);
882+
}
883+
850884
[Test]
851885
public virtual void RemovingVariableIsCorrect()
852886
{

test/MsieJavaScriptEngine.Test.Common/ValidationTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ public void NameFormatIsCorrect()
1818
bool name3FormatIsCorrect = ValidationHelpers.CheckNameFormat("fooBar");
1919
bool name4FormatIsCorrect = ValidationHelpers.CheckNameFormat("$grid");
2020
bool name5FormatIsCorrect = ValidationHelpers.CheckNameFormat("a");
21+
bool name6FormatIsCorrect = ValidationHelpers.CheckNameFormat("À_la_maison");
2122

2223
// Assert
2324
Assert.IsTrue(name1FormatIsCorrect);
2425
Assert.IsTrue(name2FormatIsCorrect);
2526
Assert.IsTrue(name3FormatIsCorrect);
2627
Assert.IsTrue(name4FormatIsCorrect);
2728
Assert.IsTrue(name5FormatIsCorrect);
29+
Assert.IsTrue(name6FormatIsCorrect);
2830
}
2931

3032
[Test]

0 commit comments

Comments
 (0)