Skip to content

Commit 3cce29f

Browse files
committed
In JsRT modes, JsVariantToValue and JsValueToVariant native methods are no longer used for embedding objects and types
1 parent bf3a8c3 commit 3cce29f

33 files changed

+345
-705
lines changed

src/MsieJavaScriptEngine/HostItemBase.cs renamed to src/MsieJavaScriptEngine/ActiveScript/HostItemBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
using MsieJavaScriptEngine.Helpers;
77

8-
namespace MsieJavaScriptEngine
8+
namespace MsieJavaScriptEngine.ActiveScript
99
{
1010
/// <summary>
1111
/// Base class of item, that implements <see cref="IReflect"/> interface

src/MsieJavaScriptEngine/HostObject.cs renamed to src/MsieJavaScriptEngine/ActiveScript/HostObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using MsieJavaScriptEngine.Constants;
88
using MsieJavaScriptEngine.Helpers;
99

10-
namespace MsieJavaScriptEngine
10+
namespace MsieJavaScriptEngine.ActiveScript
1111
{
1212
/// <summary>
1313
/// Wrapper for object, that implements <see cref="IReflect"/> interface

src/MsieJavaScriptEngine/HostType.cs renamed to src/MsieJavaScriptEngine/ActiveScript/HostType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using MsieJavaScriptEngine.Constants;
88
using MsieJavaScriptEngine.Helpers;
99

10-
namespace MsieJavaScriptEngine
10+
namespace MsieJavaScriptEngine.ActiveScript
1111
{
1212
/// <summary>
1313
/// Wrapper for type, that implements <see cref="IReflect"/> interface

src/MsieJavaScriptEngine/Extensions/StringExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Linq;
32

43
namespace MsieJavaScriptEngine.Extensions
54
{
@@ -63,6 +62,7 @@ public static string TrimStart(this string source, string trimString)
6362

6463
return result;
6564
}
65+
#if NETFRAMEWORK
6666

6767
/// <summary>
6868
/// Converts a first letter of string to capital
@@ -83,7 +83,7 @@ public static string CapitalizeFirstLetter(this string source)
8383
}
8484

8585
string result;
86-
char firstCharacter = source.First();
86+
char firstCharacter = source[0];
8787

8888
if (char.IsLower(firstCharacter))
8989
{
@@ -100,6 +100,7 @@ public static string CapitalizeFirstLetter(this string source)
100100

101101
return result;
102102
}
103+
#endif
103104

104105
/// <summary>
105106
/// Splits a string into lines

src/MsieJavaScriptEngine/Helpers/ComHelpers.cs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,6 @@ public static IntPtr CreateInstanceByClsid<T>(Guid clsid)
2727
return pInterface;
2828
}
2929

30-
public static IntPtr CreateInstanceByProgId<T>(string progId)
31-
{
32-
Guid clsid = ClsidFromProgId(progId);
33-
IntPtr pInterface = CreateInstanceByClsid<T>(clsid);
34-
35-
return pInterface;
36-
}
37-
38-
private static Guid ClsidFromProgId(string progId)
39-
{
40-
Guid clsid;
41-
42-
if (!Guid.TryParseExact(progId, "B", out clsid))
43-
{
44-
HResult.Check(NativeMethods.CLSIDFromProgID(progId, out clsid));
45-
}
46-
47-
return clsid;
48-
}
49-
5030
public static bool TryCreateComObject<T>(string progId, string serverName, out T obj) where T : class
5131
{
5232
Type type;
@@ -92,14 +72,6 @@ public static IntPtr QueryInterfaceNoThrow<T>(IntPtr pUnknown)
9272
return result == ComErrorCode.S_OK ? pInterface : IntPtr.Zero;
9373
}
9474

95-
public static T GetMethodDelegate<T>(IntPtr pInterface, int methodIndex) where T : class
96-
{
97-
var pVTable = Marshal.ReadIntPtr(pInterface);
98-
var pMethod = Marshal.ReadIntPtr(pVTable + methodIndex * IntPtr.Size);
99-
100-
return Marshal.GetDelegateForFunctionPointer(pMethod, typeof(T)) as T;
101-
}
102-
10375
public static void ReleaseAndEmpty(ref IntPtr pUnk)
10476
{
10577
if (pUnk != IntPtr.Zero)
@@ -121,12 +93,6 @@ public static extern uint CoCreateInstance(
12193
[In] ref Guid iid,
12294
[Out] out IntPtr pInterface
12395
);
124-
125-
[DllImport("ole32.dll", ExactSpelling = true)]
126-
public static extern uint CLSIDFromProgID(
127-
[In] [MarshalAs(UnmanagedType.LPWStr)] string progId,
128-
[Out] out Guid clsid
129-
);
13096
}
13197

13298
#endregion

src/MsieJavaScriptEngine/Helpers/NumericHelpers.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,6 @@ internal static class NumericHelpers
1212
private const double MAX_INTEGER_IN_DOUBLE = (1L << 53) - 1;
1313

1414

15-
/// <summary>
16-
/// Gets a value indicating whether the specified type is one of the numeric types
17-
/// </summary>
18-
/// <param name="type">The type</param>
19-
/// <returns>true if the specified type is one of the numeric types; otherwise, false</returns>
20-
public static bool IsNumericType(Type type)
21-
{
22-
TypeCode typeCode = type.GetTypeCode();
23-
24-
switch (typeCode)
25-
{
26-
case TypeCode.SByte:
27-
case TypeCode.Byte:
28-
case TypeCode.Int16:
29-
case TypeCode.UInt16:
30-
case TypeCode.Int32:
31-
case TypeCode.UInt32:
32-
case TypeCode.Int64:
33-
case TypeCode.UInt64:
34-
case TypeCode.Single:
35-
case TypeCode.Double:
36-
case TypeCode.Decimal:
37-
return true;
38-
default:
39-
return false;
40-
}
41-
}
42-
4315
/// <summary>
4416
/// Casts a double value to the correct type
4517
/// </summary>

src/MsieJavaScriptEngine/Helpers/ReflectionHelpers.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
using System;
2-
#if !NETFRAMEWORK
32
using System.Collections.Generic;
43
using System.Linq;
5-
#endif
64
using System.Reflection;
7-
#if !NETFRAMEWORK
85

96
using MsieJavaScriptEngine.Utilities;
10-
#endif
117

128
namespace MsieJavaScriptEngine.Helpers
139
{
@@ -66,7 +62,7 @@ public static MethodInfo[] GetFullyFledgedMethods(MethodInfo[] methods)
6662

6763
return fullyFledgedMethods;
6864
}
69-
#else
65+
#endif
7066

7167
public static void FixFieldValueType(ref object value, FieldInfo field)
7268
{
@@ -269,6 +265,5 @@ public ushort CompatibilityScore
269265
set;
270266
}
271267
}
272-
#endif
273268
}
274269
}

src/MsieJavaScriptEngine/Helpers/TypeMappingHelpers.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Linq;
44

5+
using MsieJavaScriptEngine.ActiveScript;
56
using MsieJavaScriptEngine.Utilities;
67

78
namespace MsieJavaScriptEngine.Helpers

src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsValue.cs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -304,24 +304,6 @@ public static EdgeJsValue FromString(string value)
304304

305305
return reference;
306306
}
307-
#if NETFRAMEWORK
308-
309-
/// <summary>
310-
/// Creates a JavaScript value that is a projection of the passed in object
311-
/// </summary>
312-
/// <remarks>
313-
/// Requires an active script context.
314-
/// </remarks>
315-
/// <param name="value">The object to be projected</param>
316-
/// <returns>The JavaScript value that is a projection of the object</returns>
317-
public static EdgeJsValue FromObject(object value)
318-
{
319-
EdgeJsValue reference;
320-
EdgeJsErrorHelpers.ThrowIfError(EdgeNativeMethods.JsVariantToValue(ref value, out reference));
321-
322-
return reference;
323-
}
324-
#endif
325307

326308
/// <summary>
327309
/// Creates a new <c>Object</c>
@@ -611,23 +593,6 @@ public int ToInt32()
611593

612594
return Marshal.PtrToStringUni(buffer, (int)length);
613595
}
614-
#if NETFRAMEWORK
615-
616-
/// <summary>
617-
/// Retrieves a object representation of an <c>Object</c> value
618-
/// </summary>
619-
/// <remarks>
620-
/// Requires an active script context.
621-
/// </remarks>
622-
/// <returns>The object representation of the value</returns>
623-
public object ToObject()
624-
{
625-
object value;
626-
EdgeJsErrorHelpers.ThrowIfError(EdgeNativeMethods.JsValueToVariant(this, out value));
627-
628-
return value;
629-
}
630-
#endif
631596

632597
/// <summary>
633598
/// Converts a value to <c>Boolean</c> using regular JavaScript semantics

src/MsieJavaScriptEngine/JsRt/Edge/EdgeNativeMethods.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,6 @@ internal static extern JsErrorCode JsSetRuntimeBeforeCollectCallback(EdgeJsRunti
148148

149149
[DllImport(DllName.Chakra)]
150150
internal static extern JsErrorCode JsConvertValueToString(EdgeJsValue value, out EdgeJsValue stringValue);
151-
#if NETFRAMEWORK
152-
153-
[DllImport(DllName.Chakra)]
154-
internal static extern JsErrorCode JsVariantToValue([MarshalAs(UnmanagedType.Struct)] ref object var,
155-
out EdgeJsValue value);
156-
157-
[DllImport(DllName.Chakra)]
158-
internal static extern JsErrorCode JsValueToVariant(EdgeJsValue obj,
159-
[MarshalAs(UnmanagedType.Struct)] out object var);
160-
#endif
161151

162152
[DllImport(DllName.Chakra)]
163153
internal static extern JsErrorCode JsGetGlobalObject(out EdgeJsValue globalObject);

0 commit comments

Comments
 (0)