Skip to content

Commit 1f89f66

Browse files
committed
In JavaScriptEngineSwitcher.V8 implemented a handling of error “Internal error. Icu error”
1 parent 16640ca commit 1f89f66

File tree

7 files changed

+67
-2
lines changed

7 files changed

+67
-2
lines changed

src/JavaScriptEngineSwitcher.V8/JavaScriptEngineSwitcher.V8.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ This package does not contain the native ClearScript.V8 assemblies. Therefore, y
3030
* Microsoft.ClearScript.V8.Native.osx-arm64</Description>
3131
<PackageTags>$(PackageCommonTags);V8;ClearScript</PackageTags>
3232
<PackageIconFullPath>../../Icons/JavaScriptEngineSwitcher_V8_Logo128x128.png</PackageIconFullPath>
33-
<PackageReleaseNotes>Microsoft ClearScript.V8 was updated to version 7.1.6.</PackageReleaseNotes>
33+
<PackageReleaseNotes>Implemented a handling of error “Internal error. Icu error”.</PackageReleaseNotes>
3434
</PropertyGroup>
3535

3636
<ItemGroup>

src/JavaScriptEngineSwitcher.V8/Resources/Strings.Designer.cs

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/JavaScriptEngineSwitcher.V8/Resources/Strings.resx

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120+
<data name="Engine_InternationalizationApiNotFullySupported" xml:space="preserve">
121+
<value>By default, some features of the JavaScript Internationalization API are not supported.</value>
122+
</data>
120123
<data name="Usage_PrecompiledScriptNotAccepted" xml:space="preserve">
121124
<value>Pre-compiled script is not accepted. To be accepted, the pre-compiled script must have been created by the same V8 build.</value>
122125
</data>

src/JavaScriptEngineSwitcher.V8/Resources/Strings.ru-ru.resx

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120+
<data name="Engine_InternationalizationApiNotFullySupported" xml:space="preserve">
121+
<value>По умолчанию некоторые возможности JavaScript Internationalization API не поддерживаются.</value>
122+
</data>
120123
<data name="Usage_PrecompiledScriptNotAccepted" xml:space="preserve">
121124
<value>Предварительно скомпилированный сценарий не принят! Чтобы быть принятым, предварительно скомпилированный сценарий должен быть создан той же сборкой V8.</value>
122125
</data>

src/JavaScriptEngineSwitcher.V8/V8JsEngine.cs

+13
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,19 @@ private static WrapperException WrapScriptEngineException(OriginalException orig
247247
}
248248
else
249249
{
250+
if (description == "Internal error. Icu error.")
251+
{
252+
var stringBuilderPool = StringBuilderPool.Shared;
253+
StringBuilder descriptionBuilder = stringBuilderPool.Rent();
254+
descriptionBuilder.Append(Strings.Engine_InternationalizationApiNotFullySupported);
255+
descriptionBuilder.Append(" ");
256+
descriptionBuilder.AppendFormat(CoreStrings.Engine_NuGetPackageInstallationRequired,
257+
"Microsoft.ClearScript.V8.ICUData");
258+
259+
description = descriptionBuilder.ToString();
260+
stringBuilderPool.Return(descriptionBuilder);
261+
}
262+
250263
callStack = JsErrorHelpers.StringifyErrorLocationItems(errorLocationItems, true);
251264
string callStackWithSourceFragment = JsErrorHelpers.StringifyErrorLocationItems(
252265
errorLocationItems);

src/JavaScriptEngineSwitcher.V8/readme.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
=============
3232
RELEASE NOTES
3333
=============
34-
Microsoft ClearScript.V8 was updated to version 7.1.6.
34+
Implemented a handling of error “Internal error. Icu error”.
3535

3636
=============
3737
DOCUMENTATION

test/JavaScriptEngineSwitcher.Tests/V8/CommonTests.cs

+38
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,44 @@ public void MappingRuntimeErrorDuringExecutionOfCodeIsCorrect()
182182
);
183183
}
184184

185+
[Fact]
186+
public void MappingRuntimeErrorDuringUsingInternationalizationApiIsCorrect()
187+
{
188+
// Arrange
189+
const string functionCode = @"function formatDate(value, locale) {
190+
if (typeof value === 'string' && value.length > 0) {
191+
value = new Date(value);
192+
}
193+
194+
return new Intl.DateTimeFormat(locale).format(value);
195+
}";
196+
197+
JsRuntimeException exception = null;
198+
199+
// Act
200+
using (var jsEngine = CreateJsEngine())
201+
{
202+
try
203+
{
204+
jsEngine.Execute(functionCode);
205+
string result = jsEngine.CallFunction<string>("formatDate", "2021-09-16", "ru-ru");
206+
}
207+
catch (JsRuntimeException e)
208+
{
209+
exception = e;
210+
}
211+
}
212+
213+
// Assert
214+
Assert.NotNull(exception);
215+
Assert.Equal("Runtime error", exception.Category);
216+
Assert.Equal(
217+
"By default, some features of the JavaScript Internationalization API are not supported. " +
218+
"Try to install the Microsoft.ClearScript.V8.ICUData package via NuGet.",
219+
exception.Description
220+
);
221+
}
222+
185223
[Fact]
186224
public void MappingRuntimeErrorDuringOutOfMemoryIsCorrect()
187225
{

0 commit comments

Comments
 (0)