Version 7.4.3: Improved handling of anonymous host types; [V8] [JScript] 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.

This commit is contained in:
ClearScript 2023-08-19 10:29:45 -04:00
Родитель a790cbb6b4
Коммит 959ec3c861
889 изменённых файлов: 5691 добавлений и 2138 удалений

Просмотреть файл

@ -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>

Просмотреть файл

@ -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>

Просмотреть файл

@ -46,34 +46,34 @@ namespace Microsoft.ClearScript
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

Просмотреть файл

@ -309,9 +309,11 @@ namespace Microsoft.ClearScript
}
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;
@ -426,7 +428,7 @@ namespace Microsoft.ClearScript
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");
}

Просмотреть файл

@ -34,6 +34,13 @@ namespace Microsoft.ClearScript
/// </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
@ -48,6 +55,8 @@ namespace Microsoft.ClearScript
#region DocumentCategory overrides
internal override DocumentKind Kind => DocumentKind.Script;
internal override string DefaultName => "Script";
#endregion
@ -63,5 +72,35 @@ namespace Microsoft.ClearScript
}
#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
}
}

Просмотреть файл

@ -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
}
}

Просмотреть файл

@ -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

Просмотреть файл

@ -17,13 +17,13 @@ namespace Microsoft.ClearScript
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;
}
@ -36,9 +36,9 @@ namespace Microsoft.ClearScript
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);
}
}

Просмотреть файл

@ -39,17 +39,17 @@ namespace Microsoft.ClearScript
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))
{
@ -70,13 +70,13 @@ namespace Microsoft.ClearScript
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;
}

Просмотреть файл

@ -270,7 +270,7 @@ namespace Microsoft.ClearScript
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)
@ -387,7 +387,7 @@ namespace Microsoft.ClearScript
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;

Просмотреть файл

@ -18,7 +18,7 @@ using Microsoft.ClearScript.Util.COM;
namespace Microsoft.ClearScript
{
internal partial class HostItem : DynamicObject, IReflect, IDynamic, IEnumVARIANT, ICustomQueryInterface, IScriptMarshalWrapper, IHostInvokeContext
internal partial class HostItem : DynamicObject, IReflect, IDynamic, IEnumVARIANT, ICustomQueryInterface, IScriptMarshalWrapper, IHostTargetContext
{
#region data
@ -122,7 +122,7 @@ namespace Microsoft.ClearScript
{
if (TargetInvocability == null)
{
TargetInvocability = Target.GetInvocability(GetCommonBindFlags(), AccessContext, DefaultAccess, Flags.HasFlag(HostItemFlags.HideDynamicMembers));
TargetInvocability = Target.GetInvocability(this, GetCommonBindFlags(), Flags.HasFlag(HostItemFlags.HideDynamicMembers));
}
return TargetInvocability.GetValueOrDefault();
@ -362,7 +362,7 @@ namespace Microsoft.ClearScript
set => targetMemberData.TargetInvocability = value;
}
private Type CurrentAccessContext => (Flags.HasFlag(HostItemFlags.PrivateAccess) || (Target.Type.IsAnonymous() && !Engine.EnforceAnonymousTypeAccess)) ? Target.Type : Engine.AccessContext;
private Type CurrentAccessContext => Flags.HasFlag(HostItemFlags.PrivateAccess) ? Target.Type : Engine.AccessContext;
private ScriptAccess CurrentDefaultAccess => Engine.DefaultAccess;
@ -613,7 +613,7 @@ namespace Microsoft.ClearScript
{
if (TypeEventNames == null)
{
var localEvents = Target.Type.GetScriptableEvents(GetCommonBindFlags(), AccessContext, DefaultAccess);
var localEvents = Target.Type.GetScriptableEvents(this, GetCommonBindFlags());
TypeEventNames = localEvents.Select(eventInfo => eventInfo.GetScriptName()).ToArray();
}
@ -624,7 +624,7 @@ namespace Microsoft.ClearScript
{
if (TypeFieldNames == null)
{
var localFields = Target.Type.GetScriptableFields(GetCommonBindFlags(), AccessContext, DefaultAccess);
var localFields = Target.Type.GetScriptableFields(this, GetCommonBindFlags());
TypeFieldNames = localFields.Select(field => field.GetScriptName()).ToArray();
}
@ -635,7 +635,7 @@ namespace Microsoft.ClearScript
{
if (TypeMethodNames == null)
{
var localMethods = Target.Type.GetScriptableMethods(GetMethodBindFlags(), AccessContext, DefaultAccess);
var localMethods = Target.Type.GetScriptableMethods(this, GetMethodBindFlags());
TypeMethodNames = localMethods.Select(method => method.GetScriptName()).ToArray();
}
@ -646,7 +646,7 @@ namespace Microsoft.ClearScript
{
if (TypePropertyNames == null)
{
var localProperties = Target.Type.GetScriptableProperties(GetCommonBindFlags(), AccessContext, DefaultAccess);
var localProperties = Target.Type.GetScriptableProperties(this, GetCommonBindFlags());
TypePropertyNames = localProperties.Select(property => property.GetScriptName()).ToArray();
}
@ -1402,7 +1402,7 @@ namespace Microsoft.ClearScript
if (name == SpecialMemberNames.Default)
{
var defaultProperty = Target.Type.GetScriptableDefaultProperty(invokeFlags, args, bindArgs, AccessContext, DefaultAccess);
var defaultProperty = Target.Type.GetScriptableDefaultProperty(this, invokeFlags, args, bindArgs);
if (defaultProperty != null)
{
return GetHostProperty(signature, defaultProperty, invokeFlags, args);
@ -1511,7 +1511,7 @@ namespace Microsoft.ClearScript
}
}
var property = Target.Type.GetScriptableProperty(name, invokeFlags, args, bindArgs, AccessContext, DefaultAccess);
var property = Target.Type.GetScriptableProperty(this, name, invokeFlags, args, bindArgs);
if (property != null)
{
return GetHostProperty(signature, property, invokeFlags, args);
@ -1522,14 +1522,14 @@ namespace Microsoft.ClearScript
throw new MissingMemberException(MiscHelpers.FormatInvariant("The object has no suitable property named '{0}'", name));
}
var eventInfo = Target.Type.GetScriptableEvent(name, invokeFlags, AccessContext, DefaultAccess);
var eventInfo = Target.Type.GetScriptableEvent(this, name, invokeFlags);
if (eventInfo != null)
{
isCacheable = (TargetDynamicMetaObject == null);
return typeof(EventSource<>).MakeSpecificType(eventInfo.EventHandlerType).CreateInstance(BindingFlags.NonPublic, Engine, Target.InvokeTarget, eventInfo);
}
var field = Target.Type.GetScriptableField(name, invokeFlags, AccessContext, DefaultAccess);
var field = Target.Type.GetScriptableField(this, name, invokeFlags);
if (field != null)
{
return GetHostField(signature, field, out isCacheable);
@ -1537,7 +1537,7 @@ namespace Microsoft.ClearScript
if (includeBoundMembers)
{
if (Target.Type.GetScriptableProperties(name, invokeFlags, AccessContext, DefaultAccess).Any())
if (Target.Type.GetScriptableProperties(this, name, invokeFlags).Any())
{
if (HostIndexedPropertyMap == null)
{
@ -1600,7 +1600,7 @@ namespace Microsoft.ClearScript
}
var getMethod = property.GetMethod;
if ((getMethod == null) || !getMethod.IsAccessible(AccessContext) || getMethod.IsBlockedFromScript(property.GetScriptAccess(DefaultAccess), false))
if ((getMethod == null) || !getMethod.IsAccessible(this) || getMethod.IsBlockedFromScript(property.GetScriptAccess(DefaultAccess), false))
{
throw new UnauthorizedAccessException("The property get method is unavailable or inaccessible");
}
@ -1654,7 +1654,7 @@ namespace Microsoft.ClearScript
object result;
var defaultProperty = Target.Type.GetScriptableDefaultProperty(invokeFlags, args.Take(args.Length - 1).ToArray(), bindArgs.Take(bindArgs.Length - 1).ToArray(), AccessContext, DefaultAccess);
var defaultProperty = Target.Type.GetScriptableDefaultProperty(this, invokeFlags, args.Take(args.Length - 1).ToArray(), bindArgs.Take(bindArgs.Length - 1).ToArray());
if (defaultProperty != null)
{
return SetHostProperty(signature, defaultProperty, args, bindArgs);
@ -1735,13 +1735,13 @@ namespace Microsoft.ClearScript
throw new InvalidOperationException("Invalid argument count");
}
var property = Target.Type.GetScriptableProperty(name, invokeFlags, args.Take(args.Length - 1).ToArray(), bindArgs.Take(bindArgs.Length - 1).ToArray(), AccessContext, DefaultAccess);
var property = Target.Type.GetScriptableProperty(this, name, invokeFlags, args.Take(args.Length - 1).ToArray(), bindArgs.Take(bindArgs.Length - 1).ToArray());
if (property != null)
{
return SetHostProperty(signature, property, args, bindArgs);
}
var field = Target.Type.GetScriptableField(name, invokeFlags, AccessContext, DefaultAccess);
var field = Target.Type.GetScriptableField(this, name, invokeFlags);
if (field != null)
{
return SetHostField(signature, field, args);
@ -1759,7 +1759,7 @@ namespace Microsoft.ClearScript
}
var setMethod = property.SetMethod;
if ((setMethod == null) || !setMethod.IsAccessible(AccessContext) || setMethod.IsBlockedFromScript(scriptAccess, false))
if ((setMethod == null) || !setMethod.IsAccessible(this) || setMethod.IsBlockedFromScript(scriptAccess, false))
{
throw new UnauthorizedAccessException("The property set method is unavailable or inaccessible");
}
@ -2366,7 +2366,7 @@ namespace Microsoft.ClearScript
#endregion
#region IHostInvokeContext implementation
#region IHostTargetContext implementation
public Type AccessContext => CachedAccessContext;

Просмотреть файл

@ -37,18 +37,18 @@ namespace Microsoft.ClearScript
public override object DynamicInvokeTarget => null;
public override HostTargetFlags GetFlags(IHostInvokeContext context)
public override HostTargetFlags GetFlags(IHostContext context)
{
return HostTargetFlags.None;
}
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, 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;
}

Просмотреть файл

@ -125,7 +125,7 @@ namespace Microsoft.ClearScript
public override object DynamicInvokeTarget => target;
public override HostTargetFlags GetFlags(IHostInvokeContext context)
public override HostTargetFlags GetFlags(IHostContext context)
{
var flags = HostTargetFlags.AllowInstanceMembers | HostTargetFlags.AllowExtensionMethods;
if (context.Engine.ExposeHostObjectStaticMembers)
@ -136,9 +136,9 @@ namespace Microsoft.ClearScript
return flags;
}
public override Invocability GetInvocability(BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess, bool ignoreDynamic)
public override Invocability GetInvocability(IHostContext context, BindingFlags bindFlags, bool ignoreDynamic)
{
return type.GetInvocability(bindFlags, accessContext, defaultAccess, ignoreDynamic);
return type.GetInvocability(context, bindFlags, ignoreDynamic);
}
#endregion

Просмотреть файл

@ -17,30 +17,30 @@ namespace Microsoft.ClearScript
public abstract object DynamicInvokeTarget { get; }
public abstract HostTargetFlags GetFlags(IHostInvokeContext context);
public abstract HostTargetFlags GetFlags(IHostContext context);
public virtual string[] GetAuxMethodNames(IHostInvokeContext context, BindingFlags bindFlags)
public virtual string[] GetAuxMethodNames(IHostContext context, BindingFlags bindFlags)
{
return ArrayHelpers.GetEmptyArray<string>();
}
public virtual string[] GetAuxPropertyNames(IHostInvokeContext context, BindingFlags bindFlags)
public virtual string[] GetAuxPropertyNames(IHostContext context, BindingFlags bindFlags)
{
return ArrayHelpers.GetEmptyArray<string>();
}
public virtual bool TryInvokeAuxMember(IHostInvokeContext context, string name, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
public virtual bool TryInvokeAuxMember(IHostContext context, string name, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
{
result = null;
return false;
}
public virtual bool TryInvoke(IHostInvokeContext context, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
public virtual bool TryInvoke(IHostContext context, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
{
result = null;
return false;
}
public abstract Invocability GetInvocability(BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess, bool ignoreDynamic);
public abstract Invocability GetInvocability(IHostContext context, BindingFlags bindFlags, bool ignoreDynamic);
}
}

Просмотреть файл

@ -142,29 +142,29 @@ namespace Microsoft.ClearScript
public override object DynamicInvokeTarget => GetSpecificType();
public override HostTargetFlags GetFlags(IHostInvokeContext context)
public override HostTargetFlags GetFlags(IHostContext context)
{
var type = GetSpecificTypeNoThrow();
return (type != null) ? HostTargetFlags.AllowStaticMembers : HostTargetFlags.None;
}
public override string[] GetAuxPropertyNames(IHostInvokeContext context, BindingFlags bindFlags)
public override string[] GetAuxPropertyNames(IHostContext context, BindingFlags bindFlags)
{
var type = GetSpecificTypeNoThrow();
if (type != null)
{
return type.GetScriptableNestedTypes(bindFlags, context.AccessContext, context.DefaultAccess).Select(testType => testType.GetRootName()).Distinct().ToArray();
return type.GetScriptableNestedTypes(context, bindFlags).Select(testType => testType.GetRootName()).Distinct().ToArray();
}
return ArrayHelpers.GetEmptyArray<string>();
}
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)
{
var type = GetSpecificTypeNoThrow();
if (type != null)
{
var nestedTypes = type.GetScriptableNestedTypes(invokeFlags, context.AccessContext, context.DefaultAccess).Where(testType => string.Equals(testType.GetRootName(), name, invokeFlags.GetMemberNameComparison())).ToIList();
var nestedTypes = type.GetScriptableNestedTypes(context, invokeFlags).Where(testType => string.Equals(testType.GetRootName(), name, invokeFlags.GetMemberNameComparison())).ToIList();
if (nestedTypes.Count > 0)
{
var tempResult = Wrap(nestedTypes.Select(testType => testType.ApplyTypeArguments(type.GetGenericArguments())).ToArray());
@ -190,7 +190,7 @@ namespace Microsoft.ClearScript
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)
{
if (!invokeFlags.HasFlag(BindingFlags.InvokeMethod) || (args.Length < 1))
{
@ -216,7 +216,7 @@ namespace Microsoft.ClearScript
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;
}

Просмотреть файл

@ -18,7 +18,7 @@ namespace Microsoft.ClearScript
{
private static readonly string[] auxPropertyNames = { "out", "ref", "value" };
public override string[] GetAuxPropertyNames(IHostInvokeContext context, BindingFlags bindFlags)
public override string[] GetAuxPropertyNames(IHostContext context, BindingFlags bindFlags)
{
return auxPropertyNames;
}
@ -70,7 +70,7 @@ namespace Microsoft.ClearScript
public override object DynamicInvokeTarget => Value;
public override HostTargetFlags GetFlags(IHostInvokeContext context)
public override HostTargetFlags GetFlags(IHostContext context)
{
var flags = HostTargetFlags.AllowInstanceMembers | HostTargetFlags.AllowExtensionMethods;
if (context.Engine.ExposeHostObjectStaticMembers)
@ -81,7 +81,7 @@ namespace Microsoft.ClearScript
return flags;
}
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)
{
const BindingFlags getPropertyFlags =
BindingFlags.GetField |
@ -147,9 +147,9 @@ namespace Microsoft.ClearScript
return false;
}
public override Invocability GetInvocability(BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess, bool ignoreDynamic)
public override Invocability GetInvocability(IHostContext context, BindingFlags bindFlags, bool ignoreDynamic)
{
return typeof(T).GetInvocability(bindFlags, accessContext, defaultAccess, ignoreDynamic);
return typeof(T).GetInvocability(context, bindFlags, ignoreDynamic);
}
#endregion

Просмотреть файл

@ -53,7 +53,6 @@ namespace Microsoft.ClearScript.JavaScript
}).valueOf()
");
}
}
public int ModuleCacheSize => moduleCache.Count;
@ -203,22 +202,29 @@ namespace Microsoft.ClearScript.JavaScript
private object Require(string specifier)
{
var document = engine.DocumentSettings.LoadDocument(DocumentInfo.Info, specifier, ModuleCategory.CommonJS, null);
if (document.Info.Category != ModuleCategory.CommonJS)
if (document.Info.Category == ModuleCategory.CommonJS)
{
var uri = document.Info.Uri;
throw new FileLoadException("Document category mismatch", uri.IsFile ? uri.LocalPath : uri.AbsoluteUri);
var code = document.GetTextContents();
if (engine.FormatCode)
{
code = MiscHelpers.FormatCode(code);
}
var target = manager.GetOrCreateModule(document.Info.MakeUnique(engine), code);
target.Process();
return target.exports;
}
var code = document.GetTextContents();
if (engine.FormatCode)
if (document.Info.Category == DocumentCategory.Json)
{
code = MiscHelpers.FormatCode(code);
return ((IJavaScriptEngine)engine).JsonModuleManager.GetOrCreateModule(document.Info.MakeUnique(engine), document.GetTextContents()).Result;
}
var target = manager.GetOrCreateModule(document.Info.MakeUnique(engine), code);
target.Process();
return target.exports;
var uri = document.Info.Uri;
var name = (uri != null) ? (uri.IsFile ? uri.LocalPath : uri.AbsoluteUri) : document.Info.Name;
throw new FileLoadException($"Unsupported document category '{document.Info.Category}'", name);
}
private ScriptObject InitializeContext(ScriptObject context)

Просмотреть файл

@ -11,6 +11,7 @@ namespace Microsoft.ClearScript.JavaScript
uint BaseLanguageVersion { get; }
CommonJSManager CommonJSManager { get; }
JsonModuleManager JsonModuleManager { get; }
object CreatePromiseForTask<T>(Task<T> task);
object CreatePromiseForTask(Task task);

Просмотреть файл

@ -0,0 +1,110 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.ClearScript.Util;
namespace Microsoft.ClearScript.JavaScript
{
internal sealed class JsonModuleManager
{
private readonly ScriptEngine engine;
private readonly List<Module> moduleCache = new List<Module>();
public JsonModuleManager(ScriptEngine engine)
{
this.engine = engine;
}
public int ModuleCacheSize => moduleCache.Count;
public Module GetOrCreateModule(UniqueDocumentInfo documentInfo, string json)
{
var jsonDigest = json.GetDigest();
var cachedModule = GetCachedModule(documentInfo, jsonDigest);
if (cachedModule != null)
{
return cachedModule;
}
return CacheModule(new Module(engine, documentInfo, jsonDigest, json));
}
private Module GetCachedModule(UniqueDocumentInfo documentInfo, UIntPtr jsonDigest)
{
for (var index = 0; index < moduleCache.Count; index++)
{
var cachedModule = moduleCache[index];
if ((cachedModule.DocumentInfo.UniqueId == documentInfo.UniqueId) && (cachedModule.JsonDigest == jsonDigest))
{
moduleCache.RemoveAt(index);
moduleCache.Insert(0, cachedModule);
return cachedModule;
}
}
return null;
}
private Module CacheModule(Module module)
{
var cachedModule = moduleCache.FirstOrDefault(testModule => (testModule.DocumentInfo.UniqueId == module.DocumentInfo.UniqueId) && (testModule.JsonDigest == module.JsonDigest));
if (cachedModule != null)
{
return cachedModule;
}
var maxModuleCacheSize = Math.Max(16, Convert.ToInt32(Math.Min(DocumentCategory.Json.MaxCacheSize, int.MaxValue)));
while (moduleCache.Count >= maxModuleCacheSize)
{
moduleCache.RemoveAt(moduleCache.Count - 1);
}
moduleCache.Insert(0, module);
return module;
}
#region Nested type: Module
public sealed class Module
{
private readonly ScriptEngine engine;
private readonly string json;
private bool parsed;
private object result;
public Module(ScriptEngine engine, UniqueDocumentInfo documentInfo, UIntPtr jsonDigest, string json)
{
this.engine = engine;
this.json = json;
DocumentInfo = documentInfo;
JsonDigest = jsonDigest;
}
public UniqueDocumentInfo DocumentInfo { get; }
public UIntPtr JsonDigest { get; }
public object Result
{
get
{
if (!parsed)
{
parsed = true;
result = ((ScriptObject)engine.Global.GetProperty("EngineInternal")).InvokeMethod("parseJson", json);
}
return result;
}
}
}
#endregion
}
}

Просмотреть файл

@ -30,6 +30,8 @@ namespace Microsoft.ClearScript.JavaScript
#region DocumentCategory overrides
internal override DocumentKind Kind => DocumentKind.JavaScriptModule;
internal override string DefaultName => "Module";
#endregion
@ -58,6 +60,8 @@ namespace Microsoft.ClearScript.JavaScript
#region DocumentCategory overrides
internal override DocumentKind Kind => DocumentKind.CommonJSModule;
internal override string DefaultName => "Module";
#endregion

Просмотреть файл

@ -18,15 +18,15 @@ using System.Runtime.InteropServices;
[assembly: InternalsVisibleTo("ClearScriptTest")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("7.4.2")]
[assembly: AssemblyFileVersion("7.4.2")]
[assembly: AssemblyInformationalVersion("7.4.2")]
[assembly: AssemblyVersion("7.4.3")]
[assembly: AssemblyFileVersion("7.4.3")]
[assembly: AssemblyInformationalVersion("7.4.3")]
namespace Microsoft.ClearScript.Properties
{
internal static class ClearScriptVersion
{
public const string Triad = "7.4.2";
public const string Informational = "7.4.2";
public const string Triad = "7.4.3";
public const string Informational = "7.4.3";
}
}

Просмотреть файл

@ -15,6 +15,6 @@ using System.Runtime.InteropServices;
[assembly: InternalsVisibleTo("ClearScript.V8")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("7.4.2")]
[assembly: AssemblyFileVersion("7.4.2")]
[assembly: AssemblyInformationalVersion("7.4.2")]
[assembly: AssemblyVersion("7.4.3")]
[assembly: AssemblyFileVersion("7.4.3")]
[assembly: AssemblyInformationalVersion("7.4.3")]

Просмотреть файл

@ -15,6 +15,6 @@ using System.Runtime.InteropServices;
[assembly: InternalsVisibleTo("ClearScriptTest")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("7.4.2")]
[assembly: AssemblyFileVersion("7.4.2")]
[assembly: AssemblyInformationalVersion("7.4.2")]
[assembly: AssemblyVersion("7.4.3")]
[assembly: AssemblyFileVersion("7.4.3")]
[assembly: AssemblyInformationalVersion("7.4.3")]

Просмотреть файл

@ -16,6 +16,6 @@ using System.Runtime.InteropServices;
[assembly: InternalsVisibleTo("ClearScriptTest")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("7.4.2")]
[assembly: AssemblyFileVersion("7.4.2")]
[assembly: AssemblyInformationalVersion("7.4.2")]
[assembly: AssemblyVersion("7.4.3")]
[assembly: AssemblyFileVersion("7.4.3")]
[assembly: AssemblyInformationalVersion("7.4.3")]

Просмотреть файл

@ -15,6 +15,6 @@ using System.Runtime.InteropServices;
[assembly: InternalsVisibleTo("ClearScriptTest")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("7.4.2")]
[assembly: AssemblyFileVersion("7.4.2")]
[assembly: AssemblyInformationalVersion("7.4.2")]
[assembly: AssemblyVersion("7.4.3")]
[assembly: AssemblyFileVersion("7.4.3")]
[assembly: AssemblyInformationalVersion("7.4.3")]

Просмотреть файл

@ -13,7 +13,7 @@ namespace Microsoft.ClearScript
/// <summary>
/// Provides the base implementation for all script engines.
/// </summary>
public abstract class ScriptEngine : IScriptEngine
public abstract class ScriptEngine : IScriptEngine, IHostContext
{
#region data
@ -80,7 +80,7 @@ namespace Microsoft.ClearScript
/// <inheritdoc/>
public abstract string FileNameExtension { get; }
/// <inheritdoc/>
/// <inheritdoc cref="ScriptEngine" />
public Type AccessContext
{
get => accessContext;
@ -92,7 +92,7 @@ namespace Microsoft.ClearScript
}
}
/// <inheritdoc/>
/// <inheritdoc cref="ScriptEngine" />
public ScriptAccess DefaultAccess
{
get => defaultAccess;
@ -760,7 +760,7 @@ namespace Microsoft.ClearScript
{
if (extensionMethodTable != emptyExtensionMethodTable)
{
if (extensionMethodTable.ProcessType(type, AccessContext, DefaultAccess))
if (extensionMethodTable.ProcessType(type, this))
{
ClearMethodBindCache();
}
@ -1130,6 +1130,12 @@ namespace Microsoft.ClearScript
#endregion
#region IHostContext implementation
ScriptEngine IHostContext.Engine => this;
#endregion
#region Nested type: ScriptFrame
internal sealed class ScriptFrame

Просмотреть файл

@ -43,18 +43,18 @@ namespace Microsoft.ClearScript
public override object DynamicInvokeTarget => null;
public override HostTargetFlags GetFlags(IHostInvokeContext context)
public override HostTargetFlags GetFlags(IHostContext context)
{
return HostTargetFlags.None;
}
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.InvokeMethod(name, args);
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;
}

Просмотреть файл

@ -134,12 +134,12 @@ namespace Microsoft.ClearScript.Util
return TryDynamicOperation(() => target.CreateInstance(args), out result);
}
public static bool TryInvoke(this DynamicMetaObject target, IHostInvokeContext context, object[] args, out object result)
public static bool TryInvoke(this DynamicMetaObject target, IHostContext context, object[] args, out object result)
{
return TryDynamicOperation(() => target.Invoke(args), out result);
}
public static bool TryInvokeMember(this DynamicMetaObject target, IHostInvokeContext context, string name, BindingFlags invokeFlags, object[] args, out object result)
public static bool TryInvokeMember(this DynamicMetaObject target, IHostContext context, string name, BindingFlags invokeFlags, object[] args, out object result)
{
return TryDynamicOperation(() => target.InvokeMember(context, name, invokeFlags, args), out result);
}
@ -384,7 +384,7 @@ namespace Microsoft.ClearScript.Util
return Invoke(block, paramExprs, args);
}
private static object InvokeMember(this DynamicMetaObject target, IHostInvokeContext context, string name, BindingFlags invokeFlags, object[] args)
private static object InvokeMember(this DynamicMetaObject target, IHostContext context, string name, BindingFlags invokeFlags, object[] args)
{
var paramNames = Enumerable.Range(0, args.Length).Select(index => "a" + index).ToArray();
var paramExprs = paramNames.Select((paramName, index) => Expression.Parameter(GetParamTypeForArg(args[index]), paramName)).ToArray();
@ -687,10 +687,10 @@ namespace Microsoft.ClearScript.Util
private sealed class DynamicInvokeMemberBinder : InvokeMemberBinder
{
private static readonly MethodInfo invokeMemberValueMethod = typeof(DynamicInvokeMemberBinder).GetMethod("InvokeMemberValue", BindingFlags.NonPublic | BindingFlags.Static);
private readonly IHostInvokeContext context;
private readonly IHostContext context;
private readonly BindingFlags invokeFlags;
public DynamicInvokeMemberBinder(IHostInvokeContext context, string name, BindingFlags invokeFlags, string[] paramNames)
public DynamicInvokeMemberBinder(IHostContext context, string name, BindingFlags invokeFlags, string[] paramNames)
: base(name, false, new CallInfo(paramNames.Length, paramNames))
{
this.context = context;
@ -731,7 +731,7 @@ namespace Microsoft.ClearScript.Util
// ReSharper disable UnusedMember.Local
private static object InvokeMemberValue(IHostInvokeContext context, object target, BindingFlags invokeFlags, object[] args)
private static object InvokeMemberValue(IHostContext context, object target, BindingFlags invokeFlags, object[] args)
{
if (InvokeHelpers.TryInvokeObject(context, target, BindingFlags.InvokeMethod, args, args, true, out var result))
{

Просмотреть файл

@ -5,11 +5,10 @@ using System;
namespace Microsoft.ClearScript.Util
{
internal interface IHostInvokeContext
internal interface IHostContext
{
ScriptEngine Engine { get; }
Type AccessContext { get; }
ScriptAccess DefaultAccess { get; }
HostTargetFlags TargetFlags { get; }
}
}

Просмотреть файл

@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
namespace Microsoft.ClearScript.Util
{
internal interface IHostTargetContext : IHostContext
{
HostTargetFlags TargetFlags { get; }
}
}

Просмотреть файл

@ -11,22 +11,22 @@ namespace Microsoft.ClearScript.Util
{
internal static class InvokeHelpers
{
public static object InvokeMethod(IHostInvokeContext context, MethodInfo method, object target, object[] args, ScriptMemberFlags flags)
public static object InvokeMethod(IHostContext context, MethodInfo method, object target, object[] args, ScriptMemberFlags flags)
{
return InvokeMethodInternal(context, method, target, args, (invokeMethod, invokeTarget, invokeArgs) => invokeMethod.Invoke(invokeTarget, invokeArgs), method.ReturnType, flags);
}
public static object InvokeConstructor(IHostInvokeContext context, ConstructorInfo constructor, object[] args)
public static object InvokeConstructor(IHostContext context, ConstructorInfo constructor, object[] args)
{
return InvokeMethodInternal(context, constructor, null, args, (invokeConstructor, invokeTarget, invokeArgs) => invokeConstructor.Invoke(invokeArgs), constructor.DeclaringType, ScriptMemberFlags.None);
}
public static object InvokeDelegate(IHostInvokeContext context, Delegate del, object[] args)
public static object InvokeDelegate(IHostContext context, Delegate del, object[] args)
{
return InvokeMethod(context, del.GetType().GetMethod("Invoke"), del, args, ScriptMemberFlags.None);
}
public static bool TryInvokeObject(IHostInvokeContext context, object target, BindingFlags invokeFlags, object[] args, object[] bindArgs, bool tryDynamic, out object result)
public static bool TryInvokeObject(IHostContext context, object target, BindingFlags invokeFlags, object[] args, object[] bindArgs, bool tryDynamic, out object result)
{
if (target is HostTarget hostTarget)
{
@ -73,7 +73,7 @@ namespace Microsoft.ClearScript.Util
return false;
}
private static object InvokeMethodInternal<T>(IHostInvokeContext context, T method, object target, object[] args, Func<T, object, object[], object> invoker, Type returnType, ScriptMemberFlags flags) where T : MethodBase
private static object InvokeMethodInternal<T>(IHostContext context, T method, object target, object[] args, Func<T, object, object[], object> invoker, Type returnType, ScriptMemberFlags flags) where T : MethodBase
{
var argList = new List<object>();
var byRefArgInfo = new List<ByRefArgItem>();

Просмотреть файл

@ -11,41 +11,41 @@ namespace Microsoft.ClearScript.Util
{
internal static class MemberHelpers
{
public static bool IsScriptable(this EventInfo eventInfo, Type accessContext, ScriptAccess defaultAccess)
public static bool IsScriptable(this EventInfo eventInfo, IHostContext context)
{
return !eventInfo.IsSpecialName && !eventInfo.IsExplicitImplementation() && eventInfo.IsAccessible(accessContext) && !eventInfo.IsBlockedFromScript(defaultAccess);
return !eventInfo.IsSpecialName && !eventInfo.IsExplicitImplementation() && eventInfo.IsAccessible(context) && !eventInfo.IsBlockedFromScript(context.DefaultAccess);
}
public static bool IsScriptable(this FieldInfo field, Type accessContext, ScriptAccess defaultAccess)
public static bool IsScriptable(this FieldInfo field, IHostContext context)
{
return !field.IsSpecialName && field.IsAccessible(accessContext) && !field.IsBlockedFromScript(defaultAccess);
return !field.IsSpecialName && field.IsAccessible(context) && !field.IsBlockedFromScript(context.DefaultAccess);
}
public static bool IsScriptable(this MethodInfo method, Type accessContext, ScriptAccess defaultAccess)
public static bool IsScriptable(this MethodInfo method, IHostContext context)
{
return !method.IsSpecialName && !method.IsExplicitImplementation() && method.IsAccessible(accessContext) && !method.IsBlockedFromScript(defaultAccess);
return !method.IsSpecialName && !method.IsExplicitImplementation() && method.IsAccessible(context) && !method.IsBlockedFromScript(context.DefaultAccess);
}
public static bool IsScriptable(this PropertyInfo property, Type accessContext, ScriptAccess defaultAccess)
public static bool IsScriptable(this PropertyInfo property, IHostContext context)
{
return !property.IsSpecialName && !property.IsExplicitImplementation() && property.IsAccessible(accessContext) && !property.IsBlockedFromScript(defaultAccess);
return !property.IsSpecialName && !property.IsExplicitImplementation() && property.IsAccessible(context) && !property.IsBlockedFromScript(context.DefaultAccess);
}
public static bool IsScriptable(this Type type, Type accessContext, ScriptAccess defaultAccess)
public static bool IsScriptable(this Type type, IHostContext context)
{
return !type.IsSpecialName && type.IsAccessible(accessContext) && !type.IsBlockedFromScript(defaultAccess);
return !type.IsSpecialName && type.IsAccessible(context) && !type.IsBlockedFromScript(context.DefaultAccess);
}
public static bool IsAccessible(this EventInfo eventInfo, Type accessContext)
public static bool IsAccessible(this EventInfo eventInfo, IHostContext context)
{
return eventInfo.AddMethod.IsAccessible(accessContext);
return eventInfo.AddMethod.IsAccessible(context);
}
public static bool IsAccessible(this FieldInfo field, Type accessContext)
public static bool IsAccessible(this FieldInfo field, IHostContext context)
{
var type = field.DeclaringType;
if (!type.IsAccessible(accessContext))
if (!type.IsAccessible(context))
{
return false;
}
@ -57,6 +57,8 @@ namespace Microsoft.ClearScript.Util
return true;
}
var accessContext = context.AccessContext;
if (accessContext == null)
{
return false;
@ -90,11 +92,11 @@ namespace Microsoft.ClearScript.Util
return false;
}
public static bool IsAccessible(this MethodBase method, Type accessContext)
public static bool IsAccessible(this MethodBase method, IHostContext context)
{
var type = method.DeclaringType;
if (!type.IsAccessible(accessContext))
if (!type.IsAccessible(context))
{
return false;
}
@ -106,6 +108,8 @@ namespace Microsoft.ClearScript.Util
return true;
}
var accessContext = context.AccessContext;
if (accessContext == null)
{
return false;
@ -139,21 +143,21 @@ namespace Microsoft.ClearScript.Util
return false;
}
public static bool IsAccessible(this MethodInfo method, Type accessContext)
public static bool IsAccessible(this MethodInfo method, IHostContext context)
{
return ((MethodBase)method.GetBaseDefinition()).IsAccessible(accessContext);
return ((MethodBase)method.GetBaseDefinition()).IsAccessible(context);
}
public static bool IsAccessible(this PropertyInfo property, Type accessContext)
public static bool IsAccessible(this PropertyInfo property, IHostContext context)
{
var getMethod = property.GetMethod;
if ((getMethod != null) && getMethod.IsAccessible(accessContext))
if ((getMethod != null) && getMethod.IsAccessible(context))
{
return true;
}
var setMethod = property.SetMethod;
if ((setMethod != null) && setMethod.IsAccessible(accessContext))
if ((setMethod != null) && setMethod.IsAccessible(context))
{
return true;
}
@ -161,18 +165,20 @@ namespace Microsoft.ClearScript.Util
return false;
}
public static bool IsAccessible(this Type type, Type accessContext)
public static bool IsAccessible(this Type type, IHostContext context)
{
var visibility = type.Attributes & TypeAttributes.VisibilityMask;
var visibility = (type.IsAnonymous() && !context.Engine.EnforceAnonymousTypeAccess) ? TypeAttributes.Public : type.Attributes & TypeAttributes.VisibilityMask;
if (visibility == TypeAttributes.Public)
{
return true;
}
var accessContext = context.AccessContext;
if (accessContext == null)
{
return (visibility == TypeAttributes.NestedPublic) && type.DeclaringType.IsAccessible(null);
return (visibility == TypeAttributes.NestedPublic) && type.DeclaringType.IsAccessible(context);
}
if (visibility == TypeAttributes.NotPublic)
@ -182,7 +188,7 @@ namespace Microsoft.ClearScript.Util
type = type.DeclaringType;
if (!type.IsAccessible(accessContext))
if (!type.IsAccessible(context))
{
return false;
}

Просмотреть файл

@ -324,22 +324,22 @@ namespace Microsoft.ClearScript.Util
return type.GetGenericArguments().Count(typeArg => typeArg.IsGenericParameter);
}
public static IEnumerable<EventInfo> GetScriptableEvents(this Type type, BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess)
public static IEnumerable<EventInfo> GetScriptableEvents(this Type type, IHostContext context, BindingFlags bindFlags)
{
var events = type.GetEvents(bindFlags).AsEnumerable();
if (type.IsInterface)
{
events = events.Concat(type.GetInterfaces().SelectMany(interfaceType => interfaceType.GetScriptableEvents(bindFlags, accessContext, defaultAccess)));
events = events.Concat(type.GetInterfaces().SelectMany(interfaceType => interfaceType.GetScriptableEvents(context, bindFlags)));
}
return events.Where(eventInfo => eventInfo.IsScriptable(accessContext, defaultAccess));
return events.Where(eventInfo => eventInfo.IsScriptable(context));
}
public static EventInfo GetScriptableEvent(this Type type, string name, BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess)
public static EventInfo GetScriptableEvent(this Type type, IHostContext context, string name, BindingFlags bindFlags)
{
try
{
var eventInfo = type.GetScriptableEventInternal(name, bindFlags, accessContext, defaultAccess);
var eventInfo = type.GetScriptableEventInternal(context, name, bindFlags);
if (eventInfo != null)
{
return eventInfo;
@ -349,54 +349,54 @@ namespace Microsoft.ClearScript.Util
{
}
return type.GetScriptableEvents(bindFlags, accessContext, defaultAccess).FirstOrDefault(eventInfo => string.Equals(eventInfo.GetScriptName(), name, bindFlags.GetMemberNameComparison()));
return type.GetScriptableEvents(context, bindFlags).FirstOrDefault(eventInfo => string.Equals(eventInfo.GetScriptName(), name, bindFlags.GetMemberNameComparison()));
}
public static IEnumerable<FieldInfo> GetScriptableFields(this Type type, BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess)
public static IEnumerable<FieldInfo> GetScriptableFields(this Type type, IHostContext context, BindingFlags bindFlags)
{
return type.GetFields(bindFlags).Where(field => field.IsScriptable(accessContext, defaultAccess));
return type.GetFields(bindFlags).Where(field => field.IsScriptable(context));
}
public static FieldInfo GetScriptableField(this Type type, string name, BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess)
public static FieldInfo GetScriptableField(this Type type, IHostContext context, string name, BindingFlags bindFlags)
{
var candidate = type.GetField(name, bindFlags);
if ((candidate != null) && candidate.IsScriptable(accessContext, defaultAccess) && string.Equals(candidate.GetScriptName(), name, bindFlags.GetMemberNameComparison()))
if ((candidate != null) && candidate.IsScriptable(context) && string.Equals(candidate.GetScriptName(), name, bindFlags.GetMemberNameComparison()))
{
return candidate;
}
return type.GetScriptableFields(bindFlags, accessContext, defaultAccess).FirstOrDefault(field => string.Equals(field.GetScriptName(), name, bindFlags.GetMemberNameComparison()));
return type.GetScriptableFields(context, bindFlags).FirstOrDefault(field => string.Equals(field.GetScriptName(), name, bindFlags.GetMemberNameComparison()));
}
public static IEnumerable<MethodInfo> GetScriptableMethods(this Type type, BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess)
public static IEnumerable<MethodInfo> GetScriptableMethods(this Type type, IHostContext context, BindingFlags bindFlags)
{
var methods = type.GetMethods(bindFlags).AsEnumerable();
if (type.IsInterface)
{
methods = methods.Concat(type.GetInterfaces().SelectMany(interfaceType => interfaceType.GetScriptableMethods(bindFlags, accessContext, defaultAccess)));
methods = methods.Concat(typeof(object).GetScriptableMethods(bindFlags, accessContext, defaultAccess));
methods = methods.Concat(type.GetInterfaces().SelectMany(interfaceType => interfaceType.GetScriptableMethods(context, bindFlags)));
methods = methods.Concat(typeof(object).GetScriptableMethods(context, bindFlags));
}
return methods.Where(method => method.IsScriptable(accessContext, defaultAccess));
return methods.Where(method => method.IsScriptable(context));
}
public static IEnumerable<MethodInfo> GetScriptableMethods(this Type type, string name, BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess)
public static IEnumerable<MethodInfo> GetScriptableMethods(this Type type, IHostContext context, string name, BindingFlags bindFlags)
{
return type.GetScriptableMethods(bindFlags, accessContext, defaultAccess).Where(method => string.Equals(method.GetScriptName(), name, bindFlags.GetMemberNameComparison()));
return type.GetScriptableMethods(context, bindFlags).Where(method => string.Equals(method.GetScriptName(), name, bindFlags.GetMemberNameComparison()));
}
public static IEnumerable<PropertyInfo> GetScriptableProperties(this Type type, BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess)
public static IEnumerable<PropertyInfo> GetScriptableProperties(this Type type, IHostContext context, BindingFlags bindFlags)
{
var properties = type.GetProperties(bindFlags).AsEnumerable();
if (type.IsInterface)
{
properties = properties.Concat(type.GetInterfaces().SelectMany(interfaceType => interfaceType.GetScriptableProperties(bindFlags, accessContext, defaultAccess)));
properties = properties.Concat(type.GetInterfaces().SelectMany(interfaceType => interfaceType.GetScriptableProperties(context, bindFlags)));
}
return properties.Where(property => property.IsScriptable(accessContext, defaultAccess));
return properties.Where(property => property.IsScriptable(context));
}
public static IEnumerable<PropertyInfo> GetScriptableDefaultProperties(this Type type, BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess)
public static IEnumerable<PropertyInfo> GetScriptableDefaultProperties(this Type type, IHostContext context, BindingFlags bindFlags)
{
if (type.IsArray)
{
@ -407,30 +407,30 @@ namespace Microsoft.ClearScript.Util
var properties = type.GetProperties(bindFlags).AsEnumerable();
if (type.IsInterface)
{
properties = properties.Concat(type.GetInterfaces().SelectMany(interfaceType => interfaceType.GetScriptableProperties(bindFlags, accessContext, defaultAccess)));
properties = properties.Concat(type.GetInterfaces().SelectMany(interfaceType => interfaceType.GetScriptableProperties(context, bindFlags)));
}
var defaultMembers = type.GetDefaultMembers();
return properties.Where(property => property.IsScriptable(accessContext, defaultAccess) && (defaultMembers.Contains(property) || property.IsDispID(SpecialDispIDs.Default)));
return properties.Where(property => property.IsScriptable(context) && (defaultMembers.Contains(property) || property.IsDispID(SpecialDispIDs.Default)));
}
public static IEnumerable<PropertyInfo> GetScriptableProperties(this Type type, string name, BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess)
public static IEnumerable<PropertyInfo> GetScriptableProperties(this Type type, IHostContext context, string name, BindingFlags bindFlags)
{
return type.GetScriptableProperties(bindFlags, accessContext, defaultAccess).Where(property => string.Equals(property.GetScriptName(), name, bindFlags.GetMemberNameComparison()));
return type.GetScriptableProperties(context, bindFlags).Where(property => string.Equals(property.GetScriptName(), name, bindFlags.GetMemberNameComparison()));
}
public static PropertyInfo GetScriptableProperty(this Type type, string name, BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess)
public static PropertyInfo GetScriptableProperty(this Type type, IHostContext context, string name, BindingFlags bindFlags)
{
var candidates = type.GetProperty(name, bindFlags)?.ToEnumerable() ?? Enumerable.Empty<PropertyInfo>();
if (type.IsInterface)
{
candidates = candidates.Concat(type.GetInterfaces().Select(interfaceType => interfaceType.GetScriptableProperty(name, bindFlags, accessContext, defaultAccess)));
candidates = candidates.Concat(type.GetInterfaces().Select(interfaceType => interfaceType.GetScriptableProperty(context, name, bindFlags)));
}
try
{
// ReSharper disable once RedundantEnumerableCastCall
return candidates.OfType<PropertyInfo>().SingleOrDefault(property => (property.GetIndexParameters().Length < 1) && property.IsScriptable(accessContext, defaultAccess) && string.Equals(property.GetScriptName(), name, bindFlags.GetMemberNameComparison()));
return candidates.OfType<PropertyInfo>().SingleOrDefault(property => (property.GetIndexParameters().Length < 1) && property.IsScriptable(context) && string.Equals(property.GetScriptName(), name, bindFlags.GetMemberNameComparison()));
}
catch (InvalidOperationException exception)
{
@ -438,13 +438,13 @@ namespace Microsoft.ClearScript.Util
}
}
public static PropertyInfo GetScriptableProperty(this Type type, string name, BindingFlags bindFlags, object[] args, object[] bindArgs, Type accessContext, ScriptAccess defaultAccess)
public static PropertyInfo GetScriptableProperty(this Type type, IHostContext context, string name, BindingFlags bindFlags, object[] args, object[] bindArgs)
{
if (bindArgs.Length < 1)
{
try
{
var property = type.GetScriptableProperty(name, bindFlags, accessContext, defaultAccess);
var property = type.GetScriptableProperty(context, name, bindFlags);
if (property != null)
{
return property;
@ -455,24 +455,24 @@ namespace Microsoft.ClearScript.Util
}
}
var candidates = type.GetScriptableProperties(name, bindFlags, accessContext, defaultAccess).Distinct(PropertySignatureComparer.Instance).ToArray();
var candidates = type.GetScriptableProperties(context, name, bindFlags).Distinct(PropertySignatureComparer.Instance).ToArray();
return BindToMember(candidates, bindFlags, args, bindArgs);
}
public static PropertyInfo GetScriptableDefaultProperty(this Type type, BindingFlags bindFlags, object[] args, object[] bindArgs, Type accessContext, ScriptAccess defaultAccess)
public static PropertyInfo GetScriptableDefaultProperty(this Type type, IHostContext context, BindingFlags bindFlags, object[] args, object[] bindArgs)
{
var candidates = type.GetScriptableDefaultProperties(bindFlags, accessContext, defaultAccess).Distinct(PropertySignatureComparer.Instance).ToArray();
var candidates = type.GetScriptableDefaultProperties(context, bindFlags).Distinct(PropertySignatureComparer.Instance).ToArray();
return BindToMember(candidates, bindFlags, args, bindArgs);
}
public static IEnumerable<Type> GetScriptableNestedTypes(this Type type, BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess)
public static IEnumerable<Type> GetScriptableNestedTypes(this Type type, IHostContext context, BindingFlags bindFlags)
{
return type.GetNestedTypes(bindFlags).Where(nestedType => nestedType.IsScriptable(accessContext, defaultAccess));
return type.GetNestedTypes(bindFlags).Where(nestedType => nestedType.IsScriptable(context));
}
public static Invocability GetInvocability(this Type type, BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess, bool ignoreDynamic)
public static Invocability GetInvocability(this Type type, IHostContext context, BindingFlags bindFlags, bool ignoreDynamic)
{
return invocabilityMap.GetOrAdd(Tuple.Create(type, bindFlags, accessContext, defaultAccess, ignoreDynamic), GetInvocabilityInternal);
return invocabilityMap.GetOrAdd(Tuple.Create(type, bindFlags, context.AccessContext, context.DefaultAccess, ignoreDynamic), _ => GetInvocabilityInternal(type, context, bindFlags, ignoreDynamic));
}
public static object CreateInstance(this Type type, params object[] args)
@ -485,7 +485,7 @@ namespace Microsoft.ClearScript.Util
return type.InvokeMember(string.Empty, BindingFlags.CreateInstance | BindingFlags.Instance | (flags & ~BindingFlags.Static), null, null, args, CultureInfo.InvariantCulture);
}
public static object CreateInstance(this Type type, IHostInvokeContext invokeContext, HostTarget target, object[] args, object[] bindArgs)
public static object CreateInstance(this Type type, IHostContext context, HostTarget target, object[] args, object[] bindArgs)
{
if (type.IsCOMObject)
{
@ -494,10 +494,10 @@ namespace Microsoft.ClearScript.Util
const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
var signature = new BindSignature(invokeContext.AccessContext, flags, target, type.TypeHandle.Value.ToString(), ArrayHelpers.GetEmptyArray<Type>(), bindArgs);
if (invokeContext.Engine.TryGetCachedConstructorBindResult(signature, out var boundConstructor))
var signature = new BindSignature(context.AccessContext, flags, target, type.TypeHandle.Value.ToString(), ArrayHelpers.GetEmptyArray<Type>(), bindArgs);
if (context.Engine.TryGetCachedConstructorBindResult(signature, out var boundConstructor))
{
return InvokeHelpers.InvokeConstructor(invokeContext, boundConstructor, args);
return InvokeHelpers.InvokeConstructor(context, boundConstructor, args);
}
var constructors = type.GetConstructors(flags);
@ -506,7 +506,7 @@ namespace Microsoft.ClearScript.Util
return type.CreateInstance();
}
var candidates = constructors.Where(testConstructor => testConstructor.IsAccessible(invokeContext.AccessContext) && !testConstructor.IsBlockedFromScript(invokeContext.DefaultAccess)).ToArray();
var candidates = constructors.Where(testConstructor => testConstructor.IsAccessible(context) && !testConstructor.IsBlockedFromScript(context.DefaultAccess)).ToArray();
if (candidates.Length < 1)
{
throw new MissingMethodException(MiscHelpers.FormatInvariant("Type '{0}' has no constructor that matches the specified arguments", type.GetFullFriendlyName()));
@ -518,8 +518,8 @@ namespace Microsoft.ClearScript.Util
throw new MissingMethodException(MiscHelpers.FormatInvariant("Type '{0}' has no constructor that matches the specified arguments", type.GetFullFriendlyName()));
}
invokeContext.Engine.CacheConstructorBindResult(signature, constructor);
return InvokeHelpers.InvokeConstructor(invokeContext, constructor, args);
context.Engine.CacheConstructorBindResult(signature, constructor);
return InvokeHelpers.InvokeConstructor(context, constructor, args);
}
public static Type MakeSpecificType(this Type template, params Type[] typeArgs)
@ -707,18 +707,18 @@ namespace Microsoft.ClearScript.Util
return MiscHelpers.FormatInvariant("{0}{1}<{2}>", parentPrefix, name, paramList);
}
private static EventInfo GetScriptableEventInternal(this Type type, string name, BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess)
private static EventInfo GetScriptableEventInternal(this Type type, IHostContext context, string name, BindingFlags bindFlags)
{
var candidates = type.GetEvent(name, bindFlags)?.ToEnumerable() ?? Enumerable.Empty<EventInfo>();
if (type.IsInterface)
{
candidates = candidates.Concat(type.GetInterfaces().Select(interfaceType => interfaceType.GetScriptableEventInternal(name, bindFlags, accessContext, defaultAccess)));
candidates = candidates.Concat(type.GetInterfaces().Select(interfaceType => interfaceType.GetScriptableEventInternal(context, name, bindFlags)));
}
try
{
// ReSharper disable once RedundantEnumerableCastCall
return candidates.OfType<EventInfo>().SingleOrDefault(eventInfo => eventInfo.IsScriptable(accessContext, defaultAccess) && string.Equals(eventInfo.GetScriptName(), name, bindFlags.GetMemberNameComparison()));
return candidates.OfType<EventInfo>().SingleOrDefault(eventInfo => eventInfo.IsScriptable(context) && string.Equals(eventInfo.GetScriptName(), name, bindFlags.GetMemberNameComparison()));
}
catch (InvalidOperationException exception)
{
@ -726,10 +726,8 @@ namespace Microsoft.ClearScript.Util
}
}
private static Invocability GetInvocabilityInternal(Tuple<Type, BindingFlags, Type, ScriptAccess, bool> args)
private static Invocability GetInvocabilityInternal(Type type, IHostContext context, BindingFlags bindFlags, bool ignoreDynamic)
{
var (type, bindFlags, accessContext, defaultAccess, ignoreDynamic) = args;
if (typeof(Delegate).IsAssignableFrom(type))
{
return Invocability.Delegate;
@ -740,7 +738,7 @@ namespace Microsoft.ClearScript.Util
return Invocability.Dynamic;
}
if (type.GetScriptableDefaultProperties(bindFlags, accessContext, defaultAccess).Any())
if (type.GetScriptableDefaultProperties(context, bindFlags).Any())
{
return Invocability.DefaultProperty;
}

Просмотреть файл

@ -137,9 +137,10 @@ namespace Microsoft.ClearScript.V8.SplitProxy
void V8Isolate_SetMaxStackUsage(V8Isolate.Handle hIsolate, UIntPtr size);
void V8Isolate_AwaitDebuggerAndPause(V8Isolate.Handle hIsolate);
void V8Isolate_CancelAwaitDebugger(V8Isolate.Handle hIsolate);
V8Script.Handle V8Isolate_Compile(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code);
V8Script.Handle V8Isolate_CompileProducingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes);
V8Script.Handle V8Isolate_CompileConsumingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted);
V8Script.Handle V8Isolate_Compile(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code);
V8Script.Handle V8Isolate_CompileProducingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes);
V8Script.Handle V8Isolate_CompileConsumingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted);
V8Script.Handle V8Isolate_CompileUpdatingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult);
bool V8Isolate_GetEnableInterruptPropagation(V8Isolate.Handle hIsolate);
void V8Isolate_SetEnableInterruptPropagation(V8Isolate.Handle hIsolate, bool value);
bool V8Isolate_GetDisableHeapSizeViolationInterrupt(V8Isolate.Handle hIsolate);
@ -169,10 +170,11 @@ namespace Microsoft.ClearScript.V8.SplitProxy
void V8Context_AddGlobalItem(V8Context.Handle hContext, string name, object value, bool globalMembers);
void V8Context_AwaitDebuggerAndPause(V8Context.Handle hContext);
void V8Context_CancelAwaitDebugger(V8Context.Handle hContext);
object V8Context_ExecuteCode(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, bool evaluate);
V8Script.Handle V8Context_Compile(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code);
V8Script.Handle V8Context_CompileProducingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes);
V8Script.Handle V8Context_CompileConsumingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted);
object V8Context_ExecuteCode(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, bool evaluate);
V8Script.Handle V8Context_Compile(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code);
V8Script.Handle V8Context_CompileProducingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes);
V8Script.Handle V8Context_CompileConsumingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted);
V8Script.Handle V8Context_CompileUpdatingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult);
object V8Context_ExecuteScript(V8Context.Handle hContext, V8Script.Handle hScript, bool evaluate);
void V8Context_Interrupt(V8Context.Handle hContext);
void V8Context_CancelInterrupt(V8Context.Handle hContext);

Просмотреть файл

@ -3,8 +3,6 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.ClearScript.JavaScript;
using Microsoft.ClearScript.Util;
namespace Microsoft.ClearScript.V8.SplitProxy
@ -76,7 +74,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
MiscHelpers.GetUrlOrPath(documentInfo.Uri, documentInfo.UniqueName),
MiscHelpers.GetUrlOrPath(documentInfo.SourceMapUri, string.Empty),
documentInfo.UniqueId,
documentInfo.Category == ModuleCategory.Standard,
documentInfo.Category.Kind,
V8ProxyHelpers.AddRefHostObject(documentInfo),
code,
evaluate
@ -90,7 +88,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
MiscHelpers.GetUrlOrPath(documentInfo.Uri, documentInfo.UniqueName),
MiscHelpers.GetUrlOrPath(documentInfo.SourceMapUri, string.Empty),
documentInfo.UniqueId,
documentInfo.Category == ModuleCategory.Standard,
documentInfo.Category.Kind,
V8ProxyHelpers.AddRefHostObject(documentInfo),
code
)));
@ -110,7 +108,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
MiscHelpers.GetUrlOrPath(documentInfo.Uri, documentInfo.UniqueName),
MiscHelpers.GetUrlOrPath(documentInfo.SourceMapUri, string.Empty),
documentInfo.UniqueId,
documentInfo.Category == ModuleCategory.Standard,
documentInfo.Category.Kind,
V8ProxyHelpers.AddRefHostObject(documentInfo),
code,
cacheKind,
@ -129,28 +127,68 @@ namespace Microsoft.ClearScript.V8.SplitProxy
return Compile(documentInfo, code);
}
var cacheSize = cacheBytes.Length;
using (var cacheBlock = new CoTaskMemBlock(cacheSize))
var tempCacheAccepted = false;
var script = new V8ScriptImpl(documentInfo, code.GetDigest(), V8SplitProxyNative.Invoke(instance => instance.V8Context_CompileConsumingCache(
Handle,
MiscHelpers.GetUrlOrPath(documentInfo.Uri, documentInfo.UniqueName),
MiscHelpers.GetUrlOrPath(documentInfo.SourceMapUri, string.Empty),
documentInfo.UniqueId,
documentInfo.Category.Kind,
V8ProxyHelpers.AddRefHostObject(documentInfo),
code,
cacheKind,
cacheBytes,
out tempCacheAccepted
)));
cacheAccepted = tempCacheAccepted;
return script;
}
public override V8.V8Script Compile(UniqueDocumentInfo documentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
if (cacheKind == V8CacheKind.None)
{
Marshal.Copy(cacheBytes, 0, cacheBlock.Addr, cacheSize);
cacheResult = V8CacheResult.Disabled;
return Compile(documentInfo, code);
}
var tempCacheAccepted = false;
var script = new V8ScriptImpl(documentInfo, code.GetDigest(), V8SplitProxyNative.Invoke(instance => instance.V8Context_CompileConsumingCache(
Handle,
MiscHelpers.GetUrlOrPath(documentInfo.Uri, documentInfo.UniqueName),
MiscHelpers.GetUrlOrPath(documentInfo.SourceMapUri, string.Empty),
documentInfo.UniqueId,
documentInfo.Category == ModuleCategory.Standard,
V8ProxyHelpers.AddRefHostObject(documentInfo),
code,
cacheKind,
cacheBytes,
out tempCacheAccepted
)));
V8.V8Script script;
var tempCacheBytes = cacheBytes;
if ((cacheBytes == null) || (cacheBytes.Length < 1))
{
script = Compile(documentInfo, code, cacheKind, out tempCacheBytes);
cacheResult = (tempCacheBytes != null) && (tempCacheBytes.Length > 0) ? V8CacheResult.Updated : V8CacheResult.UpdateFailed;
if (cacheResult == V8CacheResult.Updated)
{
cacheBytes = tempCacheBytes;
}
cacheAccepted = tempCacheAccepted;
return script;
}
var tempCacheResult = V8CacheResult.Disabled;
script = new V8ScriptImpl(documentInfo, code.GetDigest(), V8SplitProxyNative.Invoke(instance => instance.V8Context_CompileUpdatingCache(
Handle,
MiscHelpers.GetUrlOrPath(documentInfo.Uri, documentInfo.UniqueName),
MiscHelpers.GetUrlOrPath(documentInfo.SourceMapUri, string.Empty),
documentInfo.UniqueId,
documentInfo.Category.Kind,
V8ProxyHelpers.AddRefHostObject(documentInfo),
code,
cacheKind,
ref tempCacheBytes,
out tempCacheResult
)));
cacheResult = tempCacheResult;
if (cacheResult == V8CacheResult.Updated)
{
cacheBytes = tempCacheBytes;
}
return script;
}
public override object Execute(V8.V8Script script, bool evaluate)

Просмотреть файл

@ -3,8 +3,6 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.ClearScript.JavaScript;
using Microsoft.ClearScript.Util;
namespace Microsoft.ClearScript.V8.SplitProxy
@ -75,7 +73,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
MiscHelpers.GetUrlOrPath(documentInfo.Uri, documentInfo.UniqueName),
MiscHelpers.GetUrlOrPath(documentInfo.SourceMapUri, string.Empty),
documentInfo.UniqueId,
documentInfo.Category == ModuleCategory.Standard,
documentInfo.Category.Kind,
V8ProxyHelpers.AddRefHostObject(documentInfo),
code
)));
@ -95,7 +93,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
MiscHelpers.GetUrlOrPath(documentInfo.Uri, documentInfo.UniqueName),
MiscHelpers.GetUrlOrPath(documentInfo.SourceMapUri, string.Empty),
documentInfo.UniqueId,
documentInfo.Category == ModuleCategory.Standard,
documentInfo.Category.Kind,
V8ProxyHelpers.AddRefHostObject(documentInfo),
code,
cacheKind,
@ -114,28 +112,68 @@ namespace Microsoft.ClearScript.V8.SplitProxy
return Compile(documentInfo, code);
}
var cacheSize = cacheBytes.Length;
using (var cacheBlock = new CoTaskMemBlock(cacheSize))
var tempCacheAccepted = false;
var script = new V8ScriptImpl(documentInfo, code.GetDigest(), V8SplitProxyNative.Invoke(instance => instance.V8Isolate_CompileConsumingCache(
Handle,
MiscHelpers.GetUrlOrPath(documentInfo.Uri, documentInfo.UniqueName),
MiscHelpers.GetUrlOrPath(documentInfo.SourceMapUri, string.Empty),
documentInfo.UniqueId,
documentInfo.Category.Kind,
V8ProxyHelpers.AddRefHostObject(documentInfo),
code,
cacheKind,
cacheBytes,
out tempCacheAccepted
)));
cacheAccepted = tempCacheAccepted;
return script;
}
public override V8.V8Script Compile(UniqueDocumentInfo documentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
if (cacheKind == V8CacheKind.None)
{
Marshal.Copy(cacheBytes, 0, cacheBlock.Addr, cacheSize);
cacheResult = V8CacheResult.Disabled;
return Compile(documentInfo, code);
}
var tempCacheAccepted = false;
var script = new V8ScriptImpl(documentInfo, code.GetDigest(), V8SplitProxyNative.Invoke(instance => instance.V8Isolate_CompileConsumingCache(
Handle,
MiscHelpers.GetUrlOrPath(documentInfo.Uri, documentInfo.UniqueName),
MiscHelpers.GetUrlOrPath(documentInfo.SourceMapUri, string.Empty),
documentInfo.UniqueId,
documentInfo.Category == ModuleCategory.Standard,
V8ProxyHelpers.AddRefHostObject(documentInfo),
code,
cacheKind,
cacheBytes,
out tempCacheAccepted
)));
V8.V8Script script;
var tempCacheBytes = cacheBytes;
if ((cacheBytes == null) || (cacheBytes.Length < 1))
{
script = Compile(documentInfo, code, cacheKind, out tempCacheBytes);
cacheResult = (tempCacheBytes != null) && (tempCacheBytes.Length > 0) ? V8CacheResult.Updated : V8CacheResult.UpdateFailed;
if (cacheResult == V8CacheResult.Updated)
{
cacheBytes = tempCacheBytes;
}
cacheAccepted = tempCacheAccepted;
return script;
}
var tempCacheResult = V8CacheResult.Disabled;
script = new V8ScriptImpl(documentInfo, code.GetDigest(), V8SplitProxyNative.Invoke(instance => instance.V8Isolate_CompileUpdatingCache(
Handle,
MiscHelpers.GetUrlOrPath(documentInfo.Uri, documentInfo.UniqueName),
MiscHelpers.GetUrlOrPath(documentInfo.SourceMapUri, string.Empty),
documentInfo.UniqueId,
documentInfo.Category.Kind,
V8ProxyHelpers.AddRefHostObject(documentInfo),
code,
cacheKind,
ref tempCacheBytes,
out tempCacheResult
)));
cacheResult = tempCacheResult;
if (cacheResult == V8CacheResult.Updated)
{
cacheBytes = tempCacheBytes;
}
return script;
}
public override bool EnableInterruptPropagation

Просмотреть файл

@ -295,7 +295,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[Out] out ulong uniqueId,
[Out] [MarshalAs(UnmanagedType.I1)] out bool isModule,
[Out] out DocumentKind documentKind,
[In] StdString.Ptr pCode,
[Out] out IntPtr pDocumentInfo,
[In] V8Value.Ptr pExports
@ -801,7 +801,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
V8ProxyHelpers.ReleaseHostObject(pTimer);
}
private static void LoadModule(IntPtr pSourceDocumentInfo, StdString.Ptr pSpecifier, StdString.Ptr pResourceName, StdString.Ptr pSourceMapUrl, out ulong uniqueId, out bool isModule, StdString.Ptr pCode, out IntPtr pDocumentInfo, V8Value.Ptr pExports)
private static void LoadModule(IntPtr pSourceDocumentInfo, StdString.Ptr pSpecifier, StdString.Ptr pResourceName, StdString.Ptr pSourceMapUrl, out ulong uniqueId, out DocumentKind documentKind, StdString.Ptr pCode, out IntPtr pDocumentInfo, V8Value.Ptr pExports)
{
string code;
UniqueDocumentInfo documentInfo;
@ -815,7 +815,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
ScheduleHostException(exception);
uniqueId = default;
isModule = default;
documentKind = default;
pDocumentInfo = default;
return;
}
@ -823,7 +823,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
StdString.SetValue(pResourceName, MiscHelpers.GetUrlOrPath(documentInfo.Uri, documentInfo.UniqueName));
StdString.SetValue(pSourceMapUrl, MiscHelpers.GetUrlOrPath(documentInfo.SourceMapUri, string.Empty));
uniqueId = documentInfo.UniqueId;
isModule = documentInfo.Category == ModuleCategory.Standard;
documentKind = documentInfo.Category.Kind;
StdString.SetValue(pCode, code);
pDocumentInfo = V8ProxyHelpers.AddRefHostObject(documentInfo);
V8Value.Set(pExports, exports);

Просмотреть файл

@ -503,7 +503,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
V8Isolate_CancelAwaitDebugger(hIsolate);
}
V8Script.Handle IV8SplitProxyNative.V8Isolate_Compile(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code)
V8Script.Handle IV8SplitProxyNative.V8Isolate_Compile(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -511,13 +511,13 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var codeScope = StdString.CreateScope(code))
{
return V8Isolate_Compile(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value);
return V8Isolate_Compile(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value);
}
}
}
}
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileProducingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileProducingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -527,7 +527,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var cacheBytesScope = StdByteArray.CreateScope())
{
var hScript = V8Isolate_CompileProducingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value);
var hScript = V8Isolate_CompileProducingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value);
cacheBytes = StdByteArray.ToArray(cacheBytesScope.Value);
return hScript;
}
@ -536,7 +536,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
}
}
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileConsumingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileConsumingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -546,7 +546,30 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var cacheBytesScope = StdByteArray.CreateScope(cacheBytes))
{
return V8Isolate_CompileConsumingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheAccepted);
return V8Isolate_CompileConsumingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheAccepted);
}
}
}
}
}
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileUpdatingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
using (var sourceMapUrlScope = StdString.CreateScope(sourceMapUrl))
{
using (var codeScope = StdString.CreateScope(code))
{
using (var cacheBytesScope = StdByteArray.CreateScope(cacheBytes))
{
var hScript = V8Isolate_CompileUpdatingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheResult);
if (cacheResult == V8CacheResult.Updated)
{
cacheBytes = StdByteArray.ToArray(cacheBytesScope.Value);
}
return hScript;
}
}
}
@ -701,7 +724,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
V8Context_CancelAwaitDebugger(hContext);
}
object IV8SplitProxyNative.V8Context_ExecuteCode(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, bool evaluate)
object IV8SplitProxyNative.V8Context_ExecuteCode(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, bool evaluate)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -711,7 +734,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var resultScope = V8Value.CreateScope())
{
V8Context_ExecuteCode(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, evaluate, resultScope.Value);
V8Context_ExecuteCode(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, evaluate, resultScope.Value);
return V8Value.Get(resultScope.Value);
}
}
@ -719,7 +742,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
}
}
V8Script.Handle IV8SplitProxyNative.V8Context_Compile(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code)
V8Script.Handle IV8SplitProxyNative.V8Context_Compile(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -727,13 +750,13 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var codeScope = StdString.CreateScope(code))
{
return V8Context_Compile(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value);
return V8Context_Compile(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value);
}
}
}
}
V8Script.Handle IV8SplitProxyNative.V8Context_CompileProducingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
V8Script.Handle IV8SplitProxyNative.V8Context_CompileProducingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -743,7 +766,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var cacheBytesScope = StdByteArray.CreateScope())
{
var hScript = V8Context_CompileProducingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value);
var hScript = V8Context_CompileProducingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value);
cacheBytes = StdByteArray.ToArray(cacheBytesScope.Value);
return hScript;
}
@ -752,7 +775,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
}
}
V8Script.Handle IV8SplitProxyNative.V8Context_CompileConsumingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
V8Script.Handle IV8SplitProxyNative.V8Context_CompileConsumingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -762,7 +785,30 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var cacheBytesScope = StdByteArray.CreateScope(cacheBytes))
{
return V8Context_CompileConsumingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheAccepted);
return V8Context_CompileConsumingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheAccepted);
}
}
}
}
}
V8Script.Handle IV8SplitProxyNative.V8Context_CompileUpdatingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
using (var sourceMapUrlScope = StdString.CreateScope(sourceMapUrl))
{
using (var codeScope = StdString.CreateScope(code))
{
using (var cacheBytesScope = StdByteArray.CreateScope(cacheBytes))
{
var hScript = V8Context_CompileUpdatingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheResult);
if (cacheResult == V8CacheResult.Updated)
{
cacheBytes = StdByteArray.ToArray(cacheBytesScope.Value);
}
return hScript;
}
}
}
@ -1576,7 +1622,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode
);
@ -1587,7 +1633,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
@ -1600,7 +1646,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
@ -1608,6 +1654,20 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[Out] [MarshalAs(UnmanagedType.I1)] out bool cacheAccepted
);
[DllImport("<#= fileName #>", CallingConvention = CallingConvention.StdCall)]
private static extern V8Script.Handle V8Isolate_CompileUpdatingCache(
[In] V8Isolate.Handle hIsolate,
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
[In] StdByteArray.Ptr pCacheBytes,
[Out] out V8CacheResult cacheResult
);
[DllImport("<#= fileName #>", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool V8Isolate_GetEnableInterruptPropagation(
@ -1770,7 +1830,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] [MarshalAs(UnmanagedType.I1)] bool evaluate,
@ -1783,7 +1843,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode
);
@ -1794,7 +1854,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
@ -1807,7 +1867,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
@ -1815,6 +1875,20 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[Out] [MarshalAs(UnmanagedType.I1)] out bool cacheAccepted
);
[DllImport("<#= fileName #>", CallingConvention = CallingConvention.StdCall)]
private static extern V8Script.Handle V8Context_CompileUpdatingCache(
[In] V8Context.Handle hContext,
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
[In] StdByteArray.Ptr pCacheBytes,
[Out] out V8CacheResult cacheResult
);
[DllImport("<#= fileName #>", CallingConvention = CallingConvention.StdCall)]
private static extern void V8Context_ExecuteScript(
[In] V8Context.Handle hContext,

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -501,7 +501,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
V8Isolate_CancelAwaitDebugger(hIsolate);
}
V8Script.Handle IV8SplitProxyNative.V8Isolate_Compile(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code)
V8Script.Handle IV8SplitProxyNative.V8Isolate_Compile(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -509,13 +509,13 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var codeScope = StdString.CreateScope(code))
{
return V8Isolate_Compile(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value);
return V8Isolate_Compile(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value);
}
}
}
}
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileProducingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileProducingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -525,7 +525,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var cacheBytesScope = StdByteArray.CreateScope())
{
var hScript = V8Isolate_CompileProducingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value);
var hScript = V8Isolate_CompileProducingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value);
cacheBytes = StdByteArray.ToArray(cacheBytesScope.Value);
return hScript;
}
@ -534,7 +534,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
}
}
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileConsumingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileConsumingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -544,7 +544,30 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var cacheBytesScope = StdByteArray.CreateScope(cacheBytes))
{
return V8Isolate_CompileConsumingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheAccepted);
return V8Isolate_CompileConsumingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheAccepted);
}
}
}
}
}
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileUpdatingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
using (var sourceMapUrlScope = StdString.CreateScope(sourceMapUrl))
{
using (var codeScope = StdString.CreateScope(code))
{
using (var cacheBytesScope = StdByteArray.CreateScope(cacheBytes))
{
var hScript = V8Isolate_CompileUpdatingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheResult);
if (cacheResult == V8CacheResult.Updated)
{
cacheBytes = StdByteArray.ToArray(cacheBytesScope.Value);
}
return hScript;
}
}
}
@ -699,7 +722,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
V8Context_CancelAwaitDebugger(hContext);
}
object IV8SplitProxyNative.V8Context_ExecuteCode(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, bool evaluate)
object IV8SplitProxyNative.V8Context_ExecuteCode(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, bool evaluate)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -709,7 +732,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var resultScope = V8Value.CreateScope())
{
V8Context_ExecuteCode(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, evaluate, resultScope.Value);
V8Context_ExecuteCode(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, evaluate, resultScope.Value);
return V8Value.Get(resultScope.Value);
}
}
@ -717,7 +740,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
}
}
V8Script.Handle IV8SplitProxyNative.V8Context_Compile(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code)
V8Script.Handle IV8SplitProxyNative.V8Context_Compile(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -725,13 +748,13 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var codeScope = StdString.CreateScope(code))
{
return V8Context_Compile(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value);
return V8Context_Compile(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value);
}
}
}
}
V8Script.Handle IV8SplitProxyNative.V8Context_CompileProducingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
V8Script.Handle IV8SplitProxyNative.V8Context_CompileProducingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -741,7 +764,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var cacheBytesScope = StdByteArray.CreateScope())
{
var hScript = V8Context_CompileProducingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value);
var hScript = V8Context_CompileProducingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value);
cacheBytes = StdByteArray.ToArray(cacheBytesScope.Value);
return hScript;
}
@ -750,7 +773,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
}
}
V8Script.Handle IV8SplitProxyNative.V8Context_CompileConsumingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
V8Script.Handle IV8SplitProxyNative.V8Context_CompileConsumingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -760,7 +783,30 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var cacheBytesScope = StdByteArray.CreateScope(cacheBytes))
{
return V8Context_CompileConsumingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheAccepted);
return V8Context_CompileConsumingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheAccepted);
}
}
}
}
}
V8Script.Handle IV8SplitProxyNative.V8Context_CompileUpdatingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
using (var sourceMapUrlScope = StdString.CreateScope(sourceMapUrl))
{
using (var codeScope = StdString.CreateScope(code))
{
using (var cacheBytesScope = StdByteArray.CreateScope(cacheBytes))
{
var hScript = V8Context_CompileUpdatingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheResult);
if (cacheResult == V8CacheResult.Updated)
{
cacheBytes = StdByteArray.ToArray(cacheBytesScope.Value);
}
return hScript;
}
}
}
@ -1574,7 +1620,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode
);
@ -1585,7 +1631,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
@ -1598,7 +1644,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
@ -1606,6 +1652,20 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[Out] [MarshalAs(UnmanagedType.I1)] out bool cacheAccepted
);
[DllImport("ClearScriptV8.win-x86.dll", CallingConvention = CallingConvention.StdCall)]
private static extern V8Script.Handle V8Isolate_CompileUpdatingCache(
[In] V8Isolate.Handle hIsolate,
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
[In] StdByteArray.Ptr pCacheBytes,
[Out] out V8CacheResult cacheResult
);
[DllImport("ClearScriptV8.win-x86.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool V8Isolate_GetEnableInterruptPropagation(
@ -1768,7 +1828,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] [MarshalAs(UnmanagedType.I1)] bool evaluate,
@ -1781,7 +1841,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode
);
@ -1792,7 +1852,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
@ -1805,7 +1865,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
@ -1813,6 +1873,20 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[Out] [MarshalAs(UnmanagedType.I1)] out bool cacheAccepted
);
[DllImport("ClearScriptV8.win-x86.dll", CallingConvention = CallingConvention.StdCall)]
private static extern V8Script.Handle V8Context_CompileUpdatingCache(
[In] V8Context.Handle hContext,
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
[In] StdByteArray.Ptr pCacheBytes,
[Out] out V8CacheResult cacheResult
);
[DllImport("ClearScriptV8.win-x86.dll", CallingConvention = CallingConvention.StdCall)]
private static extern void V8Context_ExecuteScript(
[In] V8Context.Handle hContext,
@ -2560,7 +2634,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
V8Isolate_CancelAwaitDebugger(hIsolate);
}
V8Script.Handle IV8SplitProxyNative.V8Isolate_Compile(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code)
V8Script.Handle IV8SplitProxyNative.V8Isolate_Compile(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -2568,13 +2642,13 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var codeScope = StdString.CreateScope(code))
{
return V8Isolate_Compile(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value);
return V8Isolate_Compile(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value);
}
}
}
}
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileProducingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileProducingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -2584,7 +2658,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var cacheBytesScope = StdByteArray.CreateScope())
{
var hScript = V8Isolate_CompileProducingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value);
var hScript = V8Isolate_CompileProducingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value);
cacheBytes = StdByteArray.ToArray(cacheBytesScope.Value);
return hScript;
}
@ -2593,7 +2667,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
}
}
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileConsumingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileConsumingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -2603,7 +2677,30 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var cacheBytesScope = StdByteArray.CreateScope(cacheBytes))
{
return V8Isolate_CompileConsumingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheAccepted);
return V8Isolate_CompileConsumingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheAccepted);
}
}
}
}
}
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileUpdatingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
using (var sourceMapUrlScope = StdString.CreateScope(sourceMapUrl))
{
using (var codeScope = StdString.CreateScope(code))
{
using (var cacheBytesScope = StdByteArray.CreateScope(cacheBytes))
{
var hScript = V8Isolate_CompileUpdatingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheResult);
if (cacheResult == V8CacheResult.Updated)
{
cacheBytes = StdByteArray.ToArray(cacheBytesScope.Value);
}
return hScript;
}
}
}
@ -2758,7 +2855,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
V8Context_CancelAwaitDebugger(hContext);
}
object IV8SplitProxyNative.V8Context_ExecuteCode(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, bool evaluate)
object IV8SplitProxyNative.V8Context_ExecuteCode(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, bool evaluate)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -2768,7 +2865,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var resultScope = V8Value.CreateScope())
{
V8Context_ExecuteCode(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, evaluate, resultScope.Value);
V8Context_ExecuteCode(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, evaluate, resultScope.Value);
return V8Value.Get(resultScope.Value);
}
}
@ -2776,7 +2873,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
}
}
V8Script.Handle IV8SplitProxyNative.V8Context_Compile(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code)
V8Script.Handle IV8SplitProxyNative.V8Context_Compile(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -2784,13 +2881,13 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var codeScope = StdString.CreateScope(code))
{
return V8Context_Compile(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value);
return V8Context_Compile(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value);
}
}
}
}
V8Script.Handle IV8SplitProxyNative.V8Context_CompileProducingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
V8Script.Handle IV8SplitProxyNative.V8Context_CompileProducingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -2800,7 +2897,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var cacheBytesScope = StdByteArray.CreateScope())
{
var hScript = V8Context_CompileProducingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value);
var hScript = V8Context_CompileProducingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value);
cacheBytes = StdByteArray.ToArray(cacheBytesScope.Value);
return hScript;
}
@ -2809,7 +2906,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
}
}
V8Script.Handle IV8SplitProxyNative.V8Context_CompileConsumingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
V8Script.Handle IV8SplitProxyNative.V8Context_CompileConsumingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -2819,7 +2916,30 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var cacheBytesScope = StdByteArray.CreateScope(cacheBytes))
{
return V8Context_CompileConsumingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheAccepted);
return V8Context_CompileConsumingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheAccepted);
}
}
}
}
}
V8Script.Handle IV8SplitProxyNative.V8Context_CompileUpdatingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
using (var sourceMapUrlScope = StdString.CreateScope(sourceMapUrl))
{
using (var codeScope = StdString.CreateScope(code))
{
using (var cacheBytesScope = StdByteArray.CreateScope(cacheBytes))
{
var hScript = V8Context_CompileUpdatingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheResult);
if (cacheResult == V8CacheResult.Updated)
{
cacheBytes = StdByteArray.ToArray(cacheBytesScope.Value);
}
return hScript;
}
}
}
@ -3633,7 +3753,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode
);
@ -3644,7 +3764,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
@ -3657,7 +3777,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
@ -3665,6 +3785,20 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[Out] [MarshalAs(UnmanagedType.I1)] out bool cacheAccepted
);
[DllImport("ClearScriptV8.win-x64.dll", CallingConvention = CallingConvention.StdCall)]
private static extern V8Script.Handle V8Isolate_CompileUpdatingCache(
[In] V8Isolate.Handle hIsolate,
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
[In] StdByteArray.Ptr pCacheBytes,
[Out] out V8CacheResult cacheResult
);
[DllImport("ClearScriptV8.win-x64.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool V8Isolate_GetEnableInterruptPropagation(
@ -3827,7 +3961,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] [MarshalAs(UnmanagedType.I1)] bool evaluate,
@ -3840,7 +3974,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode
);
@ -3851,7 +3985,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
@ -3864,7 +3998,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
@ -3872,6 +4006,20 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[Out] [MarshalAs(UnmanagedType.I1)] out bool cacheAccepted
);
[DllImport("ClearScriptV8.win-x64.dll", CallingConvention = CallingConvention.StdCall)]
private static extern V8Script.Handle V8Context_CompileUpdatingCache(
[In] V8Context.Handle hContext,
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
[In] StdByteArray.Ptr pCacheBytes,
[Out] out V8CacheResult cacheResult
);
[DllImport("ClearScriptV8.win-x64.dll", CallingConvention = CallingConvention.StdCall)]
private static extern void V8Context_ExecuteScript(
[In] V8Context.Handle hContext,
@ -4619,7 +4767,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
V8Isolate_CancelAwaitDebugger(hIsolate);
}
V8Script.Handle IV8SplitProxyNative.V8Isolate_Compile(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code)
V8Script.Handle IV8SplitProxyNative.V8Isolate_Compile(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -4627,13 +4775,13 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var codeScope = StdString.CreateScope(code))
{
return V8Isolate_Compile(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value);
return V8Isolate_Compile(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value);
}
}
}
}
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileProducingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileProducingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -4643,7 +4791,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var cacheBytesScope = StdByteArray.CreateScope())
{
var hScript = V8Isolate_CompileProducingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value);
var hScript = V8Isolate_CompileProducingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value);
cacheBytes = StdByteArray.ToArray(cacheBytesScope.Value);
return hScript;
}
@ -4652,7 +4800,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
}
}
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileConsumingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileConsumingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -4662,7 +4810,30 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var cacheBytesScope = StdByteArray.CreateScope(cacheBytes))
{
return V8Isolate_CompileConsumingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheAccepted);
return V8Isolate_CompileConsumingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheAccepted);
}
}
}
}
}
V8Script.Handle IV8SplitProxyNative.V8Isolate_CompileUpdatingCache(V8Isolate.Handle hIsolate, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
using (var sourceMapUrlScope = StdString.CreateScope(sourceMapUrl))
{
using (var codeScope = StdString.CreateScope(code))
{
using (var cacheBytesScope = StdByteArray.CreateScope(cacheBytes))
{
var hScript = V8Isolate_CompileUpdatingCache(hIsolate, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheResult);
if (cacheResult == V8CacheResult.Updated)
{
cacheBytes = StdByteArray.ToArray(cacheBytesScope.Value);
}
return hScript;
}
}
}
@ -4817,7 +4988,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
V8Context_CancelAwaitDebugger(hContext);
}
object IV8SplitProxyNative.V8Context_ExecuteCode(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, bool evaluate)
object IV8SplitProxyNative.V8Context_ExecuteCode(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, bool evaluate)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -4827,7 +4998,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var resultScope = V8Value.CreateScope())
{
V8Context_ExecuteCode(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, evaluate, resultScope.Value);
V8Context_ExecuteCode(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, evaluate, resultScope.Value);
return V8Value.Get(resultScope.Value);
}
}
@ -4835,7 +5006,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
}
}
V8Script.Handle IV8SplitProxyNative.V8Context_Compile(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code)
V8Script.Handle IV8SplitProxyNative.V8Context_Compile(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -4843,13 +5014,13 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var codeScope = StdString.CreateScope(code))
{
return V8Context_Compile(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value);
return V8Context_Compile(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value);
}
}
}
}
V8Script.Handle IV8SplitProxyNative.V8Context_CompileProducingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
V8Script.Handle IV8SplitProxyNative.V8Context_CompileProducingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -4859,7 +5030,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var cacheBytesScope = StdByteArray.CreateScope())
{
var hScript = V8Context_CompileProducingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value);
var hScript = V8Context_CompileProducingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value);
cacheBytes = StdByteArray.ToArray(cacheBytesScope.Value);
return hScript;
}
@ -4868,7 +5039,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
}
}
V8Script.Handle IV8SplitProxyNative.V8Context_CompileConsumingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, bool isModule, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
V8Script.Handle IV8SplitProxyNative.V8Context_CompileConsumingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
@ -4878,7 +5049,30 @@ namespace Microsoft.ClearScript.V8.SplitProxy
{
using (var cacheBytesScope = StdByteArray.CreateScope(cacheBytes))
{
return V8Context_CompileConsumingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, isModule, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheAccepted);
return V8Context_CompileConsumingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheAccepted);
}
}
}
}
}
V8Script.Handle IV8SplitProxyNative.V8Context_CompileUpdatingCache(V8Context.Handle hContext, string resourceName, string sourceMapUrl, ulong uniqueId, DocumentKind documentKind, IntPtr pDocumentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
using (var resourceNameScope = StdString.CreateScope(resourceName))
{
using (var sourceMapUrlScope = StdString.CreateScope(sourceMapUrl))
{
using (var codeScope = StdString.CreateScope(code))
{
using (var cacheBytesScope = StdByteArray.CreateScope(cacheBytes))
{
var hScript = V8Context_CompileUpdatingCache(hContext, resourceNameScope.Value, sourceMapUrlScope.Value, uniqueId, documentKind, pDocumentInfo, codeScope.Value, cacheKind, cacheBytesScope.Value, out cacheResult);
if (cacheResult == V8CacheResult.Updated)
{
cacheBytes = StdByteArray.ToArray(cacheBytesScope.Value);
}
return hScript;
}
}
}
@ -5692,7 +5886,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode
);
@ -5703,7 +5897,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
@ -5716,7 +5910,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
@ -5724,6 +5918,20 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[Out] [MarshalAs(UnmanagedType.I1)] out bool cacheAccepted
);
[DllImport("ClearScriptV8.win-arm64.dll", CallingConvention = CallingConvention.StdCall)]
private static extern V8Script.Handle V8Isolate_CompileUpdatingCache(
[In] V8Isolate.Handle hIsolate,
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
[In] StdByteArray.Ptr pCacheBytes,
[Out] out V8CacheResult cacheResult
);
[DllImport("ClearScriptV8.win-arm64.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool V8Isolate_GetEnableInterruptPropagation(
@ -5886,7 +6094,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] [MarshalAs(UnmanagedType.I1)] bool evaluate,
@ -5899,7 +6107,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode
);
@ -5910,7 +6118,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
@ -5923,7 +6131,7 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] [MarshalAs(UnmanagedType.I1)] bool isModule,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
@ -5931,6 +6139,20 @@ namespace Microsoft.ClearScript.V8.SplitProxy
[Out] [MarshalAs(UnmanagedType.I1)] out bool cacheAccepted
);
[DllImport("ClearScriptV8.win-arm64.dll", CallingConvention = CallingConvention.StdCall)]
private static extern V8Script.Handle V8Context_CompileUpdatingCache(
[In] V8Context.Handle hContext,
[In] StdString.Ptr pResourceName,
[In] StdString.Ptr pSourceMapUrl,
[In] ulong uniqueId,
[In] DocumentKind documentKind,
[In] IntPtr pDocumentInfo,
[In] StdString.Ptr pCode,
[In] V8CacheKind cacheKind,
[In] StdByteArray.Ptr pCacheBytes,
[Out] out V8CacheResult cacheResult
);
[DllImport("ClearScriptV8.win-arm64.dll", CallingConvention = CallingConvention.StdCall)]
private static extern void V8Context_ExecuteScript(
[In] V8Context.Handle hContext,

Просмотреть файл

@ -10,7 +10,7 @@ namespace Microsoft.ClearScript.V8
/// </summary>
public enum V8CacheKind
{
// IMPORTANT: maintain bitwise equivalence with unmanaged enum V8CacheType
// IMPORTANT: maintain bitwise equivalence with unmanaged enum V8CacheKind
/// <summary>
/// Specifies that no cache data is to be generated or consumed during V8 script

Просмотреть файл

@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
namespace Microsoft.ClearScript.V8
{
/// <summary>
/// Defines cache data processing results for V8 script compilation.
/// </summary>
public enum V8CacheResult
{
// IMPORTANT: maintain bitwise equivalence with unmanaged enum V8CacheResult
/// <summary>
/// Indicates that cache data processing was disabled because the caller specified
/// <c><see cref="V8CacheKind">V8CacheKind.None</see></c>.
/// </summary>
Disabled,
/// <summary>
/// Indicates that the provided cache data was accepted and used to accelerate script
/// compilation.
/// </summary>
Accepted,
/// <summary>
/// Indicates that script compilation was bypassed because a suitable compiled script was
/// found in the V8 runtime's memory, but the provided cache data was verified to be
/// correct.
/// </summary>
Verified,
/// <summary>
/// Indicates that the provided cache data was updated because it was empty, stale, or
/// invalid.
/// </summary>
Updated,
/// <summary>
/// Indicates that the provided cache data was empty, stale, or invalid, but new cache data
/// could not be generated, and no additional information was provided by the V8 runtime.
/// </summary>
UpdateFailed
}
}

Просмотреть файл

@ -38,6 +38,8 @@ namespace Microsoft.ClearScript.V8
public abstract V8Script Compile(UniqueDocumentInfo documentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted);
public abstract V8Script Compile(UniqueDocumentInfo documentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult);
public abstract object Execute(V8Script script, bool evaluate);
public abstract void Interrupt();

Просмотреть файл

@ -24,6 +24,7 @@ namespace Microsoft.ClearScript.V8
private readonly Guid targetId = Guid.NewGuid();
private readonly string name;
private readonly string version;
private readonly int port;
private readonly IV8DebugListener listener;
private TcpListener tcpListener;
@ -39,6 +40,7 @@ namespace Microsoft.ClearScript.V8
{
this.name = name;
this.version = version;
this.port = port;
this.listener = listener;
var started = false;
@ -93,6 +95,7 @@ namespace Microsoft.ClearScript.V8
if (Interlocked.CompareExchange(ref activeClient, null, client) == client)
{
listener.DisconnectClient();
ThreadPool.QueueUserWorkItem(_ => V8Runtime.OnDebuggerDisconnected(new V8RuntimeDebuggerEventArgs(name, port)));
}
}
@ -266,6 +269,7 @@ namespace Microsoft.ClearScript.V8
{
listener.ConnectClient();
client.Start();
ThreadPool.QueueUserWorkItem(_ => V8Runtime.OnDebuggerConnected(new V8RuntimeDebuggerEventArgs(name, port)));
return true;
}
@ -279,6 +283,7 @@ namespace Microsoft.ClearScript.V8
{
client.Dispose(errorCode, message);
listener.DisconnectClient();
ThreadPool.QueueUserWorkItem(_ => V8Runtime.OnDebuggerDisconnected(new V8RuntimeDebuggerEventArgs(name, port)));
}
}

Просмотреть файл

@ -30,6 +30,8 @@ namespace Microsoft.ClearScript.V8
public abstract V8Script Compile(UniqueDocumentInfo documentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted);
public abstract V8Script Compile(UniqueDocumentInfo documentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult);
public abstract bool EnableInterruptPropagation { get; set; }
public abstract bool DisableHeapSizeViolationInterrupt { get; set; }

Просмотреть файл

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.ClearScript.JavaScript;
using Microsoft.ClearScript.Util;
@ -238,9 +239,15 @@ namespace Microsoft.ClearScript.V8
{
exports = null;
}
else if (category == DocumentCategory.Json)
{
exports = engine.MarshalToScript(javaScriptEngine.JsonModuleManager.GetOrCreateModule(documentInfo, code).Result);
}
else
{
throw new InvalidOperationException("Unsupported document category");
var uri = document.Info.Uri;
var name = (uri != null) ? (uri.IsFile ? uri.LocalPath : uri.AbsoluteUri) : document.Info.Name;
throw new FileLoadException($"Unsupported document category '{category}'", name);
}
return code;

Просмотреть файл

@ -152,6 +152,16 @@ namespace Microsoft.ClearScript.V8
#region public members
/// <summary>
/// Occurs when a debugger connects to a V8 runtime.
/// </summary>
public static event EventHandler<V8RuntimeDebuggerEventArgs> DebuggerConnected;
/// <summary>
/// Occurs when a debugger disconnects from a V8 runtime.
/// </summary>
public static event EventHandler<V8RuntimeDebuggerEventArgs> DebuggerDisconnected;
/// <summary>
/// Gets the name associated with the V8 runtime instance.
/// </summary>
@ -537,11 +547,13 @@ namespace Microsoft.ClearScript.V8
/// <param name="code">The script code to compile.</param>
/// <param name="cacheKind">The kind of cache data to be consumed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted and used to accelerate script compilation, <c>false</c> otherwise.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build.
/// the same V8 build. Note that script compilation may be bypassed if a suitable compiled
/// script already exists in the V8 runtime's memory. In that case, the cache data is
/// ignored and <paramref name="cacheAccepted"/> is set to <c>false</c>.
/// </remarks>
/// <c><seealso cref="Compile(string, V8CacheKind, out byte[])"/></c>
public V8Script Compile(string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
@ -556,11 +568,13 @@ namespace Microsoft.ClearScript.V8
/// <param name="code">The script code to compile.</param>
/// <param name="cacheKind">The kind of cache data to be consumed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted and used to accelerate script compilation, <c>false</c> otherwise.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build.
/// the same V8 build. Note that script compilation may be bypassed if a suitable compiled
/// script already exists in the V8 runtime's memory. In that case, the cache data is
/// ignored and <paramref name="cacheAccepted"/> is set to <c>false</c>.
/// </remarks>
/// <c><seealso cref="Compile(string, string, V8CacheKind, out byte[])"/></c>
public V8Script Compile(string documentName, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
@ -575,11 +589,13 @@ namespace Microsoft.ClearScript.V8
/// <param name="code">The script code to compile.</param>
/// <param name="cacheKind">The kind of cache data to be consumed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted and used to accelerate script compilation, <c>false</c> otherwise.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build.
/// the same V8 build. Note that script compilation may be bypassed if a suitable compiled
/// script already exists in the V8 runtime's memory. In that case, the cache data is
/// ignored and <paramref name="cacheAccepted"/> is set to <c>false</c>.
/// </remarks>
/// <c><seealso cref="Compile(DocumentInfo, string, V8CacheKind, out byte[])"/></c>
public V8Script Compile(DocumentInfo documentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
@ -588,6 +604,63 @@ namespace Microsoft.ClearScript.V8
return CompileInternal(documentInfo.MakeUnique(DocumentNameManager), code, cacheKind, cacheBytes, out cacheAccepted);
}
/// <summary>
/// Creates a compiled script, consuming previously generated cache data and updating it if necessary.
/// </summary>
/// <param name="code">The script code to compile.</param>
/// <param name="cacheKind">The kind of cache data to be processed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheResult">The cache data processing result for the operation.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build. If returned, the updated cache data can be stored externally and is
/// usable in other V8 script engines and application processes.
/// </remarks>
public V8Script Compile(string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
return Compile(null, code, cacheKind, ref cacheBytes, out cacheResult);
}
/// <summary>
/// Creates a compiled script with an associated document name, consuming previously generated cache data and updating it if necessary.
/// </summary>
/// <param name="documentName">A document name for the compiled script. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
/// <param name="code">The script code to compile.</param>
/// <param name="cacheKind">The kind of cache data to be processed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheResult">The cache data processing result for the operation.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build. If returned, the updated cache data can be stored externally and is
/// usable in other V8 script engines and application processes.
/// </remarks>
public V8Script Compile(string documentName, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
return Compile(new DocumentInfo(documentName), code, cacheKind, ref cacheBytes, out cacheResult);
}
/// <summary>
/// Creates a compiled script with the specified document meta-information, consuming previously generated cache data and updating it if necessary.
/// </summary>
/// <param name="documentInfo">A structure containing meta-information for the script document.</param>
/// <param name="code">The script code to compile.</param>
/// <param name="cacheKind">The kind of cache data to be processed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheResult">The cache data processing result for the operation.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build. If returned, the updated cache data can be stored externally and is
/// usable in other V8 script engines and application processes.
/// </remarks>
public V8Script Compile(DocumentInfo documentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
VerifyNotDisposed();
return CompileInternal(documentInfo.MakeUnique(DocumentNameManager), code, cacheKind, ref cacheBytes, out cacheResult);
}
/// <summary>
/// Loads and compiles a script document.
/// </summary>
@ -682,11 +755,13 @@ namespace Microsoft.ClearScript.V8
/// <param name="specifier">A string specifying the document to be loaded and compiled.</param>
/// <param name="cacheKind">The kind of cache data to be consumed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted and used to accelerate script compilation, <c>false</c> otherwise.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build.
/// the same V8 build. Note that script compilation may be bypassed if a suitable compiled
/// script already exists in the V8 runtime's memory. In that case, the cache data is
/// ignored and <paramref name="cacheAccepted"/> is set to <c>false</c>.
/// </remarks>
public V8Script CompileDocument(string specifier, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
{
@ -700,11 +775,13 @@ namespace Microsoft.ClearScript.V8
/// <param name="category">An optional category for the requested document.</param>
/// <param name="cacheKind">The kind of cache data to be consumed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted and used to accelerate script compilation, <c>false</c> otherwise.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build.
/// the same V8 build. Note that script compilation may be bypassed if a suitable compiled
/// script already exists in the V8 runtime's memory. In that case, the cache data is
/// ignored and <paramref name="cacheAccepted"/> is set to <c>false</c>.
/// </remarks>
public V8Script CompileDocument(string specifier, DocumentCategory category, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
{
@ -719,11 +796,13 @@ namespace Microsoft.ClearScript.V8
/// <param name="contextCallback">An optional context callback for the requested document.</param>
/// <param name="cacheKind">The kind of cache data to be consumed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted and used to accelerate script compilation, <c>false</c> otherwise.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build.
/// the same V8 build. Note that script compilation may be bypassed if a suitable compiled
/// script already exists in the V8 runtime's memory. In that case, the cache data is
/// ignored and <paramref name="cacheAccepted"/> is set to <c>false</c>.
/// </remarks>
public V8Script CompileDocument(string specifier, DocumentCategory category, DocumentContextCallback contextCallback, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
{
@ -732,6 +811,65 @@ namespace Microsoft.ClearScript.V8
return Compile(document.Info, document.GetTextContents(), cacheKind, cacheBytes, out cacheAccepted);
}
/// <summary>
/// Loads and compiles a script document, consuming previously generated cache data and updating it if necessary.
/// </summary>
/// <param name="specifier">A string specifying the document to be loaded and compiled.</param>
/// <param name="cacheKind">The kind of cache data to be processed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheResult">The cache data processing result for the operation.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build. If returned, the updated cache data can be stored externally and is
/// usable in other V8 script engines and application processes.
/// </remarks>
public V8Script CompileDocument(string specifier, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
return CompileDocument(specifier, null, cacheKind, ref cacheBytes, out cacheResult);
}
/// <summary>
/// Loads and compiles a document with the specified category, consuming previously generated cache data and updating it if necessary.
/// </summary>
/// <param name="specifier">A string specifying the document to be loaded and compiled.</param>
/// <param name="category">An optional category for the requested document.</param>
/// <param name="cacheKind">The kind of cache data to be processed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheResult">The cache data processing result for the operation.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build. If returned, the updated cache data can be stored externally and is
/// usable in other V8 script engines and application processes.
/// </remarks>
public V8Script CompileDocument(string specifier, DocumentCategory category, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
return CompileDocument(specifier, category, null, cacheKind, ref cacheBytes, out cacheResult);
}
/// <summary>
/// Loads and compiles a document with the specified category and context callback, consuming previously generated cache data and updating it if necessary.
/// </summary>
/// <param name="specifier">A string specifying the document to be loaded and compiled.</param>
/// <param name="category">An optional category for the requested document.</param>
/// <param name="contextCallback">An optional context callback for the requested document.</param>
/// <param name="cacheKind">The kind of cache data to be processed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheResult">The cache data processing result for the operation.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build. If returned, the updated cache data can be stored externally and is
/// usable in other V8 script engines and application processes.
/// </remarks>
public V8Script CompileDocument(string specifier, DocumentCategory category, DocumentContextCallback contextCallback, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
MiscHelpers.VerifyNonBlankArgument(specifier, nameof(specifier), "Invalid document specifier");
var document = DocumentSettings.LoadDocument(null, specifier, category, contextCallback);
return Compile(document.Info, document.GetTextContents(), cacheKind, ref cacheBytes, out cacheResult);
}
/// <summary>
/// Returns memory usage information.
/// </summary>
@ -851,6 +989,16 @@ namespace Microsoft.ClearScript.V8
internal readonly HostItemCollateral HostItemCollateral = new HostItemCollateral();
internal static void OnDebuggerConnected(V8RuntimeDebuggerEventArgs args)
{
DebuggerConnected?.Invoke(null, args);
}
internal static void OnDebuggerDisconnected(V8RuntimeDebuggerEventArgs args)
{
DebuggerDisconnected?.Invoke(null, args);
}
internal V8IsolateProxy IsolateProxy
{
get
@ -885,6 +1033,10 @@ namespace Microsoft.ClearScript.V8
{
code = CommonJSManager.Module.GetAugmentedCode(code);
}
else if ((documentInfo.Category != DocumentCategory.Script) && (documentInfo.Category != ModuleCategory.Standard))
{
throw new NotSupportedException("The V8 runtime cannot compile documents of type '" + documentInfo.Category + "'");
}
return proxy.Compile(documentInfo, code);
}
@ -900,6 +1052,10 @@ namespace Microsoft.ClearScript.V8
{
code = CommonJSManager.Module.GetAugmentedCode(code);
}
else if ((documentInfo.Category != DocumentCategory.Script) && (documentInfo.Category != ModuleCategory.Standard))
{
throw new NotSupportedException("The V8 runtime cannot compile documents of type '" + documentInfo.Category + "'");
}
return proxy.Compile(documentInfo, code, cacheKind, out cacheBytes);
}
@ -915,10 +1071,33 @@ namespace Microsoft.ClearScript.V8
{
code = CommonJSManager.Module.GetAugmentedCode(code);
}
else if ((documentInfo.Category != DocumentCategory.Script) && (documentInfo.Category != ModuleCategory.Standard))
{
throw new NotSupportedException("The V8 runtime cannot compile documents of type '" + documentInfo.Category + "'");
}
return proxy.Compile(documentInfo, code, cacheKind, cacheBytes, out cacheAccepted);
}
private V8Script CompileInternal(UniqueDocumentInfo documentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
if (FormatCode)
{
code = MiscHelpers.FormatCode(code);
}
if (documentInfo.Category == ModuleCategory.CommonJS)
{
code = CommonJSManager.Module.GetAugmentedCode(code);
}
else if ((documentInfo.Category != DocumentCategory.Script) && (documentInfo.Category != ModuleCategory.Standard))
{
throw new NotSupportedException("The V8 runtime cannot compile documents of type '" + documentInfo.Category + "'");
}
return proxy.Compile(documentInfo, code, cacheKind, ref cacheBytes, out cacheResult);
}
#endregion
#region IDisposable implementation

Просмотреть файл

@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
namespace Microsoft.ClearScript.V8
{
/// <summary>
/// Provides data for debugger events associated with V8 runtimes.
/// </summary>
public sealed class V8RuntimeDebuggerEventArgs : EventArgs
{
/// <summary>
/// Gets the name associated with the V8 runtime instance.
/// </summary>
public string Name { get; }
/// <summary>
/// Gets the TCP port of the debugger connection.
/// </summary>
public int Port { get; }
internal V8RuntimeDebuggerEventArgs(string name, int port)
{
Name = name;
Port = port;
}
}
}

Просмотреть файл

@ -9,6 +9,6 @@ namespace Microsoft.ClearScript.V8
{
public sealed partial class V8ScriptEngine
{
private const string initScript = "Object.defineProperty(this,'EngineInternal',{value:(t=>{let e=t=>t.bind();function r(){return new this(...arguments)}let o=t.isHostObjectKey;delete t.isHostObjectKey;let n=t=>!!t&&!0===t[o],c=Promise,i=Symbol(),a=t.toJson;return delete t.toJson,Object.freeze({commandHolder:{},getCommandResult:e(t=>null==t?t:'function'!=typeof t.hasOwnProperty?'Module'===t[Symbol.toStringTag]?'[module]':'[external]':!0===t[o]?t:'function'!=typeof t.toString?'['+typeof t+']':t.toString()),strictEquals:e((t,e)=>t===e),invokeConstructor:e((t,e)=>{if('function'!=typeof t)throw Error('Function expected');return r.apply(t,Array.from(e))}),invokeMethod:e((t,e,r)=>{if('function'!=typeof e)throw Error('Function expected');return e.apply(t,Array.from(r))}),createPromise:e(function(){return new c(...arguments)}),isPromise:e(t=>t instanceof c),isHostObject:e(n),completePromiseWithResult:e((t,e,r)=>{try{e(t())}catch(o){r(o)}}),completePromise:e((t,e,r)=>{try{t(),e()}catch(o){r(o)}}),throwValue:e(t=>{throw t}),getStackTrace:e(()=>{try{throw Error('[stack trace]')}catch(t){return t.stack}}),toIterator:e(function*(t){try{for(;t.ScriptableMoveNext();)yield t.ScriptableCurrent}finally{t.ScriptableDispose()}}),toAsyncIterator:e(async function*(t){try{for(;await t.ScriptableMoveNextAsync();)yield t.ScriptableCurrent}finally{await t.ScriptableDisposeAsync()}}),getIterator:e(t=>t?.[Symbol.iterator]?.()),getAsyncIterator:e(t=>t?.[Symbol.asyncIterator]?.()),checkpoint:e(()=>{let e=t[i];if(e)throw e}),toJson:e((t,e)=>a?JSON.parse(a(t,e)):e),asyncGenerator:async function*(){}().constructor})})(this)});";
private const string initScript = "Object.defineProperty(this,'EngineInternal',{value:(t=>{let e=t=>t.bind();function r(){return new this(...arguments)}let o=t.isHostObjectKey;delete t.isHostObjectKey;let n=t=>!!t&&!0===t[o],c=Promise,i=JSON,a=Symbol(),s=t.toJson;return delete t.toJson,Object.freeze({commandHolder:{},getCommandResult:e(t=>null==t?t:'function'!=typeof t.hasOwnProperty?'Module'===t[Symbol.toStringTag]?'[module]':'[external]':!0===t[o]?t:'function'!=typeof t.toString?'['+typeof t+']':t.toString()),strictEquals:e((t,e)=>t===e),invokeConstructor:e((t,e)=>{if('function'!=typeof t)throw Error('Function expected');return r.apply(t,Array.from(e))}),invokeMethod:e((t,e,r)=>{if('function'!=typeof e)throw Error('Function expected');return e.apply(t,Array.from(r))}),createPromise:e(function(){return new c(...arguments)}),isPromise:e(t=>t instanceof c),isHostObject:e(n),completePromiseWithResult:e((t,e,r)=>{try{e(t())}catch(o){r(o)}}),completePromise:e((t,e,r)=>{try{t(),e()}catch(o){r(o)}}),throwValue:e(t=>{throw t}),getStackTrace:e(()=>{try{throw Error('[stack trace]')}catch(t){return t.stack}}),toIterator:e(function*(t){try{for(;t.ScriptableMoveNext();)yield t.ScriptableCurrent}finally{t.ScriptableDispose()}}),toAsyncIterator:e(async function*(t){try{for(;await t.ScriptableMoveNextAsync();)yield t.ScriptableCurrent}finally{await t.ScriptableDisposeAsync()}}),getIterator:e(t=>t?.[Symbol.iterator]?.()),getAsyncIterator:e(t=>t?.[Symbol.asyncIterator]?.()),checkpoint:e(()=>{let e=t[a];if(e)throw e}),toJson:e((t,e)=>s?i.parse(s(t,e)):e),parseJson:e(t=>i.parse(t)),asyncGenerator:async function*(){}().constructor})})(this)});";
}
}

Просмотреть файл

@ -14,6 +14,7 @@ Object.defineProperty(this, 'EngineInternal', { value: (globalObject => {
const isHostObject = value => !!value && (value[isHostObjectKey] === true);
const savedPromise = Promise;
const savedJSON = JSON;
const checkpointSymbol = Symbol();
const toJson = globalObject.toJson;
@ -133,7 +134,9 @@ Object.defineProperty(this, 'EngineInternal', { value: (globalObject => {
}
}),
toJson: bind((key, value) => toJson ? JSON.parse(toJson(key, value)) : value),
toJson: bind((key, value) => toJson ? savedJSON.parse(toJson(key, value)) : value),
parseJson: bind(json => savedJSON.parse(json)),
asyncGenerator: (async function* () {})().constructor

Просмотреть файл

@ -51,6 +51,7 @@ namespace Microsoft.ClearScript.V8
private bool suppressExtensionMethodEnumeration;
private CommonJSManager commonJSManager;
private JsonModuleManager jsonDocumentManager;
#endregion
@ -560,11 +561,13 @@ namespace Microsoft.ClearScript.V8
/// <param name="code">The script code to compile.</param>
/// <param name="cacheKind">The kind of cache data to be consumed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted and used to accelerate script compilation, <c>false</c> otherwise.</param>
/// <returns>A compiled script that can be executed multiple times without recompilation.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build.
/// the same V8 build. Note that script compilation may be bypassed if a suitable compiled
/// script already exists in the V8 runtime's memory. In that case, the cache data is
/// ignored and <paramref name="cacheAccepted"/> is set to <c>false</c>.
/// </remarks>
/// <c><seealso cref="Compile(string, V8CacheKind, out byte[])"/></c>
public V8Script Compile(string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
@ -579,11 +582,13 @@ namespace Microsoft.ClearScript.V8
/// <param name="code">The script code to compile.</param>
/// <param name="cacheKind">The kind of cache data to be consumed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted and used to accelerate script compilation, <c>false</c> otherwise.</param>
/// <returns>A compiled script that can be executed multiple times without recompilation.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build.
/// the same V8 build. Note that script compilation may be bypassed if a suitable compiled
/// script already exists in the V8 runtime's memory. In that case, the cache data is
/// ignored and <paramref name="cacheAccepted"/> is set to <c>false</c>.
/// </remarks>
/// <c><seealso cref="Compile(string, string, V8CacheKind, out byte[])"/></c>
public V8Script Compile(string documentName, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
@ -598,11 +603,13 @@ namespace Microsoft.ClearScript.V8
/// <param name="code">The script code to compile.</param>
/// <param name="cacheKind">The kind of cache data to be consumed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted and used to accelerate script compilation, <c>false</c> otherwise.</param>
/// <returns>A compiled script that can be executed multiple times without recompilation.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build.
/// the same V8 build. Note that script compilation may be bypassed if a suitable compiled
/// script already exists in the V8 runtime's memory. In that case, the cache data is
/// ignored and <paramref name="cacheAccepted"/> is set to <c>false</c>.
/// </remarks>
/// <c><seealso cref="Compile(DocumentInfo, string, V8CacheKind, out byte[])"/></c>
public V8Script Compile(DocumentInfo documentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
@ -619,6 +626,77 @@ namespace Microsoft.ClearScript.V8
return tempScript;
}
/// <summary>
/// Creates a compiled script, consuming previously generated cache data and updating it if necessary.
/// </summary>
/// <param name="code">The script code to compile.</param>
/// <param name="cacheKind">The kind of cache data to be processed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheResult">The cache data processing result for the operation.</param>
/// <returns>A compiled script that can be executed multiple times without recompilation.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build. If returned, the updated cache data can be stored externally and is
/// usable in other V8 script engines and application processes.
/// </remarks>
public V8Script Compile(string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
return Compile(null, code, cacheKind, ref cacheBytes, out cacheResult);
}
/// <summary>
/// Creates a compiled script with an associated document name, consuming previously generated cache data and updating it if necessary.
/// </summary>
/// <param name="documentName">A document name for the compiled script. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
/// <param name="code">The script code to compile.</param>
/// <param name="cacheKind">The kind of cache data to be processed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheResult">The cache data processing result for the operation.</param>
/// <returns>A compiled script that can be executed multiple times without recompilation.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build. If returned, the updated cache data can be stored externally and is
/// usable in other V8 script engines and application processes.
/// </remarks>
public V8Script Compile(string documentName, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
return Compile(new DocumentInfo(documentName), code, cacheKind, ref cacheBytes, out cacheResult);
}
/// <summary>
/// Creates a compiled script with the specified document meta-information, consuming previously generated cache data and updating it if necessary.
/// </summary>
/// <param name="documentInfo">A structure containing meta-information for the script document.</param>
/// <param name="code">The script code to compile.</param>
/// <param name="cacheKind">The kind of cache data to be processed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheResult">The cache data processing result for the operation.</param>
/// <returns>A compiled script that can be executed multiple times without recompilation.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build. If returned, the updated cache data can be stored externally and is
/// usable in other V8 script engines and application processes.
/// </remarks>
public V8Script Compile(DocumentInfo documentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
VerifyNotDisposed();
V8Script tempScript = null;
var tempCacheBytes = cacheBytes;
cacheResult = ScriptInvoke(() =>
{
tempScript = CompileInternal(documentInfo.MakeUnique(this), code, cacheKind, ref tempCacheBytes, out var tempCacheUpdated);
return tempCacheUpdated;
});
if (cacheResult == V8CacheResult.Updated)
{
cacheBytes = tempCacheBytes;
}
return tempScript;
}
/// <summary>
/// Loads and compiles a script document.
/// </summary>
@ -713,11 +791,13 @@ namespace Microsoft.ClearScript.V8
/// <param name="specifier">A string specifying the document to be loaded and compiled.</param>
/// <param name="cacheKind">The kind of cache data to be consumed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted and used to accelerate script compilation, <c>false</c> otherwise.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build.
/// the same V8 build. Note that script compilation may be bypassed if a suitable compiled
/// script already exists in the V8 runtime's memory. In that case, the cache data is
/// ignored and <paramref name="cacheAccepted"/> is set to <c>false</c>.
/// </remarks>
public V8Script CompileDocument(string specifier, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
{
@ -731,11 +811,13 @@ namespace Microsoft.ClearScript.V8
/// <param name="category">An optional category for the requested document.</param>
/// <param name="cacheKind">The kind of cache data to be consumed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted and used to accelerate script compilation, <c>false</c> otherwise.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build.
/// the same V8 build. Note that script compilation may be bypassed if a suitable compiled
/// script already exists in the V8 runtime's memory. In that case, the cache data is
/// ignored and <paramref name="cacheAccepted"/> is set to <c>false</c>.
/// </remarks>
public V8Script CompileDocument(string specifier, DocumentCategory category, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
{
@ -750,11 +832,13 @@ namespace Microsoft.ClearScript.V8
/// <param name="contextCallback">An optional context callback for the requested document.</param>
/// <param name="cacheKind">The kind of cache data to be consumed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
/// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted and used to accelerate script compilation, <c>false</c> otherwise.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build.
/// the same V8 build. Note that script compilation may be bypassed if a suitable compiled
/// script already exists in the V8 runtime's memory. In that case, the cache data is
/// ignored and <paramref name="cacheAccepted"/> is set to <c>false</c>.
/// </remarks>
public V8Script CompileDocument(string specifier, DocumentCategory category, DocumentContextCallback contextCallback, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
{
@ -763,6 +847,65 @@ namespace Microsoft.ClearScript.V8
return Compile(document.Info, document.GetTextContents(), cacheKind, cacheBytes, out cacheAccepted);
}
/// <summary>
/// Loads and compiles a script document, consuming previously generated cache data and updating it if necessary.
/// </summary>
/// <param name="specifier">A string specifying the document to be loaded and compiled.</param>
/// <param name="cacheKind">The kind of cache data to be processed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheResult">The cache data processing result for the operation.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build. If returned, the updated cache data can be stored externally and is
/// usable in other V8 script engines and application processes.
/// </remarks>
public V8Script CompileDocument(string specifier, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
return CompileDocument(specifier, null, cacheKind, ref cacheBytes, out cacheResult);
}
/// <summary>
/// Loads and compiles a document with the specified category, consuming previously generated cache data and updating it if necessary.
/// </summary>
/// <param name="specifier">A string specifying the document to be loaded and compiled.</param>
/// <param name="category">An optional category for the requested document.</param>
/// <param name="cacheKind">The kind of cache data to be processed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheResult">The cache data processing result for the operation.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build. If returned, the updated cache data can be stored externally and is
/// usable in other V8 script engines and application processes.
/// </remarks>
public V8Script CompileDocument(string specifier, DocumentCategory category, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
return CompileDocument(specifier, category, null, cacheKind, ref cacheBytes, out cacheResult);
}
/// <summary>
/// Loads and compiles a document with the specified category and context callback, consuming previously generated cache data and updating it if necessary.
/// </summary>
/// <param name="specifier">A string specifying the document to be loaded and compiled.</param>
/// <param name="category">An optional category for the requested document.</param>
/// <param name="contextCallback">An optional context callback for the requested document.</param>
/// <param name="cacheKind">The kind of cache data to be processed.</param>
/// <param name="cacheBytes">Cache data for accelerated compilation.</param>
/// <param name="cacheResult">The cache data processing result for the operation.</param>
/// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
/// <remarks>
/// To be accepted, the cache data must have been generated for identical script code by
/// the same V8 build. If returned, the updated cache data can be stored externally and is
/// usable in other V8 script engines and application processes.
/// </remarks>
public V8Script CompileDocument(string specifier, DocumentCategory category, DocumentContextCallback contextCallback, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
MiscHelpers.VerifyNonBlankArgument(specifier, nameof(specifier), "Invalid document specifier");
var document = DocumentSettings.LoadDocument(null, specifier, category, contextCallback);
return Compile(document.Info, document.GetTextContents(), cacheKind, ref cacheBytes, out cacheResult);
}
// ReSharper disable ParameterHidesMember
/// <summary>
@ -945,6 +1088,8 @@ namespace Microsoft.ClearScript.V8
internal CommonJSManager CommonJSManager => commonJSManager ?? (commonJSManager = new CommonJSManager(this));
internal JsonModuleManager JsonModuleManager => jsonDocumentManager ?? (jsonDocumentManager = new JsonModuleManager(this));
private object GetRootItem()
{
return MarshalToHost(ScriptInvoke(() => proxy.GetRootItem()), false);
@ -1015,6 +1160,10 @@ namespace Microsoft.ClearScript.V8
module = CommonJSManager.GetOrCreateModule(documentInfo, code);
code = CommonJSManager.Module.GetAugmentedCode(code);
}
else if ((documentInfo.Category != DocumentCategory.Script) && (documentInfo.Category != ModuleCategory.Standard))
{
throw new NotSupportedException("The script engine cannot compile documents of type '" + documentInfo.Category + "'");
}
// ReSharper disable once LocalVariableHidesMember
var script = proxy.Compile(documentInfo, code);
@ -1040,6 +1189,10 @@ namespace Microsoft.ClearScript.V8
module = CommonJSManager.GetOrCreateModule(documentInfo, code);
code = CommonJSManager.Module.GetAugmentedCode(code);
}
else if ((documentInfo.Category != DocumentCategory.Script) && (documentInfo.Category != ModuleCategory.Standard))
{
throw new NotSupportedException("The script engine cannot compile documents of type '" + documentInfo.Category + "'");
}
// ReSharper disable once LocalVariableHidesMember
var script = proxy.Compile(documentInfo, code, cacheKind, out cacheBytes);
@ -1065,6 +1218,10 @@ namespace Microsoft.ClearScript.V8
module = CommonJSManager.GetOrCreateModule(documentInfo, code);
code = CommonJSManager.Module.GetAugmentedCode(code);
}
else if ((documentInfo.Category != DocumentCategory.Script) && (documentInfo.Category != ModuleCategory.Standard))
{
throw new NotSupportedException("The script engine cannot compile documents of type '" + documentInfo.Category + "'");
}
// ReSharper disable once LocalVariableHidesMember
var script = proxy.Compile(documentInfo, code, cacheKind, cacheBytes, out cacheAccepted);
@ -1077,6 +1234,35 @@ namespace Microsoft.ClearScript.V8
return script;
}
private V8Script CompileInternal(UniqueDocumentInfo documentInfo, string code, V8CacheKind cacheKind, ref byte[] cacheBytes, out V8CacheResult cacheResult)
{
if (FormatCode)
{
code = MiscHelpers.FormatCode(code);
}
CommonJSManager.Module module = null;
if (documentInfo.Category == ModuleCategory.CommonJS)
{
module = CommonJSManager.GetOrCreateModule(documentInfo, code);
code = CommonJSManager.Module.GetAugmentedCode(code);
}
else if ((documentInfo.Category != DocumentCategory.Script) && (documentInfo.Category != ModuleCategory.Standard))
{
throw new NotSupportedException("The script engine cannot compile documents of type '" + documentInfo.Category + "'");
}
// ReSharper disable once LocalVariableHidesMember
var script = proxy.Compile(documentInfo, code, cacheKind, ref cacheBytes, out cacheResult);
if (module != null)
{
module.Evaluator = () => proxy.Execute(script, true);
}
return script;
}
private object ExecuteInternal(UniqueDocumentInfo documentInfo, string code, bool evaluate)
{
if (FormatCode)
@ -1090,6 +1276,11 @@ namespace Microsoft.ClearScript.V8
return module.Process();
}
if ((documentInfo.Category != DocumentCategory.Script) && (documentInfo.Category != ModuleCategory.Standard))
{
throw new NotSupportedException("The script engine cannot execute documents of type '" + documentInfo.Category + "'");
}
return ExecuteRaw(documentInfo, code, evaluate);
}
@ -1597,6 +1788,8 @@ namespace Microsoft.ClearScript.V8
CommonJSManager IJavaScriptEngine.CommonJSManager => CommonJSManager;
JsonModuleManager IJavaScriptEngine.JsonModuleManager => JsonModuleManager;
object IJavaScriptEngine.CreatePromiseForTask<T>(Task<T> task)
{
return CreatePromise((resolve, reject) =>

Просмотреть файл

@ -720,6 +720,8 @@ namespace Microsoft.ClearScript.Windows.Core
#region IDebugDocument methods
// inherited methods only
#endregion
void GetDocumentAttributes(

Просмотреть файл

@ -9,6 +9,6 @@ namespace Microsoft.ClearScript.Windows.Core
{
public partial class JScriptEngine
{
internal const string InitScript = "EngineInternal=function(){var t=this;function n(t){var n=[];if(t.GetValue)for(var o=t.Length,e=0;e<o;e++)n.push(t[e]);else for(var o=(t=new VBArray(t)).ubound(1)+1,e=0;e<o;e++)n.push(t.getItem(e));return n}function o(t,n,o,e,u,r,i,f,c,p,s,h,a,l,y,v){return new this(t,n,o,e,u,r,i,f,c,p,s,h,a,l,y,v)}return{getCommandResult:function(t){return null!==t&&('object'==typeof t||'function'==typeof t)&&'function'==typeof t.toString?t.toString():t},invokeConstructor:function(t,e){if('function'!=typeof t)throw Error('Function expected');return o.apply(t,n(e))},invokeMethod:function(t,o,e){if('function'!=typeof o)throw Error('Function expected');return o.apply(t,n(e))},isPromise:function(t){return!1},isHostObject:function(n){return!!n&&'function'!=typeof n.constructor&&n!==t},throwValue:function(t){throw t}}}();";
internal const string InitScript = "EngineInternal=function(){var globalObject=this;function convertArgs(t){var n=[];if(t.GetValue)for(var o=t.Length,e=0;e<o;e++)n.push(t[e]);else for(var o=(t=new VBArray(t)).ubound(1)+1,e=0;e<o;e++)n.push(t.getItem(e));return n}function construct(t,n,o,e,r,u,i,f,c,p,s,a,h,l,y,v){return new this(t,n,o,e,r,u,i,f,c,p,s,a,h,l,y,v)}var savedJSON=globalObject.JSON;return{getCommandResult:function(t){return null!==t&&('object'==typeof t||'function'==typeof t)&&'function'==typeof t.toString?t.toString():t},invokeConstructor:function(t,n){if('function'!=typeof t)throw Error('Function expected');return construct.apply(t,convertArgs(n))},invokeMethod:function(t,n,o){if('function'!=typeof n)throw Error('Function expected');return n.apply(t,convertArgs(o))},isPromise:function(t){return!1},isHostObject:function(t){return!!t&&'function'!=typeof t.constructor&&t!==globalObject},throwValue:function(t){throw t},parseJson:function(json){return savedJSON?savedJSON.parse(json):eval('('+json+')')}}}();";
}
}

Просмотреть файл

@ -27,6 +27,8 @@ EngineInternal = (function () {
return new this(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15);
}
var savedJSON = globalObject.JSON;
return {
getCommandResult: function (value) {
@ -64,6 +66,10 @@ EngineInternal = (function () {
throwValue: function (value) {
throw value;
},
parseJson: function (json) {
return savedJSON ? savedJSON.parse(json) : eval('(' + json + ')');
}
};
})();

Просмотреть файл

@ -97,6 +97,7 @@ namespace Microsoft.ClearScript.Windows.Core
};
private CommonJSManager commonJSManager;
private JsonModuleManager jsonDocumentManager;
#endregion
@ -170,6 +171,8 @@ namespace Microsoft.ClearScript.Windows.Core
internal CommonJSManager CommonJSManager => commonJSManager ?? (commonJSManager = new CommonJSManager(this));
internal JsonModuleManager JsonModuleManager => jsonDocumentManager ?? (jsonDocumentManager = new JsonModuleManager(this));
#endregion
#region ScriptEngine overrides
@ -240,6 +243,8 @@ namespace Microsoft.ClearScript.Windows.Core
CommonJSManager IJavaScriptEngine.CommonJSManager => CommonJSManager;
JsonModuleManager IJavaScriptEngine.JsonModuleManager => JsonModuleManager;
object IJavaScriptEngine.CreatePromiseForTask<T>(Task<T> task)
{
throw new NotImplementedException();

Просмотреть файл

@ -129,6 +129,8 @@ namespace Microsoft.ClearScript.Windows.Core
#region IDebugDocument implementation
// inherited methods only
#endregion
#region IDebugDocumentText implementation

Просмотреть файл

@ -25,6 +25,7 @@ namespace Microsoft.ClearScript.Windows
#region data
private CommonJSManager commonJSManager;
private JsonModuleManager jsonDocumentManager;
#endregion
@ -90,6 +91,8 @@ namespace Microsoft.ClearScript.Windows
internal CommonJSManager CommonJSManager => commonJSManager ?? (commonJSManager = new CommonJSManager(this));
internal JsonModuleManager JsonModuleManager => jsonDocumentManager ?? (jsonDocumentManager = new JsonModuleManager(this));
#endregion
#region ScriptEngine overrides
@ -160,6 +163,8 @@ namespace Microsoft.ClearScript.Windows
CommonJSManager IJavaScriptEngine.CommonJSManager => CommonJSManager;
JsonModuleManager IJavaScriptEngine.JsonModuleManager => JsonModuleManager;
object IJavaScriptEngine.CreatePromiseForTask<T>(Task<T> task)
{
throw new NotImplementedException();

Двоичные данные
ClearScript/doc/Reference.chm

Двоичный файл не отображается.

Просмотреть файл

@ -68,6 +68,7 @@
</configuration>
</PlugInConfig>
</PlugInConfigurations>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
</PropertyGroup>
<!-- There are no properties for these groups. AnyCPU needs to appear in
order for Visual Studio to perform the build. The others are optional

Просмотреть файл

@ -71,6 +71,7 @@
</PlugInConfigurations>
<PostBuildEvent>copy "$(OutputPath)..\favicon.ico" "$(OutputPath)icons"</PostBuildEvent>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
</PropertyGroup>
<!-- There are no properties for these groups. AnyCPU needs to appear in
order for Visual Studio to perform the build. The others are optional

Просмотреть файл

@ -11,6 +11,6 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("(c) Microsoft Corporation")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("7.4.2")]
[assembly: AssemblyFileVersion("7.4.2")]
[assembly: AssemblyInformationalVersion("7.4.2")]
[assembly: AssemblyVersion("7.4.3")]
[assembly: AssemblyFileVersion("7.4.3")]
[assembly: AssemblyInformationalVersion("7.4.3")]

Просмотреть файл

@ -11,6 +11,6 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("(c) Microsoft Corporation")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("7.4.2")]
[assembly: AssemblyFileVersion("7.4.2")]
[assembly: AssemblyInformationalVersion("7.4.2")]
[assembly: AssemblyVersion("7.4.3")]
[assembly: AssemblyFileVersion("7.4.3")]
[assembly: AssemblyInformationalVersion("7.4.3")]

Просмотреть файл

@ -1,6 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using Microsoft.ClearScript.Util;
using Microsoft.ClearScript.V8;
using Microsoft.CSharp.RuntimeBinder;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
@ -17,11 +22,6 @@ using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.ClearScript.V8;
using Microsoft.ClearScript.Util;
using Microsoft.CSharp.RuntimeBinder;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
namespace Microsoft.ClearScript.Test
{
@ -1753,6 +1753,46 @@ namespace Microsoft.ClearScript.Test
engine.Execute("Array.from(test.Values)");
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_V8HostPropertyEnumeration()
{
var foo = new PropertyBag { { "foo", 123 }, { "bar", "baz" } };
engine.Script.foo = foo;
engine.Execute(@"
var keys = [];
for (let key in foo) {
keys.push(key);
}
");
Assert.AreEqual(foo.Keys.Count, engine.Script.keys.length);
Assert.IsTrue(foo.Keys.All(key => engine.Script.keys.includes(key)));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_AnonymousTypeMemberEnumeration()
{
var foo = new { foo = 123, bar = "baz" };
((V8ScriptEngine)engine).SuppressInstanceMethodEnumeration = true;
Assert.AreEqual(2, engine.Script.Object.keys(foo).length);
Assert.IsTrue(new[] { "foo", "bar" }.All(key => engine.Script.Object.keys(foo).includes(key)));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_AnonymousTypeMemberEnumeration_VB()
{
TestUtil.InvokeVBTestSub(@"
Using engine As New V8ScriptEngine
engine.Script.foo = New With {.foo = 123, .bar = ""baz""}
engine.SuppressInstanceMethodEnumeration = True
Assert.AreEqual(2, engine.Evaluate(""Object.keys(foo).length""))
Assert.IsTrue((New String() {""foo"", ""bar""}).All(Function (key) engine.Evaluate(""Object.keys(foo).includes('"" & key & ""')"")))
End Using
");
}
#if NET6_0_OR_GREATER
[TestMethod, TestCategory("BugFix")]

Просмотреть файл

@ -1,10 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.ClearScript.JavaScript;
using Microsoft.ClearScript.Windows.Core;
@ -314,6 +315,128 @@ namespace Microsoft.ClearScript.Test
"));
}
[TestMethod, TestCategory("JScriptCoreModule")]
public void JScriptCoreModule_CommonJS_Json_Object()
{
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
var result = (ScriptObject)engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('JavaScript/Object.json')");
Assert.AreEqual(2, result.PropertyNames.Count());
Assert.AreEqual(123, result.GetProperty("foo"));
Assert.AreEqual("baz", result.GetProperty("bar"));
engine.DocumentSettings.AddSystemDocument("ObjectWithFunction.json", DocumentCategory.Json, "{ \"foo\": 123, \"bar\": \"baz\", \"qux\": function(){} }");
result = (ScriptObject)engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('ObjectWithFunction.json')");
Assert.AreEqual(3, result.PropertyNames.Count());
Assert.AreEqual(123, result.GetProperty("foo"));
Assert.AreEqual("baz", result.GetProperty("bar"));
engine.Dispose();
engine = new JScriptEngine(Windows.WindowsScriptEngineFlags.EnableDebugging | Windows.WindowsScriptEngineFlags.EnableStandardsMode, NullSyncInvoker.Instance);
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
result = (ScriptObject)engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('JavaScript/Object.json')");
Assert.AreEqual(2, result.PropertyNames.Count());
Assert.AreEqual(123, result.GetProperty("foo"));
Assert.AreEqual("baz", result.GetProperty("bar"));
engine.DocumentSettings.AddSystemDocument("ObjectWithFunction.json", DocumentCategory.Json, "{ \"foo\": 123, \"bar\": \"baz\", \"qux\": function(){} }");
TestUtil.AssertException<ScriptEngineException>(() => engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('ObjectWithFunction.json')"));
}
[TestMethod, TestCategory("JScriptCoreModule")]
public void JScriptCoreModule_CommonJS_Json_Array()
{
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
var result = (ScriptObject)engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('JavaScript/Array.json')");
Assert.AreEqual(4, result.PropertyIndices.Count());
Assert.AreEqual(123, result.GetProperty(0));
Assert.AreEqual("foo", result.GetProperty(1));
Assert.AreEqual(4.56, result.GetProperty(2));
Assert.AreEqual("bar", result.GetProperty(3));
engine.DocumentSettings.AddSystemDocument("ArrayWithFunction.json", DocumentCategory.Json, "[ 123, \"foo\", 4.56, \"bar\", function(){} ]");
result = (ScriptObject)engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('ArrayWithFunction.json')");
Assert.AreEqual(5, result.PropertyIndices.Count());
Assert.AreEqual(123, result.GetProperty(0));
Assert.AreEqual("foo", result.GetProperty(1));
Assert.AreEqual(4.56, result.GetProperty(2));
Assert.AreEqual("bar", result.GetProperty(3));
engine.Dispose();
engine = new JScriptEngine(Windows.WindowsScriptEngineFlags.EnableDebugging | Windows.WindowsScriptEngineFlags.EnableStandardsMode, NullSyncInvoker.Instance);
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
result = (ScriptObject)engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('JavaScript/Array.json')");
Assert.AreEqual(4, result.PropertyIndices.Count());
Assert.AreEqual(123, result.GetProperty(0));
Assert.AreEqual("foo", result.GetProperty(1));
Assert.AreEqual(4.56, result.GetProperty(2));
Assert.AreEqual("bar", result.GetProperty(3));
engine.DocumentSettings.AddSystemDocument("ArrayWithFunction.json", DocumentCategory.Json, "[ 123, \"foo\", 4.56, \"bar\", function(){} ]");
TestUtil.AssertException<ScriptEngineException>(() => engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('ArrayWithFunction.json')"));
}
[TestMethod, TestCategory("JScriptCoreModule")]
public void JScriptCoreModule_CommonJS_Json_Malformed()
{
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
// ReSharper disable once AccessToDisposedClosure
TestUtil.AssertException<ScriptEngineException>(() => engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('JavaScript/Malformed.json')"));
engine.Dispose();
engine = new JScriptEngine(Windows.WindowsScriptEngineFlags.EnableDebugging | Windows.WindowsScriptEngineFlags.EnableStandardsMode, NullSyncInvoker.Instance);
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
TestUtil.AssertException<ScriptEngineException>(() => engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('JavaScript/Malformed.json')"));
}
// ReSharper restore InconsistentNaming
#endregion

Просмотреть файл

@ -1,10 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.ClearScript.JavaScript;
using Microsoft.ClearScript.Windows;
@ -314,6 +315,128 @@ namespace Microsoft.ClearScript.Test
"));
}
[TestMethod, TestCategory("JScriptModule")]
public void JScriptModule_CommonJS_Json_Object()
{
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
var result = (ScriptObject)engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('JavaScript/Object.json')");
Assert.AreEqual(2, result.PropertyNames.Count());
Assert.AreEqual(123, result.GetProperty("foo"));
Assert.AreEqual("baz", result.GetProperty("bar"));
engine.DocumentSettings.AddSystemDocument("ObjectWithFunction.json", DocumentCategory.Json, "{ \"foo\": 123, \"bar\": \"baz\", \"qux\": function(){} }");
result = (ScriptObject)engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('ObjectWithFunction.json')");
Assert.AreEqual(3, result.PropertyNames.Count());
Assert.AreEqual(123, result.GetProperty("foo"));
Assert.AreEqual("baz", result.GetProperty("bar"));
engine.Dispose();
engine = new JScriptEngine(WindowsScriptEngineFlags.EnableDebugging | WindowsScriptEngineFlags.EnableStandardsMode);
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
result = (ScriptObject)engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('JavaScript/Object.json')");
Assert.AreEqual(2, result.PropertyNames.Count());
Assert.AreEqual(123, result.GetProperty("foo"));
Assert.AreEqual("baz", result.GetProperty("bar"));
engine.DocumentSettings.AddSystemDocument("ObjectWithFunction.json", DocumentCategory.Json, "{ \"foo\": 123, \"bar\": \"baz\", \"qux\": function(){} }");
TestUtil.AssertException<ScriptEngineException>(() => engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('ObjectWithFunction.json')"));
}
[TestMethod, TestCategory("JScriptModule")]
public void JScriptModule_CommonJS_Json_Array()
{
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
var result = (ScriptObject)engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('JavaScript/Array.json')");
Assert.AreEqual(4, result.PropertyIndices.Count());
Assert.AreEqual(123, result.GetProperty(0));
Assert.AreEqual("foo", result.GetProperty(1));
Assert.AreEqual(4.56, result.GetProperty(2));
Assert.AreEqual("bar", result.GetProperty(3));
engine.DocumentSettings.AddSystemDocument("ArrayWithFunction.json", DocumentCategory.Json, "[ 123, \"foo\", 4.56, \"bar\", function(){} ]");
result = (ScriptObject)engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('ArrayWithFunction.json')");
Assert.AreEqual(5, result.PropertyIndices.Count());
Assert.AreEqual(123, result.GetProperty(0));
Assert.AreEqual("foo", result.GetProperty(1));
Assert.AreEqual(4.56, result.GetProperty(2));
Assert.AreEqual("bar", result.GetProperty(3));
engine.Dispose();
engine = new JScriptEngine(WindowsScriptEngineFlags.EnableDebugging | WindowsScriptEngineFlags.EnableStandardsMode);
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
result = (ScriptObject)engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('JavaScript/Array.json')");
Assert.AreEqual(4, result.PropertyIndices.Count());
Assert.AreEqual(123, result.GetProperty(0));
Assert.AreEqual("foo", result.GetProperty(1));
Assert.AreEqual(4.56, result.GetProperty(2));
Assert.AreEqual("bar", result.GetProperty(3));
engine.DocumentSettings.AddSystemDocument("ArrayWithFunction.json", DocumentCategory.Json, "[ 123, \"foo\", 4.56, \"bar\", function(){} ]");
TestUtil.AssertException<ScriptEngineException>(() => engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('ArrayWithFunction.json')"));
}
[TestMethod, TestCategory("JScriptModule")]
public void JScriptModule_CommonJS_Json_Malformed()
{
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
// ReSharper disable once AccessToDisposedClosure
TestUtil.AssertException<ScriptEngineException>(() => engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('JavaScript/Malformed.json')"));
engine.Dispose();
engine = new JScriptEngine(WindowsScriptEngineFlags.EnableDebugging | WindowsScriptEngineFlags.EnableStandardsMode);
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
TestUtil.AssertException<ScriptEngineException>(() => engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('JavaScript/Malformed.json')"));
}
// ReSharper restore InconsistentNaming
#endregion

Просмотреть файл

@ -0,0 +1 @@
[ 123, "foo", 4.56, "bar" ]

Просмотреть файл

@ -0,0 +1 @@
This is not JSON!

Просмотреть файл

@ -0,0 +1 @@
{ "foo": 123, "bar": "baz" }

Просмотреть файл

@ -11,6 +11,6 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("(c) Microsoft Corporation")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("7.4.2")]
[assembly: AssemblyFileVersion("7.4.2")]
[assembly: AssemblyInformationalVersion("7.4.2")]
[assembly: AssemblyVersion("7.4.3")]
[assembly: AssemblyFileVersion("7.4.3")]
[assembly: AssemblyInformationalVersion("7.4.3")]

Просмотреть файл

@ -844,6 +844,68 @@ namespace Microsoft.ClearScript.Test
Assert.AreEqual(engine.Script.Rectangle2, engine.Script.Rectangle3);
}
[TestMethod, TestCategory("V8Module")]
public void V8Module_Standard_Json_Object()
{
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
engine.Execute(new DocumentInfo { Category = ModuleCategory.Standard }, "import result from 'JavaScript/Object.json'; globalThis.result = result;");
var result = (ScriptObject)engine.Global.GetProperty("result");
Assert.AreEqual(2, result.PropertyNames.Count());
Assert.AreEqual(123, result.GetProperty("foo"));
Assert.AreEqual("baz", result.GetProperty("bar"));
engine.DocumentSettings.AddSystemDocument("ObjectWithFunction.json", DocumentCategory.Json, "{ \"foo\": 123, \"bar\": \"baz\", \"qux\": function(){} }");
TestUtil.AssertException<ScriptEngineException>(() => engine.Execute(new DocumentInfo { Category = ModuleCategory.Standard }, "import result from 'ObjectWithFunction.json'; globalThis.result = result;"));
}
[TestMethod, TestCategory("V8Module")]
public void V8Module_Standard_Json_Array()
{
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
engine.Execute(new DocumentInfo { Category = ModuleCategory.Standard }, "import result from 'JavaScript/Array.json'; globalThis.result = result;");
var result = (ScriptObject)engine.Global.GetProperty("result");
Assert.AreEqual(4, result.PropertyIndices.Count());
Assert.AreEqual(123, result.GetProperty(0));
Assert.AreEqual("foo", result.GetProperty(1));
Assert.AreEqual(4.56, result.GetProperty(2));
Assert.AreEqual("bar", result.GetProperty(3));
engine.DocumentSettings.AddSystemDocument("ArrayWithFunction.json", DocumentCategory.Json, "[ 123, \"foo\", 4.56, \"bar\", function(){} ]");
TestUtil.AssertException<ScriptEngineException>(() => engine.Execute(new DocumentInfo { Category = ModuleCategory.Standard }, "import result from 'ArrayWithFunction.json'; globalThis.result = result;"));
}
[TestMethod, TestCategory("V8Module")]
public void V8Module_Standard_Json_Malformed()
{
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
// ReSharper disable once AccessToDisposedClosure
TestUtil.AssertException<ScriptEngineException>(() => engine.Execute(new DocumentInfo { Category = ModuleCategory.Standard }, "import result from 'JavaScript/Malformed.json'; globalThis.result = result;"));
}
[TestMethod, TestCategory("V8Module")]
public void V8Module_CommonJS_File()
{
@ -1291,6 +1353,67 @@ namespace Microsoft.ClearScript.Test
"));
}
[TestMethod, TestCategory("V8Module")]
public void V8Module_CommonJS_Json_Object()
{
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
var result = (ScriptObject)engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('JavaScript/Object.json')");
Assert.AreEqual(2, result.PropertyNames.Count());
Assert.AreEqual(123, result.GetProperty("foo"));
Assert.AreEqual("baz", result.GetProperty("bar"));
engine.DocumentSettings.AddSystemDocument("ObjectWithFunction.json", DocumentCategory.Json, "{ \"foo\": 123, \"bar\": \"baz\", \"qux\": function(){} }");
TestUtil.AssertException<ScriptEngineException>(() => engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('ObjectWithFunction.json')"));
}
[TestMethod, TestCategory("V8Module")]
public void V8Module_CommonJS_Json_Array()
{
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
var result = (ScriptObject)engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('JavaScript/Array.json')");
Assert.AreEqual(4, result.PropertyIndices.Count());
Assert.AreEqual(123, result.GetProperty(0));
Assert.AreEqual("foo", result.GetProperty(1));
Assert.AreEqual(4.56, result.GetProperty(2));
Assert.AreEqual("bar", result.GetProperty(3));
engine.DocumentSettings.AddSystemDocument("ArrayWithFunction.json", DocumentCategory.Json, "[ 123, \"foo\", 4.56, \"bar\", function(){} ]");
TestUtil.AssertException<ScriptEngineException>(() => engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('ArrayWithFunction.json')"));
}
[TestMethod, TestCategory("V8Module")]
public void V8Module_CommonJS_Json_Malformed()
{
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading | DocumentAccessFlags.AllowCategoryMismatch;
engine.DocumentSettings.LoadCallback = (ref DocumentInfo info) =>
{
if (Path.GetExtension(info.Uri.AbsolutePath).Equals(".json", StringComparison.OrdinalIgnoreCase))
{
info.Category = DocumentCategory.Json;
}
};
// ReSharper disable once AccessToDisposedClosure
TestUtil.AssertException<ScriptEngineException>(() => engine.Evaluate(new DocumentInfo { Category = ModuleCategory.CommonJS }, "return require('JavaScript/Malformed.json')"));
}
#endregion
#region miscellaneous

Просмотреть файл

@ -4648,6 +4648,524 @@ namespace Microsoft.ClearScript.Test
Assert.IsTrue(c.All(value => ((ConstructorBindingTest)value).A == 789));
}
[TestMethod, TestCategory("V8ScriptEngine")]
public void V8ScriptEngine_Compilation_CacheResult()
{
using (var runtime = new V8Runtime())
{
engine.Dispose();
engine = runtime.CreateScriptEngine(); // default engine enables debugging, which disables caching (in older V8 versions)
const string code = "obj = { foo: 123, bar: 'baz', qux: 456.789 }; count = 0; for (let name in obj) count += 1; Math.PI";
var info = new DocumentInfo("foo.js");
byte[] goodCacheBytes;
{
byte[] cacheBytes = null;
var script = engine.Compile(code, V8CacheKind.None, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Disabled, cacheResult);
Assert.IsNull(cacheBytes);
}
{
byte[] cacheBytes = null;
var script = engine.Compile(info, code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
goodCacheBytes = cacheBytes;
}
{
var cacheBytes = ArrayHelpers.GetEmptyArray<byte>();
var script = engine.Compile(code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes;
var script = engine.Compile(code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Accepted, cacheResult);
Assert.AreEqual(goodCacheBytes, cacheBytes);
}
{
var cacheBytes = goodCacheBytes.ToArray();
var script = engine.Compile(code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Accepted, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes.ToArray();
var script = engine.Compile(info, code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Verified, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes.Take(goodCacheBytes.Length - 1).ToArray();
var script = engine.Compile(code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
byte[] cacheBytes = null;
var script = runtime.Compile(code, V8CacheKind.None, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Disabled, cacheResult);
Assert.IsNull(cacheBytes);
}
{
byte[] cacheBytes = null;
var script = runtime.Compile(code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = ArrayHelpers.GetEmptyArray<byte>();
var script = runtime.Compile(code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes;
var script = runtime.Compile(code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Accepted, cacheResult);
Assert.AreEqual(goodCacheBytes, cacheBytes);
}
{
var cacheBytes = goodCacheBytes.ToArray();
var script = runtime.Compile(code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Accepted, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes.ToArray();
var script = runtime.Compile(info, code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Verified, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes.Take(goodCacheBytes.Length - 1).ToArray();
var script = runtime.Compile(code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
}
}
[TestMethod, TestCategory("V8ScriptEngine")]
public void V8ScriptEngine_Compilation_CacheResult_Module()
{
using (var runtime = new V8Runtime())
{
engine.Dispose();
engine = runtime.CreateScriptEngine(); // default engine enables debugging, which disables caching (in older V8 versions)
const string code = "let obj = { foo: 123, bar: 'baz', qux: 456.789 }; let count = 0; for (let name in obj) count += 1; Math.PI";
var info = new DocumentInfo("foo.js") { Category = ModuleCategory.Standard };
byte[] goodCacheBytes;
{
byte[] cacheBytes = null;
var script = engine.Compile(new DocumentInfo { Category = ModuleCategory.Standard }, code, V8CacheKind.None, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Disabled, cacheResult);
Assert.IsNull(cacheBytes);
}
{
byte[] cacheBytes = null;
var script = engine.Compile(info, code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
goodCacheBytes = cacheBytes;
}
{
var cacheBytes = ArrayHelpers.GetEmptyArray<byte>();
var script = engine.Compile(new DocumentInfo { Category = ModuleCategory.Standard }, code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes;
var script = engine.Compile(new DocumentInfo { Category = ModuleCategory.Standard }, code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Accepted, cacheResult);
Assert.AreEqual(goodCacheBytes, cacheBytes);
}
{
var cacheBytes = goodCacheBytes.ToArray();
var script = engine.Compile(new DocumentInfo { Category = ModuleCategory.Standard }, code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Accepted, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes.ToArray();
var script = engine.Compile(info, code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.IsInstanceOfType(engine.Evaluate(script), typeof(Undefined));
Assert.AreEqual(V8CacheResult.Verified, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes.Take(goodCacheBytes.Length - 1).ToArray();
var script = engine.Compile(new DocumentInfo { Category = ModuleCategory.Standard }, code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
byte[] cacheBytes = null;
var script = runtime.Compile(new DocumentInfo { Category = ModuleCategory.Standard }, code, V8CacheKind.None, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Disabled, cacheResult);
Assert.IsNull(cacheBytes);
}
{
byte[] cacheBytes = null;
var script = runtime.Compile(new DocumentInfo { Category = ModuleCategory.Standard }, code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = ArrayHelpers.GetEmptyArray<byte>();
var script = runtime.Compile(new DocumentInfo { Category = ModuleCategory.Standard }, code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes;
var script = runtime.Compile(new DocumentInfo { Category = ModuleCategory.Standard }, code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Accepted, cacheResult);
Assert.AreEqual(goodCacheBytes, cacheBytes);
}
{
var cacheBytes = goodCacheBytes.ToArray();
var script = runtime.Compile(new DocumentInfo { Category = ModuleCategory.Standard }, code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Accepted, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes.ToArray();
var script = runtime.Compile(info, code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.IsInstanceOfType(engine.Evaluate(script), typeof(Undefined));
Assert.AreEqual(V8CacheResult.Verified, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes.Take(goodCacheBytes.Length - 1).ToArray();
var script = runtime.Compile(new DocumentInfo { Category = ModuleCategory.Standard }, code, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
}
}
[TestMethod, TestCategory("V8ScriptEngine")]
public void V8ScriptEngine_DocumentCompilation_CacheResult()
{
using (var runtime = new V8Runtime())
{
engine.Dispose();
engine = runtime.CreateScriptEngine(); // default engine enables debugging, which disables caching (in older V8 versions)
const string code = "obj = { foo: 123, bar: 'baz', qux: 456.789 }; count = 0; for (let name in obj) count += 1; Math.PI";
byte[] goodCacheBytes;
runtime.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading;
runtime.DocumentSettings.AddSystemDocument("foo.js", code);
engine.DocumentSettings = runtime.DocumentSettings;
{
byte[] cacheBytes = null;
var script = engine.CompileDocument("foo.js", V8CacheKind.None, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Disabled, cacheResult);
Assert.IsNull(cacheBytes);
}
{
byte[] cacheBytes = null;
var script = engine.CompileDocument("foo.js", V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
goodCacheBytes = cacheBytes;
}
{
var cacheBytes = ArrayHelpers.GetEmptyArray<byte>();
var script = engine.CompileDocument("foo.js", V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes;
var script = engine.CompileDocument("foo.js", V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Verified, cacheResult);
Assert.AreEqual(goodCacheBytes, cacheBytes);
}
{
var cacheBytes = goodCacheBytes.ToArray();
var script = engine.CompileDocument("foo.js", V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Verified, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes.Take(goodCacheBytes.Length - 1).ToArray();
var script = engine.CompileDocument("foo.js", V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
byte[] cacheBytes = null;
var script = runtime.CompileDocument("foo.js", V8CacheKind.None, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Disabled, cacheResult);
Assert.IsNull(cacheBytes);
}
{
byte[] cacheBytes = null;
var script = runtime.CompileDocument("foo.js", V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = ArrayHelpers.GetEmptyArray<byte>();
var script = runtime.CompileDocument("foo.js", V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes;
var script = runtime.CompileDocument("foo.js", V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Verified, cacheResult);
Assert.AreEqual(goodCacheBytes, cacheBytes);
}
{
var cacheBytes = goodCacheBytes.ToArray();
var script = runtime.CompileDocument("foo.js", V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Verified, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes.Take(goodCacheBytes.Length - 1).ToArray();
var script = runtime.CompileDocument("foo.js", V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
}
}
[TestMethod, TestCategory("V8ScriptEngine")]
public void V8ScriptEngine_DocumentCompilation_CacheResult_Module()
{
using (var runtime = new V8Runtime())
{
engine.Dispose();
engine = runtime.CreateScriptEngine(); // default engine enables debugging, which disables caching (in older V8 versions)
const string code = "let obj = { foo: 123, bar: 'baz', qux: 456.789 }; let count = 0; for (let name in obj) count += 1; Math.PI";
byte[] goodCacheBytes;
runtime.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading;
runtime.DocumentSettings.AddSystemDocument("foo.js", ModuleCategory.Standard, code);
engine.DocumentSettings = runtime.DocumentSettings;
{
byte[] cacheBytes = null;
var script = engine.CompileDocument("foo.js", ModuleCategory.Standard, V8CacheKind.None, ref cacheBytes, out var cacheResult);
Assert.AreEqual(Math.PI, engine.Evaluate(script));
Assert.AreEqual(V8CacheResult.Disabled, cacheResult);
Assert.IsNull(cacheBytes);
}
{
byte[] cacheBytes = null;
var script = engine.CompileDocument("foo.js", ModuleCategory.Standard, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.IsInstanceOfType(engine.Evaluate(script), typeof(Undefined));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
goodCacheBytes = cacheBytes;
}
{
var cacheBytes = ArrayHelpers.GetEmptyArray<byte>();
var script = engine.CompileDocument("foo.js", ModuleCategory.Standard, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.IsInstanceOfType(engine.Evaluate(script), typeof(Undefined));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes;
var script = engine.CompileDocument("foo.js", ModuleCategory.Standard, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.IsInstanceOfType(engine.Evaluate(script), typeof(Undefined));
Assert.AreEqual(V8CacheResult.Verified, cacheResult);
Assert.AreEqual(goodCacheBytes, cacheBytes);
}
{
var cacheBytes = goodCacheBytes.ToArray();
var script = engine.CompileDocument("foo.js", ModuleCategory.Standard, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.IsInstanceOfType(engine.Evaluate(script), typeof(Undefined));
Assert.AreEqual(V8CacheResult.Verified, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes.Take(goodCacheBytes.Length - 1).ToArray();
var script = engine.CompileDocument("foo.js", ModuleCategory.Standard, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.IsInstanceOfType(engine.Evaluate(script), typeof(Undefined));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
byte[] cacheBytes = null;
var script = runtime.CompileDocument("foo.js", ModuleCategory.Standard, V8CacheKind.None, ref cacheBytes, out var cacheResult);
Assert.IsInstanceOfType(engine.Evaluate(script), typeof(Undefined));
Assert.AreEqual(V8CacheResult.Disabled, cacheResult);
Assert.IsNull(cacheBytes);
}
{
byte[] cacheBytes = null;
var script = runtime.CompileDocument("foo.js", ModuleCategory.Standard, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.IsInstanceOfType(engine.Evaluate(script), typeof(Undefined));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = ArrayHelpers.GetEmptyArray<byte>();
var script = runtime.CompileDocument("foo.js", ModuleCategory.Standard, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.IsInstanceOfType(engine.Evaluate(script), typeof(Undefined));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes;
var script = runtime.CompileDocument("foo.js", ModuleCategory.Standard, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.IsInstanceOfType(engine.Evaluate(script), typeof(Undefined));
Assert.AreEqual(V8CacheResult.Verified, cacheResult);
Assert.AreEqual(goodCacheBytes, cacheBytes);
}
{
var cacheBytes = goodCacheBytes.ToArray();
var script = runtime.CompileDocument("foo.js", ModuleCategory.Standard, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.IsInstanceOfType(engine.Evaluate(script), typeof(Undefined));
Assert.AreEqual(V8CacheResult.Verified, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
{
var cacheBytes = goodCacheBytes.Take(goodCacheBytes.Length - 1).ToArray();
var script = runtime.CompileDocument("foo.js", ModuleCategory.Standard, V8CacheKind.Code, ref cacheBytes, out var cacheResult);
Assert.IsInstanceOfType(engine.Evaluate(script), typeof(Undefined));
Assert.AreEqual(V8CacheResult.Updated, cacheResult);
Assert.IsNotNull(cacheBytes);
Assert.IsTrue(cacheBytes.Length > 0);
}
}
}
// ReSharper restore InconsistentNaming
#endregion

Просмотреть файл

@ -19,7 +19,7 @@
#include "V8ScriptHolder.h"
#include "HostException.h"
#include "V8Exception.h"
#include "V8CacheType.h"
#include "V8CacheTypes.h"
#include "V8GlobalFlags.h"
#include "IV8Entity.h"
#include "V8Isolate.h"

Просмотреть файл

@ -230,12 +230,12 @@ public:
StdString resourceName;
StdString sourceMapUrl;
uint64_t uniqueId;
StdBool isModule;
DocumentKind documentKind;
StdString code;
void* pvDocumentInfo;
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID(LoadModule, sourceDocumentInfo.GetDocumentInfo(), specifier, resourceName, sourceMapUrl, uniqueId, isModule, code, pvDocumentInfo, exports);
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID(LoadModule, sourceDocumentInfo.GetDocumentInfo(), specifier, resourceName, sourceMapUrl, uniqueId, documentKind, code, pvDocumentInfo, exports);
documentInfo = V8DocumentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, isModule, pvDocumentInfo);
documentInfo = V8DocumentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo);
return code;
}

Просмотреть файл

@ -1,16 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#pragma once
//-----------------------------------------------------------------------------
// V8CacheType
//-----------------------------------------------------------------------------
enum class V8CacheType: int32_t
{
// IMPORTANT: maintain bitwise equivalence with managed enum V8.V8CacheKind
None,
Parser,
Code
};

Просмотреть файл

@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#pragma once
//-----------------------------------------------------------------------------
// V8CacheKind
//-----------------------------------------------------------------------------
enum class V8CacheKind: int32_t
{
// IMPORTANT: maintain bitwise equivalence with managed enum V8.V8CacheKind
None,
Parser,
Code
};
//-----------------------------------------------------------------------------
// V8CacheResult
//-----------------------------------------------------------------------------
enum class V8CacheResult : int32_t
{
// IMPORTANT: maintain bitwise equivalence with managed enum V8.V8CacheResult
Disabled,
Accepted,
Verified,
Updated,
UpdateFailed
};

Просмотреть файл

@ -64,9 +64,12 @@ public:
virtual void CancelAwaitDebugger() = 0;
virtual V8Value Execute(const V8DocumentInfo& documentInfo, const StdString& code, bool evaluate) = 0;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code) = 0;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheType cacheType, std::vector<uint8_t>& cacheBytes) = 0;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheType cacheType, const std::vector<uint8_t>& cacheBytes, bool& cacheAccepted) = 0;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes) = 0;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, const std::vector<uint8_t>& cacheBytes, bool& cacheAccepted) = 0;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes, V8CacheResult& cacheResult) = 0;
virtual bool CanExecute(const SharedPtr<V8ScriptHolder>& spHolder) = 0;
virtual V8Value Execute(const SharedPtr<V8ScriptHolder>& spHolder, bool evaluate) = 0;

Просмотреть файл

@ -304,7 +304,7 @@ V8ContextImpl::V8ContextImpl(SharedPtr<V8IsolateImpl>&& spIsolateImpl, const Std
m_hHostObjectTemplate->InstanceTemplate()->SetHandler(v8::IndexedPropertyHandlerConfiguration(GetHostObjectProperty, SetHostObjectProperty, QueryHostObjectProperty, DeleteHostObjectProperty, GetHostObjectPropertyIndices, hContextImpl));
m_hHostObjectTemplate->PrototypeTemplate()->Set(GetIteratorSymbol(), hGetIteratorFunction);
m_hHostObjectTemplate->PrototypeTemplate()->Set(GetAsyncIteratorSymbol(), hGetAsyncIteratorFunction);
m_hHostObjectTemplate->PrototypeTemplate()->Set(hToJSON, hGetJsonFunction);
m_hHostObjectTemplate->PrototypeTemplate()->Set(hToJSON, hGetJsonFunction, CombineFlags(v8::ReadOnly, v8::DontDelete, v8::DontEnum));
m_hHostInvocableTemplate = CreatePersistent(CreateFunctionTemplate());
m_hHostInvocableTemplate->SetClassName(CreateString("HostInvocable"));
@ -313,7 +313,7 @@ V8ContextImpl::V8ContextImpl(SharedPtr<V8IsolateImpl>&& spIsolateImpl, const Std
m_hHostInvocableTemplate->InstanceTemplate()->SetHandler(v8::IndexedPropertyHandlerConfiguration(GetHostObjectProperty, SetHostObjectProperty, QueryHostObjectProperty, DeleteHostObjectProperty, GetHostObjectPropertyIndices, hContextImpl));
m_hHostInvocableTemplate->PrototypeTemplate()->Set(GetIteratorSymbol(), hGetIteratorFunction);
m_hHostInvocableTemplate->PrototypeTemplate()->Set(GetAsyncIteratorSymbol(), hGetAsyncIteratorFunction);
m_hHostInvocableTemplate->PrototypeTemplate()->Set(hToJSON, hGetJsonFunction);
m_hHostInvocableTemplate->PrototypeTemplate()->Set(hToJSON, hGetJsonFunction, CombineFlags(v8::ReadOnly, v8::DontDelete, v8::DontEnum));
m_hHostInvocableTemplate->InstanceTemplate()->SetCallAsFunctionHandler(InvokeHostObject, hContextImpl);
m_hHostDelegateTemplate = CreatePersistent(CreateFunctionTemplate());
@ -323,7 +323,7 @@ V8ContextImpl::V8ContextImpl(SharedPtr<V8IsolateImpl>&& spIsolateImpl, const Std
m_hHostDelegateTemplate->InstanceTemplate()->SetHandler(v8::IndexedPropertyHandlerConfiguration(GetHostObjectProperty, SetHostObjectProperty, QueryHostObjectProperty, DeleteHostObjectProperty, GetHostObjectPropertyIndices, hContextImpl));
m_hHostDelegateTemplate->PrototypeTemplate()->Set(GetIteratorSymbol(), hGetIteratorFunction);
m_hHostDelegateTemplate->PrototypeTemplate()->Set(GetAsyncIteratorSymbol(), hGetAsyncIteratorFunction);
m_hHostDelegateTemplate->PrototypeTemplate()->Set(hToJSON, hGetJsonFunction);
m_hHostDelegateTemplate->PrototypeTemplate()->Set(hToJSON, hGetJsonFunction, CombineFlags(v8::ReadOnly, v8::DontDelete, v8::DontEnum));
m_hHostDelegateTemplate->InstanceTemplate()->SetCallAsFunctionHandler(InvokeHostObject, hContextImpl);
m_hHostDelegateTemplate->InstanceTemplate()->SetHostDelegate(); // instructs our patched V8 typeof implementation to return "function"
m_hHostDelegateTemplate->PrototypeTemplate()->Set(CreateString("toFunction"), hToFunctionFunction);
@ -628,9 +628,9 @@ V8ScriptHolder* V8ContextImpl::Compile(const V8DocumentInfo& documentInfo, StdSt
//-----------------------------------------------------------------------------
V8ScriptHolder* V8ContextImpl::Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheType cacheType, std::vector<uint8_t>& cacheBytes)
V8ScriptHolder* V8ContextImpl::Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes)
{
if (cacheType == V8CacheType::None)
if (cacheKind == V8CacheKind::None)
{
cacheBytes.clear();
return Compile(documentInfo, std::move(code));
@ -644,11 +644,10 @@ V8ScriptHolder* V8ContextImpl::Compile(const V8DocumentInfo& documentInfo, StdSt
auto codeDigest = code.GetDigest();
v8::ScriptCompiler::Source source(FROM_MAYBE(CreateString(code)), CreateScriptOrigin(documentInfo));
std::unique_ptr<V8ScriptHolder> upScriptHolder;
std::unique_ptr<v8::ScriptCompiler::CachedData> upCachedData;
if (documentInfo.IsModule())
{
auto hModule = GetCachedModule(documentInfo.GetUniqueId(), codeDigest);
auto hModule = GetCachedModule(documentInfo.GetUniqueId(), codeDigest, cacheBytes);
if (hModule.IsEmpty())
{
hModule = VERIFY_MAYBE(CompileModule(&source));
@ -657,15 +656,31 @@ V8ScriptHolder* V8ContextImpl::Compile(const V8DocumentInfo& documentInfo, StdSt
throw V8Exception(V8Exception::Type::General, m_Name, StdString(SL("Module compilation failed; no additional information was provided by the V8 runtime")), false /*executionStarted*/);
}
CacheModule(documentInfo, codeDigest, hModule);
std::unique_ptr<v8::ScriptCompiler::CachedData> upCachedData(v8::ScriptCompiler::CreateCodeCache(hModule->GetUnboundModuleScript()));
if (upCachedData && (upCachedData->length > 0) && (upCachedData->data != nullptr))
{
cacheBytes.resize(upCachedData->length);
memcpy(cacheBytes.data(), upCachedData->data, upCachedData->length);
}
CacheModule(documentInfo, codeDigest, hModule, cacheBytes);
}
else if (cacheBytes.empty())
{
std::unique_ptr<v8::ScriptCompiler::CachedData> upCachedData(v8::ScriptCompiler::CreateCodeCache(hModule->GetUnboundModuleScript()));
if (upCachedData && (upCachedData->length > 0) && (upCachedData->data != nullptr))
{
cacheBytes.resize(upCachedData->length);
memcpy(cacheBytes.data(), upCachedData->data, upCachedData->length);
SetCachedModuleCacheBytes(documentInfo.GetUniqueId(), codeDigest, cacheBytes);
}
}
upScriptHolder.reset(new V8ScriptHolderImpl(GetWeakBinding(), ::PtrFromHandle(CreatePersistent(hModule)), documentInfo, codeDigest, std::move(code)));
upCachedData.reset(v8::ScriptCompiler::CreateCodeCache(hModule->GetUnboundModuleScript()));
}
else
{
auto hScript = GetCachedScript(documentInfo.GetUniqueId(), codeDigest);
auto hScript = GetCachedScript(documentInfo.GetUniqueId(), codeDigest, cacheBytes);
if (hScript.IsEmpty())
{
hScript = VERIFY_MAYBE(CompileUnboundScript(&source));
@ -674,23 +689,32 @@ V8ScriptHolder* V8ContextImpl::Compile(const V8DocumentInfo& documentInfo, StdSt
throw V8Exception(V8Exception::Type::General, m_Name, StdString(SL("Script compilation failed; no additional information was provided by the V8 runtime")), false /*executionStarted*/);
}
CacheScript(documentInfo, codeDigest, hScript);
std::unique_ptr<v8::ScriptCompiler::CachedData> upCachedData(v8::ScriptCompiler::CreateCodeCache(hScript));
if (upCachedData && (upCachedData->length > 0) && (upCachedData->data != nullptr))
{
cacheBytes.resize(upCachedData->length);
memcpy(cacheBytes.data(), upCachedData->data, upCachedData->length);
}
CacheScript(documentInfo, codeDigest, hScript, cacheBytes);
}
else if (cacheBytes.empty())
{
std::unique_ptr<v8::ScriptCompiler::CachedData> upCachedData(v8::ScriptCompiler::CreateCodeCache(hScript));
if (upCachedData && (upCachedData->length > 0) && (upCachedData->data != nullptr))
{
cacheBytes.resize(upCachedData->length);
memcpy(cacheBytes.data(), upCachedData->data, upCachedData->length);
SetCachedScriptCacheBytes(documentInfo.GetUniqueId(), codeDigest, cacheBytes);
}
}
upScriptHolder.reset(new V8ScriptHolderImpl(GetWeakBinding(), ::PtrFromHandle(CreatePersistent(hScript)), documentInfo, codeDigest));
upCachedData.reset(v8::ScriptCompiler::CreateCodeCache(hScript));
}
cacheBytes.clear();
if (upCachedData && (upCachedData->length > 0) && (upCachedData->data != nullptr))
if (!cacheBytes.empty() && documentInfo.IsModule())
{
cacheBytes.resize(upCachedData->length);
memcpy(cacheBytes.data(), upCachedData->data, upCachedData->length);
if (documentInfo.IsModule())
{
upScriptHolder->SetCacheBytes(cacheBytes);
}
upScriptHolder->SetCacheBytes(cacheBytes);
}
return upScriptHolder.release();
@ -707,11 +731,12 @@ V8ScriptHolder* V8ContextImpl::Compile(const V8DocumentInfo& documentInfo, StdSt
//-----------------------------------------------------------------------------
V8ScriptHolder* V8ContextImpl::Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheType cacheType, const std::vector<uint8_t>& cacheBytes, bool& cacheAccepted)
V8ScriptHolder* V8ContextImpl::Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, const std::vector<uint8_t>& cacheBytes, bool& cacheAccepted)
{
if ((cacheType == V8CacheType::None) || (cacheBytes.size() < 1))
cacheAccepted = false;
if ((cacheKind == V8CacheKind::None) || cacheBytes.empty())
{
cacheAccepted = false;
return Compile(documentInfo, std::move(code));
}
@ -736,7 +761,8 @@ V8ScriptHolder* V8ContextImpl::Compile(const V8DocumentInfo& documentInfo, StdSt
throw V8Exception(V8Exception::Type::General, m_Name, StdString(SL("Module compilation failed; no additional information was provided by the V8 runtime")), false /*executionStarted*/);
}
CacheModule(documentInfo, codeDigest, hModule);
cacheAccepted = !pCachedData->rejected;
CacheModule(documentInfo, codeDigest, hModule, cacheAccepted ? cacheBytes : std::vector<uint8_t>());
}
upScriptHolder.reset(new V8ScriptHolderImpl(GetWeakBinding(), ::PtrFromHandle(CreatePersistent(hModule)), documentInfo, codeDigest, std::move(code)));
@ -752,13 +778,13 @@ V8ScriptHolder* V8ContextImpl::Compile(const V8DocumentInfo& documentInfo, StdSt
throw V8Exception(V8Exception::Type::General, m_Name, StdString(SL("Script compilation failed; no additional information was provided by the V8 runtime")), false /*executionStarted*/);
}
CacheScript(documentInfo, codeDigest, hScript);
cacheAccepted = !pCachedData->rejected;
CacheScript(documentInfo, codeDigest, hScript, cacheAccepted ? cacheBytes : std::vector<uint8_t>());
}
upScriptHolder.reset(new V8ScriptHolderImpl(GetWeakBinding(), ::PtrFromHandle(CreatePersistent(hScript)), documentInfo, codeDigest));
}
cacheAccepted = !pCachedData->rejected;
if (cacheAccepted && documentInfo.IsModule())
{
upScriptHolder->SetCacheBytes(cacheBytes);
@ -778,6 +804,170 @@ V8ScriptHolder* V8ContextImpl::Compile(const V8DocumentInfo& documentInfo, StdSt
//-----------------------------------------------------------------------------
V8ScriptHolder* V8ContextImpl::Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes, V8CacheResult& cacheResult)
{
if (cacheKind == V8CacheKind::None)
{
cacheResult = V8CacheResult::Disabled;
return Compile(documentInfo, std::move(code));
}
if (cacheBytes.empty())
{
auto pScriptHolder = Compile(documentInfo, std::move(code), cacheKind, cacheBytes);
cacheResult = !cacheBytes.empty() ? V8CacheResult::Updated : V8CacheResult::UpdateFailed;
return pScriptHolder;
}
BEGIN_CONTEXT_SCOPE
BEGIN_DOCUMENT_SCOPE(documentInfo)
BEGIN_EXECUTION_SCOPE
FROM_MAYBE_TRY
auto codeDigest = code.GetDigest();
auto pCachedData = new v8::ScriptCompiler::CachedData(cacheBytes.data(), static_cast<int>(cacheBytes.size()), v8::ScriptCompiler::CachedData::BufferNotOwned);
v8::ScriptCompiler::Source source(FROM_MAYBE(CreateString(code)), CreateScriptOrigin(documentInfo), pCachedData);
std::unique_ptr<V8ScriptHolder> upScriptHolder;
std::vector<uint8_t> cachedCacheBytes;
if (documentInfo.IsModule())
{
auto hModule = GetCachedModule(documentInfo.GetUniqueId(), codeDigest, cachedCacheBytes);
if (hModule.IsEmpty())
{
hModule = VERIFY_MAYBE(CompileModule(&source, v8::ScriptCompiler::kConsumeCodeCache));
if (hModule.IsEmpty())
{
throw V8Exception(V8Exception::Type::General, m_Name, StdString(SL("Module compilation failed; no additional information was provided by the V8 runtime")), false /*executionStarted*/);
}
if (!pCachedData->rejected)
{
cacheResult = V8CacheResult::Accepted;
}
else
{
std::unique_ptr<v8::ScriptCompiler::CachedData> upCachedData(v8::ScriptCompiler::CreateCodeCache(hModule->GetUnboundModuleScript()));
if (upCachedData && (upCachedData->length > 0) && (upCachedData->data != nullptr))
{
cacheBytes.resize(upCachedData->length);
memcpy(cacheBytes.data(), upCachedData->data, upCachedData->length);
cacheResult = V8CacheResult::Updated;
}
else
{
cacheResult = V8CacheResult::UpdateFailed;
}
}
CacheModule(documentInfo, codeDigest, hModule, (cacheResult != V8CacheResult::UpdateFailed) ? cacheBytes : std::vector<uint8_t>());
}
else if (cachedCacheBytes.empty())
{
std::unique_ptr<v8::ScriptCompiler::CachedData> upCachedData(v8::ScriptCompiler::CreateCodeCache(hModule->GetUnboundModuleScript()));
if (upCachedData && (upCachedData->length > 0) && (upCachedData->data != nullptr))
{
cacheBytes.resize(upCachedData->length);
memcpy(cacheBytes.data(), upCachedData->data, upCachedData->length);
SetCachedModuleCacheBytes(documentInfo.GetUniqueId(), codeDigest, cacheBytes);
cacheResult = V8CacheResult::Updated;
}
else
{
cacheResult = V8CacheResult::UpdateFailed;
}
}
else if (cachedCacheBytes == cacheBytes)
{
cacheResult = V8CacheResult::Verified;
}
else
{
cacheBytes = cachedCacheBytes;
cacheResult = V8CacheResult::Updated;
}
upScriptHolder.reset(new V8ScriptHolderImpl(GetWeakBinding(), ::PtrFromHandle(CreatePersistent(hModule)), documentInfo, codeDigest, std::move(code)));
}
else
{
auto hScript = GetCachedScript(documentInfo.GetUniqueId(), codeDigest, cachedCacheBytes);
if (hScript.IsEmpty())
{
hScript = VERIFY_MAYBE(CompileUnboundScript(&source, v8::ScriptCompiler::kConsumeCodeCache));
if (hScript.IsEmpty())
{
throw V8Exception(V8Exception::Type::General, m_Name, StdString(SL("Script compilation failed; no additional information was provided by the V8 runtime")), false /*executionStarted*/);
}
if (!pCachedData->rejected)
{
cacheResult = V8CacheResult::Accepted;
}
else
{
std::unique_ptr<v8::ScriptCompiler::CachedData> upCachedData(v8::ScriptCompiler::CreateCodeCache(hScript));
if (upCachedData && (upCachedData->length > 0) && (upCachedData->data != nullptr))
{
cacheBytes.resize(upCachedData->length);
memcpy(cacheBytes.data(), upCachedData->data, upCachedData->length);
cacheResult = V8CacheResult::Updated;
}
else
{
cacheResult = V8CacheResult::UpdateFailed;
}
}
CacheScript(documentInfo, codeDigest, hScript, (cacheResult != V8CacheResult::UpdateFailed) ? cacheBytes : std::vector<uint8_t>());
}
else if (cachedCacheBytes.empty())
{
std::unique_ptr<v8::ScriptCompiler::CachedData> upCachedData(v8::ScriptCompiler::CreateCodeCache(hScript));
if (upCachedData && (upCachedData->length > 0) && (upCachedData->data != nullptr))
{
cacheBytes.resize(upCachedData->length);
memcpy(cacheBytes.data(), upCachedData->data, upCachedData->length);
SetCachedScriptCacheBytes(documentInfo.GetUniqueId(), codeDigest, cacheBytes);
cacheResult = V8CacheResult::Updated;
}
else
{
cacheResult = V8CacheResult::UpdateFailed;
}
}
else if (cachedCacheBytes == cacheBytes)
{
cacheResult = V8CacheResult::Verified;
}
else
{
cacheBytes = cachedCacheBytes;
cacheResult = V8CacheResult::Updated;
}
upScriptHolder.reset(new V8ScriptHolderImpl(GetWeakBinding(), ::PtrFromHandle(CreatePersistent(hScript)), documentInfo, codeDigest));
}
if (cacheResult != V8CacheResult::UpdateFailed)
{
upScriptHolder->SetCacheBytes(cacheBytes);
}
return upScriptHolder.release();
FROM_MAYBE_CATCH
throw V8Exception(V8Exception::Type::General, m_Name, StdString(SL("The V8 runtime cannot perform the requested operation because a script exception is pending")), EXECUTION_STARTED);
FROM_MAYBE_END
END_EXECUTION_SCOPE
END_DOCUMENT_SCOPE
END_CONTEXT_SCOPE
}
//-----------------------------------------------------------------------------
bool V8ContextImpl::CanExecute(const SharedPtr<V8ScriptHolder>& spHolder)
{
return spHolder->IsSameIsolate(m_spIsolateImpl);
@ -805,7 +995,7 @@ V8Value V8ContextImpl::Execute(const SharedPtr<V8ScriptHolder>& spHolder, bool e
auto hModule = GetCachedModule(spHolder->GetDocumentInfo().GetUniqueId(), codeDigest);
if (hModule.IsEmpty())
{
if (spHolder->GetCacheBytes().size() > 0)
if (!spHolder->GetCacheBytes().empty())
{
auto pCachedData = new v8::ScriptCompiler::CachedData(spHolder->GetCacheBytes().data(), static_cast<int>(spHolder->GetCacheBytes().size()), v8::ScriptCompiler::CachedData::BufferNotOwned);
v8::ScriptCompiler::Source source(FROM_MAYBE(CreateString(spHolder->GetCode())), CreateScriptOrigin(spHolder->GetDocumentInfo()), pCachedData);
@ -1552,10 +1742,22 @@ v8::MaybeLocal<v8::Module> V8ContextImpl::ResolveModule(v8::Local<v8::String> hS
std::vector<v8::Local<v8::String>> names;
std::vector<SyntheticModuleExport> exports;
auto hExports = ::ValueAsObject(ImportValue(exportsValue));
if (!hExports.IsEmpty())
auto hExportsValue = ImportValue(exportsValue);
if (hExportsValue.IsEmpty())
{
auto hOwnPropertyNames = FROM_MAYBE(hExports->GetOwnPropertyNames(m_hContext, v8::SKIP_SYMBOLS, v8::KeyConversionMode::kNoNumbers));
hExportsValue = GetUndefined();
}
if ((documentInfo.GetKind() == DocumentKind::Json) || !hExportsValue->IsObject())
{
auto hName = CreateString("default");
names.push_back(hName);
exports.push_back({ CreatePersistent(hName), CreatePersistent(hExportsValue) });
}
else
{
auto hExports = hExportsValue.As<v8::Object>();
auto hOwnPropertyNames = FROM_MAYBE(hExports->GetOwnPropertyNames(m_hContext, v8::SKIP_SYMBOLS, v8::KeyConversionMode::kConvertToString));
if (!hOwnPropertyNames.IsEmpty())
{
auto length = hOwnPropertyNames->Length();
@ -1931,7 +2133,7 @@ void V8ContextImpl::GetGlobalProperty(v8::Local<v8::Name> hKey, const v8::Proper
if (CheckContextImplForGlobalObjectCallback(pContextImpl))
{
const auto& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
if (!stack.empty())
{
for (auto it = stack.rbegin(); it != stack.rend(); it++)
{
@ -1962,7 +2164,7 @@ void V8ContextImpl::SetGlobalProperty(v8::Local<v8::Name> hKey, v8::Local<v8::Va
if (CheckContextImplForGlobalObjectCallback(pContextImpl))
{
const auto& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
if (!stack.empty())
{
for (auto it = stack.rbegin(); it != stack.rend(); it++)
{
@ -1994,7 +2196,7 @@ void V8ContextImpl::QueryGlobalProperty(v8::Local<v8::Name> hKey, const v8::Prop
if (CheckContextImplForGlobalObjectCallback(pContextImpl))
{
const auto& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
if (!stack.empty())
{
for (auto it = stack.rbegin(); it != stack.rend(); it++)
{
@ -2025,7 +2227,7 @@ void V8ContextImpl::DeleteGlobalProperty(v8::Local<v8::Name> hKey, const v8::Pro
if (CheckContextImplForGlobalObjectCallback(pContextImpl))
{
const auto& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
if (!stack.empty())
{
for (auto it = stack.rbegin(); it != stack.rend(); it++)
{
@ -2069,7 +2271,7 @@ void V8ContextImpl::GetGlobalPropertyNames(const v8::PropertyCallbackInfo<v8::Ar
try
{
const auto& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
if (!stack.empty())
{
std::vector<StdString> names;
for (auto it = stack.rbegin(); it != stack.rend(); it++)
@ -2121,7 +2323,7 @@ void V8ContextImpl::GetGlobalProperty(uint32_t index, const v8::PropertyCallback
if (CheckContextImplForGlobalObjectCallback(pContextImpl))
{
const auto& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
if (!stack.empty())
{
auto hName = FROM_MAYBE(pContextImpl->CreateInteger(index)->ToString(pContextImpl->m_hContext));
for (auto it = stack.rbegin(); it != stack.rend(); it++)
@ -2147,7 +2349,7 @@ void V8ContextImpl::SetGlobalProperty(uint32_t index, v8::Local<v8::Value> hValu
if (CheckContextImplForGlobalObjectCallback(pContextImpl))
{
const auto& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
if (!stack.empty())
{
auto hName = FROM_MAYBE(pContextImpl->CreateInteger(index)->ToString(pContextImpl->m_hContext));
for (auto it = stack.rbegin(); it != stack.rend(); it++)
@ -2174,7 +2376,7 @@ void V8ContextImpl::QueryGlobalProperty(uint32_t index, const v8::PropertyCallba
if (CheckContextImplForGlobalObjectCallback(pContextImpl))
{
const auto& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
if (!stack.empty())
{
auto hIndex = pContextImpl->CreateInteger(index);
auto hName = FROM_MAYBE(hIndex->ToString(pContextImpl->m_hContext));
@ -2201,7 +2403,7 @@ void V8ContextImpl::DeleteGlobalProperty(uint32_t index, const v8::PropertyCallb
if (CheckContextImplForGlobalObjectCallback(pContextImpl))
{
const auto& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
if (!stack.empty())
{
auto hName = FROM_MAYBE(pContextImpl->CreateInteger(index)->ToString(pContextImpl->m_hContext));
for (auto it = stack.rbegin(); it != stack.rend(); it++)
@ -2229,7 +2431,7 @@ void V8ContextImpl::GetGlobalPropertyIndices(const v8::PropertyCallbackInfo<v8::
try
{
const auto& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
if (!stack.empty())
{
std::vector<int> indices;
for (auto it = stack.rbegin(); it != stack.rend(); it++)
@ -2874,7 +3076,34 @@ v8::Local<v8::Module> V8ContextImpl::GetCachedModule(uint64_t uniqueId, size_t c
//-----------------------------------------------------------------------------
v8::Local<v8::Module> V8ContextImpl::GetCachedModule(uint64_t uniqueId, size_t codeDigest, std::vector<uint8_t>& cacheBytes)
{
_ASSERTE(m_spIsolateImpl->IsCurrent() && m_spIsolateImpl->IsLocked());
for (auto it = m_ModuleCache.begin(); it != m_ModuleCache.end(); it++)
{
if ((it->DocumentInfo.GetUniqueId() == uniqueId) && (it->CodeDigest == codeDigest))
{
m_ModuleCache.splice(m_ModuleCache.begin(), m_ModuleCache, it);
cacheBytes = it->CacheBytes;
return it->hModule;
}
}
cacheBytes.clear();
return v8::Local<v8::Module>();
}
//-----------------------------------------------------------------------------
void V8ContextImpl::CacheModule(const V8DocumentInfo& documentInfo, size_t codeDigest, v8::Local<v8::Module> hModule)
{
CacheModule(documentInfo, codeDigest, hModule, std::vector<uint8_t>());
}
//-----------------------------------------------------------------------------
void V8ContextImpl::CacheModule(const V8DocumentInfo& documentInfo, size_t codeDigest, v8::Local<v8::Module> hModule, const std::vector<uint8_t>& cacheBytes)
{
_ASSERTE(m_spIsolateImpl->IsCurrent() && m_spIsolateImpl->IsLocked());
@ -2891,7 +3120,7 @@ void V8ContextImpl::CacheModule(const V8DocumentInfo& documentInfo, size_t codeD
return (entry.DocumentInfo.GetUniqueId() == documentInfo.GetUniqueId()) && (entry.CodeDigest == codeDigest);
}));
ModuleCacheEntry entry { documentInfo, codeDigest, CreatePersistent(hModule) };
ModuleCacheEntry entry { documentInfo, codeDigest, CreatePersistent(hModule), cacheBytes };
m_ModuleCache.push_front(std::move(entry));
m_Statistics.ModuleCacheSize = m_ModuleCache.size();
@ -2899,11 +3128,28 @@ void V8ContextImpl::CacheModule(const V8DocumentInfo& documentInfo, size_t codeD
//-----------------------------------------------------------------------------
void V8ContextImpl::SetCachedModuleCacheBytes(uint64_t uniqueId, size_t codeDigest, const std::vector<uint8_t>& cacheBytes)
{
_ASSERTE(m_spIsolateImpl->IsCurrent() && m_spIsolateImpl->IsLocked());
for (auto it = m_ModuleCache.begin(); it != m_ModuleCache.end(); it++)
{
if ((it->DocumentInfo.GetUniqueId() == uniqueId) && (it->CodeDigest == codeDigest))
{
m_ModuleCache.splice(m_ModuleCache.begin(), m_ModuleCache, it);
it->CacheBytes = cacheBytes;
return;
}
}
}
//-----------------------------------------------------------------------------
void V8ContextImpl::ClearModuleCache()
{
_ASSERTE(m_spIsolateImpl->IsCurrent() && m_spIsolateImpl->IsLocked());
while (m_ModuleCache.size() > 0)
while (!m_ModuleCache.empty())
{
Dispose(m_ModuleCache.front().hModule);
m_ModuleCache.pop_front();
@ -2928,6 +3174,13 @@ v8::Local<v8::UnboundScript> V8ContextImpl::GetCachedScript(uint64_t uniqueId, s
//-----------------------------------------------------------------------------
v8::Local<v8::UnboundScript> V8ContextImpl::GetCachedScript(uint64_t uniqueId, size_t codeDigest, std::vector<uint8_t>& cacheBytes)
{
return m_spIsolateImpl->GetCachedScript(uniqueId, codeDigest, cacheBytes);
}
//-----------------------------------------------------------------------------
void V8ContextImpl::CacheScript(const V8DocumentInfo& documentInfo, size_t codeDigest, v8::Local<v8::UnboundScript> hScript)
{
m_spIsolateImpl->CacheScript(documentInfo, codeDigest, hScript);
@ -2935,6 +3188,18 @@ void V8ContextImpl::CacheScript(const V8DocumentInfo& documentInfo, size_t codeD
//-----------------------------------------------------------------------------
void V8ContextImpl::CacheScript(const V8DocumentInfo& documentInfo, size_t codeDigest, v8::Local<v8::UnboundScript> hScript, const std::vector<uint8_t>& cacheBytes)
{
m_spIsolateImpl->CacheScript(documentInfo, codeDigest, hScript, cacheBytes);
}
void V8ContextImpl::SetCachedScriptCacheBytes(uint64_t uniqueId, size_t codeDigest, const std::vector<uint8_t>& cacheBytes)
{
m_spIsolateImpl->SetCachedScriptCacheBytes(uniqueId, codeDigest, cacheBytes);
}
//-----------------------------------------------------------------------------
v8::Local<v8::Value> V8ContextImpl::ImportValue(const V8Value& value)
{
FROM_MAYBE_TRY

Просмотреть файл

@ -43,9 +43,12 @@ public:
virtual void CancelAwaitDebugger() override;
virtual V8Value Execute(const V8DocumentInfo& documentInfo, const StdString& code, bool evaluate) override;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code) override;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheType cacheType, std::vector<uint8_t>& cacheBytes) override;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheType cacheType, const std::vector<uint8_t>& cacheBytes, bool& cacheAccepted) override;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes) override;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, const std::vector<uint8_t>& cacheBytes, bool& cacheAccepted) override;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes, V8CacheResult& cacheResult) override;
virtual bool CanExecute(const SharedPtr<V8ScriptHolder>& spHolder) override;
virtual V8Value Execute(const SharedPtr<V8ScriptHolder>& spHolder, bool evaluate) override;
@ -118,6 +121,7 @@ private:
V8DocumentInfo DocumentInfo;
size_t CodeDigest;
Persistent<v8::Module> hModule;
std::vector<uint8_t> CacheBytes;
};
struct SyntheticModuleExport final
@ -465,12 +469,18 @@ private:
bool TryGetCachedModuleInfo(uint64_t uniqueId, V8DocumentInfo& documentInfo);
bool TryGetCachedModuleInfo(v8::Local<v8::Module> hModule, V8DocumentInfo& documentInfo);
v8::Local<v8::Module> GetCachedModule(uint64_t uniqueId, size_t codeDigest);
v8::Local<v8::Module> GetCachedModule(uint64_t uniqueId, size_t codeDigest, std::vector<uint8_t>& cacheBytes);
void CacheModule(const V8DocumentInfo& documentInfo, size_t codeDigest, v8::Local<v8::Module> hModule);
void CacheModule(const V8DocumentInfo& documentInfo, size_t codeDigest, v8::Local<v8::Module> hModule, const std::vector<uint8_t>& cacheBytes);
void SetCachedModuleCacheBytes(uint64_t uniqueId, size_t codeDigest, const std::vector<uint8_t>& cacheBytes);
void ClearModuleCache();
bool TryGetCachedScriptInfo(uint64_t uniqueId, V8DocumentInfo& documentInfo);
v8::Local<v8::UnboundScript> GetCachedScript(uint64_t uniqueId, size_t codeDigest);
v8::Local<v8::UnboundScript> GetCachedScript(uint64_t uniqueId, size_t codeDigest, std::vector<uint8_t>& cacheBytes);
void CacheScript(const V8DocumentInfo& documentInfo, size_t codeDigest, v8::Local<v8::UnboundScript> hScript);
void CacheScript(const V8DocumentInfo& documentInfo, size_t codeDigest, v8::Local<v8::UnboundScript> hScript, const std::vector<uint8_t>& cacheBytes);
void SetCachedScriptCacheBytes(uint64_t uniqueId, size_t codeDigest, const std::vector<uint8_t>& cacheBytes);
v8::Local<v8::Value> ImportValue(const V8Value& value);
V8Value ExportValue(v8::Local<v8::Value> hValue);

Просмотреть файл

@ -3,30 +3,39 @@
#pragma once
enum class DocumentKind : int32_t
{
// IMPORTANT: maintain bitwise equivalence with managed enum DocumentKind
Script,
JavaScriptModule,
CommonJSModule,
Json
};
struct V8DocumentInfo final
{
public:
V8DocumentInfo():
m_IsModule(false),
m_Kind(DocumentKind::Script),
m_pvDocumentInfo(nullptr)
{
}
V8DocumentInfo(const StdChar* pResourceName, const StdChar* pSourceMapUrl, uint64_t uniqueId, bool isModule, void* pvDocumentInfo):
V8DocumentInfo(const StdChar* pResourceName, const StdChar* pSourceMapUrl, uint64_t uniqueId, DocumentKind kind, void* pvDocumentInfo):
m_ResourceName(pResourceName),
m_SourceMapUrl(pSourceMapUrl),
m_UniqueId(uniqueId),
m_IsModule(isModule),
m_Kind(kind),
m_pvDocumentInfo(pvDocumentInfo)
{
}
V8DocumentInfo(StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, bool isModule, void* pvDocumentInfo):
V8DocumentInfo(StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind kind, void* pvDocumentInfo):
m_ResourceName(std::move(resourceName)),
m_SourceMapUrl(std::move(sourceMapUrl)),
m_UniqueId(uniqueId),
m_IsModule(isModule),
m_Kind(kind),
m_pvDocumentInfo(pvDocumentInfo)
{
}
@ -35,7 +44,7 @@ public:
m_ResourceName(that.m_ResourceName),
m_SourceMapUrl(that.m_SourceMapUrl),
m_UniqueId(that.m_UniqueId),
m_IsModule(that.m_IsModule),
m_Kind(that.m_Kind),
m_pvDocumentInfo((that.m_pvDocumentInfo != nullptr) ? HostObjectUtil::GetInstance().AddRef(that.m_pvDocumentInfo) : nullptr)
{
}
@ -44,7 +53,7 @@ public:
m_ResourceName(std::move(that.m_ResourceName)),
m_SourceMapUrl(std::move(that.m_SourceMapUrl)),
m_UniqueId(that.m_UniqueId),
m_IsModule(that.m_IsModule),
m_Kind(that.m_Kind),
m_pvDocumentInfo(that.m_pvDocumentInfo)
{
that.m_pvDocumentInfo = nullptr;
@ -56,7 +65,7 @@ public:
m_ResourceName = that.m_ResourceName;
m_SourceMapUrl = that.m_SourceMapUrl;
m_UniqueId = that.m_UniqueId;
m_IsModule = that.m_IsModule;
m_Kind = that.m_Kind;
m_pvDocumentInfo = (that.m_pvDocumentInfo != nullptr) ? HostObjectUtil::GetInstance().AddRef(that.m_pvDocumentInfo) : nullptr;
return *this;
}
@ -67,7 +76,7 @@ public:
m_ResourceName = std::move(that.m_ResourceName);
m_SourceMapUrl = std::move(that.m_SourceMapUrl);
m_UniqueId = that.m_UniqueId;
m_IsModule = that.m_IsModule;
m_Kind = that.m_Kind;
m_pvDocumentInfo = that.m_pvDocumentInfo;
that.m_pvDocumentInfo = nullptr;
return *this;
@ -84,14 +93,16 @@ public:
const StdString& GetResourceName() const { return m_ResourceName; }
const StdString& GetSourceMapUrl() const { return m_SourceMapUrl; }
uint64_t GetUniqueId() const { return m_UniqueId; }
bool IsModule() const { return m_IsModule; }
DocumentKind GetKind() const { return m_Kind; }
void* GetDocumentInfo() const { return m_pvDocumentInfo; }
bool IsModule() const { return GetKind() == DocumentKind::JavaScriptModule; }
private:
StdString m_ResourceName;
StdString m_SourceMapUrl;
uint64_t m_UniqueId {};
bool m_IsModule;
DocumentKind m_Kind;
void* m_pvDocumentInfo;
};

Просмотреть файл

@ -75,8 +75,9 @@ public:
virtual void CancelAwaitDebugger() = 0;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code) = 0;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheType cacheType, std::vector<uint8_t>& cacheBytes) = 0;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheType cacheType, const std::vector<uint8_t>& cacheBytes, bool& cacheAccepted) = 0;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes) = 0;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, const std::vector<uint8_t>& cacheBytes, bool& cacheAccepted) = 0;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes, V8CacheResult& cacheResult) = 0;
virtual bool GetEnableInterruptPropagation() = 0;
virtual void SetEnableInterruptPropagation(bool value) = 0;

Просмотреть файл

@ -759,7 +759,7 @@ V8ScriptHolder* V8IsolateImpl::Compile(const V8DocumentInfo& documentInfo, StdSt
{
BEGIN_ISOLATE_SCOPE
SharedPtr<V8ContextImpl> spContextImpl((m_ContextEntries.size() > 0) ? m_ContextEntries.front().pContextImpl : new V8ContextImpl(this, m_Name));
SharedPtr<V8ContextImpl> spContextImpl(!m_ContextEntries.empty() ? m_ContextEntries.front().pContextImpl : new V8ContextImpl(this, m_Name));
return spContextImpl->Compile(documentInfo, std::move(code));
END_ISOLATE_SCOPE
@ -767,24 +767,36 @@ V8ScriptHolder* V8IsolateImpl::Compile(const V8DocumentInfo& documentInfo, StdSt
//-----------------------------------------------------------------------------
V8ScriptHolder* V8IsolateImpl::Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheType cacheType, std::vector<uint8_t>& cacheBytes)
V8ScriptHolder* V8IsolateImpl::Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes)
{
BEGIN_ISOLATE_SCOPE
SharedPtr<V8ContextImpl> spContextImpl((m_ContextEntries.size() > 0) ? m_ContextEntries.front().pContextImpl : new V8ContextImpl(this, m_Name));
return spContextImpl->Compile(documentInfo, std::move(code), cacheType, cacheBytes);
SharedPtr<V8ContextImpl> spContextImpl(!m_ContextEntries.empty() ? m_ContextEntries.front().pContextImpl : new V8ContextImpl(this, m_Name));
return spContextImpl->Compile(documentInfo, std::move(code), cacheKind, cacheBytes);
END_ISOLATE_SCOPE
}
//-----------------------------------------------------------------------------
V8ScriptHolder* V8IsolateImpl::Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheType cacheType, const std::vector<uint8_t>& cacheBytes, bool& cacheAccepted)
V8ScriptHolder* V8IsolateImpl::Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, const std::vector<uint8_t>& cacheBytes, bool& cacheAccepted)
{
BEGIN_ISOLATE_SCOPE
SharedPtr<V8ContextImpl> spContextImpl((m_ContextEntries.size() > 0) ? m_ContextEntries.front().pContextImpl : new V8ContextImpl(this, m_Name));
return spContextImpl->Compile(documentInfo, std::move(code), cacheType, cacheBytes, cacheAccepted);
SharedPtr<V8ContextImpl> spContextImpl(!m_ContextEntries.empty() ? m_ContextEntries.front().pContextImpl : new V8ContextImpl(this, m_Name));
return spContextImpl->Compile(documentInfo, std::move(code), cacheKind, cacheBytes, cacheAccepted);
END_ISOLATE_SCOPE
}
//-----------------------------------------------------------------------------
V8ScriptHolder* V8IsolateImpl::Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes, V8CacheResult& cacheResult)
{
BEGIN_ISOLATE_SCOPE
SharedPtr<V8ContextImpl> spContextImpl(!m_ContextEntries.empty() ? m_ContextEntries.front().pContextImpl : new V8ContextImpl(this, m_Name));
return spContextImpl->Compile(documentInfo, std::move(code), cacheKind, cacheBytes, cacheResult);
END_ISOLATE_SCOPE
}
@ -1003,7 +1015,7 @@ v8::Local<v8::Context> V8IsolateImpl::ensureDefaultContextInGroup(int contextGro
{
_ASSERTE(IsCurrent() && IsLocked());
if (m_ContextEntries.size() > 0)
if (!m_ContextEntries.empty())
{
return m_ContextEntries.front().pContextImpl->GetContext();
}
@ -1463,7 +1475,7 @@ bool V8IsolateImpl::TryGetCachedScriptInfo(uint64_t uniqueId, V8DocumentInfo& do
{
_ASSERTE(IsCurrent() && IsLocked());
for (auto it = m_ScriptCache.begin(); it != m_ScriptCache.end(); it++)
for (auto it = m_ScriptCache.cbegin(); it != m_ScriptCache.cend(); it++)
{
if (it->DocumentInfo.GetUniqueId() == uniqueId)
{
@ -1482,7 +1494,7 @@ v8::Local<v8::UnboundScript> V8IsolateImpl::GetCachedScript(uint64_t uniqueId, s
{
_ASSERTE(IsCurrent() && IsLocked());
for (auto it = m_ScriptCache.begin(); it != m_ScriptCache.end(); it++)
for (auto it = m_ScriptCache.cbegin(); it != m_ScriptCache.cend(); it++)
{
if ((it->DocumentInfo.GetUniqueId() == uniqueId) && (it->CodeDigest == codeDigest))
{
@ -1496,7 +1508,34 @@ v8::Local<v8::UnboundScript> V8IsolateImpl::GetCachedScript(uint64_t uniqueId, s
//-----------------------------------------------------------------------------
v8::Local<v8::UnboundScript> V8IsolateImpl::GetCachedScript(uint64_t uniqueId, size_t codeDigest, std::vector<uint8_t>& cacheBytes)
{
_ASSERTE(IsCurrent() && IsLocked());
for (auto it = m_ScriptCache.cbegin(); it != m_ScriptCache.cend(); it++)
{
if ((it->DocumentInfo.GetUniqueId() == uniqueId) && (it->CodeDigest == codeDigest))
{
m_ScriptCache.splice(m_ScriptCache.begin(), m_ScriptCache, it);
cacheBytes = it->CacheBytes;
return it->hScript;
}
}
cacheBytes.clear();
return v8::Local<v8::UnboundScript>();
}
//-----------------------------------------------------------------------------
void V8IsolateImpl::CacheScript(const V8DocumentInfo& documentInfo, size_t codeDigest, v8::Local<v8::UnboundScript> hScript)
{
CacheScript(documentInfo, codeDigest, hScript, std::vector<uint8_t>());
}
//-----------------------------------------------------------------------------
void V8IsolateImpl::CacheScript(const V8DocumentInfo& documentInfo, size_t codeDigest, v8::Local<v8::UnboundScript> hScript, const std::vector<uint8_t>& cacheBytes)
{
_ASSERTE(IsCurrent() && IsLocked());
@ -1513,7 +1552,7 @@ void V8IsolateImpl::CacheScript(const V8DocumentInfo& documentInfo, size_t codeD
return (entry.DocumentInfo.GetUniqueId() == documentInfo.GetUniqueId()) && (entry.CodeDigest == codeDigest);
}));
ScriptCacheEntry entry { documentInfo, codeDigest, CreatePersistent(hScript) };
ScriptCacheEntry entry { documentInfo, codeDigest, CreatePersistent(hScript), cacheBytes };
m_ScriptCache.push_front(std::move(entry));
m_Statistics.ScriptCacheSize = m_ScriptCache.size();
@ -1521,11 +1560,28 @@ void V8IsolateImpl::CacheScript(const V8DocumentInfo& documentInfo, size_t codeD
//-----------------------------------------------------------------------------
void V8IsolateImpl::SetCachedScriptCacheBytes(uint64_t uniqueId, size_t codeDigest, const std::vector<uint8_t>& cacheBytes)
{
_ASSERTE(IsCurrent() && IsLocked());
for (auto it = m_ScriptCache.begin(); it != m_ScriptCache.end(); it++)
{
if ((it->DocumentInfo.GetUniqueId() == uniqueId) && (it->CodeDigest == codeDigest))
{
m_ScriptCache.splice(m_ScriptCache.begin(), m_ScriptCache, it);
it->CacheBytes = cacheBytes;
return;
}
}
}
//-----------------------------------------------------------------------------
void V8IsolateImpl::ClearScriptCache()
{
_ASSERTE(IsCurrent() && IsLocked());
while (m_ScriptCache.size() > 0)
while (!m_ScriptCache.empty())
{
Dispose(m_ScriptCache.front().hScript);
m_ScriptCache.pop_front();
@ -1686,7 +1742,7 @@ void V8IsolateImpl::ProcessCallWithLockQueue(std::unique_lock<std::mutex>& lock)
_ASSERTE(lock.owns_lock());
CallWithLockQueue callWithLockQueue(PopCallWithLockQueue(lock));
while (callWithLockQueue.size() > 0)
while (!callWithLockQueue.empty())
{
lock.unlock();
ProcessCallWithLockQueue(callWithLockQueue);
@ -1703,7 +1759,7 @@ void V8IsolateImpl::ProcessCallWithLockQueue(CallWithLockQueue& callWithLockQueu
BEGIN_PULSE_VALUE_SCOPE(&m_CallWithLockLevel, m_CallWithLockLevel + 1)
while (callWithLockQueue.size() > 0)
while (!callWithLockQueue.empty())
{
try
{
@ -1736,7 +1792,7 @@ V8IsolateImpl::CallWithLockQueue V8IsolateImpl::PopCallWithLockQueue(const std::
CallWithLockQueue nestableCallWithLockQueue;
CallWithLockQueue nonNestableCallWithLockQueue;
while (m_CallWithLockQueue.size() > 0)
while (!m_CallWithLockQueue.empty())
{
auto& callWithLockEntry = m_CallWithLockQueue.front();
auto& callWithLockQueue = callWithLockEntry.first ? nestableCallWithLockQueue : nonNestableCallWithLockQueue;

Просмотреть файл

@ -476,8 +476,9 @@ public:
virtual void CancelAwaitDebugger() override;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code) override;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheType cacheType, std::vector<uint8_t>& cacheBytes) override;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheType cacheType, const std::vector<uint8_t>& cacheBytes, bool& cacheAccepted) override;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes) override;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, const std::vector<uint8_t>& cacheBytes, bool& cacheAccepted) override;
virtual V8ScriptHolder* Compile(const V8DocumentInfo& documentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes, V8CacheResult& cacheResult) override;
virtual bool GetEnableInterruptPropagation() override;
virtual void SetEnableInterruptPropagation(bool value) override;
@ -535,7 +536,10 @@ public:
bool TryGetCachedScriptInfo(uint64_t uniqueId, V8DocumentInfo& documentInfo);
v8::Local<v8::UnboundScript> GetCachedScript(uint64_t uniqueId, size_t codeDigest);
v8::Local<v8::UnboundScript> GetCachedScript(uint64_t uniqueId, size_t codeDigest, std::vector<uint8_t>& cacheBytes);
void CacheScript(const V8DocumentInfo& documentInfo, size_t codeDigest, v8::Local<v8::UnboundScript> hScript);
void CacheScript(const V8DocumentInfo& documentInfo, size_t codeDigest, v8::Local<v8::UnboundScript> hScript, const std::vector<uint8_t>& cacheBytes);
void SetCachedScriptCacheBytes(uint64_t uniqueId, size_t codeDigest, const std::vector<uint8_t>& cacheBytes);
void ClearScriptCache();
~V8IsolateImpl();
@ -585,6 +589,7 @@ private:
V8DocumentInfo DocumentInfo;
size_t CodeDigest;
Persistent<v8::UnboundScript> hScript;
std::vector<uint8_t> CacheBytes;
};
enum class RunMessageLoopReason

Просмотреть файл

@ -21,8 +21,8 @@ V8ScriptHolderImpl::V8ScriptHolderImpl(const SharedPtr<V8WeakContextBinding>& sp
m_spBinding(spBinding),
m_pvScript(pvScript),
m_DocumentInfo(documentInfo),
m_Code(std::move(code)),
m_CodeDigest(codeDigest)
m_CodeDigest(codeDigest),
m_Code(std::move(code))
{
}

Просмотреть файл

@ -62,7 +62,7 @@
V8_SPLIT_PROXY_MANAGED_METHOD(StdBool, ChangeNativeCallbackTimer, void* pvTimer, int32_t dueTime, int32_t period) \
V8_SPLIT_PROXY_MANAGED_METHOD(void, DestroyNativeCallbackTimer, void* pvTimer) \
\
V8_SPLIT_PROXY_MANAGED_METHOD(void, LoadModule, void* pvSourceDocumentInfo, const StdString& specifier, StdString& resourceName, StdString& sourceMapUrl, uint64_t& uniqueId, StdBool& isModule, StdString& code, void*& pvDocumentInfo, V8Value& exports) \
V8_SPLIT_PROXY_MANAGED_METHOD(void, LoadModule, void* pvSourceDocumentInfo, const StdString& specifier, StdString& resourceName, StdString& sourceMapUrl, uint64_t& uniqueId, DocumentKind& documentKind, StdString& code, void*& pvDocumentInfo, V8Value& exports) \
V8_SPLIT_PROXY_MANAGED_METHOD(int32_t, CreateModuleContext, void* pvDocumentInfo, std::vector<StdString>& names, std::vector<V8Value>& values) \
\
V8_SPLIT_PROXY_MANAGED_METHOD(void, WriteBytesToStream, void* pvStream, const uint8_t* pBytes, int32_t count) \

Просмотреть файл

@ -800,9 +800,9 @@ NATIVE_ENTRY_POINT(void) V8Isolate_CancelAwaitDebugger(const V8IsolateHandle& ha
//-----------------------------------------------------------------------------
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_Compile(const V8IsolateHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, StdBool isModule, void* pvDocumentInfo, StdString&& code) noexcept
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_Compile(const V8IsolateHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, StdString&& code) noexcept
{
V8DocumentInfo documentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, isModule, pvDocumentInfo);
V8DocumentInfo documentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo);
auto spIsolate = handle.GetEntity();
if (!spIsolate.IsEmpty())
@ -822,23 +822,23 @@ NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_Compile(const V8IsolateHandle& han
//-----------------------------------------------------------------------------
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_CompileProducingCache(const V8IsolateHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, StdBool isModule, void* pvDocumentInfo, StdString&& code, V8CacheType cacheType, std::vector<uint8_t>& cacheBytes) noexcept
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_CompileProducingCache(const V8IsolateHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes) noexcept
{
cacheBytes.clear();
if (cacheType == V8CacheType::None)
if (cacheKind == V8CacheKind::None)
{
return V8Isolate_Compile(handle, std::move(resourceName), std::move(sourceMapUrl), uniqueId, isModule, pvDocumentInfo, std::move(code));
return V8Isolate_Compile(handle, std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo, std::move(code));
}
V8DocumentInfo documentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, isModule, pvDocumentInfo);
V8DocumentInfo documentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo);
auto spIsolate = handle.GetEntity();
if (!spIsolate.IsEmpty())
{
try
{
return new V8ScriptHandle(spIsolate->Compile(documentInfo, std::move(code), cacheType, cacheBytes));
return new V8ScriptHandle(spIsolate->Compile(documentInfo, std::move(code), cacheKind, cacheBytes));
}
catch (const V8Exception& exception)
{
@ -851,16 +851,16 @@ NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_CompileProducingCache(const V8Isol
//-----------------------------------------------------------------------------
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_CompileConsumingCache(const V8IsolateHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, StdBool isModule, void* pvDocumentInfo, StdString&& code, V8CacheType cacheType, const std::vector<uint8_t>& cacheBytes, StdBool& cacheAccepted) noexcept
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_CompileConsumingCache(const V8IsolateHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, StdString&& code, V8CacheKind cacheKind, const std::vector<uint8_t>& cacheBytes, StdBool& cacheAccepted) noexcept
{
cacheAccepted = false;
if ((cacheType == V8CacheType::None) || cacheBytes.empty())
if ((cacheKind == V8CacheKind::None) || cacheBytes.empty())
{
return V8Isolate_Compile(handle, std::move(resourceName), std::move(sourceMapUrl), uniqueId, isModule, pvDocumentInfo, std::move(code));
return V8Isolate_Compile(handle, std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo, std::move(code));
}
V8DocumentInfo documentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, isModule, pvDocumentInfo);
V8DocumentInfo documentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo);
auto spIsolate = handle.GetEntity();
if (!spIsolate.IsEmpty())
@ -868,7 +868,7 @@ NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_CompileConsumingCache(const V8Isol
try
{
auto tempCacheAccepted = false;
auto pScriptHandle = new V8ScriptHandle(spIsolate->Compile(documentInfo, std::move(code), cacheType, cacheBytes, tempCacheAccepted));
auto pScriptHandle = new V8ScriptHandle(spIsolate->Compile(documentInfo, std::move(code), cacheKind, cacheBytes, tempCacheAccepted));
cacheAccepted = tempCacheAccepted;
return pScriptHandle;
@ -884,6 +884,41 @@ NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_CompileConsumingCache(const V8Isol
//-----------------------------------------------------------------------------
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_CompileUpdatingCache(const V8IsolateHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes, V8CacheResult& cacheResult) noexcept
{
if (cacheKind == V8CacheKind::None)
{
cacheResult = V8CacheResult::Disabled;
return V8Isolate_Compile(handle, std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo, std::move(code));
}
if (cacheBytes.empty())
{
auto pScriptHandle = V8Isolate_CompileProducingCache(handle, std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo, std::move(code), cacheKind, cacheBytes);
cacheResult = !cacheBytes.empty() ? V8CacheResult::Updated : V8CacheResult::UpdateFailed;
return pScriptHandle;
}
V8DocumentInfo documentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo);
auto spIsolate = handle.GetEntity();
if (!spIsolate.IsEmpty())
{
try
{
return new V8ScriptHandle(spIsolate->Compile(documentInfo, std::move(code), cacheKind, cacheBytes, cacheResult));
}
catch (const V8Exception& exception)
{
exception.ScheduleScriptEngineException();
}
}
return nullptr;
}
//-----------------------------------------------------------------------------
NATIVE_ENTRY_POINT(StdBool) V8Isolate_GetEnableInterruptPropagation(const V8IsolateHandle& handle) noexcept
{
auto spIsolate = handle.GetEntity();
@ -1190,9 +1225,9 @@ NATIVE_ENTRY_POINT(void) V8Context_CancelAwaitDebugger(const V8ContextHandle& ha
//-----------------------------------------------------------------------------
NATIVE_ENTRY_POINT(void) V8Context_ExecuteCode(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, StdBool isModule, void* pvDocumentInfo, const StdString& code, StdBool evaluate, V8Value& result) noexcept
NATIVE_ENTRY_POINT(void) V8Context_ExecuteCode(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, const StdString& code, StdBool evaluate, V8Value& result) noexcept
{
V8DocumentInfo documentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, isModule, pvDocumentInfo);
V8DocumentInfo documentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo);
auto spContext = handle.GetEntity();
if (!spContext.IsEmpty())
@ -1210,9 +1245,9 @@ NATIVE_ENTRY_POINT(void) V8Context_ExecuteCode(const V8ContextHandle& handle, St
//-----------------------------------------------------------------------------
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_Compile(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, StdBool isModule, void* pvDocumentInfo, StdString&& code) noexcept
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_Compile(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, StdString&& code) noexcept
{
V8DocumentInfo documentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, isModule, pvDocumentInfo);
V8DocumentInfo documentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo);
auto spContext = handle.GetEntity();
if (!spContext.IsEmpty())
@ -1232,23 +1267,23 @@ NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_Compile(const V8ContextHandle& han
//-----------------------------------------------------------------------------
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_CompileProducingCache(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, StdBool isModule, void* pvDocumentInfo, StdString&& code, V8CacheType cacheType, std::vector<uint8_t>& cacheBytes) noexcept
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_CompileProducingCache(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes) noexcept
{
cacheBytes.clear();
if (cacheType == V8CacheType::None)
if (cacheKind == V8CacheKind::None)
{
return V8Context_Compile(handle, std::move(resourceName), std::move(sourceMapUrl), uniqueId, isModule, pvDocumentInfo, std::move(code));
return V8Context_Compile(handle, std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo, std::move(code));
}
V8DocumentInfo documentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, isModule, pvDocumentInfo);
V8DocumentInfo documentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo);
auto spContext = handle.GetEntity();
if (!spContext.IsEmpty())
{
try
{
return new V8ScriptHandle(spContext->Compile(documentInfo, std::move(code), cacheType, cacheBytes));
return new V8ScriptHandle(spContext->Compile(documentInfo, std::move(code), cacheKind, cacheBytes));
}
catch (const V8Exception& exception)
{
@ -1261,16 +1296,16 @@ NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_CompileProducingCache(const V8Cont
//-----------------------------------------------------------------------------
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_CompileConsumingCache(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, StdBool isModule, void* pvDocumentInfo, StdString&& code, V8CacheType cacheType, const std::vector<uint8_t>& cacheBytes, StdBool& cacheAccepted) noexcept
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_CompileConsumingCache(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, StdString&& code, V8CacheKind cacheKind, const std::vector<uint8_t>& cacheBytes, StdBool& cacheAccepted) noexcept
{
cacheAccepted = false;
if ((cacheType == V8CacheType::None) || cacheBytes.empty())
if ((cacheKind == V8CacheKind::None) || cacheBytes.empty())
{
return V8Context_Compile(handle, std::move(resourceName), std::move(sourceMapUrl), uniqueId, isModule, pvDocumentInfo, std::move(code));
return V8Context_Compile(handle, std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo, std::move(code));
}
V8DocumentInfo documentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, isModule, pvDocumentInfo);
V8DocumentInfo documentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo);
auto spContext = handle.GetEntity();
if (!spContext.IsEmpty())
@ -1278,7 +1313,7 @@ NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_CompileConsumingCache(const V8Cont
try
{
auto tempCacheAccepted = false;
auto pScriptHandle = new V8ScriptHandle(spContext->Compile(documentInfo, std::move(code), cacheType, cacheBytes, tempCacheAccepted));
auto pScriptHandle = new V8ScriptHandle(spContext->Compile(documentInfo, std::move(code), cacheKind, cacheBytes, tempCacheAccepted));
cacheAccepted = tempCacheAccepted;
return pScriptHandle;
@ -1294,6 +1329,41 @@ NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_CompileConsumingCache(const V8Cont
//-----------------------------------------------------------------------------
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_CompileUpdatingCache(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes, V8CacheResult& cacheResult) noexcept
{
if (cacheKind == V8CacheKind::None)
{
cacheResult = V8CacheResult::Disabled;
return V8Context_Compile(handle, std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo, std::move(code));
}
if (cacheBytes.empty())
{
auto pScriptHandle = V8Context_CompileProducingCache(handle, std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo, std::move(code), cacheKind, cacheBytes);
cacheResult = !cacheBytes.empty() ? V8CacheResult::Updated : V8CacheResult::UpdateFailed;
return pScriptHandle;
}
V8DocumentInfo documentInfo(std::move(resourceName), std::move(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo);
auto spContext = handle.GetEntity();
if (!spContext.IsEmpty())
{
try
{
return new V8ScriptHandle(spContext->Compile(documentInfo, std::move(code), cacheKind, cacheBytes, cacheResult));
}
catch (const V8Exception& exception)
{
exception.ScheduleScriptEngineException();
}
}
return nullptr;
}
//-----------------------------------------------------------------------------
NATIVE_ENTRY_POINT(void) V8Context_ExecuteScript(const V8ContextHandle& handle, const V8ScriptHandle& scriptHandle, StdBool evaluate, V8Value& result) noexcept
{
auto spContext = handle.GetEntity();

Просмотреть файл

@ -240,9 +240,10 @@ NATIVE_ENTRY_POINT(size_t) V8Isolate_GetMaxStackUsage(const V8IsolateHandle& han
NATIVE_ENTRY_POINT(void) V8Isolate_SetMaxStackUsage(const V8IsolateHandle& handle, size_t size) noexcept;
NATIVE_ENTRY_POINT(void) V8Isolate_AwaitDebuggerAndPause(const V8IsolateHandle& handle) noexcept;
NATIVE_ENTRY_POINT(void) V8Isolate_CancelAwaitDebugger(const V8IsolateHandle& handle) noexcept;
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_Compile(const V8IsolateHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, StdBool isModule, void* pvDocumentInfo, StdString&& code) noexcept;
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_CompileProducingCache(const V8IsolateHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, StdBool isModule, void* pvDocumentInfo, StdString&& code, V8CacheType cacheType, std::vector<uint8_t>& cacheBytes) noexcept;
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_CompileConsumingCache(const V8IsolateHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, StdBool isModule, void* pvDocumentInfo, StdString&& code, V8CacheType cacheType, const std::vector<uint8_t>& cacheBytes, StdBool& cacheAccepted) noexcept;
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_Compile(const V8IsolateHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, StdString&& code) noexcept;
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_CompileProducingCache(const V8IsolateHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes) noexcept;
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_CompileConsumingCache(const V8IsolateHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, StdString&& code, V8CacheKind cacheKind, const std::vector<uint8_t>& cacheBytes, StdBool& cacheAccepted) noexcept;
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Isolate_CompileUpdatingCache(const V8IsolateHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes, V8CacheResult& cacheResult) noexcept;
NATIVE_ENTRY_POINT(StdBool) V8Isolate_GetEnableInterruptPropagation(const V8IsolateHandle& handle) noexcept;
NATIVE_ENTRY_POINT(void) V8Isolate_SetEnableInterruptPropagation(const V8IsolateHandle& handle, StdBool value) noexcept;
NATIVE_ENTRY_POINT(StdBool) V8Isolate_GetDisableHeapSizeViolationInterrupt(const V8IsolateHandle& handle) noexcept;
@ -268,10 +269,11 @@ NATIVE_ENTRY_POINT(void) V8Context_GetRootItem(const V8ContextHandle& handle, V8
NATIVE_ENTRY_POINT(void) V8Context_AddGlobalItem(const V8ContextHandle& handle, const StdString& name, const V8Value& value, StdBool globalMembers) noexcept;
NATIVE_ENTRY_POINT(void) V8Context_AwaitDebuggerAndPause(const V8ContextHandle& handle) noexcept;
NATIVE_ENTRY_POINT(void) V8Context_CancelAwaitDebugger(const V8ContextHandle& handle) noexcept;
NATIVE_ENTRY_POINT(void) V8Context_ExecuteCode(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, StdBool isModule, void* pvDocumentInfo, const StdString& code, StdBool evaluate, V8Value& result) noexcept;
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_Compile(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, StdBool isModule, void* pvDocumentInfo, StdString&& code) noexcept;
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_CompileProducingCache(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, StdBool isModule, void* pvDocumentInfo, StdString&& code, V8CacheType cacheType, std::vector<uint8_t>& cacheBytes) noexcept;
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_CompileConsumingCache(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, StdBool isModule, void* pvDocumentInfo, StdString&& code, V8CacheType cacheType, const std::vector<uint8_t>& cacheBytes, StdBool& cacheAccepted) noexcept;
NATIVE_ENTRY_POINT(void) V8Context_ExecuteCode(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, const StdString& code, StdBool evaluate, V8Value& result) noexcept;
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_Compile(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, StdString&& code) noexcept;
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_CompileProducingCache(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes) noexcept;
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_CompileConsumingCache(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, StdString&& code, V8CacheKind cacheKind, const std::vector<uint8_t>& cacheBytes, StdBool& cacheAccepted) noexcept;
NATIVE_ENTRY_POINT(V8ScriptHandle*) V8Context_CompileUpdatingCache(const V8ContextHandle& handle, StdString&& resourceName, StdString&& sourceMapUrl, uint64_t uniqueId, DocumentKind documentKind, void* pvDocumentInfo, StdString&& code, V8CacheKind cacheKind, std::vector<uint8_t>& cacheBytes, V8CacheResult& cacheResult) noexcept;
NATIVE_ENTRY_POINT(void) V8Context_ExecuteScript(const V8ContextHandle& handle, const V8ScriptHandle& scriptHandle, StdBool evaluate, V8Value& result) noexcept;
NATIVE_ENTRY_POINT(void) V8Context_Interrupt(const V8ContextHandle& handle) noexcept;
NATIVE_ENTRY_POINT(void) V8Context_CancelInterrupt(const V8ContextHandle& handle) noexcept;

Просмотреть файл

@ -175,7 +175,7 @@
<ClInclude Include="..\SharedPtr.h" />
<ClInclude Include="..\StdString.h" />
<ClInclude Include="..\Timer.h" />
<ClInclude Include="..\V8CacheType.h" />
<ClInclude Include="..\V8CacheTypes.h" />
<ClInclude Include="..\V8Context.h" />
<ClInclude Include="..\V8ContextImpl.h" />
<ClInclude Include="..\V8DocumentInfo.h" />

Просмотреть файл

@ -141,7 +141,7 @@
<ClInclude Include="..\HighResolutionClock.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\V8CacheType.h">
<ClInclude Include="..\V8CacheTypes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\V8DocumentInfo.h">

Просмотреть файл

@ -175,7 +175,7 @@
<ClInclude Include="..\SharedPtr.h" />
<ClInclude Include="..\StdString.h" />
<ClInclude Include="..\Timer.h" />
<ClInclude Include="..\V8CacheType.h" />
<ClInclude Include="..\V8CacheTypes.h" />
<ClInclude Include="..\V8Context.h" />
<ClInclude Include="..\V8ContextImpl.h" />
<ClInclude Include="..\V8DocumentInfo.h" />

Просмотреть файл

@ -141,7 +141,7 @@
<ClInclude Include="..\HighResolutionClock.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\V8CacheType.h">
<ClInclude Include="..\V8CacheTypes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\V8DocumentInfo.h">

Просмотреть файл

@ -174,7 +174,7 @@
<ClInclude Include="..\SharedPtr.h" />
<ClInclude Include="..\StdString.h" />
<ClInclude Include="..\Timer.h" />
<ClInclude Include="..\V8CacheType.h" />
<ClInclude Include="..\V8CacheTypes.h" />
<ClInclude Include="..\V8Context.h" />
<ClInclude Include="..\V8ContextImpl.h" />
<ClInclude Include="..\V8DocumentInfo.h" />

Просмотреть файл

@ -141,7 +141,7 @@
<ClInclude Include="..\HighResolutionClock.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\V8CacheType.h">
<ClInclude Include="..\V8CacheTypes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\V8DocumentInfo.h">

Просмотреть файл

@ -56,6 +56,7 @@
<Compile Include="..\..\ClearScript\DocumentContextCallback.cs" Link="DocumentContextCallback.cs" />
<Compile Include="..\..\ClearScript\DocumentFlags.cs" Link="DocumentFlags.cs" />
<Compile Include="..\..\ClearScript\DocumentInfo.cs" Link="DocumentInfo.cs" />
<Compile Include="..\..\ClearScript\DocumentKind.cs" Link="DocumentKind.cs" />
<Compile Include="..\..\ClearScript\DocumentLoadCallback.cs" Link="DocumentLoadCallback.cs" />
<Compile Include="..\..\ClearScript\DocumentLoader.cs" Link="DocumentLoader.cs" />
<Compile Include="..\..\ClearScript\DocumentSettings.cs" Link="DocumentSettings.cs" />
@ -101,6 +102,7 @@
<Compile Include="..\..\ClearScript\JavaScript\JavaScriptExtensions.NetStandard.cs" Link="JavaScript\JavaScriptExtensions.NetStandard.cs" />
<Compile Include="..\..\ClearScript\JavaScript\JavaScriptObjectFlags.cs" Link="JavaScript\JavaScriptObjectFlags.cs" />
<Compile Include="..\..\ClearScript\JavaScript\JavaScriptObjectKind.cs" Link="JavaScript\JavaScriptObjectKind.cs" />
<Compile Include="..\..\ClearScript\JavaScript\JsonModuleManager.cs" Link="JavaScript\JsonModuleManager.cs" />
<Compile Include="..\..\ClearScript\JavaScript\ModuleCategory.cs" Link="JavaScript\ModuleCategory.cs" />
<Compile Include="..\..\ClearScript\NoDefaultScriptAccessAttribute.cs" Link="NoDefaultScriptAccessAttribute.cs" />
<Compile Include="..\..\ClearScript\NoScriptAccessAttribute.cs" Link="NoScriptAccessAttribute.cs" />
@ -145,7 +147,8 @@
<Compile Include="..\..\ClearScript\Util\Holder.cs" Link="Util\Holder.cs" />
<Compile Include="..\..\ClearScript\Util\IDynamic.cs" Link="Util\IDynamic.cs" />
<Compile Include="..\..\ClearScript\Util\IExpando.cs" Link="Util\IExpando.cs" />
<Compile Include="..\..\ClearScript\Util\IHostInvokeContext.cs" Link="Util\IHostInvokeContext.cs" />
<Compile Include="..\..\ClearScript\Util\IHostContext.cs" Link="Util\IHostContext.cs" />
<Compile Include="..\..\ClearScript\Util\IHostTargetContext.cs" Link="Util\IHostTargetContext.cs" />
<Compile Include="..\..\ClearScript\Util\INativeCallback.cs" Link="Util\INativeCallback.cs" />
<Compile Include="..\..\ClearScript\Util\InvokeHelpers.cs" Link="Util\InvokeHelpers.cs" />
<Compile Include="..\..\ClearScript\Util\IScriptMarshalWrapper.cs" Link="Util\IScriptMarshalWrapper.cs" />

Просмотреть файл

@ -57,6 +57,7 @@
<Compile Include="..\..\ClearScript\V8\V8ArrayBufferOrViewInfo.cs" Link="V8\V8ArrayBufferOrViewInfo.cs" />
<Compile Include="..\..\ClearScript\V8\V8ArrayBufferOrViewKind.cs" Link="V8\V8ArrayBufferOrViewKind.cs" />
<Compile Include="..\..\ClearScript\V8\V8CacheKind.cs" Link="V8\V8CacheKind.cs" />
<Compile Include="..\..\ClearScript\V8\V8CacheResult.cs" Link="V8\V8CacheResult.cs" />
<Compile Include="..\..\ClearScript\V8\V8ContextProxy.cs" Link="V8\V8ContextProxy.cs" />
<Compile Include="..\..\ClearScript\V8\V8CpuProfile.cs" Link="V8\V8CpuProfile.cs" />
<Compile Include="..\..\ClearScript\V8\V8CpuProfileFlags.cs" Link="V8\V8CpuProfileFlags.cs" />
@ -70,6 +71,7 @@
<Compile Include="..\..\ClearScript\V8\V8ProxyHelpers.cs" Link="V8\V8ProxyHelpers.cs" />
<Compile Include="..\..\ClearScript\V8\V8Runtime.cs" Link="V8\V8Runtime.cs" />
<Compile Include="..\..\ClearScript\V8\V8RuntimeConstraints.cs" Link="V8\V8RuntimeConstraints.cs" />
<Compile Include="..\..\ClearScript\V8\V8RuntimeDebuggerEventArgs.cs" Link="V8\V8RuntimeDebuggerEventArgs.cs" />
<Compile Include="..\..\ClearScript\V8\V8RuntimeFlags.cs" Link="V8\V8RuntimeFlags.cs" />
<Compile Include="..\..\ClearScript\V8\V8RuntimeHeapInfo.cs" Link="V8\V8RuntimeHeapInfo.cs" />
<Compile Include="..\..\ClearScript\V8\V8Script.cs" Link="V8\V8Script.cs" />

Просмотреть файл

@ -23,7 +23,6 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<OutputPath>..\..\bin\Debug</OutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
@ -31,7 +30,6 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<OutputPath>..\..\bin\Release</OutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>

Просмотреть файл

@ -178,6 +178,15 @@
<None Include="..\..\ClearScriptTest\JavaScript\General.js" Link="JavaScript\General.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\ClearScriptTest\JavaScript\Object.json" Link="JavaScript\Object.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\ClearScriptTest\JavaScript\Array.json" Link="JavaScript\Array.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\ClearScriptTest\JavaScript\Malformed.json" Link="JavaScript\Malformed.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\ClearScriptTest\JavaScript\LegacyCommonJS\Arithmetic\Arithmetic.js" Link="JavaScript\LegacyCommonJS\Arithmetic\Arithmetic.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

Просмотреть файл

@ -57,6 +57,7 @@
<Compile Include="..\..\ClearScript\DocumentContextCallback.cs" Link="DocumentContextCallback.cs" />
<Compile Include="..\..\ClearScript\DocumentFlags.cs" Link="DocumentFlags.cs" />
<Compile Include="..\..\ClearScript\DocumentInfo.cs" Link="DocumentInfo.cs" />
<Compile Include="..\..\ClearScript\DocumentKind.cs" Link="DocumentKind.cs" />
<Compile Include="..\..\ClearScript\DocumentLoadCallback.cs" Link="DocumentLoadCallback.cs" />
<Compile Include="..\..\ClearScript\DocumentLoader.cs" Link="DocumentLoader.cs" />
<Compile Include="..\..\ClearScript\DocumentSettings.cs" Link="DocumentSettings.cs" />
@ -100,6 +101,7 @@
<Compile Include="..\..\ClearScript\JavaScript\JavaScriptExtensions.cs" Link="JavaScript\JavaScriptExtensions.cs" />
<Compile Include="..\..\ClearScript\JavaScript\JavaScriptObjectFlags.cs" Link="JavaScript\JavaScriptObjectFlags.cs" />
<Compile Include="..\..\ClearScript\JavaScript\JavaScriptObjectKind.cs" Link="JavaScript\JavaScriptObjectKind.cs" />
<Compile Include="..\..\ClearScript\JavaScript\JsonModuleManager.cs" Link="JavaScript\JsonModuleManager.cs" />
<Compile Include="..\..\ClearScript\JavaScript\ModuleCategory.cs" Link="JavaScript\ModuleCategory.cs" />
<Compile Include="..\..\ClearScript\NoDefaultScriptAccessAttribute.cs" Link="NoDefaultScriptAccessAttribute.cs" />
<Compile Include="..\..\ClearScript\NoScriptAccessAttribute.cs" Link="NoScriptAccessAttribute.cs" />
@ -147,7 +149,8 @@
<Compile Include="..\..\ClearScript\Util\EnumerableHelpers.NetFramework.cs" Link="Util\EnumerableHelpers.NetFramework.cs" />
<Compile Include="..\..\ClearScript\Util\Holder.cs" Link="Util\Holder.cs" />
<Compile Include="..\..\ClearScript\Util\IDynamic.cs" Link="Util\IDynamic.cs" />
<Compile Include="..\..\ClearScript\Util\IHostInvokeContext.cs" Link="Util\IHostInvokeContext.cs" />
<Compile Include="..\..\ClearScript\Util\IHostContext.cs" Link="Util\IHostContext.cs" />
<Compile Include="..\..\ClearScript\Util\IHostTargetContext.cs" Link="Util\IHostTargetContext.cs" />
<Compile Include="..\..\ClearScript\Util\INativeCallback.cs" Link="Util\INativeCallback.cs" />
<Compile Include="..\..\ClearScript\Util\InvokeHelpers.cs" Link="Util\InvokeHelpers.cs" />
<Compile Include="..\..\ClearScript\Util\IScriptMarshalWrapper.cs" Link="Util\IScriptMarshalWrapper.cs" />

Просмотреть файл

@ -62,6 +62,7 @@
<Compile Include="..\..\ClearScript\V8\V8ArrayBufferOrViewInfo.cs" Link="V8\V8ArrayBufferOrViewInfo.cs" />
<Compile Include="..\..\ClearScript\V8\V8ArrayBufferOrViewKind.cs" Link="V8\V8ArrayBufferOrViewKind.cs" />
<Compile Include="..\..\ClearScript\V8\V8CacheKind.cs" Link="V8\V8CacheKind.cs" />
<Compile Include="..\..\ClearScript\V8\V8CacheResult.cs" Link="V8\V8CacheResult.cs" />
<Compile Include="..\..\ClearScript\V8\V8ContextProxy.cs" Link="V8\V8ContextProxy.cs" />
<Compile Include="..\..\ClearScript\V8\V8CpuProfile.cs" Link="V8\V8CpuProfile.cs" />
<Compile Include="..\..\ClearScript\V8\V8CpuProfileFlags.cs" Link="V8\V8CpuProfileFlags.cs" />
@ -75,6 +76,7 @@
<Compile Include="..\..\ClearScript\V8\V8ProxyHelpers.cs" Link="V8\V8ProxyHelpers.cs" />
<Compile Include="..\..\ClearScript\V8\V8Runtime.cs" Link="V8\V8Runtime.cs" />
<Compile Include="..\..\ClearScript\V8\V8RuntimeConstraints.cs" Link="V8\V8RuntimeConstraints.cs" />
<Compile Include="..\..\ClearScript\V8\V8RuntimeDebuggerEventArgs.cs" Link="V8\V8RuntimeDebuggerEventArgs.cs" />
<Compile Include="..\..\ClearScript\V8\V8RuntimeFlags.cs" Link="V8\V8RuntimeFlags.cs" />
<Compile Include="..\..\ClearScript\V8\V8RuntimeHeapInfo.cs" Link="V8\V8RuntimeHeapInfo.cs" />
<Compile Include="..\..\ClearScript\V8\V8Script.cs" Link="V8\V8Script.cs" />

Просмотреть файл

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>net471</TargetFramework>
@ -169,6 +169,15 @@
<None Include="..\..\ClearScriptTest\JavaScript\General.js" Link="JavaScript\General.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\ClearScriptTest\JavaScript\Object.json" Link="JavaScript\Object.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\ClearScriptTest\JavaScript\Array.json" Link="JavaScript\Array.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\ClearScriptTest\JavaScript\Malformed.json" Link="JavaScript\Malformed.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\ClearScriptTest\JavaScript\LegacyCommonJS\Arithmetic\Arithmetic.js" Link="JavaScript\LegacyCommonJS\Arithmetic\Arithmetic.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

Просмотреть файл

@ -55,6 +55,7 @@
<Compile Include="..\..\ClearScript\DocumentContextCallback.cs" Link="DocumentContextCallback.cs" />
<Compile Include="..\..\ClearScript\DocumentFlags.cs" Link="DocumentFlags.cs" />
<Compile Include="..\..\ClearScript\DocumentInfo.cs" Link="DocumentInfo.cs" />
<Compile Include="..\..\ClearScript\DocumentKind.cs" Link="DocumentKind.cs" />
<Compile Include="..\..\ClearScript\DocumentLoadCallback.cs" Link="DocumentLoadCallback.cs" />
<Compile Include="..\..\ClearScript\DocumentLoader.cs" Link="DocumentLoader.cs" />
<Compile Include="..\..\ClearScript\DocumentSettings.cs" Link="DocumentSettings.cs" />
@ -100,6 +101,7 @@
<Compile Include="..\..\ClearScript\JavaScript\JavaScriptExtensions.NetStandard.cs" Link="JavaScript\JavaScriptExtensions.NetStandard.cs" />
<Compile Include="..\..\ClearScript\JavaScript\JavaScriptObjectFlags.cs" Link="JavaScript\JavaScriptObjectFlags.cs" />
<Compile Include="..\..\ClearScript\JavaScript\JavaScriptObjectKind.cs" Link="JavaScript\JavaScriptObjectKind.cs" />
<Compile Include="..\..\ClearScript\JavaScript\JsonModuleManager.cs" Link="JavaScript\JsonModuleManager.cs" />
<Compile Include="..\..\ClearScript\JavaScript\ModuleCategory.cs" Link="JavaScript\ModuleCategory.cs" />
<Compile Include="..\..\ClearScript\NoDefaultScriptAccessAttribute.cs" Link="NoDefaultScriptAccessAttribute.cs" />
<Compile Include="..\..\ClearScript\NoScriptAccessAttribute.cs" Link="NoScriptAccessAttribute.cs" />
@ -144,7 +146,8 @@
<Compile Include="..\..\ClearScript\Util\Holder.cs" Link="Util\Holder.cs" />
<Compile Include="..\..\ClearScript\Util\IDynamic.cs" Link="Util\IDynamic.cs" />
<Compile Include="..\..\ClearScript\Util\IExpando.cs" Link="Util\IExpando.cs" />
<Compile Include="..\..\ClearScript\Util\IHostInvokeContext.cs" Link="Util\IHostInvokeContext.cs" />
<Compile Include="..\..\ClearScript\Util\IHostContext.cs" Link="Util\IHostContext.cs" />
<Compile Include="..\..\ClearScript\Util\IHostTargetContext.cs" Link="Util\IHostTargetContext.cs" />
<Compile Include="..\..\ClearScript\Util\INativeCallback.cs" Link="Util\INativeCallback.cs" />
<Compile Include="..\..\ClearScript\Util\InvokeHelpers.cs" Link="Util\InvokeHelpers.cs" />
<Compile Include="..\..\ClearScript\Util\IScriptMarshalWrapper.cs" Link="Util\IScriptMarshalWrapper.cs" />

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше