Skip to content

Commit

Permalink
Version 7.4.3: Improved handling of anonymous host types; [V8] [JScri…
Browse files Browse the repository at this point in the history
…pt] added support for JSON modules; [V8] made host object toJSON method non-enumerable; [V8] added enhanced compilation APIs (GitHub Issue #521); [V8] added debugger connection events (GitHub Issue #518); added Microsoft.ClearScript.Complete NuGet package (GitHub Issue #515); updated API documentation. Tested with V8 11.6.189.18.
  • Loading branch information
ClearScriptLib committed Aug 19, 2023
1 parent a790cbb commit 959ec3c
Show file tree
Hide file tree
Showing 889 changed files with 5,695 additions and 2,142 deletions.
1 change: 0 additions & 1 deletion ClearScript.NoV8.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Numerics/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=oleaut/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Parameterless/@EntryIndexedValue">True</s:Boolean>

<s:Boolean x:Key="/Default/UserDictionary/Words/=Plex/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=prog/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ptrs/@EntryIndexedValue">True</s:Boolean>
Expand Down
1 change: 0 additions & 1 deletion ClearScript.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Numerics/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=oleaut/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Parameterless/@EntryIndexedValue">True</s:Boolean>

<s:Boolean x:Key="/Default/UserDictionary/Words/=Plex/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=prog/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ptrs/@EntryIndexedValue">True</s:Boolean>
Expand Down
14 changes: 7 additions & 7 deletions ClearScript/ByRefArg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,34 @@ public T Value

public override object DynamicInvokeTarget => target.DynamicInvokeTarget;

public override HostTargetFlags GetFlags(IHostInvokeContext context)
public override HostTargetFlags GetFlags(IHostContext context)
{
return target.GetFlags(context);
}

public override string[] GetAuxMethodNames(IHostInvokeContext context, BindingFlags bindFlags)
public override string[] GetAuxMethodNames(IHostContext context, BindingFlags bindFlags)
{
return target.GetAuxMethodNames(context, bindFlags);
}

public override string[] GetAuxPropertyNames(IHostInvokeContext context, BindingFlags bindFlags)
public override string[] GetAuxPropertyNames(IHostContext context, BindingFlags bindFlags)
{
return target.GetAuxPropertyNames(context, bindFlags);
}

public override bool TryInvokeAuxMember(IHostInvokeContext context, string name, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
public override bool TryInvokeAuxMember(IHostContext context, string name, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
{
return target.TryInvokeAuxMember(context, name, invokeFlags, args, bindArgs, out result);
}

public override bool TryInvoke(IHostInvokeContext context, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
public override bool TryInvoke(IHostContext context, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
{
return target.TryInvoke(context, invokeFlags, args, bindArgs, out result);
}

public override Invocability GetInvocability(BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess, bool ignoreDynamic)
public override Invocability GetInvocability(IHostContext context, BindingFlags bindFlags, bool ignoreDynamic)
{
return target.GetInvocability(bindFlags, accessContext, defaultAccess, ignoreDynamic);
return target.GetInvocability(context, bindFlags, ignoreDynamic);
}

#endregion
Expand Down
8 changes: 5 additions & 3 deletions ClearScript/DefaultDocumentLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,11 @@ private async Task<Document> LoadDocumentAsync(DocumentSettings settings, Uri ur
}

var document = CacheDocument((bytes != null) ? new StringDocument(documentInfo, bytes) : new StringDocument(documentInfo, contents), false);
if (!settings.AccessFlags.HasFlag(DocumentAccessFlags.AllowCategoryMismatch) && (documentInfo.Category != (category ?? DocumentCategory.Script)))

var expectedCategory = category ?? DocumentCategory.Script;
if (!settings.AccessFlags.HasFlag(DocumentAccessFlags.AllowCategoryMismatch) && (documentInfo.Category != expectedCategory))
{
throw new FileLoadException("Document category mismatch", uri.IsFile ? uri.LocalPath : uri.AbsoluteUri);
throw new FileLoadException($"Document category mismatch: '{expectedCategory}' expected, '{documentInfo.Category}' loaded", uri.IsFile ? uri.LocalPath : uri.AbsoluteUri);
}

return document;
Expand Down Expand Up @@ -426,7 +428,7 @@ public override Document GetCachedDocument(Uri uri)
public override Document CacheDocument(Document document, bool replace)
{
MiscHelpers.VerifyNonNullArgument(document, nameof(document));
if (!document.Info.Uri.IsAbsoluteUri)
if ((document.Info.Uri == null) || !document.Info.Uri.IsAbsoluteUri)
{
throw new ArgumentException("The document must have an absolute URI");
}
Expand Down
39 changes: 39 additions & 0 deletions ClearScript/DocumentCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ internal DocumentCategory()
/// </summary>
public static DocumentCategory Script => ScriptDocument.Instance;

/// <summary>
/// Gets the document category for JSON documents.
/// </summary>
public static DocumentCategory Json => JsonDocument.Instance;

internal abstract DocumentKind Kind { get; }

internal abstract string DefaultName { get; }

#region Nested type: ScriptDocument
Expand All @@ -48,6 +55,8 @@ private ScriptDocument()

#region DocumentCategory overrides

internal override DocumentKind Kind => DocumentKind.Script;

internal override string DefaultName => "Script";

#endregion
Expand All @@ -63,5 +72,35 @@ public override string ToString()
}

#endregion

#region Nested type: JsonDocument

private sealed class JsonDocument : DocumentCategory
{
public static readonly JsonDocument Instance = new JsonDocument();

private JsonDocument()
{
}

#region DocumentCategory overrides

internal override DocumentKind Kind => DocumentKind.Json;

internal override string DefaultName => "JSON";

#endregion

#region Object overrides

public override string ToString()
{
return "JSON Document";
}

#endregion
}

#endregion
}
}
14 changes: 14 additions & 0 deletions ClearScript/DocumentKind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

namespace Microsoft.ClearScript
{
internal enum DocumentKind
{
// IMPORTANT: maintain bitwise equivalence with native enum DocumentKind
Script,
JavaScriptModule,
CommonJSModule,
Json
}
}
6 changes: 3 additions & 3 deletions ClearScript/Exports/VersionSymbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma once

#define CLEARSCRIPT_VERSION_STRING "7.4.2"
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,4,2
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.4.2"
#define CLEARSCRIPT_VERSION_STRING "7.4.3"
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,4,3
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.4.3"
#define CLEARSCRIPT_FILE_FLAGS 0L
8 changes: 4 additions & 4 deletions ClearScript/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ internal sealed class ExtensionMethodTable

public ExtensionMethodSummary Summary { get; private set; } = new ExtensionMethodSummary();

public bool ProcessType(Type type, Type accessContext, ScriptAccess defaultAccess)
public bool ProcessType(Type type, IHostContext context)
{
Debug.Assert(type.IsSpecific());
if (!table.ContainsKey(type) && type.HasExtensionMethods())
{
const BindingFlags bindFlags = BindingFlags.Public | BindingFlags.Static;
table[type] = type.GetMethods(bindFlags).Where(method => IsScriptableExtensionMethod(method, accessContext, defaultAccess)).ToArray();
table[type] = type.GetMethods(bindFlags).Where(method => IsScriptableExtensionMethod(method, context)).ToArray();
RebuildSummary();
return true;
}
Expand All @@ -36,9 +36,9 @@ public void RebuildSummary()
Summary = new ExtensionMethodSummary(table);
}

private static bool IsScriptableExtensionMethod(MethodInfo method, Type accessContext, ScriptAccess defaultAccess)
private static bool IsScriptableExtensionMethod(MethodInfo method, IHostContext context)
{
return method.IsScriptable(accessContext, defaultAccess) && method.HasCustomAttributes<ExtensionAttribute>(false);
return method.IsScriptable(context) && method.HasCustomAttributes<ExtensionAttribute>(false);
}
}

Expand Down
10 changes: 5 additions & 5 deletions ClearScript/HostIndexedProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ public override string ToString()

public override object DynamicInvokeTarget => null;

public override HostTargetFlags GetFlags(IHostInvokeContext context)
public override HostTargetFlags GetFlags(IHostContext context)
{
return HostTargetFlags.None;
}

public override string[] GetAuxMethodNames(IHostInvokeContext context, BindingFlags bindFlags)
public override string[] GetAuxMethodNames(IHostContext context, BindingFlags bindFlags)
{
return auxMethodNames;
}

public override bool TryInvokeAuxMember(IHostInvokeContext context, string memberName, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
public override bool TryInvokeAuxMember(IHostContext context, string memberName, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
{
if (invokeFlags.HasFlag(BindingFlags.InvokeMethod))
{
Expand All @@ -70,13 +70,13 @@ public override bool TryInvokeAuxMember(IHostInvokeContext context, string membe
return false;
}

public override bool TryInvoke(IHostInvokeContext context, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
public override bool TryInvoke(IHostContext context, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
{
result = target.InvokeMember(name, (invokeFlags.HasFlag(BindingFlags.SetField) ? BindingFlags.SetProperty : BindingFlags.GetProperty) | BindingFlags.SuppressChangeType, args, bindArgs, null, true);
return true;
}

public override Invocability GetInvocability(BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess, bool ignoreDynamic)
public override Invocability GetInvocability(IHostContext context, BindingFlags bindFlags, bool ignoreDynamic)
{
return Invocability.Delegate;
}
Expand Down
4 changes: 2 additions & 2 deletions ClearScript/HostItem.InvokeMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private IEnumerable<string> GetAltMethodNames(string name, BindingFlags bindFlag

private IEnumerable<string> GetAltMethodNamesInternal(string name, BindingFlags bindFlags)
{
foreach (var method in Target.Type.GetScriptableMethods(name, bindFlags, AccessContext, DefaultAccess))
foreach (var method in Target.Type.GetScriptableMethods(this, name, bindFlags))
{
var methodName = method.GetShortName();
if (methodName != name)
Expand Down Expand Up @@ -387,7 +387,7 @@ private IEnumerable<MethodInfo> GetReflectionCandidates(BindingFlags bindFlags,

private IEnumerable<MethodInfo> GetReflectionCandidates(BindingFlags bindFlags, Type type, string name, Type[] typeArgs)
{
foreach (var method in type.GetScriptableMethods(name, bindFlags, AccessContext, DefaultAccess))
foreach (var method in type.GetScriptableMethods(this, name, bindFlags))
{
MethodInfo tempMethod = null;

Expand Down
Loading

0 comments on commit 959ec3c

Please sign in to comment.