Skip to content

Commit efccbff

Browse files
committed
1. Added the EmbedHostType method (embeds a host type to script code);
2. In JavaScriptEngineSwitcher.Msie added support of MSIE JavaScript Engine version 1.7.0 Beta 1; 3. In JavaScriptEngineSwitcher.Jurassic added support of Jurassic version of February 24, 2016; 4. In JavaScriptEngineSwitcher.Jint added support of Jint version of February 18, 2016.
1 parent 0deb53f commit efccbff

File tree

27 files changed

+1074
-70
lines changed

27 files changed

+1074
-70
lines changed

Binaries/Jint/Jint.dll

-8 KB
Binary file not shown.

Binaries/Jurassic/Jurassic.dll

49.5 KB
Binary file not shown.

src/JavaScriptEngineSwitcher.ChakraCore/ChakraCoreJsEngine.cs

Lines changed: 221 additions & 63 deletions
Large diffs are not rendered by default.

src/JavaScriptEngineSwitcher.ChakraCore/Helpers/ReflectionHelpers.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@
1111
/// </summary>
1212
internal static class ReflectionHelpers
1313
{
14+
public static BindingFlags GetDefaultBindingFlags(bool instance)
15+
{
16+
BindingFlags bindingFlags = BindingFlags.Public;
17+
if (instance)
18+
{
19+
bindingFlags |= BindingFlags.Instance;
20+
}
21+
else
22+
{
23+
bindingFlags |= BindingFlags.Static;
24+
}
25+
26+
return bindingFlags;
27+
}
28+
1429
public static void FixFieldValueType(ref object value, FieldInfo field)
1530
{
1631
Type valueType = value.GetType();
@@ -67,7 +82,7 @@ public static void FixArgumentTypes(ref object[] argValues, ParameterInfo[] para
6782
}
6883
}
6984

70-
public static MethodInfo GetBestFitMethod(MethodInfo[] methods, object[] argValues)
85+
public static MethodBase GetBestFitMethod(MethodBase[] methods, object[] argValues)
7186
{
7287
int argCount = argValues.Length;
7388
var methodCandidates = methods

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

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/JavaScriptEngineSwitcher.ChakraCore/Resources/Strings.resx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,27 @@
141141
<data name="Runtime_HostObjectPropertySettingFailed" xml:space="preserve">
142142
<value>During setting value of '{0}' property of the host object an error has occurred - “{1}”.</value>
143143
</data>
144+
<data name="Runtime_HostTypeConstructorInvocationFailed" xml:space="preserve">
145+
<value>During invocation of constructor of the `{0}` host type an error has occurred - “{1}”.</value>
146+
</data>
147+
<data name="Runtime_HostTypeConstructorNotFound" xml:space="preserve">
148+
<value>Could not create instance of the `{0}` host type, because it does not have any public constructor.</value>
149+
</data>
150+
<data name="Runtime_HostTypeFieldGettingFailed" xml:space="preserve">
151+
<value>During getting value of '{0}' field of the `{1}` host type an error has occurred - “{2}”.</value>
152+
</data>
153+
<data name="Runtime_HostTypeFieldSettingFailed" xml:space="preserve">
154+
<value>During setting value of '{0}' field of the `{1}` host type an error has occurred - “{2}”.</value>
155+
</data>
156+
<data name="Runtime_HostTypeMethodInvocationFailed" xml:space="preserve">
157+
<value>During invocation of '{0}' method of the `{1}` host type an error has occurred - “{2}”.</value>
158+
</data>
159+
<data name="Runtime_HostTypePropertyGettingFailed" xml:space="preserve">
160+
<value>During getting value of '{0}' property of the `{1}` host type an error has occurred - “{2}”.</value>
161+
</data>
162+
<data name="Runtime_HostTypePropertySettingFailed" xml:space="preserve">
163+
<value>During setting value of '{0}' property of the host type `{1}` an error has occurred - “{2}”.</value>
164+
</data>
144165
<data name="Runtime_InvalidThisContextForHostObjectField" xml:space="preserve">
145166
<value>Could not retrieve field '{0}' of the host object, because there was an invalid `this` context.</value>
146167
</data>
@@ -150,6 +171,9 @@
150171
<data name="Runtime_InvalidThisContextForHostObjectProperty" xml:space="preserve">
151172
<value>Could not retrieve property '{0}' of the host object, because there was an invalid `this` context.</value>
152173
</data>
174+
<data name="Runtime_SuitableConstructorOfHostTypeNotFound" xml:space="preserve">
175+
<value>Could not find suitable constructor or not enough arguments to invoke of constructor of the `{0}` host type.</value>
176+
</data>
153177
<data name="Runtime_SuitableMethodOfHostObjectNotFound" xml:space="preserve">
154178
<value>Could not find suitable method or not enough arguments to invoke of '{0}' method of the host object.</value>
155179
</data>

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,27 @@
141141
<data name="Runtime_HostObjectPropertySettingFailed" xml:space="preserve">
142142
<value>Во время присваивания значения свойству "{0}" объекта хоста произошла ошибка - «{1}»!</value>
143143
</data>
144+
<data name="Runtime_HostTypeConstructorInvocationFailed" xml:space="preserve">
145+
<value>Во время вызова конструктора типа хоста `{0}` произошла ошибка - «{1}»!</value>
146+
</data>
147+
<data name="Runtime_HostTypeConstructorNotFound" xml:space="preserve">
148+
<value>Не удается создать экземпляр типа хоста `{0}`, потому что он не имеет ни одного публичного конструктора!</value>
149+
</data>
150+
<data name="Runtime_HostTypeFieldGettingFailed" xml:space="preserve">
151+
<value>Во время получения значения поля "{0}" типа хоста `{1}` произошла ошибка - «{2}»!</value>
152+
</data>
153+
<data name="Runtime_HostTypeFieldSettingFailed" xml:space="preserve">
154+
<value>Во время присваивания значения полю "{0}" типа хоста `{1}` произошла ошибка - «{2}»!</value>
155+
</data>
156+
<data name="Runtime_HostTypeMethodInvocationFailed" xml:space="preserve">
157+
<value>Во время вызова метода "{0}" типа хоста `{1}` произошла ошибка - «{2}»!</value>
158+
</data>
159+
<data name="Runtime_HostTypePropertyGettingFailed" xml:space="preserve">
160+
<value>Во время получения значения свойства "{0}" типа хоста `{1}` произошла ошибка - «{2}»!</value>
161+
</data>
162+
<data name="Runtime_HostTypePropertySettingFailed" xml:space="preserve">
163+
<value>Во время присваивания значения свойству "{0}" типа хоста `{1}` произошла ошибка - «{2}»!</value>
164+
</data>
144165
<data name="Runtime_InvalidThisContextForHostObjectField" xml:space="preserve">
145166
<value>Не удалось получить поле "{0}" объекта хоста, потому что контекст `this` недействителен!</value>
146167
</data>
@@ -150,7 +171,10 @@
150171
<data name="Runtime_InvalidThisContextForHostObjectProperty" xml:space="preserve">
151172
<value>Не удалось получить свойство "{0}" объекта хоста, потому что контекст `this` недействителен!</value>
152173
</data>
174+
<data name="Runtime_SuitableConstructorOfHostTypeNotFound" xml:space="preserve">
175+
<value>Не получается найти подходящий конструктор или не хватает аргументов для вызова конструктора `{0}` типа хоста!</value>
176+
</data>
153177
<data name="Runtime_SuitableMethodOfHostObjectNotFound" xml:space="preserve">
154-
<value>Не получается найти подходящий метод или не хватает аргументов для вызова метода "{0}"объекта хоста!</value>
178+
<value>Не получается найти подходящий метод или не хватает аргументов для вызова метода "{0}" объекта хоста!</value>
155179
</data>
156180
</root>

src/JavaScriptEngineSwitcher.Core/IJsEngine.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,16 @@ string Version
127127
/// <param name="value">The object to expose</param>
128128
/// <remarks>Allows to embed instances of simple classes (or structures) and delegates.</remarks>
129129
void EmbedHostObject(string itemName, object value);
130+
131+
/// <summary>
132+
/// Embeds a host type to script code
133+
/// </summary>
134+
/// <param name="itemName">The name for the new global variable that will represent the type</param>
135+
/// <param name="type">The type to expose</param>
136+
/// <remarks>
137+
/// Host types are exposed to script code in the form of objects whose properties and
138+
/// methods are bound to the type's static members.
139+
/// </remarks>
140+
void EmbedHostType(string itemName, Type type);
130141
}
131142
}

src/JavaScriptEngineSwitcher.Core/JsEngineBase.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ protected virtual void InnerEmbedHostObject(string itemName, object value)
5252
throw new NotImplementedException();
5353
}
5454

55+
protected virtual void InnerEmbedHostType(string itemName, Type type)
56+
{
57+
throw new NotImplementedException();
58+
}
59+
5560
#region IJsEngine implementation
5661

5762
public abstract string Name
@@ -391,7 +396,7 @@ public virtual void EmbedHostObject(string itemName, object value)
391396
|| itemType == typeof(DateTime))
392397
{
393398
throw new NotSupportedTypeException(
394-
string.Format(Strings.Runtime_EmbeddedHostObjectTypeNotSupported, itemType.FullName));
399+
string.Format(Strings.Runtime_EmbeddedHostObjectTypeNotSupported, itemName, itemType.FullName));
395400
}
396401
}
397402
else
@@ -402,6 +407,39 @@ public virtual void EmbedHostObject(string itemName, object value)
402407
InnerEmbedHostObject(itemName, value);
403408
}
404409

410+
public virtual void EmbedHostType(string itemName, Type type)
411+
{
412+
VerifyNotDisposed();
413+
414+
if (string.IsNullOrWhiteSpace(itemName))
415+
{
416+
throw new ArgumentException(
417+
string.Format(Strings.Common_ArgumentIsEmpty, "itemName"), "itemName");
418+
}
419+
420+
if (!ValidationHelpers.CheckNameFormat(itemName))
421+
{
422+
throw new FormatException(
423+
string.Format(Strings.Runtime_InvalidScriptItemNameFormat, itemName));
424+
}
425+
426+
if (type != null)
427+
{
428+
if (ValidationHelpers.IsPrimitiveType(type)
429+
|| type == typeof(Undefined))
430+
{
431+
throw new NotSupportedTypeException(
432+
string.Format(Strings.Runtime_EmbeddedHostTypeNotSupported, type.FullName));
433+
}
434+
}
435+
else
436+
{
437+
throw new ArgumentNullException("type", string.Format(Strings.Common_ArgumentIsNull, "type"));
438+
}
439+
440+
InnerEmbedHostType(itemName, type);
441+
}
442+
405443
#endregion
406444

407445
#region IDisposable implementation

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

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)