Skip to content

Commit b2fc98e

Browse files
committed
Now when you call the overloaded version of the ExecuteResource method, that takes the type, need to pass the resource name without the namespace
1 parent f2cbeba commit b2fc98e

File tree

6 files changed

+96
-33
lines changed

6 files changed

+96
-33
lines changed

NuGet/MsieJavaScriptEngine.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1313
<description>This library is a .NET wrapper for working with the JavaScript engines of Internet Explorer and Edge (JsRT versions of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine). Project was based on the code of SassAndCoffee.JavaScript (http://github.com/paulcbetts/SassAndCoffee), Chakra Sample Hosts (http://github.com/panopticoncentral/chakra-host) and jsrt-dotnet (http://github.com/robpaveza/jsrt-dotnet).</description>
1414
<summary>This library is a .NET wrapper for working with the JavaScript engines of Internet Explorer and Edge (JsRT versions of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine).</summary>
15-
<releaseNotes>Another attempt to prevent occurrence of the access violation exception in the `CallFunction` method.</releaseNotes>
15+
<releaseNotes>Now when you call the overloaded version of the `ExecuteResource` method, that takes the type, need to pass the resource name without the namespace.</releaseNotes>
1616
<copyright>Copyright (c) 2012-2016 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
1717
<language>en-US</language>
1818
<tags>JavaScript ECMAScript MSIE IE Edge Chakra</tags>

NuGet/readme.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
=============
2222
RELEASE NOTES
2323
=============
24-
Another attempt to prevent occurrence of the access violation exception in the
25-
`CallFunction` method.
24+
Now when you call the overloaded version of the `ExecuteResource` method, that
25+
takes the type, need to pass the resource name without the namespace.
2626

2727
============
2828
PROJECT SITE

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -512,39 +512,45 @@ private void InnerCollectGarbage(ScriptGCType type)
512512
/// <param name="useJson2Library">Flag for whether to use the JSON2 library</param>
513513
private void LoadResources(bool useEcmaScript5Polyfill, bool useJson2Library)
514514
{
515-
Type type = GetType();
515+
Assembly assembly = GetType().GetTypeInfo().Assembly;
516516

517517
if (useEcmaScript5Polyfill)
518518
{
519-
ExecuteResource(ES5_POLYFILL_RESOURCE_NAME, type);
519+
ExecuteResource(ES5_POLYFILL_RESOURCE_NAME, assembly);
520520
}
521521

522522
if (useJson2Library)
523523
{
524-
ExecuteResource(JSON2_LIBRARY_RESOURCE_NAME, type);
524+
ExecuteResource(JSON2_LIBRARY_RESOURCE_NAME, assembly);
525525
}
526526
}
527527

528528
/// <summary>
529529
/// Executes a code from embedded JS-resource
530530
/// </summary>
531-
/// <param name="resourceName">JS-resource name</param>
532-
/// <param name="type">Type from assembly that containing an embedded resource</param>
533-
private void ExecuteResource(string resourceName, Type type)
531+
/// <param name="resourceName">The case-sensitive resource name</param>
532+
/// <param name="assembly">The assembly, which contains the embedded resource</param>
533+
private void ExecuteResource(string resourceName, Assembly assembly)
534534
{
535-
if (string.IsNullOrWhiteSpace(resourceName))
535+
if (resourceName == null)
536536
{
537-
throw new ArgumentException(
538-
string.Format(CommonStrings.Common_ArgumentIsEmpty, "resourceName"), "resourceName");
537+
throw new ArgumentNullException(
538+
"resourceName", string.Format(CommonStrings.Common_ArgumentIsNull, "resourceName"));
539539
}
540540

541-
if (type == null)
541+
if (assembly == null)
542542
{
543543
throw new ArgumentNullException(
544-
"type", string.Format(CommonStrings.Common_ArgumentIsNull, "type"));
544+
"assembly", string.Format(CommonStrings.Common_ArgumentIsNull, "assembly"));
545+
}
546+
547+
if (string.IsNullOrWhiteSpace(resourceName))
548+
{
549+
throw new ArgumentException(
550+
string.Format(CommonStrings.Common_ArgumentIsEmpty, "resourceName"), "resourceName");
545551
}
546552

547-
string code = Utils.GetResourceAsString(resourceName, type);
553+
string code = Utils.GetResourceAsString(resourceName, assembly);
548554
Execute(code);
549555
}
550556

src/MsieJavaScriptEngine/MsieJsEngine.cs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,9 @@ public void ExecuteFile(string path, Encoding encoding = null)
305305
/// <summary>
306306
/// Executes a code from embedded JS-resource
307307
/// </summary>
308-
/// <param name="resourceName">JS-resource name</param>
309-
/// <param name="type">Type from assembly that containing an embedded resource</param>
308+
/// <param name="resourceName">The case-sensitive resource name without the namespace of the specified type</param>
309+
/// <param name="type">The type, that determines the assembly and whose namespace is used to scope
310+
/// the resource name</param>
310311
/// <exception cref="System.ObjectDisposedException">Operation is performed on a disposed MSIE
311312
/// JavaScript engine.</exception>
312313
/// <exception cref="System.ArgumentException" />
@@ -316,10 +317,10 @@ public void ExecuteResource(string resourceName, Type type)
316317
{
317318
VerifyNotDisposed();
318319

319-
if (string.IsNullOrWhiteSpace(resourceName))
320+
if (resourceName == null)
320321
{
321-
throw new ArgumentException(
322-
string.Format(CommonStrings.Common_ArgumentIsEmpty, "resourceName"), "resourceName");
322+
throw new ArgumentNullException(
323+
"resourceName", string.Format(CommonStrings.Common_ArgumentIsNull, "resourceName"));
323324
}
324325

325326
if (type == null)
@@ -328,15 +329,21 @@ public void ExecuteResource(string resourceName, Type type)
328329
"type", string.Format(CommonStrings.Common_ArgumentIsNull, "type"));
329330
}
330331

332+
if (string.IsNullOrWhiteSpace(resourceName))
333+
{
334+
throw new ArgumentException(
335+
string.Format(CommonStrings.Common_ArgumentIsEmpty, "resourceName"), "resourceName");
336+
}
337+
331338
string code = Utils.GetResourceAsString(resourceName, type);
332339
Execute(code);
333340
}
334341

335342
/// <summary>
336343
/// Executes a code from embedded JS-resource
337344
/// </summary>
338-
/// <param name="resourceName">JS-resource name</param>
339-
/// <param name="assembly">Assembly that containing an embedded resource</param>
345+
/// <param name="resourceName">The case-sensitive resource name</param>
346+
/// <param name="assembly">The assembly, which contains the embedded resource</param>
340347
/// <exception cref="System.ObjectDisposedException">Operation is performed on a disposed MSIE
341348
/// JavaScript engine.</exception>
342349
/// <exception cref="System.ArgumentException" />
@@ -346,10 +353,10 @@ public void ExecuteResource(string resourceName, Assembly assembly)
346353
{
347354
VerifyNotDisposed();
348355

349-
if (string.IsNullOrWhiteSpace(resourceName))
356+
if (resourceName == null)
350357
{
351-
throw new ArgumentException(
352-
string.Format(CommonStrings.Common_ArgumentIsEmpty, "resourceName"), "resourceName");
358+
throw new ArgumentNullException(
359+
"resourceName", string.Format(CommonStrings.Common_ArgumentIsNull, "resourceName"));
353360
}
354361

355362
if (assembly == null)
@@ -358,6 +365,12 @@ public void ExecuteResource(string resourceName, Assembly assembly)
358365
"assembly", string.Format(CommonStrings.Common_ArgumentIsNull, "assembly"));
359366
}
360367

368+
if (string.IsNullOrWhiteSpace(resourceName))
369+
{
370+
throw new ArgumentException(
371+
string.Format(CommonStrings.Common_ArgumentIsEmpty, "resourceName"), "resourceName");
372+
}
373+
361374
string code = Utils.GetResourceAsString(resourceName, assembly);
362375
Execute(code);
363376
}

src/MsieJavaScriptEngine/Utilities/Utils.cs

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,67 @@ public static bool Is64BitProcess()
2929
/// <summary>
3030
/// Gets a content of the embedded resource as string
3131
/// </summary>
32-
/// <param name="resourceName">Resource name</param>
33-
/// <param name="type">Type from assembly that containing an embedded resource</param>
32+
/// <param name="resourceName">The case-sensitive resource name without the namespace of the specified type</param>
33+
/// <param name="type">The type, that determines the assembly and whose namespace is used to scope
34+
/// the resource name</param>
3435
/// <returns>Сontent of the embedded resource as string</returns>
3536
public static string GetResourceAsString(string resourceName, Type type)
3637
{
38+
if (resourceName == null)
39+
{
40+
throw new ArgumentNullException(
41+
"resourceName", string.Format(CommonStrings.Common_ArgumentIsNull, "resourceName"));
42+
}
43+
44+
if (type == null)
45+
{
46+
throw new ArgumentNullException(
47+
"type", string.Format(CommonStrings.Common_ArgumentIsNull, "type"));
48+
}
49+
50+
if (string.IsNullOrWhiteSpace(resourceName))
51+
{
52+
throw new ArgumentException(
53+
string.Format(CommonStrings.Common_ArgumentIsEmpty, "resourceName"), "resourceName");
54+
}
55+
3756
Assembly assembly = type.GetTypeInfo().Assembly;
57+
string nameSpace = type.Namespace;
58+
string resourceFullName = nameSpace != null ? nameSpace + "." + resourceName : resourceName;
3859

39-
return GetResourceAsString(resourceName, assembly);
60+
return InnerGetResourceAsString(resourceFullName, assembly);
4061
}
4162

4263
/// <summary>
4364
/// Gets a content of the embedded resource as string
4465
/// </summary>
45-
/// <param name="resourceName">Resource name</param>
46-
/// <param name="assembly">Assembly that containing an embedded resource</param>
66+
/// <param name="resourceName">The case-sensitive resource name</param>
67+
/// <param name="assembly">The assembly, which contains the embedded resource</param>
4768
/// <returns>Сontent of the embedded resource as string</returns>
4869
public static string GetResourceAsString(string resourceName, Assembly assembly)
70+
{
71+
if (resourceName == null)
72+
{
73+
throw new ArgumentNullException(
74+
"resourceName", string.Format(CommonStrings.Common_ArgumentIsNull, "resourceName"));
75+
}
76+
77+
if (assembly == null)
78+
{
79+
throw new ArgumentNullException(
80+
"assembly", string.Format(CommonStrings.Common_ArgumentIsNull, "assembly"));
81+
}
82+
83+
if (string.IsNullOrWhiteSpace(resourceName))
84+
{
85+
throw new ArgumentException(
86+
string.Format(CommonStrings.Common_ArgumentIsEmpty, "resourceName"), "resourceName");
87+
}
88+
89+
return InnerGetResourceAsString(resourceName, assembly);
90+
}
91+
92+
private static string InnerGetResourceAsString(string resourceName, Assembly assembly)
4993
{
5094
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
5195
{

test/MsieJavaScriptEngine.Test.Common/CommonTestsBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ public virtual void ExecutionOfFileIsCorrect()
201201
}
202202

203203
[Test]
204-
public virtual void ExecutionOfResourceByTypeIsCorrect()
204+
public virtual void ExecutionOfResourceByNameAndTypeIsCorrect()
205205
{
206206
// Arrange
207-
const string resourceName = "MsieJavaScriptEngine.Test.Common.Resources.cube.js";
207+
const string resourceName = "Resources.cube.js";
208208
const string input = "cube(5);";
209209
const int targetOutput = 125;
210210

@@ -222,7 +222,7 @@ public virtual void ExecutionOfResourceByTypeIsCorrect()
222222
}
223223

224224
[Test]
225-
public virtual void ExecutionOfResourceByAssemblyIsCorrect()
225+
public virtual void ExecutionOfResourceByNameAndAssemblyIsCorrect()
226226
{
227227
// Arrange
228228
const string resourceName = "MsieJavaScriptEngine.Test.Common.Resources.power.js";

0 commit comments

Comments
 (0)