diff --git a/Directory.Packages.props b/Directory.Packages.props
index c59f121edb..4c694bd49c 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -6,24 +6,33 @@
+
-
+
+
+
+
+
+
-
-
+
+
+
+
+
+
-
diff --git a/Jint.SourceGenerators/FunctionDefinition.cs b/Jint.SourceGenerators/FunctionDefinition.cs
new file mode 100644
index 0000000000..7e85258e41
--- /dev/null
+++ b/Jint.SourceGenerators/FunctionDefinition.cs
@@ -0,0 +1,98 @@
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+
+namespace Jint.SourceGenerators;
+
+internal class FunctionDefinition : IComparable
+{
+ public FunctionDefinition(IMethodSymbol method, AttributeData attribute)
+ {
+ var attributes = SourceGenerationHelper.GetAttributes((AttributeSyntax) attribute.ApplicationSyntaxReference!.GetSyntax());
+ attributes.TryGetValue("Name", out var name);
+ attributes.TryGetValue("Length", out var length);
+
+ if (string.IsNullOrWhiteSpace(name))
+ {
+ name = method.Name;
+ if (char.IsUpper(name[0]))
+ {
+ name = char.ToLowerInvariant(name[0]) + name.Substring(1);
+ }
+ }
+
+ Name = name ?? throw new InvalidOperationException("Could not get name");
+ ClrName = method.Name;
+
+ ProvideThis = method.Parameters.Any(x => x.Name.StartsWith("thisObj"));
+ ProvideArguments = method.Parameters.Any(x => x.Name == "args" || x.Name.StartsWith("arguments"));
+
+ IsStatic = method.IsStatic;
+
+ if (string.IsNullOrWhiteSpace(length))
+ {
+ Length = method.Parameters.Length;
+ if (ProvideThis)
+ {
+ Length--;
+ }
+ }
+ else
+ {
+ Length = Convert.ToInt32(length);
+ }
+
+ ParametersString = "";
+ var needsComma = false;
+ if (ProvideThis)
+ {
+ needsComma = true;
+ ParametersString += "thisObject";
+ }
+
+ var tmp = method.Parameters.Length;
+ if (ProvideThis)
+ {
+ tmp--;
+ }
+
+ if (ProvideArguments)
+ {
+ tmp--;
+ }
+
+ for (var i = 0; i < tmp; ++i)
+ {
+ if (i > 0 || needsComma)
+ {
+ ParametersString += ", ";
+ }
+
+ ParametersString += "arguments.At(" + i + ")";
+ }
+
+ // arguments always last
+ if (ProvideArguments)
+ {
+ if (needsComma)
+ {
+ ParametersString += ", ";
+ }
+ ParametersString += "arguments";
+ }
+ }
+
+ public string Name { get; }
+ public string ClrName { get; }
+ public bool IsStatic { get; }
+ public int Length { get; }
+
+ public bool ProvideThis { get; }
+ public bool ProvideArguments { get; }
+
+ public string ParametersString { get; }
+
+ public int CompareTo(object obj)
+ {
+ return string.Compare(Name, (obj as FunctionDefinition)?.Name, StringComparison.Ordinal);
+ }
+}
diff --git a/Jint.SourceGenerators/Jint.SourceGenerators.csproj b/Jint.SourceGenerators/Jint.SourceGenerators.csproj
new file mode 100644
index 0000000000..01aec40921
--- /dev/null
+++ b/Jint.SourceGenerators/Jint.SourceGenerators.csproj
@@ -0,0 +1,45 @@
+
+
+
+ netstandard2.0
+ enable
+ enable
+ latest
+ true
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $(GetTargetPathDependsOn);GetDependencyTargetPaths
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Jint.SourceGenerators/ObjectDefinition.cs b/Jint.SourceGenerators/ObjectDefinition.cs
new file mode 100644
index 0000000000..e8c5350ec9
--- /dev/null
+++ b/Jint.SourceGenerators/ObjectDefinition.cs
@@ -0,0 +1,60 @@
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+
+namespace Jint.SourceGenerators;
+
+internal class ObjectDefinition
+{
+ public ObjectDefinition(
+ ClassDeclarationSyntax syntax,
+ List functions,
+ List properties)
+ {
+ Namespace = SourceGenerationHelper.GetNamespace(syntax);
+ Name = syntax.Identifier.ToString();
+ Syntax = syntax;
+ Functions = functions;
+ Properties = properties;
+
+ PropertyLookup = SourceGenerationHelper.GenerateLookups(false, this, "str", static (sb, indentStr, item) =>
+ {
+ sb.Append(indentStr);
+ sb.AppendLine(" {");
+ sb.Append(indentStr);
+ sb.Append(" ").Append("match").Append(" = ");
+ sb.Append(item.Accessor);
+ sb.AppendLine(";");
+ }, "_property", 12);
+
+ PropertySet = SourceGenerationHelper.GenerateLookups(false, this, "str", static (sb, indentStr, item) =>
+ {
+ sb.Append(indentStr);
+ sb.AppendLine(" {");
+ sb.Append(indentStr);
+ sb.Append(" ").Append("match").Append(" = ");
+ sb.Append(item.Accessor);
+ sb.AppendLine(";");
+ }, "_property", 12);
+
+ ValueLookup = SourceGenerationHelper.GenerateLookups(true, this, "str", static (sb, indentStr, item) =>
+ {
+ sb.Append(indentStr);
+ sb.AppendLine(" {");
+ sb.Append(indentStr);
+ sb.Append(" ").Append(item.Accessor).Append("_backingField").Append(" = ");
+ sb.Append("value");
+ sb.AppendLine(";");
+ }, "", 12);
+ }
+
+ public string Namespace { get; }
+
+ public string Name { get; }
+ public ClassDeclarationSyntax Syntax { get; }
+
+ public List Functions { get; }
+ public List Properties { get; }
+ public string PropertyLookup { get; }
+ public string PropertySet { get; }
+ public string ValueLookup { get; }
+
+}
diff --git a/Jint.SourceGenerators/ObjectGenerator.cs b/Jint.SourceGenerators/ObjectGenerator.cs
new file mode 100644
index 0000000000..641c9c6bff
--- /dev/null
+++ b/Jint.SourceGenerators/ObjectGenerator.cs
@@ -0,0 +1,166 @@
+using System.Collections.Immutable;
+using System.Text;
+using Fluid;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+using Microsoft.CodeAnalysis.Text;
+
+namespace Jint.SourceGenerators;
+
+[Generator]
+public class ObjectGenerator : IIncrementalGenerator
+{
+ private IFluidTemplate _objectTemplate = null!;
+
+ private const string JsObjectAttribute = "Jint.JsObjectAttribute";
+ private const string JsFunctionAttribute = "Jint.JsFunctionAttribute";
+
+ public void Initialize(IncrementalGeneratorInitializationContext context)
+ {
+ using var stream = new StreamReader(typeof(ObjectGenerator).Assembly.GetManifestResourceStream(typeof(ObjectGenerator), "Templates.JsObject.liquid")!);
+ var template = stream.ReadToEnd();
+
+ var parser = new FluidParser();
+ _objectTemplate = parser.Parse(template);
+
+ context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
+ "Attributes.g.cs", SourceText.From(SourceGenerationHelper.Attributes, Encoding.UTF8)));
+
+ IncrementalValuesProvider classDeclarations = context.SyntaxProvider
+ .CreateSyntaxProvider(
+ predicate: static (s, _) => IsSyntaxTargetForGeneration(s),
+ transform: static (ctx, _) => GetSemanticTargetForGeneration(ctx))
+ .Where(static m => m is not null)!;
+
+ IncrementalValueProvider<(Compilation, ImmutableArray)> compilationAndClasses
+ = context.CompilationProvider.Combine(classDeclarations.Collect());
+
+ context.RegisterSourceOutput(compilationAndClasses,
+ (spc, source) => Execute(source.Item1, source.Item2, spc));
+ }
+
+ private static bool IsSyntaxTargetForGeneration(SyntaxNode node)
+ => node is ClassDeclarationSyntax { AttributeLists.Count: > 0 };
+
+ private static ClassDeclarationSyntax? GetSemanticTargetForGeneration(GeneratorSyntaxContext context)
+ {
+ var classDeclarationSyntax = (ClassDeclarationSyntax) context.Node;
+
+ // loop through all the attributes on the method
+ foreach (AttributeListSyntax attributeListSyntax in classDeclarationSyntax.AttributeLists)
+ {
+ foreach (AttributeSyntax attributeSyntax in attributeListSyntax.Attributes)
+ {
+ var symbolInfo = context.SemanticModel.GetSymbolInfo(attributeSyntax);
+ IMethodSymbol symbol;
+ if (symbolInfo.Symbol is IMethodSymbol methodSymbol)
+ {
+ symbol = methodSymbol;
+ }
+ else if (symbolInfo.CandidateSymbols.Length > 0 && symbolInfo.CandidateSymbols[0] is IMethodSymbol fromCandidate)
+ {
+ symbol = fromCandidate;
+ }
+ else
+ {
+ // weird, we couldn't get the symbol, ignore it
+ continue;
+ }
+
+ INamedTypeSymbol attributeContainingTypeSymbol = symbol.ContainingType;
+ string fullName = attributeContainingTypeSymbol.ToDisplayString();
+
+ // Is the attribute the [JsObject] attribute?
+ if (fullName == JsObjectAttribute)
+ {
+ // return the class
+ return classDeclarationSyntax;
+ }
+ }
+ }
+
+ // we didn't find the attribute we were looking for
+ return null;
+ }
+
+ private void Execute(Compilation compilation, ImmutableArray classes, SourceProductionContext context)
+ {
+ if (classes.IsDefaultOrEmpty)
+ {
+ // nothing to do yet
+ return;
+ }
+
+ var distinctClasses = classes.Distinct();
+ var toGenerate = GetTypesToGenerate(compilation, distinctClasses, context.CancellationToken);
+
+ var templateOptions = new TemplateOptions { MemberAccessStrategy = UnsafeMemberAccessStrategy.Instance };
+ foreach (var target in toGenerate)
+ {
+ // generate the source code and add it to the output
+ var templateContext = new TemplateContext(target, templateOptions);
+ var result = _objectTemplate.Render(templateContext);
+ context.AddSource(target.Name + ".g.cs", SourceText.From(result, Encoding.UTF8));
+ }
+ }
+
+ private static List GetTypesToGenerate(Compilation compilation, IEnumerable classes, CancellationToken ct)
+ {
+ var classesToGenerate = new List();
+ var objectAttribute = compilation.GetTypeByMetadataName(JsObjectAttribute);
+ if (objectAttribute == null)
+ {
+ // nothing to do if this type isn't available
+ return classesToGenerate;
+ }
+
+ foreach (var classDeclarationSyntax in classes)
+ {
+ // stop if we're asked to
+ ct.ThrowIfCancellationRequested();
+
+ SemanticModel semanticModel = compilation.GetSemanticModel(classDeclarationSyntax.SyntaxTree);
+ if (semanticModel.GetDeclaredSymbol(classDeclarationSyntax) is not INamedTypeSymbol classSymbol)
+ {
+ // something went wrong
+ continue;
+ }
+
+ var allMembers = classSymbol.GetMembers();
+ var functions = new List();
+ var properties = new List();
+
+ foreach (ISymbol member in allMembers)
+ {
+ if (member is IMethodSymbol method)
+ {
+ foreach (var attribute in method.GetAttributes())
+ {
+ if (attribute.AttributeClass?.Name == "JsFunctionAttribute")
+ {
+ functions.Add(new FunctionDefinition(method, attribute));
+ break;
+ }
+ }
+ }
+
+ if (member is IPropertySymbol property)
+ {
+ foreach (var attribute in property.GetAttributes())
+ {
+ if (attribute.AttributeClass?.Name == "JsPropertyAttribute")
+ {
+ properties.Add(new PropertyDefinition(property, attribute));
+ break;
+ }
+ }
+ }
+ }
+
+ functions.Sort();
+ classesToGenerate.Add(new ObjectDefinition(classDeclarationSyntax, functions, properties));
+ }
+
+ return classesToGenerate;
+ }
+}
diff --git a/Jint.SourceGenerators/PropertyDefinition.cs b/Jint.SourceGenerators/PropertyDefinition.cs
new file mode 100644
index 0000000000..bb58a8bd2c
--- /dev/null
+++ b/Jint.SourceGenerators/PropertyDefinition.cs
@@ -0,0 +1,38 @@
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+
+namespace Jint.SourceGenerators;
+
+internal class PropertyDefinition : IComparable
+{
+ public PropertyDefinition(IPropertySymbol property, AttributeData attribute)
+ {
+ var attributes = SourceGenerationHelper.GetAttributes((AttributeSyntax) attribute.ApplicationSyntaxReference!.GetSyntax());
+
+ attributes.TryGetValue("Name", out var name);
+
+ if (string.IsNullOrWhiteSpace(name))
+ {
+ name = property.Name;
+ if (char.IsUpper(name[0]))
+ {
+ name = char.ToLowerInvariant(name[0]) + name.Substring(1);
+ }
+ }
+ Name = name ?? throw new InvalidOperationException("Could not get name");
+ ClrName = property.Name;
+ IsStatic = property.IsStatic;
+
+ Accessor = IsStatic ? property.ContainingType.Name + "." + ClrName : ClrName;
+ }
+
+ public string Name { get; }
+ public string ClrName { get; }
+ public string Accessor { get; }
+ public bool IsStatic { get; }
+
+ public int CompareTo(object obj)
+ {
+ return string.Compare(Name, (obj as PropertyDefinition)?.Name, StringComparison.Ordinal);
+ }
+}
\ No newline at end of file
diff --git a/Jint.SourceGenerators/SourceGenerationHelper.cs b/Jint.SourceGenerators/SourceGenerationHelper.cs
new file mode 100644
index 0000000000..aaaf27742c
--- /dev/null
+++ b/Jint.SourceGenerators/SourceGenerationHelper.cs
@@ -0,0 +1,203 @@
+using System.Text;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+
+namespace Jint.SourceGenerators;
+
+///
+/// Helpers from mostly based Andrew Lock's work: https://andrewlock.net/series/creating-a-source-generator/
+///
+internal static class SourceGenerationHelper
+{
+ public const string Attributes = @"
+namespace Jint;
+
+[System.AttributeUsage(System.AttributeTargets.Class)]
+internal class JsObjectAttribute : System.Attribute
+{
+}
+
+[System.AttributeUsage(System.AttributeTargets.Method)]
+internal class JsFunctionAttribute : System.Attribute
+{
+ public string Name { get; set; }
+ public int Length { get; set; }
+}
+
+[System.AttributeUsage(System.AttributeTargets.Property)]
+internal class JsPropertyAttribute : System.Attribute
+{
+ public string Name { get; set; }
+ public Jint.Runtime.Descriptors.PropertyFlag Flags { get; set; }
+}
+";
+
+ ///
+ /// Builds optimized value lookup using known facts about keys.
+ ///
+ internal static string GenerateLookups(
+ bool value,
+ ObjectDefinition obj,
+ string source,
+ Action doAction,
+ string fieldPostfix,
+ int indent)
+ {
+ var sb = new StringBuilder();
+
+ var indentStr = new string(' ', indent);
+
+ sb.Append("switch (");
+ sb.Append(source);
+ sb.AppendLine(".Length)");
+ sb.Append(indentStr);
+ sb.AppendLine("{");
+
+ var definitions = obj.Functions
+ .Select(x => (x.Name, Accessor: "__" + x.Name + fieldPostfix))
+ .Concat(obj.Properties.Select(x => (x.Name, Accessor: value ? x.Accessor : "__" + x.Name + fieldPostfix)));
+
+ foreach (var group in definitions.ToLookup(x => x.Name.Length).OrderBy(x => x.Key))
+ {
+ sb.Append(indentStr);
+ sb.Append(" case ");
+ sb.Append(group.Key);
+ sb.AppendLine(":");
+
+ var discriminatorIndex = group.Count() > 1 ? FindDiscriminatorIndex(group) : -1;
+
+ if (discriminatorIndex != -1)
+ {
+ sb.Append(indentStr);
+ sb.Append(" var disc").Append(group.Key).Append(" = ").Append(source).Append("[").Append(discriminatorIndex).AppendLine("];");
+ }
+ else if (group.Count() > 1)
+ {
+ // going to be slow
+ }
+
+ var first = true;
+ foreach (var item in group)
+ {
+ sb.Append(indentStr);
+ sb.Append(" ");
+ if (!first)
+ {
+ sb.Append("else ");
+ }
+ sb.Append("if (");
+ if (discriminatorIndex != -1)
+ {
+ sb.Append("disc").Append(group.Key).Append(" == '").Append(item.Name[discriminatorIndex]).Append("' && ");
+ }
+ sb.Append(source);
+ sb.Append(" == \"");
+ sb.Append(item.Name);
+ sb.AppendLine("\")");
+
+ doAction(sb, indentStr, item);
+
+ sb.Append(indentStr);
+ sb.AppendLine(" }");
+
+ first = false;
+ }
+
+ sb.AppendLine(" break;");
+ sb.AppendLine();
+ }
+
+
+ sb.AppendLine(" }");
+
+ return sb.ToString();
+ }
+
+ private static int FindDiscriminatorIndex(IGrouping grouping)
+ {
+ var chars = new HashSet();
+ for (var i = 0; i < grouping.Key; ++i)
+ {
+ chars.Clear();
+ var allDifferent = true;
+ foreach (var item in grouping)
+ {
+ allDifferent &= chars.Add(item.Name[i]);
+ if (!allDifferent)
+ {
+ break;
+ }
+ }
+
+ if (allDifferent)
+ {
+ return i;
+ }
+ }
+
+ // not found
+ return -1;
+ }
+
+ // determine the namespace the class/enum/struct is declared in, if any
+ public static string GetNamespace(BaseTypeDeclarationSyntax syntax)
+ {
+ // If we don't have a namespace at all we'll return an empty string
+ // This accounts for the "default namespace" case
+ var nameSpace = string.Empty;
+
+ // Get the containing syntax node for the type declaration
+ // (could be a nested type, for example)
+ var potentialNamespaceParent = syntax.Parent;
+
+ // Keep moving "out" of nested classes etc until we get to a namespace
+ // or until we run out of parents
+ while (potentialNamespaceParent != null &&
+ potentialNamespaceParent is not NamespaceDeclarationSyntax
+ && potentialNamespaceParent is not FileScopedNamespaceDeclarationSyntax)
+ {
+ potentialNamespaceParent = potentialNamespaceParent.Parent;
+ }
+
+ // Build up the final namespace by looping until we no longer have a namespace declaration
+ if (potentialNamespaceParent is BaseNamespaceDeclarationSyntax namespaceParent)
+ {
+ // We have a namespace. Use that as the type
+ nameSpace = namespaceParent.Name.ToString();
+
+ // Keep moving "out" of the namespace declarations until we
+ // run out of nested namespace declarations
+ while (true)
+ {
+ if (namespaceParent.Parent is not NamespaceDeclarationSyntax parent)
+ {
+ break;
+ }
+
+ // Add the outer namespace as a prefix to the final namespace
+ nameSpace = $"{namespaceParent.Name}.{nameSpace}";
+ namespaceParent = parent;
+ }
+ }
+
+ // return the final namespace
+ return nameSpace;
+ }
+
+ public static Dictionary GetAttributes(AttributeSyntax syntax)
+ {
+ var attributes = new Dictionary();
+ foreach (var item in syntax.ChildNodes())
+ {
+ if (item is AttributeArgumentListSyntax arguments)
+ {
+ foreach (var ag in arguments.Arguments)
+ {
+ attributes.Add(ag.NameEquals!.Name.NormalizeWhitespace().ToFullString(), ag!.Expression.ChildTokens().FirstOrDefault().Value?.ToString() ?? "");
+ }
+ }
+ }
+
+ return attributes;
+ }
+}
diff --git a/Jint.SourceGenerators/Templates/JsObject.liquid b/Jint.SourceGenerators/Templates/JsObject.liquid
new file mode 100644
index 0000000000..29f429e63b
--- /dev/null
+++ b/Jint.SourceGenerators/Templates/JsObject.liquid
@@ -0,0 +1,113 @@
+#nullable enable
+
+#pragma warning disable CS0219
+
+using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
+using System.Runtime.CompilerServices;
+
+using Jint.HighPerformance;
+using Jint.Native.Function;
+using Jint.Native.Object;
+using Jint.Runtime;
+using Jint.Runtime.Descriptors;
+using Jint.Runtime.Interop;
+
+namespace {{ Namespace }};
+
+partial class {{ Name }}
+{
+{%- for item in Properties %}
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __{{ item.Name }}_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __{{ item.Name }}_property
+ {
+ [DebuggerStepThrough]
+ get { return __{{ item.Name }}_property_backingField ??= new PropertyDescriptor({% if item.IsStatic %}{{ Name }}.{% endif %}{{ item.ClrName }}, PropertyFlag.AllForbidden); }
+ }
+{% endfor %}
+
+{% for item in Functions %}
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __{{ item.Name }}_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __{{ item.Name }} { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __{{ item.Name }}_backingField ??= new {{ item.ClrName }}Function(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __{{ item.Name }}_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __{{ item.Name }}_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __{{ item.Name }}_property_backingField ??= new PropertyDescriptor(__{{ item.Name }}, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+{% endfor %}
+ protected override void Initialize()
+ {
+ CreateProperties();
+ CreateSymbols();
+ }
+
+ protected override bool TryGetProperty(JsValue property, [NotNullWhen(true)] out PropertyDescriptor? descriptor)
+ {
+ if (property is JsString jsString)
+ {
+ var str = jsString._value;
+ PropertyDescriptor? match = null;
+ {{ PropertyLookup }}
+ if (match is not null)
+ {
+ descriptor = match;
+ return true;
+ }
+ }
+ return base.TryGetProperty(property, out descriptor);
+ }
+
+ public override PropertyDescriptor GetOwnProperty(JsValue property)
+ {
+ if (property is JsString jsString)
+ {
+ var str = jsString._value;
+ PropertyDescriptor? match = null;
+ {{ PropertyLookup }}
+ if (match is not null)
+ {
+ return match;
+ }
+ }
+ return base.GetOwnProperty(property);
+ }
+
+ protected internal override void SetOwnProperty(JsValue property, PropertyDescriptor desc)
+ {
+ if (property is JsString jsString)
+ {
+ var str = jsString._value;
+ PropertyDescriptor? match = null;
+ {{ PropertySet }}
+ if (match is not null)
+ {
+throw new System.Exception("TROUBLE");
+ // return;
+ }
+ }
+ }
+
+{%- for item in Functions %}
+ private sealed class {{ item.ClrName }}Function : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("{{ item.Name }}");
+ private readonly {{ Name }} _host;
+
+ public {{ item.ClrName }}Function({{ Name }} host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create({{ item.Length }}), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+{%- if item.IsStatic %}
+ return {{ Name }}.{{ item.ClrName }}({{ item.ParametersString }});
+{%- else %}
+ return _host.{{ item.ClrName }}({{ item.ParametersString }});
+{%- endif %}
+ }
+
+ public override string ToString() => "function {{ item.Name }}() { [native code] }";
+ }
+{% endfor %}
+}
diff --git a/Jint.Tests.SourceGenerators/Jint.Tests.SourceGenerators.csproj b/Jint.Tests.SourceGenerators/Jint.Tests.SourceGenerators.csproj
new file mode 100644
index 0000000000..218581cd22
--- /dev/null
+++ b/Jint.Tests.SourceGenerators/Jint.Tests.SourceGenerators.csproj
@@ -0,0 +1,25 @@
+
+
+
+ net6.0
+ enable
+ enable
+ latest
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Jint.Tests.SourceGenerators/ModuleInitializer.cs b/Jint.Tests.SourceGenerators/ModuleInitializer.cs
new file mode 100644
index 0000000000..d18f454fef
--- /dev/null
+++ b/Jint.Tests.SourceGenerators/ModuleInitializer.cs
@@ -0,0 +1,12 @@
+using System.Runtime.CompilerServices;
+
+namespace Jint.Tests.SourceGenerators;
+
+public static class ModuleInitializer
+{
+ [ModuleInitializer]
+ public static void Init()
+ {
+ VerifySourceGenerators.Initialize();
+ }
+}
diff --git a/Jint.Tests.SourceGenerators/ObjectGeneratorTests.cs b/Jint.Tests.SourceGenerators/ObjectGeneratorTests.cs
new file mode 100644
index 0000000000..d59b3ca099
--- /dev/null
+++ b/Jint.Tests.SourceGenerators/ObjectGeneratorTests.cs
@@ -0,0 +1,30 @@
+using static Jint.Tests.SourceGenerators.VerifyHelper;
+
+namespace Jint.Tests.SourceGenerators;
+
+[UsesVerify]
+public class ObjectGeneratorTests
+{
+ [Fact]
+ public Task ArrayPrototype()
+ {
+ return VerifyJintSourceFile("Native/Array/ArrayPrototype.cs");
+ }
+
+ [Fact]
+ public Task MathInstance()
+ {
+ return VerifyJintSourceFile("Native/Math/MathInstance.cs");
+ }
+
+ private static Task VerifyJintSourceFile(string file)
+ {
+ var source = File.ReadAllText(ToJintSourcePath(file));
+ return Verify(source);
+ }
+
+ private static string ToJintSourcePath(string path)
+ {
+ return "../../../../Jint/" + path;
+ }
+}
diff --git a/Jint.Tests.SourceGenerators/Snapshots/ObjectGeneratorTests.ArrayPrototype.00.verified.cs b/Jint.Tests.SourceGenerators/Snapshots/ObjectGeneratorTests.ArrayPrototype.00.verified.cs
new file mode 100644
index 0000000000..5e9678e0e5
--- /dev/null
+++ b/Jint.Tests.SourceGenerators/Snapshots/ObjectGeneratorTests.ArrayPrototype.00.verified.cs
@@ -0,0 +1,22 @@
+//HintName: Attributes.g.cs
+
+namespace Jint;
+
+[System.AttributeUsage(System.AttributeTargets.Class)]
+internal class JsObjectAttribute : System.Attribute
+{
+}
+
+[System.AttributeUsage(System.AttributeTargets.Method)]
+internal class JsFunctionAttribute : System.Attribute
+{
+ public string Name { get; set; }
+ public int Length { get; set; }
+}
+
+[System.AttributeUsage(System.AttributeTargets.Property)]
+internal class JsPropertyAttribute : System.Attribute
+{
+ public string Name { get; set; }
+ public Jint.Runtime.Descriptors.PropertyFlag Flags { get; set; }
+}
diff --git a/Jint.Tests.SourceGenerators/Snapshots/ObjectGeneratorTests.ArrayPrototype.01.verified.cs b/Jint.Tests.SourceGenerators/Snapshots/ObjectGeneratorTests.ArrayPrototype.01.verified.cs
new file mode 100644
index 0000000000..dac0cd3ab6
--- /dev/null
+++ b/Jint.Tests.SourceGenerators/Snapshots/ObjectGeneratorTests.ArrayPrototype.01.verified.cs
@@ -0,0 +1,1522 @@
+//HintName: ArrayPrototype.g.cs
+#nullable enable
+
+#pragma warning disable CS0219
+
+using System.Diagnostics;
+using System.Runtime.CompilerServices;
+
+using Jint.HighPerformance;
+using Jint.Native.Function;
+using Jint.Native.Object;
+using Jint.Runtime;
+using Jint.Runtime.Descriptors;
+using Jint.Runtime.Interop;
+
+namespace Jint.Native.Array;
+
+public partial class ArrayPrototype
+{
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __constructor_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __constructor_property
+ {
+ [DebuggerStepThrough]
+ get { return __constructor_property_backingField ??= new PropertyDescriptor(Constructor, PropertyFlag.AllForbidden); }
+ }
+
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __at_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __at { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __at_backingField ??= new AtFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __at_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __at_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __at_property_backingField ??= new PropertyDescriptor(__at, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __concat_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __concat { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __concat_backingField ??= new ConcatFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __concat_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __concat_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __concat_property_backingField ??= new PropertyDescriptor(__concat, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __copyWithin_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __copyWithin { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __copyWithin_backingField ??= new CopyWithinFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __copyWithin_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __copyWithin_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __copyWithin_property_backingField ??= new PropertyDescriptor(__copyWithin, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __entries_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __entries { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __entries_backingField ??= new EntriesFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __entries_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __entries_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __entries_property_backingField ??= new PropertyDescriptor(__entries, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __every_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __every { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __every_backingField ??= new EveryFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __every_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __every_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __every_property_backingField ??= new PropertyDescriptor(__every, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __fill_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __fill { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __fill_backingField ??= new FillFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __fill_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __fill_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __fill_property_backingField ??= new PropertyDescriptor(__fill, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __filter_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __filter { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __filter_backingField ??= new FilterFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __filter_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __filter_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __filter_property_backingField ??= new PropertyDescriptor(__filter, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __find_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __find { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __find_backingField ??= new FindFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __find_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __find_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __find_property_backingField ??= new PropertyDescriptor(__find, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __findIndex_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __findIndex { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __findIndex_backingField ??= new FindIndexFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __findIndex_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __findIndex_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __findIndex_property_backingField ??= new PropertyDescriptor(__findIndex, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __findLast_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __findLast { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __findLast_backingField ??= new FindLastFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __findLast_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __findLast_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __findLast_property_backingField ??= new PropertyDescriptor(__findLast, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __findLastIndex_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __findLastIndex { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __findLastIndex_backingField ??= new FindLastIndexFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __findLastIndex_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __findLastIndex_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __findLastIndex_property_backingField ??= new PropertyDescriptor(__findLastIndex, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __flat_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __flat { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __flat_backingField ??= new FlatFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __flat_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __flat_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __flat_property_backingField ??= new PropertyDescriptor(__flat, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __flatMap_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __flatMap { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __flatMap_backingField ??= new FlatMapFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __flatMap_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __flatMap_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __flatMap_property_backingField ??= new PropertyDescriptor(__flatMap, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __forEach_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __forEach { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __forEach_backingField ??= new ForEachFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __forEach_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __forEach_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __forEach_property_backingField ??= new PropertyDescriptor(__forEach, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __includes_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __includes { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __includes_backingField ??= new IncludesFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __includes_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __includes_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __includes_property_backingField ??= new PropertyDescriptor(__includes, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __indexOf_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __indexOf { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __indexOf_backingField ??= new IndexOfFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __indexOf_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __indexOf_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __indexOf_property_backingField ??= new PropertyDescriptor(__indexOf, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __join_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __join { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __join_backingField ??= new JoinFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __join_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __join_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __join_property_backingField ??= new PropertyDescriptor(__join, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __keys_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __keys { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __keys_backingField ??= new KeysFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __keys_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __keys_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __keys_property_backingField ??= new PropertyDescriptor(__keys, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __lastIndexOf_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __lastIndexOf { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __lastIndexOf_backingField ??= new LastIndexOfFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __lastIndexOf_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __lastIndexOf_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __lastIndexOf_property_backingField ??= new PropertyDescriptor(__lastIndexOf, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __map_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __map { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __map_backingField ??= new MapFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __map_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __map_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __map_property_backingField ??= new PropertyDescriptor(__map, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __pop_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __pop { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __pop_backingField ??= new PopFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __pop_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __pop_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __pop_property_backingField ??= new PropertyDescriptor(__pop, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __push_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __push { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __push_backingField ??= new PushFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __push_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __push_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __push_property_backingField ??= new PropertyDescriptor(__push, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __reduce_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __reduce { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __reduce_backingField ??= new ReduceFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __reduce_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __reduce_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __reduce_property_backingField ??= new PropertyDescriptor(__reduce, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __reduceRight_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __reduceRight { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __reduceRight_backingField ??= new ReduceRightFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __reduceRight_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __reduceRight_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __reduceRight_property_backingField ??= new PropertyDescriptor(__reduceRight, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __reverse_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __reverse { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __reverse_backingField ??= new ReverseFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __reverse_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __reverse_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __reverse_property_backingField ??= new PropertyDescriptor(__reverse, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __shift_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __shift { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __shift_backingField ??= new ShiftFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __shift_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __shift_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __shift_property_backingField ??= new PropertyDescriptor(__shift, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __slice_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __slice { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __slice_backingField ??= new SliceFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __slice_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __slice_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __slice_property_backingField ??= new PropertyDescriptor(__slice, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __some_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __some { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __some_backingField ??= new SomeFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __some_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __some_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __some_property_backingField ??= new PropertyDescriptor(__some, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __sort_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __sort { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __sort_backingField ??= new SortFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __sort_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __sort_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __sort_property_backingField ??= new PropertyDescriptor(__sort, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __splice_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __splice { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __splice_backingField ??= new SpliceFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __splice_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __splice_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __splice_property_backingField ??= new PropertyDescriptor(__splice, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __toLocaleString_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __toLocaleString { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __toLocaleString_backingField ??= new ToLocaleStringFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __toLocaleString_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __toLocaleString_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __toLocaleString_property_backingField ??= new PropertyDescriptor(__toLocaleString, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __toString_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __toString { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __toString_backingField ??= new ToStringFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __toString_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __toString_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __toString_property_backingField ??= new PropertyDescriptor(__toString, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __unshift_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __unshift { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __unshift_backingField ??= new UnshiftFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __unshift_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __unshift_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __unshift_property_backingField ??= new PropertyDescriptor(__unshift, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __values_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __values { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __values_backingField ??= new ValuesFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __values_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __values_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __values_property_backingField ??= new PropertyDescriptor(__values, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ protected override void Initialize()
+ {
+ CreateProperties();
+ CreateSymbols();
+ }
+
+ protected override bool TryGetProperty(JsValue property, out PropertyDescriptor? descriptor)
+ {
+ if (property is JsString jsString)
+ {
+ var str = jsString._value;
+ PropertyDescriptor? match = null;
+ switch (str.Length)
+ {
+ case 2:
+ if (str == "at")
+ {
+ match = __at_property;
+ }
+ break;
+
+ case 3:
+ var disc3 = str[0];
+ if (disc3 == 'm' && str == "map")
+ {
+ match = __map_property;
+ }
+ else if (disc3 == 'p' && str == "pop")
+ {
+ match = __pop_property;
+ }
+ break;
+
+ case 4:
+ var disc4 = str[2];
+ if (disc4 == 'l' && str == "fill")
+ {
+ match = __fill_property;
+ }
+ else if (disc4 == 'n' && str == "find")
+ {
+ match = __find_property;
+ }
+ else if (disc4 == 'a' && str == "flat")
+ {
+ match = __flat_property;
+ }
+ else if (disc4 == 'i' && str == "join")
+ {
+ match = __join_property;
+ }
+ else if (disc4 == 'y' && str == "keys")
+ {
+ match = __keys_property;
+ }
+ else if (disc4 == 's' && str == "push")
+ {
+ match = __push_property;
+ }
+ else if (disc4 == 'm' && str == "some")
+ {
+ match = __some_property;
+ }
+ else if (disc4 == 'r' && str == "sort")
+ {
+ match = __sort_property;
+ }
+ break;
+
+ case 5:
+ var disc5 = str[1];
+ if (disc5 == 'v' && str == "every")
+ {
+ match = __every_property;
+ }
+ else if (disc5 == 'h' && str == "shift")
+ {
+ match = __shift_property;
+ }
+ else if (disc5 == 'l' && str == "slice")
+ {
+ match = __slice_property;
+ }
+ break;
+
+ case 6:
+ var disc6 = str[0];
+ if (disc6 == 'c' && str == "concat")
+ {
+ match = __concat_property;
+ }
+ else if (disc6 == 'f' && str == "filter")
+ {
+ match = __filter_property;
+ }
+ else if (disc6 == 'r' && str == "reduce")
+ {
+ match = __reduce_property;
+ }
+ else if (disc6 == 's' && str == "splice")
+ {
+ match = __splice_property;
+ }
+ else if (disc6 == 'v' && str == "values")
+ {
+ match = __values_property;
+ }
+ break;
+
+ case 7:
+ var disc7 = str[2];
+ if (disc7 == 't' && str == "entries")
+ {
+ match = __entries_property;
+ }
+ else if (disc7 == 'a' && str == "flatMap")
+ {
+ match = __flatMap_property;
+ }
+ else if (disc7 == 'r' && str == "forEach")
+ {
+ match = __forEach_property;
+ }
+ else if (disc7 == 'd' && str == "indexOf")
+ {
+ match = __indexOf_property;
+ }
+ else if (disc7 == 'v' && str == "reverse")
+ {
+ match = __reverse_property;
+ }
+ else if (disc7 == 's' && str == "unshift")
+ {
+ match = __unshift_property;
+ }
+ break;
+
+ case 8:
+ var disc8 = str[0];
+ if (disc8 == 'f' && str == "findLast")
+ {
+ match = __findLast_property;
+ }
+ else if (disc8 == 'i' && str == "includes")
+ {
+ match = __includes_property;
+ }
+ else if (disc8 == 't' && str == "toString")
+ {
+ match = __toString_property;
+ }
+ break;
+
+ case 9:
+ if (str == "findIndex")
+ {
+ match = __findIndex_property;
+ }
+ break;
+
+ case 10:
+ if (str == "copyWithin")
+ {
+ match = __copyWithin_property;
+ }
+ break;
+
+ case 11:
+ var disc11 = str[0];
+ if (disc11 == 'l' && str == "lastIndexOf")
+ {
+ match = __lastIndexOf_property;
+ }
+ else if (disc11 == 'r' && str == "reduceRight")
+ {
+ match = __reduceRight_property;
+ }
+ else if (disc11 == 'c' && str == "constructor")
+ {
+ match = __constructor_property;
+ }
+ break;
+
+ case 13:
+ if (str == "findLastIndex")
+ {
+ match = __findLastIndex_property;
+ }
+ break;
+
+ case 14:
+ if (str == "toLocaleString")
+ {
+ match = __toLocaleString_property;
+ }
+ break;
+
+ }
+
+ if (match is not null)
+ {
+ descriptor = match;
+ return true;
+ }
+ }
+ return base.TryGetProperty(property, out descriptor);
+ }
+
+ public override PropertyDescriptor GetOwnProperty(JsValue property)
+ {
+ if (property is JsString jsString)
+ {
+ var str = jsString._value;
+ PropertyDescriptor? match = null;
+ switch (str.Length)
+ {
+ case 2:
+ if (str == "at")
+ {
+ match = __at_property;
+ }
+ break;
+
+ case 3:
+ var disc3 = str[0];
+ if (disc3 == 'm' && str == "map")
+ {
+ match = __map_property;
+ }
+ else if (disc3 == 'p' && str == "pop")
+ {
+ match = __pop_property;
+ }
+ break;
+
+ case 4:
+ var disc4 = str[2];
+ if (disc4 == 'l' && str == "fill")
+ {
+ match = __fill_property;
+ }
+ else if (disc4 == 'n' && str == "find")
+ {
+ match = __find_property;
+ }
+ else if (disc4 == 'a' && str == "flat")
+ {
+ match = __flat_property;
+ }
+ else if (disc4 == 'i' && str == "join")
+ {
+ match = __join_property;
+ }
+ else if (disc4 == 'y' && str == "keys")
+ {
+ match = __keys_property;
+ }
+ else if (disc4 == 's' && str == "push")
+ {
+ match = __push_property;
+ }
+ else if (disc4 == 'm' && str == "some")
+ {
+ match = __some_property;
+ }
+ else if (disc4 == 'r' && str == "sort")
+ {
+ match = __sort_property;
+ }
+ break;
+
+ case 5:
+ var disc5 = str[1];
+ if (disc5 == 'v' && str == "every")
+ {
+ match = __every_property;
+ }
+ else if (disc5 == 'h' && str == "shift")
+ {
+ match = __shift_property;
+ }
+ else if (disc5 == 'l' && str == "slice")
+ {
+ match = __slice_property;
+ }
+ break;
+
+ case 6:
+ var disc6 = str[0];
+ if (disc6 == 'c' && str == "concat")
+ {
+ match = __concat_property;
+ }
+ else if (disc6 == 'f' && str == "filter")
+ {
+ match = __filter_property;
+ }
+ else if (disc6 == 'r' && str == "reduce")
+ {
+ match = __reduce_property;
+ }
+ else if (disc6 == 's' && str == "splice")
+ {
+ match = __splice_property;
+ }
+ else if (disc6 == 'v' && str == "values")
+ {
+ match = __values_property;
+ }
+ break;
+
+ case 7:
+ var disc7 = str[2];
+ if (disc7 == 't' && str == "entries")
+ {
+ match = __entries_property;
+ }
+ else if (disc7 == 'a' && str == "flatMap")
+ {
+ match = __flatMap_property;
+ }
+ else if (disc7 == 'r' && str == "forEach")
+ {
+ match = __forEach_property;
+ }
+ else if (disc7 == 'd' && str == "indexOf")
+ {
+ match = __indexOf_property;
+ }
+ else if (disc7 == 'v' && str == "reverse")
+ {
+ match = __reverse_property;
+ }
+ else if (disc7 == 's' && str == "unshift")
+ {
+ match = __unshift_property;
+ }
+ break;
+
+ case 8:
+ var disc8 = str[0];
+ if (disc8 == 'f' && str == "findLast")
+ {
+ match = __findLast_property;
+ }
+ else if (disc8 == 'i' && str == "includes")
+ {
+ match = __includes_property;
+ }
+ else if (disc8 == 't' && str == "toString")
+ {
+ match = __toString_property;
+ }
+ break;
+
+ case 9:
+ if (str == "findIndex")
+ {
+ match = __findIndex_property;
+ }
+ break;
+
+ case 10:
+ if (str == "copyWithin")
+ {
+ match = __copyWithin_property;
+ }
+ break;
+
+ case 11:
+ var disc11 = str[0];
+ if (disc11 == 'l' && str == "lastIndexOf")
+ {
+ match = __lastIndexOf_property;
+ }
+ else if (disc11 == 'r' && str == "reduceRight")
+ {
+ match = __reduceRight_property;
+ }
+ else if (disc11 == 'c' && str == "constructor")
+ {
+ match = __constructor_property;
+ }
+ break;
+
+ case 13:
+ if (str == "findLastIndex")
+ {
+ match = __findLastIndex_property;
+ }
+ break;
+
+ case 14:
+ if (str == "toLocaleString")
+ {
+ match = __toLocaleString_property;
+ }
+ break;
+
+ }
+
+ if (match is not null)
+ {
+ return match;
+ }
+ }
+ return base.GetOwnProperty(property);
+ }
+
+ protected internal override void SetOwnProperty(JsValue property, PropertyDescriptor desc)
+ {
+ if (property is JsString jsString)
+ {
+ var str = jsString._value;
+ PropertyDescriptor? match = null;
+ switch (str.Length)
+ {
+ case 2:
+ if (str == "at")
+ {
+ match = __at_property;
+ }
+ break;
+
+ case 3:
+ var disc3 = str[0];
+ if (disc3 == 'm' && str == "map")
+ {
+ match = __map_property;
+ }
+ else if (disc3 == 'p' && str == "pop")
+ {
+ match = __pop_property;
+ }
+ break;
+
+ case 4:
+ var disc4 = str[2];
+ if (disc4 == 'l' && str == "fill")
+ {
+ match = __fill_property;
+ }
+ else if (disc4 == 'n' && str == "find")
+ {
+ match = __find_property;
+ }
+ else if (disc4 == 'a' && str == "flat")
+ {
+ match = __flat_property;
+ }
+ else if (disc4 == 'i' && str == "join")
+ {
+ match = __join_property;
+ }
+ else if (disc4 == 'y' && str == "keys")
+ {
+ match = __keys_property;
+ }
+ else if (disc4 == 's' && str == "push")
+ {
+ match = __push_property;
+ }
+ else if (disc4 == 'm' && str == "some")
+ {
+ match = __some_property;
+ }
+ else if (disc4 == 'r' && str == "sort")
+ {
+ match = __sort_property;
+ }
+ break;
+
+ case 5:
+ var disc5 = str[1];
+ if (disc5 == 'v' && str == "every")
+ {
+ match = __every_property;
+ }
+ else if (disc5 == 'h' && str == "shift")
+ {
+ match = __shift_property;
+ }
+ else if (disc5 == 'l' && str == "slice")
+ {
+ match = __slice_property;
+ }
+ break;
+
+ case 6:
+ var disc6 = str[0];
+ if (disc6 == 'c' && str == "concat")
+ {
+ match = __concat_property;
+ }
+ else if (disc6 == 'f' && str == "filter")
+ {
+ match = __filter_property;
+ }
+ else if (disc6 == 'r' && str == "reduce")
+ {
+ match = __reduce_property;
+ }
+ else if (disc6 == 's' && str == "splice")
+ {
+ match = __splice_property;
+ }
+ else if (disc6 == 'v' && str == "values")
+ {
+ match = __values_property;
+ }
+ break;
+
+ case 7:
+ var disc7 = str[2];
+ if (disc7 == 't' && str == "entries")
+ {
+ match = __entries_property;
+ }
+ else if (disc7 == 'a' && str == "flatMap")
+ {
+ match = __flatMap_property;
+ }
+ else if (disc7 == 'r' && str == "forEach")
+ {
+ match = __forEach_property;
+ }
+ else if (disc7 == 'd' && str == "indexOf")
+ {
+ match = __indexOf_property;
+ }
+ else if (disc7 == 'v' && str == "reverse")
+ {
+ match = __reverse_property;
+ }
+ else if (disc7 == 's' && str == "unshift")
+ {
+ match = __unshift_property;
+ }
+ break;
+
+ case 8:
+ var disc8 = str[0];
+ if (disc8 == 'f' && str == "findLast")
+ {
+ match = __findLast_property;
+ }
+ else if (disc8 == 'i' && str == "includes")
+ {
+ match = __includes_property;
+ }
+ else if (disc8 == 't' && str == "toString")
+ {
+ match = __toString_property;
+ }
+ break;
+
+ case 9:
+ if (str == "findIndex")
+ {
+ match = __findIndex_property;
+ }
+ break;
+
+ case 10:
+ if (str == "copyWithin")
+ {
+ match = __copyWithin_property;
+ }
+ break;
+
+ case 11:
+ var disc11 = str[0];
+ if (disc11 == 'l' && str == "lastIndexOf")
+ {
+ match = __lastIndexOf_property;
+ }
+ else if (disc11 == 'r' && str == "reduceRight")
+ {
+ match = __reduceRight_property;
+ }
+ else if (disc11 == 'c' && str == "constructor")
+ {
+ match = __constructor_property;
+ }
+ break;
+
+ case 13:
+ if (str == "findLastIndex")
+ {
+ match = __findLastIndex_property;
+ }
+ break;
+
+ case 14:
+ if (str == "toLocaleString")
+ {
+ match = __toLocaleString_property;
+ }
+ break;
+
+ }
+
+ if (match is not null)
+ {
+throw new System.Exception("TROUBLE");
+ // return;
+ }
+ }
+ }
+ private sealed class AtFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("at");
+ private readonly ArrayPrototype _host;
+
+ public AtFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.At(thisObject, arguments.At(0));
+ }
+
+ public override string ToString() => "function at() { [native code] }";
+ }
+
+ private sealed class ConcatFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("concat");
+ private readonly ArrayPrototype _host;
+
+ public ConcatFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Concat(thisObject, arguments);
+ }
+
+ public override string ToString() => "function concat() { [native code] }";
+ }
+
+ private sealed class CopyWithinFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("copyWithin");
+ private readonly ArrayPrototype _host;
+
+ public CopyWithinFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(99), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.CopyWithin(thisObject, arguments.At(0), arguments.At(1), arguments.At(2));
+ }
+
+ public override string ToString() => "function copyWithin() { [native code] }";
+ }
+
+ private sealed class EntriesFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("entries");
+ private readonly ArrayPrototype _host;
+
+ public EntriesFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(0), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Entries(thisObject);
+ }
+
+ public override string ToString() => "function entries() { [native code] }";
+ }
+
+ private sealed class EveryFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("every");
+ private readonly ArrayPrototype _host;
+
+ public EveryFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Every(thisObject, arguments.At(0), arguments.At(1));
+ }
+
+ public override string ToString() => "function every() { [native code] }";
+ }
+
+ private sealed class FillFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("fill");
+ private readonly ArrayPrototype _host;
+
+ public FillFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Fill(thisObject, arguments.At(0), arguments.At(1), arguments.At(2));
+ }
+
+ public override string ToString() => "function fill() { [native code] }";
+ }
+
+ private sealed class FilterFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("filter");
+ private readonly ArrayPrototype _host;
+
+ public FilterFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Filter(thisObject, arguments.At(0), arguments.At(1));
+ }
+
+ public override string ToString() => "function filter() { [native code] }";
+ }
+
+ private sealed class FindFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("find");
+ private readonly ArrayPrototype _host;
+
+ public FindFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Find(thisObject, arguments);
+ }
+
+ public override string ToString() => "function find() { [native code] }";
+ }
+
+ private sealed class FindIndexFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("findIndex");
+ private readonly ArrayPrototype _host;
+
+ public FindIndexFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.FindIndex(thisObject, arguments);
+ }
+
+ public override string ToString() => "function findIndex() { [native code] }";
+ }
+
+ private sealed class FindLastFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("findLast");
+ private readonly ArrayPrototype _host;
+
+ public FindLastFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.FindLast(thisObject, arguments);
+ }
+
+ public override string ToString() => "function findLast() { [native code] }";
+ }
+
+ private sealed class FindLastIndexFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("findLastIndex");
+ private readonly ArrayPrototype _host;
+
+ public FindLastIndexFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.FindLastIndex(thisObject, arguments);
+ }
+
+ public override string ToString() => "function findLastIndex() { [native code] }";
+ }
+
+ private sealed class FlatFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("flat");
+ private readonly ArrayPrototype _host;
+
+ public FlatFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(0), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Flat(thisObject, arguments.At(0));
+ }
+
+ public override string ToString() => "function flat() { [native code] }";
+ }
+
+ private sealed class FlatMapFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("flatMap");
+ private readonly ArrayPrototype _host;
+
+ public FlatMapFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.FlatMap(thisObject, arguments.At(0), arguments.At(1));
+ }
+
+ public override string ToString() => "function flatMap() { [native code] }";
+ }
+
+ private sealed class ForEachFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("forEach");
+ private readonly ArrayPrototype _host;
+
+ public ForEachFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(2), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.ForEach(thisObject, arguments.At(0), arguments.At(1));
+ }
+
+ public override string ToString() => "function forEach() { [native code] }";
+ }
+
+ private sealed class IncludesFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("includes");
+ private readonly ArrayPrototype _host;
+
+ public IncludesFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Includes(thisObject, arguments.At(0), arguments.At(1));
+ }
+
+ public override string ToString() => "function includes() { [native code] }";
+ }
+
+ private sealed class IndexOfFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("indexOf");
+ private readonly ArrayPrototype _host;
+
+ public IndexOfFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.IndexOf(thisObject, arguments);
+ }
+
+ public override string ToString() => "function indexOf() { [native code] }";
+ }
+
+ private sealed class JoinFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("join");
+ private readonly ArrayPrototype _host;
+
+ public JoinFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Join(thisObject, arguments.At(0));
+ }
+
+ public override string ToString() => "function join() { [native code] }";
+ }
+
+ private sealed class KeysFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("keys");
+ private readonly ArrayPrototype _host;
+
+ public KeysFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(0), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Keys(thisObject);
+ }
+
+ public override string ToString() => "function keys() { [native code] }";
+ }
+
+ private sealed class LastIndexOfFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("lastIndexOf");
+ private readonly ArrayPrototype _host;
+
+ public LastIndexOfFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.LastIndexOf(thisObject, arguments);
+ }
+
+ public override string ToString() => "function lastIndexOf() { [native code] }";
+ }
+
+ private sealed class MapFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("map");
+ private readonly ArrayPrototype _host;
+
+ public MapFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Map(thisObject, arguments);
+ }
+
+ public override string ToString() => "function map() { [native code] }";
+ }
+
+ private sealed class PopFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("pop");
+ private readonly ArrayPrototype _host;
+
+ public PopFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(0), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Pop(thisObject);
+ }
+
+ public override string ToString() => "function pop() { [native code] }";
+ }
+
+ private sealed class PushFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("push");
+ private readonly ArrayPrototype _host;
+
+ public PushFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Push(thisObject, arguments);
+ }
+
+ public override string ToString() => "function push() { [native code] }";
+ }
+
+ private sealed class ReduceFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("reduce");
+ private readonly ArrayPrototype _host;
+
+ public ReduceFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Reduce(thisObject, arguments);
+ }
+
+ public override string ToString() => "function reduce() { [native code] }";
+ }
+
+ private sealed class ReduceRightFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("reduceRight");
+ private readonly ArrayPrototype _host;
+
+ public ReduceRightFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(2), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.ReduceRight(thisObject, arguments);
+ }
+
+ public override string ToString() => "function reduceRight() { [native code] }";
+ }
+
+ private sealed class ReverseFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("reverse");
+ private readonly ArrayPrototype _host;
+
+ public ReverseFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(0), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Reverse(thisObject);
+ }
+
+ public override string ToString() => "function reverse() { [native code] }";
+ }
+
+ private sealed class ShiftFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("shift");
+ private readonly ArrayPrototype _host;
+
+ public ShiftFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(0), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Shift(thisObject);
+ }
+
+ public override string ToString() => "function shift() { [native code] }";
+ }
+
+ private sealed class SliceFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("slice");
+ private readonly ArrayPrototype _host;
+
+ public SliceFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(2), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Slice(thisObject, arguments);
+ }
+
+ public override string ToString() => "function slice() { [native code] }";
+ }
+
+ private sealed class SomeFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("some");
+ private readonly ArrayPrototype _host;
+
+ public SomeFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Some(thisObject, arguments);
+ }
+
+ public override string ToString() => "function some() { [native code] }";
+ }
+
+ private sealed class SortFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("sort");
+ private readonly ArrayPrototype _host;
+
+ public SortFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Sort(thisObject, arguments);
+ }
+
+ public override string ToString() => "function sort() { [native code] }";
+ }
+
+ private sealed class SpliceFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("splice");
+ private readonly ArrayPrototype _host;
+
+ public SpliceFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(3), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Splice(thisObject, arguments.At(0), arguments.At(1), arguments);
+ }
+
+ public override string ToString() => "function splice() { [native code] }";
+ }
+
+ private sealed class ToLocaleStringFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("toLocaleString");
+ private readonly ArrayPrototype _host;
+
+ public ToLocaleStringFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(0), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.ToLocaleString(thisObject);
+ }
+
+ public override string ToString() => "function toLocaleString() { [native code] }";
+ }
+
+ private sealed class ToStringFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("toString");
+ private readonly ArrayPrototype _host;
+
+ public ToStringFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(0), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.ToString(thisObject, arguments);
+ }
+
+ public override string ToString() => "function toString() { [native code] }";
+ }
+
+ private sealed class UnshiftFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("unshift");
+ private readonly ArrayPrototype _host;
+
+ public UnshiftFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Unshift(thisObject, arguments);
+ }
+
+ public override string ToString() => "function unshift() { [native code] }";
+ }
+
+ private sealed class ValuesFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("values");
+ private readonly ArrayPrototype _host;
+
+ public ValuesFunction(ArrayPrototype host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(0), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Values(thisObject, arguments);
+ }
+
+ public override string ToString() => "function values() { [native code] }";
+ }
+
+}
diff --git a/Jint.Tests.SourceGenerators/Snapshots/ObjectGeneratorTests.MathInstance.00.verified.cs b/Jint.Tests.SourceGenerators/Snapshots/ObjectGeneratorTests.MathInstance.00.verified.cs
new file mode 100644
index 0000000000..5e9678e0e5
--- /dev/null
+++ b/Jint.Tests.SourceGenerators/Snapshots/ObjectGeneratorTests.MathInstance.00.verified.cs
@@ -0,0 +1,22 @@
+//HintName: Attributes.g.cs
+
+namespace Jint;
+
+[System.AttributeUsage(System.AttributeTargets.Class)]
+internal class JsObjectAttribute : System.Attribute
+{
+}
+
+[System.AttributeUsage(System.AttributeTargets.Method)]
+internal class JsFunctionAttribute : System.Attribute
+{
+ public string Name { get; set; }
+ public int Length { get; set; }
+}
+
+[System.AttributeUsage(System.AttributeTargets.Property)]
+internal class JsPropertyAttribute : System.Attribute
+{
+ public string Name { get; set; }
+ public Jint.Runtime.Descriptors.PropertyFlag Flags { get; set; }
+}
diff --git a/Jint.Tests.SourceGenerators/Snapshots/ObjectGeneratorTests.MathInstance.01.verified.cs b/Jint.Tests.SourceGenerators/Snapshots/ObjectGeneratorTests.MathInstance.01.verified.cs
new file mode 100644
index 0000000000..2650ce5889
--- /dev/null
+++ b/Jint.Tests.SourceGenerators/Snapshots/ObjectGeneratorTests.MathInstance.01.verified.cs
@@ -0,0 +1,1554 @@
+//HintName: MathInstance.g.cs
+#nullable enable
+
+#pragma warning disable CS0219
+
+using System.Diagnostics;
+using System.Runtime.CompilerServices;
+
+using Jint.HighPerformance;
+using Jint.Native.Function;
+using Jint.Native.Object;
+using Jint.Runtime;
+using Jint.Runtime.Descriptors;
+using Jint.Runtime.Interop;
+
+namespace Jint.Native.Math;
+
+public partial class MathInstance
+{
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __E_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __E_property
+ {
+ [DebuggerStepThrough]
+ get { return __E_property_backingField ??= new PropertyDescriptor(MathInstance.E, PropertyFlag.AllForbidden); }
+ }
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __LN10_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __LN10_property
+ {
+ [DebuggerStepThrough]
+ get { return __LN10_property_backingField ??= new PropertyDescriptor(MathInstance.LN10, PropertyFlag.AllForbidden); }
+ }
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __LN2_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __LN2_property
+ {
+ [DebuggerStepThrough]
+ get { return __LN2_property_backingField ??= new PropertyDescriptor(MathInstance.LN2, PropertyFlag.AllForbidden); }
+ }
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __LOG2E_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __LOG2E_property
+ {
+ [DebuggerStepThrough]
+ get { return __LOG2E_property_backingField ??= new PropertyDescriptor(MathInstance.LOG2E, PropertyFlag.AllForbidden); }
+ }
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __LOG10E_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __LOG10E_property
+ {
+ [DebuggerStepThrough]
+ get { return __LOG10E_property_backingField ??= new PropertyDescriptor(MathInstance.LOG10E, PropertyFlag.AllForbidden); }
+ }
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __PI_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __PI_property
+ {
+ [DebuggerStepThrough]
+ get { return __PI_property_backingField ??= new PropertyDescriptor(MathInstance.PI, PropertyFlag.AllForbidden); }
+ }
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __SQRT1_2_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __SQRT1_2_property
+ {
+ [DebuggerStepThrough]
+ get { return __SQRT1_2_property_backingField ??= new PropertyDescriptor(MathInstance.SQRT1_2, PropertyFlag.AllForbidden); }
+ }
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __SQRT2_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __SQRT2_property
+ {
+ [DebuggerStepThrough]
+ get { return __SQRT2_property_backingField ??= new PropertyDescriptor(MathInstance.SQRT2, PropertyFlag.AllForbidden); }
+ }
+
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __abs_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __abs { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __abs_backingField ??= new AbsFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __abs_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __abs_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __abs_property_backingField ??= new PropertyDescriptor(__abs, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __acos_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __acos { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __acos_backingField ??= new AcosFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __acos_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __acos_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __acos_property_backingField ??= new PropertyDescriptor(__acos, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __acosh_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __acosh { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __acosh_backingField ??= new AcoshFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __acosh_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __acosh_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __acosh_property_backingField ??= new PropertyDescriptor(__acosh, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __asin_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __asin { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __asin_backingField ??= new AsinFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __asin_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __asin_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __asin_property_backingField ??= new PropertyDescriptor(__asin, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __asinh_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __asinh { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __asinh_backingField ??= new AsinhFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __asinh_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __asinh_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __asinh_property_backingField ??= new PropertyDescriptor(__asinh, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __atan_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __atan { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __atan_backingField ??= new AtanFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __atan_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __atan_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __atan_property_backingField ??= new PropertyDescriptor(__atan, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __atan2_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __atan2 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __atan2_backingField ??= new Atan2Function(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __atan2_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __atan2_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __atan2_property_backingField ??= new PropertyDescriptor(__atan2, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __atanh_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __atanh { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __atanh_backingField ??= new AtanhFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __atanh_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __atanh_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __atanh_property_backingField ??= new PropertyDescriptor(__atanh, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __cbrt_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __cbrt { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __cbrt_backingField ??= new CbrtFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __cbrt_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __cbrt_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __cbrt_property_backingField ??= new PropertyDescriptor(__cbrt, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __ceil_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __ceil { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __ceil_backingField ??= new CeilFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __ceil_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __ceil_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __ceil_property_backingField ??= new PropertyDescriptor(__ceil, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __clz32_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __clz32 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __clz32_backingField ??= new Clz32Function(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __clz32_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __clz32_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __clz32_property_backingField ??= new PropertyDescriptor(__clz32, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __cos_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __cos { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __cos_backingField ??= new CosFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __cos_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __cos_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __cos_property_backingField ??= new PropertyDescriptor(__cos, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __cosh_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __cosh { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __cosh_backingField ??= new CoshFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __cosh_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __cosh_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __cosh_property_backingField ??= new PropertyDescriptor(__cosh, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __exp_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __exp { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __exp_backingField ??= new ExpFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __exp_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __exp_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __exp_property_backingField ??= new PropertyDescriptor(__exp, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __floor_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __floor { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __floor_backingField ??= new FloorFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __floor_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __floor_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __floor_property_backingField ??= new PropertyDescriptor(__floor, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __fround_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __fround { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __fround_backingField ??= new FroundFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __fround_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __fround_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __fround_property_backingField ??= new PropertyDescriptor(__fround, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __hypot_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __hypot { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __hypot_backingField ??= new HypotFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __hypot_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __hypot_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __hypot_property_backingField ??= new PropertyDescriptor(__hypot, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __imul_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __imul { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __imul_backingField ??= new ImulFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __imul_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __imul_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __imul_property_backingField ??= new PropertyDescriptor(__imul, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __log_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __log { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __log_backingField ??= new LogFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __log_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __log_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __log_property_backingField ??= new PropertyDescriptor(__log, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __log10_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __log10 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __log10_backingField ??= new Log10Function(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __log10_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __log10_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __log10_property_backingField ??= new PropertyDescriptor(__log10, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __log2_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __log2 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __log2_backingField ??= new Log2Function(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __log2_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __log2_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __log2_property_backingField ??= new PropertyDescriptor(__log2, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __max_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __max { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __max_backingField ??= new MaxFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __max_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __max_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __max_property_backingField ??= new PropertyDescriptor(__max, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __min_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __min { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __min_backingField ??= new MinFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __min_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __min_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __min_property_backingField ??= new PropertyDescriptor(__min, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __pow_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __pow { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __pow_backingField ??= new PowFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __pow_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __pow_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __pow_property_backingField ??= new PropertyDescriptor(__pow, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __random_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __random { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __random_backingField ??= new RandomFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __random_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __random_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __random_property_backingField ??= new PropertyDescriptor(__random, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __round_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __round { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __round_backingField ??= new RoundFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __round_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __round_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __round_property_backingField ??= new PropertyDescriptor(__round, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __sign_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __sign { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __sign_backingField ??= new SignFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __sign_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __sign_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __sign_property_backingField ??= new PropertyDescriptor(__sign, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __sin_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __sin { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __sin_backingField ??= new SinFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __sin_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __sin_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __sin_property_backingField ??= new PropertyDescriptor(__sin, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __sinh_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __sinh { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __sinh_backingField ??= new SinhFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __sinh_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __sinh_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __sinh_property_backingField ??= new PropertyDescriptor(__sinh, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __sqrt_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __sqrt { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __sqrt_backingField ??= new SqrtFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __sqrt_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __sqrt_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __sqrt_property_backingField ??= new PropertyDescriptor(__sqrt, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __tan_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __tan { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __tan_backingField ??= new TanFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __tan_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __tan_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __tan_property_backingField ??= new PropertyDescriptor(__tan, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __tanh_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __tanh { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __tanh_backingField ??= new TanhFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __tanh_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __tanh_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __tanh_property_backingField ??= new PropertyDescriptor(__tanh, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance? __trunc_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private FunctionInstance __trunc { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return __trunc_backingField ??= new TruncFunction(this); } }
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor? __trunc_property_backingField;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)] private PropertyDescriptor __trunc_property { [MethodImpl(MethodImplOptions.AggressiveInlining)] [DebuggerStepThrough] get { return __trunc_property_backingField ??= new PropertyDescriptor(__trunc, PropertyFlag.Writable | PropertyFlag.Configurable); } }
+
+
+ protected override void Initialize()
+ {
+ CreateProperties();
+ CreateSymbols();
+ }
+
+ protected override bool TryGetProperty(JsValue property, out PropertyDescriptor? descriptor)
+ {
+ if (property is JsString jsString)
+ {
+ var str = jsString._value;
+ PropertyDescriptor? match = null;
+ switch (str.Length)
+ {
+ case 1:
+ if (str == "E")
+ {
+ match = __E_property;
+ }
+ break;
+
+ case 2:
+ if (str == "PI")
+ {
+ match = __PI_property;
+ }
+ break;
+
+ case 3:
+ if (str == "abs")
+ {
+ match = __abs_property;
+ }
+ else if (str == "cos")
+ {
+ match = __cos_property;
+ }
+ else if (str == "exp")
+ {
+ match = __exp_property;
+ }
+ else if (str == "log")
+ {
+ match = __log_property;
+ }
+ else if (str == "max")
+ {
+ match = __max_property;
+ }
+ else if (str == "min")
+ {
+ match = __min_property;
+ }
+ else if (str == "pow")
+ {
+ match = __pow_property;
+ }
+ else if (str == "sin")
+ {
+ match = __sin_property;
+ }
+ else if (str == "tan")
+ {
+ match = __tan_property;
+ }
+ else if (str == "LN2")
+ {
+ match = __LN2_property;
+ }
+ break;
+
+ case 4:
+ if (str == "acos")
+ {
+ match = __acos_property;
+ }
+ else if (str == "asin")
+ {
+ match = __asin_property;
+ }
+ else if (str == "atan")
+ {
+ match = __atan_property;
+ }
+ else if (str == "cbrt")
+ {
+ match = __cbrt_property;
+ }
+ else if (str == "ceil")
+ {
+ match = __ceil_property;
+ }
+ else if (str == "cosh")
+ {
+ match = __cosh_property;
+ }
+ else if (str == "imul")
+ {
+ match = __imul_property;
+ }
+ else if (str == "log2")
+ {
+ match = __log2_property;
+ }
+ else if (str == "sign")
+ {
+ match = __sign_property;
+ }
+ else if (str == "sinh")
+ {
+ match = __sinh_property;
+ }
+ else if (str == "sqrt")
+ {
+ match = __sqrt_property;
+ }
+ else if (str == "tanh")
+ {
+ match = __tanh_property;
+ }
+ else if (str == "LN10")
+ {
+ match = __LN10_property;
+ }
+ break;
+
+ case 5:
+ if (str == "acosh")
+ {
+ match = __acosh_property;
+ }
+ else if (str == "asinh")
+ {
+ match = __asinh_property;
+ }
+ else if (str == "atan2")
+ {
+ match = __atan2_property;
+ }
+ else if (str == "atanh")
+ {
+ match = __atanh_property;
+ }
+ else if (str == "clz32")
+ {
+ match = __clz32_property;
+ }
+ else if (str == "floor")
+ {
+ match = __floor_property;
+ }
+ else if (str == "hypot")
+ {
+ match = __hypot_property;
+ }
+ else if (str == "log10")
+ {
+ match = __log10_property;
+ }
+ else if (str == "round")
+ {
+ match = __round_property;
+ }
+ else if (str == "trunc")
+ {
+ match = __trunc_property;
+ }
+ else if (str == "LOG2E")
+ {
+ match = __LOG2E_property;
+ }
+ else if (str == "SQRT2")
+ {
+ match = __SQRT2_property;
+ }
+ break;
+
+ case 6:
+ var disc6 = str[0];
+ if (disc6 == 'f' && str == "fround")
+ {
+ match = __fround_property;
+ }
+ else if (disc6 == 'r' && str == "random")
+ {
+ match = __random_property;
+ }
+ else if (disc6 == 'L' && str == "LOG10E")
+ {
+ match = __LOG10E_property;
+ }
+ break;
+
+ case 7:
+ if (str == "SQRT1_2")
+ {
+ match = __SQRT1_2_property;
+ }
+ break;
+
+ }
+
+ if (match is not null)
+ {
+ descriptor = match;
+ return true;
+ }
+ }
+ return base.TryGetProperty(property, out descriptor);
+ }
+
+ public override PropertyDescriptor GetOwnProperty(JsValue property)
+ {
+ if (property is JsString jsString)
+ {
+ var str = jsString._value;
+ PropertyDescriptor? match = null;
+ switch (str.Length)
+ {
+ case 1:
+ if (str == "E")
+ {
+ match = __E_property;
+ }
+ break;
+
+ case 2:
+ if (str == "PI")
+ {
+ match = __PI_property;
+ }
+ break;
+
+ case 3:
+ if (str == "abs")
+ {
+ match = __abs_property;
+ }
+ else if (str == "cos")
+ {
+ match = __cos_property;
+ }
+ else if (str == "exp")
+ {
+ match = __exp_property;
+ }
+ else if (str == "log")
+ {
+ match = __log_property;
+ }
+ else if (str == "max")
+ {
+ match = __max_property;
+ }
+ else if (str == "min")
+ {
+ match = __min_property;
+ }
+ else if (str == "pow")
+ {
+ match = __pow_property;
+ }
+ else if (str == "sin")
+ {
+ match = __sin_property;
+ }
+ else if (str == "tan")
+ {
+ match = __tan_property;
+ }
+ else if (str == "LN2")
+ {
+ match = __LN2_property;
+ }
+ break;
+
+ case 4:
+ if (str == "acos")
+ {
+ match = __acos_property;
+ }
+ else if (str == "asin")
+ {
+ match = __asin_property;
+ }
+ else if (str == "atan")
+ {
+ match = __atan_property;
+ }
+ else if (str == "cbrt")
+ {
+ match = __cbrt_property;
+ }
+ else if (str == "ceil")
+ {
+ match = __ceil_property;
+ }
+ else if (str == "cosh")
+ {
+ match = __cosh_property;
+ }
+ else if (str == "imul")
+ {
+ match = __imul_property;
+ }
+ else if (str == "log2")
+ {
+ match = __log2_property;
+ }
+ else if (str == "sign")
+ {
+ match = __sign_property;
+ }
+ else if (str == "sinh")
+ {
+ match = __sinh_property;
+ }
+ else if (str == "sqrt")
+ {
+ match = __sqrt_property;
+ }
+ else if (str == "tanh")
+ {
+ match = __tanh_property;
+ }
+ else if (str == "LN10")
+ {
+ match = __LN10_property;
+ }
+ break;
+
+ case 5:
+ if (str == "acosh")
+ {
+ match = __acosh_property;
+ }
+ else if (str == "asinh")
+ {
+ match = __asinh_property;
+ }
+ else if (str == "atan2")
+ {
+ match = __atan2_property;
+ }
+ else if (str == "atanh")
+ {
+ match = __atanh_property;
+ }
+ else if (str == "clz32")
+ {
+ match = __clz32_property;
+ }
+ else if (str == "floor")
+ {
+ match = __floor_property;
+ }
+ else if (str == "hypot")
+ {
+ match = __hypot_property;
+ }
+ else if (str == "log10")
+ {
+ match = __log10_property;
+ }
+ else if (str == "round")
+ {
+ match = __round_property;
+ }
+ else if (str == "trunc")
+ {
+ match = __trunc_property;
+ }
+ else if (str == "LOG2E")
+ {
+ match = __LOG2E_property;
+ }
+ else if (str == "SQRT2")
+ {
+ match = __SQRT2_property;
+ }
+ break;
+
+ case 6:
+ var disc6 = str[0];
+ if (disc6 == 'f' && str == "fround")
+ {
+ match = __fround_property;
+ }
+ else if (disc6 == 'r' && str == "random")
+ {
+ match = __random_property;
+ }
+ else if (disc6 == 'L' && str == "LOG10E")
+ {
+ match = __LOG10E_property;
+ }
+ break;
+
+ case 7:
+ if (str == "SQRT1_2")
+ {
+ match = __SQRT1_2_property;
+ }
+ break;
+
+ }
+
+ if (match is not null)
+ {
+ return match;
+ }
+ }
+ return base.GetOwnProperty(property);
+ }
+
+ protected internal override void SetOwnProperty(JsValue property, PropertyDescriptor desc)
+ {
+ if (property is JsString jsString)
+ {
+ var str = jsString._value;
+ PropertyDescriptor? match = null;
+ switch (str.Length)
+ {
+ case 1:
+ if (str == "E")
+ {
+ match = __E_property;
+ }
+ break;
+
+ case 2:
+ if (str == "PI")
+ {
+ match = __PI_property;
+ }
+ break;
+
+ case 3:
+ if (str == "abs")
+ {
+ match = __abs_property;
+ }
+ else if (str == "cos")
+ {
+ match = __cos_property;
+ }
+ else if (str == "exp")
+ {
+ match = __exp_property;
+ }
+ else if (str == "log")
+ {
+ match = __log_property;
+ }
+ else if (str == "max")
+ {
+ match = __max_property;
+ }
+ else if (str == "min")
+ {
+ match = __min_property;
+ }
+ else if (str == "pow")
+ {
+ match = __pow_property;
+ }
+ else if (str == "sin")
+ {
+ match = __sin_property;
+ }
+ else if (str == "tan")
+ {
+ match = __tan_property;
+ }
+ else if (str == "LN2")
+ {
+ match = __LN2_property;
+ }
+ break;
+
+ case 4:
+ if (str == "acos")
+ {
+ match = __acos_property;
+ }
+ else if (str == "asin")
+ {
+ match = __asin_property;
+ }
+ else if (str == "atan")
+ {
+ match = __atan_property;
+ }
+ else if (str == "cbrt")
+ {
+ match = __cbrt_property;
+ }
+ else if (str == "ceil")
+ {
+ match = __ceil_property;
+ }
+ else if (str == "cosh")
+ {
+ match = __cosh_property;
+ }
+ else if (str == "imul")
+ {
+ match = __imul_property;
+ }
+ else if (str == "log2")
+ {
+ match = __log2_property;
+ }
+ else if (str == "sign")
+ {
+ match = __sign_property;
+ }
+ else if (str == "sinh")
+ {
+ match = __sinh_property;
+ }
+ else if (str == "sqrt")
+ {
+ match = __sqrt_property;
+ }
+ else if (str == "tanh")
+ {
+ match = __tanh_property;
+ }
+ else if (str == "LN10")
+ {
+ match = __LN10_property;
+ }
+ break;
+
+ case 5:
+ if (str == "acosh")
+ {
+ match = __acosh_property;
+ }
+ else if (str == "asinh")
+ {
+ match = __asinh_property;
+ }
+ else if (str == "atan2")
+ {
+ match = __atan2_property;
+ }
+ else if (str == "atanh")
+ {
+ match = __atanh_property;
+ }
+ else if (str == "clz32")
+ {
+ match = __clz32_property;
+ }
+ else if (str == "floor")
+ {
+ match = __floor_property;
+ }
+ else if (str == "hypot")
+ {
+ match = __hypot_property;
+ }
+ else if (str == "log10")
+ {
+ match = __log10_property;
+ }
+ else if (str == "round")
+ {
+ match = __round_property;
+ }
+ else if (str == "trunc")
+ {
+ match = __trunc_property;
+ }
+ else if (str == "LOG2E")
+ {
+ match = __LOG2E_property;
+ }
+ else if (str == "SQRT2")
+ {
+ match = __SQRT2_property;
+ }
+ break;
+
+ case 6:
+ var disc6 = str[0];
+ if (disc6 == 'f' && str == "fround")
+ {
+ match = __fround_property;
+ }
+ else if (disc6 == 'r' && str == "random")
+ {
+ match = __random_property;
+ }
+ else if (disc6 == 'L' && str == "LOG10E")
+ {
+ match = __LOG10E_property;
+ }
+ break;
+
+ case 7:
+ if (str == "SQRT1_2")
+ {
+ match = __SQRT1_2_property;
+ }
+ break;
+
+ }
+
+ if (match is not null)
+ {
+throw new System.Exception("TROUBLE");
+ // return;
+ }
+ }
+ }
+ private sealed class AbsFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("abs");
+ private readonly MathInstance _host;
+
+ public AbsFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Abs(arguments.At(0));
+ }
+
+ public override string ToString() => "function abs() { [native code] }";
+ }
+
+ private sealed class AcosFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("acos");
+ private readonly MathInstance _host;
+
+ public AcosFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Acos(arguments.At(0));
+ }
+
+ public override string ToString() => "function acos() { [native code] }";
+ }
+
+ private sealed class AcoshFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("acosh");
+ private readonly MathInstance _host;
+
+ public AcoshFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Acosh(arguments.At(0));
+ }
+
+ public override string ToString() => "function acosh() { [native code] }";
+ }
+
+ private sealed class AsinFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("asin");
+ private readonly MathInstance _host;
+
+ public AsinFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Asin(arguments.At(0));
+ }
+
+ public override string ToString() => "function asin() { [native code] }";
+ }
+
+ private sealed class AsinhFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("asinh");
+ private readonly MathInstance _host;
+
+ public AsinhFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Asinh(arguments.At(0));
+ }
+
+ public override string ToString() => "function asinh() { [native code] }";
+ }
+
+ private sealed class AtanFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("atan");
+ private readonly MathInstance _host;
+
+ public AtanFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Atan(arguments.At(0));
+ }
+
+ public override string ToString() => "function atan() { [native code] }";
+ }
+
+ private sealed class Atan2Function : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("atan2");
+ private readonly MathInstance _host;
+
+ public Atan2Function(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(2), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Atan2(arguments.At(0), arguments.At(1));
+ }
+
+ public override string ToString() => "function atan2() { [native code] }";
+ }
+
+ private sealed class AtanhFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("atanh");
+ private readonly MathInstance _host;
+
+ public AtanhFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Atanh(arguments.At(0));
+ }
+
+ public override string ToString() => "function atanh() { [native code] }";
+ }
+
+ private sealed class CbrtFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("cbrt");
+ private readonly MathInstance _host;
+
+ public CbrtFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Cbrt(arguments.At(0));
+ }
+
+ public override string ToString() => "function cbrt() { [native code] }";
+ }
+
+ private sealed class CeilFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("ceil");
+ private readonly MathInstance _host;
+
+ public CeilFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Ceil(arguments.At(0));
+ }
+
+ public override string ToString() => "function ceil() { [native code] }";
+ }
+
+ private sealed class Clz32Function : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("clz32");
+ private readonly MathInstance _host;
+
+ public Clz32Function(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Clz32(arguments.At(0));
+ }
+
+ public override string ToString() => "function clz32() { [native code] }";
+ }
+
+ private sealed class CosFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("cos");
+ private readonly MathInstance _host;
+
+ public CosFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Cos(arguments.At(0));
+ }
+
+ public override string ToString() => "function cos() { [native code] }";
+ }
+
+ private sealed class CoshFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("cosh");
+ private readonly MathInstance _host;
+
+ public CoshFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Cosh(arguments.At(0));
+ }
+
+ public override string ToString() => "function cosh() { [native code] }";
+ }
+
+ private sealed class ExpFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("exp");
+ private readonly MathInstance _host;
+
+ public ExpFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Exp(arguments.At(0));
+ }
+
+ public override string ToString() => "function exp() { [native code] }";
+ }
+
+ private sealed class FloorFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("floor");
+ private readonly MathInstance _host;
+
+ public FloorFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Floor(arguments.At(0));
+ }
+
+ public override string ToString() => "function floor() { [native code] }";
+ }
+
+ private sealed class FroundFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("fround");
+ private readonly MathInstance _host;
+
+ public FroundFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Fround(arguments.At(0));
+ }
+
+ public override string ToString() => "function fround() { [native code] }";
+ }
+
+ private sealed class HypotFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("hypot");
+ private readonly MathInstance _host;
+
+ public HypotFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(2), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Hypot(arguments);
+ }
+
+ public override string ToString() => "function hypot() { [native code] }";
+ }
+
+ private sealed class ImulFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("imul");
+ private readonly MathInstance _host;
+
+ public ImulFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(2), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Imul(arguments.At(0), arguments.At(1));
+ }
+
+ public override string ToString() => "function imul() { [native code] }";
+ }
+
+ private sealed class LogFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("log");
+ private readonly MathInstance _host;
+
+ public LogFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Log(arguments.At(0));
+ }
+
+ public override string ToString() => "function log() { [native code] }";
+ }
+
+ private sealed class Log10Function : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("log10");
+ private readonly MathInstance _host;
+
+ public Log10Function(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Log10(arguments.At(0));
+ }
+
+ public override string ToString() => "function log10() { [native code] }";
+ }
+
+ private sealed class Log2Function : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("log2");
+ private readonly MathInstance _host;
+
+ public Log2Function(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Log2(arguments.At(0));
+ }
+
+ public override string ToString() => "function log2() { [native code] }";
+ }
+
+ private sealed class MaxFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("max");
+ private readonly MathInstance _host;
+
+ public MaxFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Max(arguments);
+ }
+
+ public override string ToString() => "function max() { [native code] }";
+ }
+
+ private sealed class MinFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("min");
+ private readonly MathInstance _host;
+
+ public MinFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Min(arguments);
+ }
+
+ public override string ToString() => "function min() { [native code] }";
+ }
+
+ private sealed class PowFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("pow");
+ private readonly MathInstance _host;
+
+ public PowFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(2), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Pow(arguments.At(0), arguments.At(1));
+ }
+
+ public override string ToString() => "function pow() { [native code] }";
+ }
+
+ private sealed class RandomFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("random");
+ private readonly MathInstance _host;
+
+ public RandomFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(0), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return _host.Random();
+ }
+
+ public override string ToString() => "function random() { [native code] }";
+ }
+
+ private sealed class RoundFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("round");
+ private readonly MathInstance _host;
+
+ public RoundFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Round(arguments.At(0));
+ }
+
+ public override string ToString() => "function round() { [native code] }";
+ }
+
+ private sealed class SignFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("sign");
+ private readonly MathInstance _host;
+
+ public SignFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Sign(arguments.At(0));
+ }
+
+ public override string ToString() => "function sign() { [native code] }";
+ }
+
+ private sealed class SinFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("sin");
+ private readonly MathInstance _host;
+
+ public SinFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Sin(arguments.At(0));
+ }
+
+ public override string ToString() => "function sin() { [native code] }";
+ }
+
+ private sealed class SinhFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("sinh");
+ private readonly MathInstance _host;
+
+ public SinhFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Sinh(arguments.At(0));
+ }
+
+ public override string ToString() => "function sinh() { [native code] }";
+ }
+
+ private sealed class SqrtFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("sqrt");
+ private readonly MathInstance _host;
+
+ public SqrtFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Sqrt(arguments.At(0));
+ }
+
+ public override string ToString() => "function sqrt() { [native code] }";
+ }
+
+ private sealed class TanFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("tan");
+ private readonly MathInstance _host;
+
+ public TanFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Tan(arguments.At(0));
+ }
+
+ public override string ToString() => "function tan() { [native code] }";
+ }
+
+ private sealed class TanhFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("tanh");
+ private readonly MathInstance _host;
+
+ public TanhFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Tanh(arguments.At(0));
+ }
+
+ public override string ToString() => "function tanh() { [native code] }";
+ }
+
+ private sealed class TruncFunction : FunctionInstance
+ {
+ private static readonly JsString _name = new JsString("trunc");
+ private readonly MathInstance _host;
+
+ public TruncFunction(MathInstance host) : base(host.Engine, host.Engine.Realm, _name)
+ {
+ _host = host;
+ _prototype = host.Engine._originalIntrinsics.Function.PrototypeObject;
+ _length = new PropertyDescriptor(JsNumber.Create(1), PropertyFlag.Configurable);
+ }
+
+ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
+ {
+ return MathInstance.Trunc(arguments.At(0));
+ }
+
+ public override string ToString() => "function trunc() { [native code] }";
+ }
+
+}
diff --git a/Jint.Tests.SourceGenerators/VerifyHelper.cs b/Jint.Tests.SourceGenerators/VerifyHelper.cs
new file mode 100644
index 0000000000..c90e5e6e4b
--- /dev/null
+++ b/Jint.Tests.SourceGenerators/VerifyHelper.cs
@@ -0,0 +1,27 @@
+using Jint.SourceGenerators;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
+
+namespace Jint.Tests.SourceGenerators;
+
+public static class VerifyHelper
+{
+ public static Task Verify(string source)
+ {
+ var syntaxTree = CSharpSyntaxTree.ParseText(source);
+
+ var compilation = CSharpCompilation.Create(
+ assemblyName: "Tests",
+ syntaxTrees: new[] { syntaxTree });
+
+ var generator = new ObjectGenerator();
+
+ GeneratorDriver driver = CSharpGeneratorDriver.Create(generator);
+
+ driver = driver.RunGenerators(compilation);
+
+ return Verifier
+ .Verify(driver)
+ .UseDirectory("Snapshots");
+ }
+}
\ No newline at end of file
diff --git a/Jint.sln b/Jint.sln
index fad3255cfe..b8b404634f 100644
--- a/Jint.sln
+++ b/Jint.sln
@@ -25,6 +25,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Build.props = Directory.Build.props
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jint.SourceGenerators", "Jint.SourceGenerators\Jint.SourceGenerators.csproj", "{DE11A5A8-859E-4457-AD73-3BFC64201197}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jint.Tests.SourceGenerators", "Jint.Tests.SourceGenerators\Jint.Tests.SourceGenerators.csproj", "{A3AD24B8-0AE9-48DC-8C02-0C79291CF3CA}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -59,6 +63,14 @@ Global
{70198CE9-7DFE-40CA-BBAC-1454C92C4109}.Debug|Any CPU.Build.0 = Debug|Any CPU
{70198CE9-7DFE-40CA-BBAC-1454C92C4109}.Release|Any CPU.ActiveCfg = Release|Any CPU
{70198CE9-7DFE-40CA-BBAC-1454C92C4109}.Release|Any CPU.Build.0 = Release|Any CPU
+ {DE11A5A8-859E-4457-AD73-3BFC64201197}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DE11A5A8-859E-4457-AD73-3BFC64201197}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DE11A5A8-859E-4457-AD73-3BFC64201197}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DE11A5A8-859E-4457-AD73-3BFC64201197}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A3AD24B8-0AE9-48DC-8C02-0C79291CF3CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A3AD24B8-0AE9-48DC-8C02-0C79291CF3CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A3AD24B8-0AE9-48DC-8C02-0C79291CF3CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A3AD24B8-0AE9-48DC-8C02-0C79291CF3CA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Jint/HighPerformance/README.md b/Jint/HighPerformance/README.md
new file mode 100644
index 0000000000..eec4f11ef4
--- /dev/null
+++ b/Jint/HighPerformance/README.md
@@ -0,0 +1,5 @@
+Some helpers extracted from:
+
+https://github.com/CommunityToolkit/dotnet/tree/main/CommunityToolkit.HighPerformance
+
+MIT License
\ No newline at end of file
diff --git a/Jint/HighPerformance/SpanHelper.cs b/Jint/HighPerformance/SpanHelper.cs
new file mode 100644
index 0000000000..f1146bb601
--- /dev/null
+++ b/Jint/HighPerformance/SpanHelper.cs
@@ -0,0 +1,308 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Numerics;
+using System.Runtime.CompilerServices;
+
+namespace Jint.HighPerformance;
+
+internal static class SpanHelper
+{
+ ///
+ /// Calculates the djb2 hash for the target sequence of items of a given type.
+ ///
+ /// The type of items to hash.
+ /// The reference to the target memory area to hash.
+ /// The number of items to hash.
+ /// The Djb2 value for the input sequence of items.
+ public static int GetDjb2HashCode(ref T r0, nint length)
+ where T : notnull
+ {
+ int hash = 5381;
+ nint offset = 0;
+
+ while (length >= 8)
+ {
+ // Doing a left shift by 5 and adding is equivalent to multiplying by 33.
+ // This is preferred for performance reasons, as when working with integer
+ // values most CPUs have higher latency for multiplication operations
+ // compared to a simple shift and add. For more info on this, see the
+ // details for imul, shl, add: https://gmplib.org/~tege/x86-timing.pdf.
+ hash = unchecked(((hash << 5) + hash) ^ Unsafe.Add(ref r0, offset + 0).GetHashCode());
+ hash = unchecked(((hash << 5) + hash) ^ Unsafe.Add(ref r0, offset + 1).GetHashCode());
+ hash = unchecked(((hash << 5) + hash) ^ Unsafe.Add(ref r0, offset + 2).GetHashCode());
+ hash = unchecked(((hash << 5) + hash) ^ Unsafe.Add(ref r0, offset + 3).GetHashCode());
+ hash = unchecked(((hash << 5) + hash) ^ Unsafe.Add(ref r0, offset + 4).GetHashCode());
+ hash = unchecked(((hash << 5) + hash) ^ Unsafe.Add(ref r0, offset + 5).GetHashCode());
+ hash = unchecked(((hash << 5) + hash) ^ Unsafe.Add(ref r0, offset + 6).GetHashCode());
+ hash = unchecked(((hash << 5) + hash) ^ Unsafe.Add(ref r0, offset + 7).GetHashCode());
+
+ length -= 8;
+ offset += 8;
+ }
+
+ if (length >= 4)
+ {
+ hash = unchecked(((hash << 5) + hash) ^ Unsafe.Add(ref r0, offset + 0).GetHashCode());
+ hash = unchecked(((hash << 5) + hash) ^ Unsafe.Add(ref r0, offset + 1).GetHashCode());
+ hash = unchecked(((hash << 5) + hash) ^ Unsafe.Add(ref r0, offset + 2).GetHashCode());
+ hash = unchecked(((hash << 5) + hash) ^ Unsafe.Add(ref r0, offset + 3).GetHashCode());
+
+ length -= 4;
+ offset += 4;
+ }
+
+ while (length > 0)
+ {
+ hash = unchecked(((hash << 5) + hash) ^ Unsafe.Add(ref r0, offset).GetHashCode());
+
+ length -= 1;
+ offset += 1;
+ }
+
+ return hash;
+ }
+
+ ///
+ /// Gets a content hash from a given memory area.
+ ///
+ /// A reference to the start of the memory area.
+ /// The size in bytes of the memory area.
+ /// The hash code for the contents of the source memory area.
+ ///
+ /// While this method is similar to and can in some cases
+ /// produce the same output for a given memory area, it is not guaranteed to always be that way.
+ /// This is because this method can use SIMD instructions if possible, which can cause a computed
+ /// hash to differ for the same data, if processed on different machines with different CPU features.
+ /// The advantage of this method is that when SIMD instructions are available, it performs much
+ /// faster than , as it can parallelize much of the workload.
+ ///
+ public static unsafe int GetDjb2LikeByteHash(ref byte r0, nint length)
+ {
+ int hash = 5381;
+ nint offset = 0;
+
+ // Check whether SIMD instructions are supported, and also check
+ // whether we have enough data to perform at least one unrolled
+ // iteration of the vectorized path. This heuristics is to balance
+ // the overhead of loading the constant values in the two registers,
+ // and the final loop to combine the partial hash values.
+ // Note that even when we use the vectorized path we don't need to do
+ // any preprocessing to try to get memory aligned, as that would cause
+ // the hash codes to potentially be different for the same data.
+ if (Vector.IsHardwareAccelerated &&
+ length >= (Vector.Count << 3))
+ {
+ Vector vh = new(5381);
+ Vector v33 = new(33);
+
+ // First vectorized loop, with 8 unrolled iterations.
+ // Assuming 256-bit registers (AVX2), a total of 256 bytes are processed
+ // per iteration, with the partial hashes being accumulated for later use.
+ while (length >= (Vector.Count << 3))
+ {
+ ref byte ri0 = ref Unsafe.Add(ref r0, offset + (Vector.Count * 0));
+ Vector vi0 = Unsafe.ReadUnaligned>(ref ri0);
+ Vector vp0 = Vector.Multiply(vh, v33);
+ vh = Vector.Xor(vp0, vi0);
+
+ ref byte ri1 = ref Unsafe.Add(ref r0, offset + (Vector.Count * 1));
+ Vector vi1 = Unsafe.ReadUnaligned>(ref ri1);
+ Vector vp1 = Vector.Multiply(vh, v33);
+ vh = Vector.Xor(vp1, vi1);
+
+ ref byte ri2 = ref Unsafe.Add(ref r0, offset + (Vector.Count * 2));
+ Vector vi2 = Unsafe.ReadUnaligned>(ref ri2);
+ Vector vp2 = Vector.Multiply(vh, v33);
+ vh = Vector.Xor(vp2, vi2);
+
+ ref byte ri3 = ref Unsafe.Add(ref r0, offset + (Vector.Count * 3));
+ Vector vi3 = Unsafe.ReadUnaligned>(ref ri3);
+ Vector vp3 = Vector.Multiply(vh, v33);
+ vh = Vector.Xor(vp3, vi3);
+
+ ref byte ri4 = ref Unsafe.Add(ref r0, offset + (Vector.Count * 4));
+ Vector vi4 = Unsafe.ReadUnaligned>(ref ri4);
+ Vector vp4 = Vector.Multiply(vh, v33);
+ vh = Vector.Xor(vp4, vi4);
+
+ ref byte ri5 = ref Unsafe.Add(ref r0, offset + (Vector.Count * 5));
+ Vector vi5 = Unsafe.ReadUnaligned>(ref ri5);
+ Vector vp5 = Vector.Multiply(vh, v33);
+ vh = Vector.Xor(vp5, vi5);
+
+ ref byte ri6 = ref Unsafe.Add(ref r0, offset + (Vector.Count * 6));
+ Vector vi6 = Unsafe.ReadUnaligned>(ref ri6);
+ Vector vp6 = Vector.Multiply(vh, v33);
+ vh = Vector.Xor(vp6, vi6);
+
+ ref byte ri7 = ref Unsafe.Add(ref r0, offset + (Vector.Count * 7));
+ Vector vi7 = Unsafe.ReadUnaligned>(ref ri7);
+ Vector vp7 = Vector.Multiply(vh, v33);
+ vh = Vector.Xor(vp7, vi7);
+
+ length -= Vector.Count << 3;
+ offset += Vector.Count << 3;
+ }
+
+ // When this loop is reached, there are up to 255 bytes left (on AVX2).
+ // Each iteration processed an additional 32 bytes and accumulates the results.
+ while (length >= Vector.Count)
+ {
+ ref byte ri = ref Unsafe.Add(ref r0, offset);
+ Vector vi = Unsafe.ReadUnaligned>(ref ri);
+ Vector vp = Vector.Multiply(vh, v33);
+ vh = Vector.Xor(vp, vi);
+
+ length -= Vector.Count;
+ offset += Vector.Count;
+ }
+
+ // Combine the partial hash values in each position.
+ // The loop below should automatically be unrolled by the JIT.
+ for (int j = 0; j < Vector.Count; j++)
+ {
+ hash = unchecked(((hash << 5) + hash) ^ vh[j]);
+ }
+ }
+ else
+ {
+ // Only use the loop working with 64-bit values if we are on a
+ // 64-bit processor, otherwise the result would be much slower.
+ // Each unrolled iteration processes 64 bytes.
+ if (sizeof(nint) == sizeof(ulong))
+ {
+ while (length >= (sizeof(ulong) << 3))
+ {
+ ref byte ri0 = ref Unsafe.Add(ref r0, offset + (sizeof(ulong) * 0));
+ ulong value0 = Unsafe.ReadUnaligned(ref ri0);
+ hash = unchecked(((hash << 5) + hash) ^ (int)value0 ^ (int)(value0 >> 32));
+
+ ref byte ri1 = ref Unsafe.Add(ref r0, offset + (sizeof(ulong) * 1));
+ ulong value1 = Unsafe.ReadUnaligned(ref ri1);
+ hash = unchecked(((hash << 5) + hash) ^ (int)value1 ^ (int)(value1 >> 32));
+
+ ref byte ri2 = ref Unsafe.Add(ref r0, offset + (sizeof(ulong) * 2));
+ ulong value2 = Unsafe.ReadUnaligned(ref ri2);
+ hash = unchecked(((hash << 5) + hash) ^ (int)value2 ^ (int)(value2 >> 32));
+
+ ref byte ri3 = ref Unsafe.Add(ref r0, offset + (sizeof(ulong) * 3));
+ ulong value3 = Unsafe.ReadUnaligned(ref ri3);
+ hash = unchecked(((hash << 5) + hash) ^ (int)value3 ^ (int)(value3 >> 32));
+
+ ref byte ri4 = ref Unsafe.Add(ref r0, offset + (sizeof(ulong) * 4));
+ ulong value4 = Unsafe.ReadUnaligned(ref ri4);
+ hash = unchecked(((hash << 5) + hash) ^ (int)value4 ^ (int)(value4 >> 32));
+
+ ref byte ri5 = ref Unsafe.Add(ref r0, offset + (sizeof(ulong) * 5));
+ ulong value5 = Unsafe.ReadUnaligned(ref ri5);
+ hash = unchecked(((hash << 5) + hash) ^ (int)value5 ^ (int)(value5 >> 32));
+
+ ref byte ri6 = ref Unsafe.Add(ref r0, offset + (sizeof(ulong) * 6));
+ ulong value6 = Unsafe.ReadUnaligned(ref ri6);
+ hash = unchecked(((hash << 5) + hash) ^ (int)value6 ^ (int)(value6 >> 32));
+
+ ref byte ri7 = ref Unsafe.Add(ref r0, offset + (sizeof(ulong) * 7));
+ ulong value7 = Unsafe.ReadUnaligned(ref ri7);
+ hash = unchecked(((hash << 5) + hash) ^ (int)value7 ^ (int)(value7 >> 32));
+
+ length -= sizeof(ulong) << 3;
+ offset += sizeof(ulong) << 3;
+ }
+ }
+
+ // Each unrolled iteration processes 32 bytes
+ while (length >= (sizeof(uint) << 3))
+ {
+ ref byte ri0 = ref Unsafe.Add(ref r0, offset + (sizeof(uint) * 0));
+ uint value0 = Unsafe.ReadUnaligned(ref ri0);
+ hash = unchecked(((hash << 5) + hash) ^ (int)value0);
+
+ ref byte ri1 = ref Unsafe.Add(ref r0, offset + (sizeof(uint) * 1));
+ uint value1 = Unsafe.ReadUnaligned(ref ri1);
+ hash = unchecked(((hash << 5) + hash) ^ (int)value1);
+
+ ref byte ri2 = ref Unsafe.Add(ref r0, offset + (sizeof(uint) * 2));
+ uint value2 = Unsafe.ReadUnaligned(ref ri2);
+ hash = unchecked(((hash << 5) + hash) ^ (int)value2);
+
+ ref byte ri3 = ref Unsafe.Add(ref r0, offset + (sizeof(uint) * 3));
+ uint value3 = Unsafe.ReadUnaligned(ref ri3);
+ hash = unchecked(((hash << 5) + hash) ^ (int)value3);
+
+ ref byte ri4 = ref Unsafe.Add(ref r0, offset + (sizeof(uint) * 4));
+ uint value4 = Unsafe.ReadUnaligned(ref ri4);
+ hash = unchecked(((hash << 5) + hash) ^ (int)value4);
+
+ ref byte ri5 = ref Unsafe.Add(ref r0, offset + (sizeof(uint) * 5));
+ uint value5 = Unsafe.ReadUnaligned(ref ri5);
+ hash = unchecked(((hash << 5) + hash) ^ (int)value5);
+
+ ref byte ri6 = ref Unsafe.Add(ref r0, offset + (sizeof(uint) * 6));
+ uint value6 = Unsafe.ReadUnaligned(ref ri6);
+ hash = unchecked(((hash << 5) + hash) ^ (int)value6);
+
+ ref byte ri7 = ref Unsafe.Add(ref r0, offset + (sizeof(uint) * 7));
+ uint value7 = Unsafe.ReadUnaligned(ref ri7);
+ hash = unchecked(((hash << 5) + hash) ^ (int)value7);
+
+ length -= sizeof(uint) << 3;
+ offset += sizeof(uint) << 3;
+ }
+ }
+
+ // At this point (assuming AVX2), there will be up to 31 bytes
+ // left, both for the vectorized and non vectorized paths.
+ // That number would go up to 63 on AVX512 systems, in which case it is
+ // still useful to perform this last loop unrolling.
+ if (length >= (sizeof(ushort) << 3))
+ {
+ ref byte ri0 = ref Unsafe.Add(ref r0, offset + (sizeof(ushort) * 0));
+ ushort value0 = Unsafe.ReadUnaligned(ref ri0);
+ hash = unchecked(((hash << 5) + hash) ^ value0);
+
+ ref byte ri1 = ref Unsafe.Add(ref r0, offset + (sizeof(ushort) * 1));
+ ushort value1 = Unsafe.ReadUnaligned(ref ri1);
+ hash = unchecked(((hash << 5) + hash) ^ value1);
+
+ ref byte ri2 = ref Unsafe.Add(ref r0, offset + (sizeof(ushort) * 2));
+ ushort value2 = Unsafe.ReadUnaligned(ref ri2);
+ hash = unchecked(((hash << 5) + hash) ^ value2);
+
+ ref byte ri3 = ref Unsafe.Add(ref r0, offset + (sizeof(ushort) * 3));
+ ushort value3 = Unsafe.ReadUnaligned(ref ri3);
+ hash = unchecked(((hash << 5) + hash) ^ value3);
+
+ ref byte ri4 = ref Unsafe.Add(ref r0, offset + (sizeof(ushort) * 4));
+ ushort value4 = Unsafe.ReadUnaligned(ref ri4);
+ hash = unchecked(((hash << 5) + hash) ^ value4);
+
+ ref byte ri5 = ref Unsafe.Add(ref r0, offset + (sizeof(ushort) * 5));
+ ushort value5 = Unsafe.ReadUnaligned(ref ri5);
+ hash = unchecked(((hash << 5) + hash) ^ value5);
+
+ ref byte ri6 = ref Unsafe.Add(ref r0, offset + (sizeof(ushort) * 6));
+ ushort value6 = Unsafe.ReadUnaligned(ref ri6);
+ hash = unchecked(((hash << 5) + hash) ^ value6);
+
+ ref byte ri7 = ref Unsafe.Add(ref r0, offset + (sizeof(ushort) * 7));
+ ushort value7 = Unsafe.ReadUnaligned(ref ri7);
+ hash = unchecked(((hash << 5) + hash) ^ value7);
+
+ length -= sizeof(ushort) << 3;
+ offset += sizeof(ushort) << 3;
+ }
+
+ // Handle the leftover items
+ while (length > 0)
+ {
+ hash = unchecked(((hash << 5) + hash) ^ Unsafe.Add(ref r0, offset));
+
+ length -= 1;
+ offset += 1;
+ }
+
+ return hash;
+ }
+}
\ No newline at end of file
diff --git a/Jint/HighPerformance/StringExtensions.cs b/Jint/HighPerformance/StringExtensions.cs
new file mode 100644
index 0000000000..721e320108
--- /dev/null
+++ b/Jint/HighPerformance/StringExtensions.cs
@@ -0,0 +1,46 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+namespace Jint.HighPerformance;
+
+///
+/// Helpers for working with the type.
+///
+internal static class StringExtensions
+{
+ ///
+ /// Returns a reference to the first element within a given , with no bounds checks.
+ ///
+ /// The input instance.
+ /// A reference to the first element within , or the location it would have used, if is empty.
+ /// This method doesn't do any bounds checks, therefore it is responsibility of the caller to perform checks in case the returned value is dereferenced.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static ref char DangerousGetReference(this string text)
+ {
+#if NETCOREAPP3_1_OR_GREATER
+ return ref Unsafe.AsRef(in text.GetPinnableReference());
+#else
+ return ref MemoryMarshal.GetReference(text.AsSpan());
+#endif
+ }
+
+ ///
+ /// Gets a content hash from the input instance using the Djb2 algorithm.
+ /// For more info, see the documentation for .
+ ///
+ /// The source to enumerate.
+ /// The Djb2 value for the input instance.
+ /// The Djb2 hash is fully deterministic and with no random components.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static unsafe int GetDjb2HashCode(this string text)
+ {
+ ref char r0 = ref text.DangerousGetReference();
+ nint length = (nint)(uint)text.Length;
+
+ return SpanHelper.GetDjb2HashCode(ref r0, length);
+ }
+}
diff --git a/Jint/Jint.csproj b/Jint/Jint.csproj
index 450bc7bad1..621050427e 100644
--- a/Jint/Jint.csproj
+++ b/Jint/Jint.csproj
@@ -29,9 +29,27 @@
+
+
+
+ true
+ Generated
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Jint/Native/Math/MathInstance.cs b/Jint/Native/Math/MathInstance.cs
index dfb7fbe203..e5ced5c417 100644
--- a/Jint/Native/Math/MathInstance.cs
+++ b/Jint/Native/Math/MathInstance.cs
@@ -4,1089 +4,1256 @@
using Jint.Native.Symbol;
using Jint.Runtime;
using Jint.Runtime.Descriptors;
-using Jint.Runtime.Interop;
-namespace Jint.Native.Math
+namespace Jint.Native.Math;
+
+[JsObject]
+internal sealed partial class MathInstance : ObjectInstance
{
- internal sealed class MathInstance : ObjectInstance
+#if !NET6_0_OR_GREATER
+ private Random? _random;
+#endif
+
+ internal MathInstance(Engine engine, ObjectPrototype objectPrototype) : base(engine)
{
- private Random? _random;
+ _prototype = objectPrototype;
+ }
- internal MathInstance(Engine engine, ObjectPrototype objectPrototype) : base(engine)
+ private void CreateProperties()
+ {
+ var properties = new PropertyDictionary(45, checkExistingKeys: false)
{
- _prototype = objectPrototype;
- }
+ /*
+ ["abs"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "abs", Abs, 1, PropertyFlag.Configurable), true, false, true),
+ ["acos"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "acos", Acos, 1, PropertyFlag.Configurable), true, false, true),
+ ["acosh"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "acosh", Acosh, 1, PropertyFlag.Configurable), true, false, true),
+ ["asin"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "asin", Asin, 1, PropertyFlag.Configurable), true, false, true),
+ ["asinh"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "asinh", Asinh, 1, PropertyFlag.Configurable), true, false, true),
+ ["atan"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "atan", Atan, 1, PropertyFlag.Configurable), true, false, true),
+ ["atanh"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "atanh", Atanh, 1, PropertyFlag.Configurable), true, false, true),
+ ["atan2"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "atan2", Atan2, 2, PropertyFlag.Configurable), true, false, true),
+ ["ceil"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "ceil", Ceil, 1, PropertyFlag.Configurable), true, false, true),
+ ["cos"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "cos", Cos, 1, PropertyFlag.Configurable), true, false, true),
+ ["cosh"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "cosh", Cosh, 1, PropertyFlag.Configurable), true, false, true),
+ ["exp"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "exp", Exp, 1, PropertyFlag.Configurable), true, false, true),
+ ["expm1"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "expm1", Expm1, 1, PropertyFlag.Configurable), true, false, true),
+ ["floor"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "floor", Floor, 1, PropertyFlag.Configurable), true, false, true),
+ ["log"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "log", Log, 1, PropertyFlag.Configurable), true, false, true),
+ ["log1p"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "log1p", Log1p, 1, PropertyFlag.Configurable), true, false, true),
+ ["log2"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "log2", Log2, 1, PropertyFlag.Configurable), true, false, true),
+ ["log10"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "log10", Log10, 1, PropertyFlag.Configurable), true, false, true),
+ ["max"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "max", Max, 2, PropertyFlag.Configurable), true, false, true),
+ ["min"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "min", Min, 2, PropertyFlag.Configurable), true, false, true),
+ ["pow"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "pow", Pow, 2, PropertyFlag.Configurable), true, false, true),
+ ["random"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "random", Random, 0, PropertyFlag.Configurable), true, false, true),
+ ["round"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "round", Round, 1, PropertyFlag.Configurable), true, false, true),
+ ["fround"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "fround", Fround, 1, PropertyFlag.Configurable), true, false, true),
+ ["sin"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "sin", Sin, 1, PropertyFlag.Configurable), true, false, true),
+ ["sinh"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "sinh", Sinh, 1, PropertyFlag.Configurable), true, false, true),
+ ["sqrt"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "sqrt", Sqrt, 1, PropertyFlag.Configurable), true, false, true),
+ ["tan"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "tan", Tan, 1, PropertyFlag.Configurable), true, false, true),
+ ["tanh"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "tanh", Tanh, 1, PropertyFlag.Configurable), true, false, true),
+ ["trunc"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "trunc", Truncate, 1, PropertyFlag.Configurable), true, false, true),
+ ["sign"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "sign", Sign, 1, PropertyFlag.Configurable), true, false, true),
+ ["cbrt"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "cbrt", Cbrt, 1, PropertyFlag.Configurable), true, false, true),
+ ["hypot"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "hypot", Hypot, 2, PropertyFlag.Configurable), true, false, true),
+ ["imul"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "imul", Imul, 2, PropertyFlag.Configurable), true, false, true),
+ ["clz32"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "clz32", Clz32, 1, PropertyFlag.Configurable), true, false, true),
+ ["E"] = new PropertyDescriptor(System.Math.E, false, false, false),
+ ["LN10"] = new PropertyDescriptor(System.Math.Log(10), false, false, false),
+ ["LN2"] = new PropertyDescriptor(System.Math.Log(2), false, false, false),
+ ["LOG2E"] = new PropertyDescriptor(System.Math.Log(System.Math.E, 2), false, false, false),
+ ["LOG10E"] = new PropertyDescriptor(System.Math.Log(System.Math.E, 10), false, false, false),
+ ["PI"] = new PropertyDescriptor(System.Math.PI, false, false, false),
+ ["SQRT1_2"] = new PropertyDescriptor(System.Math.Sqrt(0.5), false, false, false),
+ ["SQRT2"] = new PropertyDescriptor(System.Math.Sqrt(2), false, false, false)
+ */
+ };
+ SetProperties(properties);
+ }
- protected override void Initialize()
+ private void CreateSymbols()
+ {
+ var symbols = new SymbolDictionary(1)
{
- var properties = new PropertyDictionary(45, checkExistingKeys: false)
- {
- ["abs"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "abs", Abs, 1, PropertyFlag.Configurable), true, false, true),
- ["acos"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "acos", Acos, 1, PropertyFlag.Configurable), true, false, true),
- ["acosh"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "acosh", Acosh, 1, PropertyFlag.Configurable), true, false, true),
- ["asin"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "asin", Asin, 1, PropertyFlag.Configurable), true, false, true),
- ["asinh"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "asinh", Asinh, 1, PropertyFlag.Configurable), true, false, true),
- ["atan"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "atan", Atan, 1, PropertyFlag.Configurable), true, false, true),
- ["atanh"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "atanh", Atanh, 1, PropertyFlag.Configurable), true, false, true),
- ["atan2"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "atan2", Atan2, 2, PropertyFlag.Configurable), true, false, true),
- ["ceil"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "ceil", Ceil, 1, PropertyFlag.Configurable), true, false, true),
- ["cos"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "cos", Cos, 1, PropertyFlag.Configurable), true, false, true),
- ["cosh"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "cosh", Cosh, 1, PropertyFlag.Configurable), true, false, true),
- ["exp"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "exp", Exp, 1, PropertyFlag.Configurable), true, false, true),
- ["expm1"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "expm1", Expm1, 1, PropertyFlag.Configurable), true, false, true),
- ["floor"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "floor", Floor, 1, PropertyFlag.Configurable), true, false, true),
- ["log"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "log", Log, 1, PropertyFlag.Configurable), true, false, true),
- ["log1p"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "log1p", Log1p, 1, PropertyFlag.Configurable), true, false, true),
- ["log2"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "log2", Log2, 1, PropertyFlag.Configurable), true, false, true),
- ["log10"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "log10", Log10, 1, PropertyFlag.Configurable), true, false, true),
- ["max"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "max", Max, 2, PropertyFlag.Configurable), true, false, true),
- ["min"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "min", Min, 2, PropertyFlag.Configurable), true, false, true),
- ["pow"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "pow", Pow, 2, PropertyFlag.Configurable), true, false, true),
- ["random"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "random", Random, 0, PropertyFlag.Configurable), true, false, true),
- ["round"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "round", Round, 1, PropertyFlag.Configurable), true, false, true),
- ["fround"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "fround", Fround, 1, PropertyFlag.Configurable), true, false, true),
- ["sin"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "sin", Sin, 1, PropertyFlag.Configurable), true, false, true),
- ["sinh"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "sinh", Sinh, 1, PropertyFlag.Configurable), true, false, true),
- ["sqrt"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "sqrt", Sqrt, 1, PropertyFlag.Configurable), true, false, true),
- ["tan"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "tan", Tan, 1, PropertyFlag.Configurable), true, false, true),
- ["tanh"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "tanh", Tanh, 1, PropertyFlag.Configurable), true, false, true),
- ["trunc"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "trunc", Truncate, 1, PropertyFlag.Configurable), true, false, true),
- ["sign"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "sign", Sign, 1, PropertyFlag.Configurable), true, false, true),
- ["cbrt"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "cbrt", Cbrt, 1, PropertyFlag.Configurable), true, false, true),
- ["hypot"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "hypot", Hypot, 2, PropertyFlag.Configurable), true, false, true),
- ["imul"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "imul", Imul, 2, PropertyFlag.Configurable), true, false, true),
- ["clz32"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "clz32", Clz32, 1, PropertyFlag.Configurable), true, false, true),
- ["E"] = new PropertyDescriptor(System.Math.E, false, false, false),
- ["LN10"] = new PropertyDescriptor(System.Math.Log(10), false, false, false),
- ["LN2"] = new PropertyDescriptor(System.Math.Log(2), false, false, false),
- ["LOG2E"] = new PropertyDescriptor(System.Math.Log(System.Math.E, 2), false, false, false),
- ["LOG10E"] = new PropertyDescriptor(System.Math.Log(System.Math.E, 10), false, false, false),
- ["PI"] = new PropertyDescriptor(System.Math.PI, false, false, false),
- ["SQRT1_2"] = new PropertyDescriptor(System.Math.Sqrt(0.5), false, false, false),
- ["SQRT2"] = new PropertyDescriptor(System.Math.Sqrt(2), false, false, false)
- };
- SetProperties(properties);
-
- var symbols = new SymbolDictionary(1)
- {
- [GlobalSymbolRegistry.ToStringTag] = new PropertyDescriptor(new JsString("Math"), PropertyFlag.Configurable)
- };
- SetSymbols(symbols);
- }
+ [GlobalSymbolRegistry.ToStringTag] = new(new JsString("Math"), PropertyFlag.Configurable)
+ };
+ SetSymbols(symbols);
+ }
- private static JsValue Abs(JsValue thisObject, JsValue[] arguments)
+ [JsProperty(Name = "E")] private static JsNumber E { get; } = new(System.Math.E);
+ [JsProperty(Name = "LN10")] private static JsNumber LN10 { get; } = new(System.Math.Log(10));
+ [JsProperty(Name = "LN2")] private static JsNumber LN2 { get; } = new(System.Math.Log(2));
+ [JsProperty(Name = "LOG2E")] private static JsNumber LOG2E { get; } = new(System.Math.Log(System.Math.E, 2));
+ [JsProperty(Name = "LOG10E")] private static JsNumber LOG10E { get; } = new(System.Math.Log(System.Math.E, 10));
+ [JsProperty(Name = "PI")] private static JsNumber PI { get; } = new(System.Math.PI);
+ [JsProperty(Name = "SQRT1_2")] private static JsNumber SQRT1_2 { get; } = new(System.Math.Sqrt(0.5));
+ [JsProperty(Name = "SQRT2")] private static JsNumber SQRT2 { get; } = new(System.Math.Sqrt(2));
+
+ ///
+ /// https://tc39.es/ecma262/#sec-math.abs
+ ///
+ [JsFunction]
+ private static JsValue Abs(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
+
+ if (double.IsNaN(n))
+ {
+ return JsNumber.DoubleNaN;
+ }
+ else if (NumberInstance.IsNegativeZero(n))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return JsNumber.PositiveZero;
+ }
+ else if (double.IsInfinity(n))
+ {
+ return JsNumber.DoublePositiveInfinity;
+ }
- if (double.IsNaN(x))
- {
- return JsNumber.DoubleNaN;
- }
- else if (NumberInstance.IsNegativeZero(x))
- {
- return JsNumber.PositiveZero;
- }
- else if (double.IsInfinity(x))
- {
- return JsNumber.DoublePositiveInfinity;
- }
+ return System.Math.Abs(n);
+ }
- return System.Math.Abs(x);
+ ///
+ /// https://tc39.es/ecma262/#sec-math.acos
+ ///
+ [JsFunction]
+ private static JsValue Acos(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
+
+ if (double.IsNaN(n) || (n > 1) || (n < -1))
+ {
+ return JsNumber.DoubleNaN;
}
- private static JsValue Acos(JsValue thisObject, JsValue[] arguments)
+ if (n == 1)
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return JsNumber.PositiveZero;
+ }
- if (double.IsNaN(x) || (x > 1) || (x < -1))
- {
- return JsNumber.DoubleNaN;
- }
- else if (x == 1)
- {
- return 0;
- }
+ return System.Math.Acos(n);
+ }
- return System.Math.Acos(x);
- }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.acosh
+ ///
+ [JsFunction]
+ private static JsValue Acosh(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
- private static JsValue Acosh(JsValue thisObject, JsValue[] arguments)
+ if (double.IsNaN(n) || n < 1)
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return JsNumber.DoubleNaN;
+ }
- if (double.IsNaN(x) || x < 1)
- {
- return JsNumber.DoubleNaN;
- }
+ return System.Math.Log(n + System.Math.Sqrt(n * n - 1.0));
+ }
- return System.Math.Log(x + System.Math.Sqrt(x * x - 1.0));
- }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.asin
+ ///
+ [JsFunction]
+ private static JsValue Asin(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
- private static JsValue Asin(JsValue thisObject, JsValue[] arguments)
+ if (double.IsNaN(n) || (n > 1) || (n < -1))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return JsNumber.DoubleNaN;
+ }
+ else if (NumberInstance.IsPositiveZero(n) || NumberInstance.IsNegativeZero(n))
+ {
+ return n;
+ }
- if (double.IsNaN(x) || (x > 1) || (x < -1))
- {
- return JsNumber.DoubleNaN;
- }
- else if (NumberInstance.IsPositiveZero(x) || NumberInstance.IsNegativeZero(x))
- {
- return x;
- }
+ return System.Math.Asin(n);
+ }
- return System.Math.Asin(x);
+ ///
+ /// https://tc39.es/ecma262/#sec-math.asinh
+ ///
+ [JsFunction]
+ private static JsValue Asinh(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
+ if (double.IsInfinity(n) || NumberInstance.IsPositiveZero(n) || NumberInstance.IsNegativeZero(n))
+ {
+ return n;
}
- private static JsValue Asinh(JsValue thisObject, JsValue[] arguments)
- {
- var x = TypeConverter.ToNumber(arguments.At(0));
- if (double.IsInfinity(x) || NumberInstance.IsPositiveZero(x) || NumberInstance.IsNegativeZero(x))
- {
- return x;
- }
+ return System.Math.Log(n + System.Math.Sqrt(n * n + 1.0));
+ }
- return System.Math.Log(x + System.Math.Sqrt(x * x + 1.0));
- }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.atan
+ ///
+ [JsFunction]
+ private static JsValue Atan(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
- private static JsValue Atan(JsValue thisObject, JsValue[] arguments)
+ if (double.IsNaN(n))
+ {
+ return JsNumber.DoubleNaN;
+ }
+ else if (NumberInstance.IsPositiveZero(n) || NumberInstance.IsNegativeZero(n))
+ {
+ return n;
+ }
+ else if (double.IsPositiveInfinity(n))
+ {
+ return System.Math.PI / 2;
+ }
+ else if (double.IsNegativeInfinity(n))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return -System.Math.PI / 2;
+ }
- if (double.IsNaN(x))
- {
- return JsNumber.DoubleNaN;
- }
- else if (NumberInstance.IsPositiveZero(x) || NumberInstance.IsNegativeZero(x))
- {
- return x;
- }
- else if (double.IsPositiveInfinity(x))
- {
- return System.Math.PI / 2;
- }
- else if (double.IsNegativeInfinity(x))
- {
- return -System.Math.PI / 2;
- }
+ return System.Math.Atan(n);
+ }
+
+ ///
+ /// https://tc39.es/ecma262/#sec-math.atanh
+ ///
+ [JsFunction]
+ private static JsValue Atanh(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
- return System.Math.Atan(x);
+ if (double.IsNaN(n))
+ {
+ return JsNumber.DoubleNaN;
}
- private static JsValue Atanh(JsValue thisObject, JsValue[] arguments)
+
+ if (NumberInstance.IsPositiveZero(n) || NumberInstance.IsNegativeZero(n))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return n;
+ }
- if (double.IsNaN(x))
- {
- return JsNumber.DoubleNaN;
- }
+ return 0.5 * System.Math.Log((1.0 + n) / (1.0 - n));
+ }
- if (NumberInstance.IsPositiveZero(x) || NumberInstance.IsNegativeZero(x))
- {
- return x;
- }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.atan2
+ ///
+ [JsFunction]
+ private static JsValue Atan2(JsValue y, JsValue x)
+ {
+ var ny = TypeConverter.ToNumber(y);
+ var nx = TypeConverter.ToNumber(x);
- return 0.5 * System.Math.Log((1.0 + x) / (1.0 - x));
+ // If either x or y is NaN, the result is NaN.
+ if (double.IsNaN(nx) || double.IsNaN(ny))
+ {
+ return JsNumber.DoubleNaN;
}
- private static JsValue Atan2(JsValue thisObject, JsValue[] arguments)
+ if (ny > 0 && nx.Equals(0))
{
- var y = TypeConverter.ToNumber(arguments.At(0));
- var x = TypeConverter.ToNumber(arguments.At(1));
+ return System.Math.PI/2;
+ }
- // If either x or y is NaN, the result is NaN.
- if (double.IsNaN(x) || double.IsNaN(y))
+ if (NumberInstance.IsPositiveZero(ny))
+ {
+ // If y is +0 and x>0, the result is +0.
+ if (nx > 0)
{
- return JsNumber.DoubleNaN;
+ return JsNumber.PositiveZero;
}
- if (y > 0 && x.Equals(0))
+ // If y is +0 and x is +0, the result is +0.
+ if (NumberInstance.IsPositiveZero(nx))
{
- return System.Math.PI/2;
+ return JsNumber.PositiveZero;
}
- if (NumberInstance.IsPositiveZero(y))
+ // If y is +0 and x is −0, the result is an implementation-dependent approximation to +π.
+ if (NumberInstance.IsNegativeZero(nx))
{
- // If y is +0 and x>0, the result is +0.
- if (x > 0)
- {
- return JsNumber.PositiveZero;
- }
-
- // If y is +0 and x is +0, the result is +0.
- if (NumberInstance.IsPositiveZero(x))
- {
- return JsNumber.PositiveZero;
- }
-
- // If y is +0 and x is −0, the result is an implementation-dependent approximation to +π.
- if (NumberInstance.IsNegativeZero(x))
- {
- return JsNumber.PI;
- }
-
- // If y is +0 and x<0, the result is an implementation-dependent approximation to +π.
- if (x < 0)
- {
- return JsNumber.PI;
- }
+ return JsNumber.PI;
}
- if (NumberInstance.IsNegativeZero(y))
+ // If y is +0 and x<0, the result is an implementation-dependent approximation to +π.
+ if (nx < 0)
{
- // If y is −0 and x>0, the result is −0.
- if (x > 0)
- {
- return JsNumber.NegativeZero;
- }
-
- // If y is −0 and x is +0, the result is −0.
- if (NumberInstance.IsPositiveZero(x))
- {
- return JsNumber.NegativeZero;
- }
-
- // If y is −0 and x is −0, the result is an implementation-dependent approximation to −π.
- if (NumberInstance.IsNegativeZero(x))
- {
- return -System.Math.PI;
- }
-
- // If y is −0 and x<0, the result is an implementation-dependent approximation to −π.
- if (x < 0)
- {
- return -System.Math.PI;
- }
+ return JsNumber.PI;
}
+ }
- // If y<0 and x is +0, the result is an implementation-dependent approximation to −π/2.
- // If y<0 and x is −0, the result is an implementation-dependent approximation to −π/2.
- if (y < 0 && x.Equals(0))
+ if (NumberInstance.IsNegativeZero(ny))
+ {
+ // If y is −0 and x>0, the result is −0.
+ if (nx > 0)
{
- return -System.Math.PI/2;
+ return JsNumber.NegativeZero;
}
- // If y>0 and y is finite and x is +∞, the result is +0.
- if (y > 0 && !double.IsInfinity(y))
+ // If y is −0 and x is +0, the result is −0.
+ if (NumberInstance.IsPositiveZero(nx))
{
- if (double.IsPositiveInfinity(x))
- {
- return JsNumber.PositiveZero;
- }
-
- // If y>0 and y is finite and x is −∞, the result if an implementation-dependent approximation to +π.
- if (double.IsNegativeInfinity(x))
- {
- return JsNumber.PI;
- }
+ return JsNumber.NegativeZero;
}
-
- // If y<0 and y is finite and x is +∞, the result is −0.
- // If y<0 and y is finite and x is −∞, the result is an implementation-dependent approximation to −π.
- if (y < 0 && !double.IsInfinity(y))
+ // If y is −0 and x is −0, the result is an implementation-dependent approximation to −π.
+ if (NumberInstance.IsNegativeZero(nx))
{
- if (double.IsPositiveInfinity(x))
- {
- return JsNumber.NegativeZero;
- }
-
- // If y>0 and y is finite and x is −∞, the result if an implementation-dependent approximation to +π.
- if (double.IsNegativeInfinity(x))
- {
- return -System.Math.PI;
- }
+ return -System.Math.PI;
}
- // If y is +∞ and x is finite, the result is an implementation-dependent approximation to +π/2.
- if (double.IsPositiveInfinity(y) && !double.IsInfinity(x))
+ // If y is −0 and x<0, the result is an implementation-dependent approximation to −π.
+ if (nx < 0)
{
- return System.Math.PI/2;
+ return -System.Math.PI;
}
+ }
- // If y is −∞ and x is finite, the result is an implementation-dependent approximation to −π/2.
- if (double.IsNegativeInfinity(y) && !double.IsInfinity(x))
- {
- return -System.Math.PI / 2;
- }
+ // If y<0 and x is +0, the result is an implementation-dependent approximation to −π/2.
+ // If y<0 and x is −0, the result is an implementation-dependent approximation to −π/2.
+ if (ny < 0 && nx.Equals(0))
+ {
+ return -System.Math.PI/2;
+ }
- // If y is +∞ and x is +∞, the result is an implementation-dependent approximation to +π/4.
- if (double.IsPositiveInfinity(y) && double.IsPositiveInfinity(x))
+ // If y>0 and y is finite and x is +∞, the result is +0.
+ if (ny > 0 && !double.IsInfinity(ny))
+ {
+ if (double.IsPositiveInfinity(nx))
{
- return System.Math.PI/4;
+ return JsNumber.PositiveZero;
}
- // If y is +∞ and x is −∞, the result is an implementation-dependent approximation to +3π/4.
- if (double.IsPositiveInfinity(y) && double.IsNegativeInfinity(x))
+ // If y>0 and y is finite and x is −∞, the result if an implementation-dependent approximation to +π.
+ if (double.IsNegativeInfinity(nx))
{
- return 3 * System.Math.PI / 4;
+ return JsNumber.PI;
}
+ }
+
- // If y is −∞ and x is +∞, the result is an implementation-dependent approximation to −π/4.
- if (double.IsNegativeInfinity(y) && double.IsPositiveInfinity(x))
+ // If y<0 and y is finite and x is +∞, the result is −0.
+ // If y<0 and y is finite and x is −∞, the result is an implementation-dependent approximation to −π.
+ if (ny < 0 && !double.IsInfinity(ny))
+ {
+ if (double.IsPositiveInfinity(nx))
{
- return -System.Math.PI / 4;
+ return JsNumber.NegativeZero;
}
- // If y is −∞ and x is −∞, the result is an implementation-dependent approximation to −3π/4.
- if (double.IsNegativeInfinity(y) && double.IsNegativeInfinity(x))
+ // If y>0 and y is finite and x is −∞, the result if an implementation-dependent approximation to +π.
+ if (double.IsNegativeInfinity(nx))
{
- return - 3 * System.Math.PI / 4;
+ return -System.Math.PI;
}
+ }
- return System.Math.Atan2(y, x);
+ // If y is +∞ and x is finite, the result is an implementation-dependent approximation to +π/2.
+ if (double.IsPositiveInfinity(ny) && !double.IsInfinity(nx))
+ {
+ return System.Math.PI/2;
}
- private static JsValue Ceil(JsValue thisObject, JsValue[] arguments)
+ // If y is −∞ and x is finite, the result is an implementation-dependent approximation to −π/2.
+ if (double.IsNegativeInfinity(ny) && !double.IsInfinity(nx))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return -System.Math.PI / 2;
+ }
- if (double.IsNaN(x))
- {
- return JsNumber.DoubleNaN;
- }
- else if (NumberInstance.IsPositiveZero(x))
- {
- return JsNumber.PositiveZero;
- }
- else if (NumberInstance.IsNegativeZero(x))
- {
- return JsNumber.NegativeZero;
- }
- else if (double.IsPositiveInfinity(x))
- {
- return JsNumber.DoublePositiveInfinity;
- }
- else if (double.IsNegativeInfinity(x))
- {
- return JsNumber.DoubleNegativeInfinity;
- }
+ // If y is +∞ and x is +∞, the result is an implementation-dependent approximation to +π/4.
+ if (double.IsPositiveInfinity(ny) && double.IsPositiveInfinity(nx))
+ {
+ return System.Math.PI/4;
+ }
+
+ // If y is +∞ and x is −∞, the result is an implementation-dependent approximation to +3π/4.
+ if (double.IsPositiveInfinity(ny) && double.IsNegativeInfinity(nx))
+ {
+ return 3 * System.Math.PI / 4;
+ }
+
+ // If y is −∞ and x is +∞, the result is an implementation-dependent approximation to −π/4.
+ if (double.IsNegativeInfinity(ny) && double.IsPositiveInfinity(nx))
+ {
+ return -System.Math.PI / 4;
+ }
+
+ // If y is −∞ and x is −∞, the result is an implementation-dependent approximation to −3π/4.
+ if (double.IsNegativeInfinity(ny) && double.IsNegativeInfinity(nx))
+ {
+ return - 3 * System.Math.PI / 4;
+ }
+
+ return System.Math.Atan2(ny, nx);
+ }
+
+ ///
+ /// https://tc39.es/ecma262/#sec-math.ceil
+ ///
+ [JsFunction]
+ private static JsValue Ceil(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
+
+ if (double.IsNaN(n))
+ {
+ return JsNumber.DoubleNaN;
+ }
+ else if (NumberInstance.IsPositiveZero(n))
+ {
+ return JsNumber.PositiveZero;
+ }
+ else if (NumberInstance.IsNegativeZero(n))
+ {
+ return JsNumber.NegativeZero;
+ }
+ else if (double.IsPositiveInfinity(n))
+ {
+ return JsNumber.DoublePositiveInfinity;
+ }
+ else if (double.IsNegativeInfinity(n))
+ {
+ return JsNumber.DoubleNegativeInfinity;
+ }
#if NETFRAMEWORK
- if (x < 0 && x > -1)
+ if (n < 0 && n > -1)
{
return JsNumber.NegativeZero;
}
#endif
- return System.Math.Ceiling(x);
+ return System.Math.Ceiling(n);
+ }
+
+ ///
+ /// https://tc39.es/ecma262/#sec-math.cos
+ ///
+ [JsFunction]
+ private static JsValue Cos(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
+
+ if (double.IsNaN(n))
+ {
+ return JsNumber.DoubleNaN;
+ }
+ else if (NumberInstance.IsPositiveZero(n))
+ {
+ return JsNumber.PositiveOne;
+ }
+ else if (NumberInstance.IsNegativeZero(n))
+ {
+ return JsNumber.PositiveOne;
}
+ else if (double.IsInfinity(n))
+ {
+ return JsNumber.DoubleNaN;
+ }
+
+ return System.Math.Cos(n);
+ }
+
+ ///
+ /// https://tc39.es/ecma262/#sec-math.cosh
+ ///
+ [JsFunction]
+ private static JsValue Cosh(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
- private static JsValue Cos(JsValue thisObject, JsValue[] arguments)
+ if (double.IsNaN(n))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return JsNumber.DoubleNaN;
+ }
+ else if (NumberInstance.IsPositiveZero(n))
+ {
+ return JsNumber.PositiveOne;
+ }
+ else if (NumberInstance.IsNegativeZero(n))
+ {
+ return JsNumber.PositiveOne;
+ }
+ else if (double.IsInfinity(n))
+ {
+ return JsNumber.DoublePositiveInfinity;
+ }
- if (double.IsNaN(x))
- {
- return JsNumber.DoubleNaN;
- }
- else if (NumberInstance.IsPositiveZero(x))
- {
- return 1;
- }
- else if (NumberInstance.IsNegativeZero(x))
- {
- return 1;
- }
- else if (double.IsInfinity(x))
- {
- return JsNumber.DoubleNaN;
- }
+ return System.Math.Cosh(n);
+ }
- return System.Math.Cos(x);
+ ///
+ /// https://tc39.es/ecma262/#sec-math.exp
+ ///
+ [JsFunction]
+ private static JsValue Exp(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
+
+ if (double.IsNaN(n))
+ {
+ return JsNumber.DoubleNaN;
+ }
+ else if (NumberInstance.IsPositiveZero(n) || NumberInstance.IsNegativeZero(n))
+ {
+ return JsNumber.PositiveOne;
+ }
+ else if (double.IsPositiveInfinity(n))
+ {
+ return JsNumber.DoublePositiveInfinity;
+ }
+ else if (double.IsNegativeInfinity(n))
+ {
+ return JsNumber.PositiveZero;
}
- private static JsValue Cosh(JsValue thisObject, JsValue[] arguments)
+ return System.Math.Exp(n);
+ }
+
+ ///
+ /// https://tc39.es/ecma262/#sec-math.expm1
+ ///
+ [JsFunction]
+ private static JsValue Expm1(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
+
+ if (double.IsNaN(n) || NumberInstance.IsPositiveZero(n) || NumberInstance.IsNegativeZero(n) || double.IsPositiveInfinity(n))
+ {
+ return x;
+ }
+ if (double.IsNegativeInfinity(n))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return JsNumber.DoubleNegativeOne;
+ }
- if (double.IsNaN(x))
- {
- return JsNumber.DoubleNaN;
- }
- else if (NumberInstance.IsPositiveZero(x))
- {
- return 1;
- }
- else if (NumberInstance.IsNegativeZero(x))
- {
- return 1;
- }
- else if (double.IsInfinity(x))
- {
- return JsNumber.DoublePositiveInfinity;
- }
+ return System.Math.Exp(n) - 1.0;
+ }
+
+ ///
+ /// https://tc39.es/ecma262/#sec-math.floor
+ ///
+ [JsFunction]
+ private static JsValue Floor(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
- return System.Math.Cosh(x);
+ if (double.IsNaN(n))
+ {
+ return JsNumber.DoubleNaN;
}
+ else if (NumberInstance.IsPositiveZero(n))
+ {
+ return JsNumber.PositiveZero;
+ }
+ else if (NumberInstance.IsNegativeZero(n))
+ {
+ return JsNumber.NegativeZero;
+ }
+ else if (double.IsPositiveInfinity(n))
+ {
+ return JsNumber.DoublePositiveInfinity;
+ }
+ else if (double.IsNegativeInfinity(n))
+ {
+ return JsNumber.DoubleNegativeInfinity;
+ }
+
+ return System.Math.Floor(n);
+ }
- private static JsValue Exp(JsValue thisObject, JsValue[] arguments)
+ ///
+ /// https://tc39.es/ecma262/#sec-math.log
+ ///
+ [JsFunction]
+ private static JsValue Log(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
+
+ if (double.IsNaN(n))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return JsNumber.DoubleNaN;
+ }
+ if (n < 0)
+ {
+ return JsNumber.DoubleNaN;
+ }
+ else if (n == 0)
+ {
+ return JsNumber.DoubleNegativeInfinity;
+ }
+ else if (double.IsPositiveInfinity(n))
+ {
+ return JsNumber.DoublePositiveInfinity;
+ }
+ else if (n == 1)
+ {
+ return JsNumber.PositiveZero;
+ }
- if (double.IsNaN(x))
- {
- return JsNumber.DoubleNaN;
- }
- else if (NumberInstance.IsPositiveZero(x) || NumberInstance.IsNegativeZero(x))
- {
- return 1;
- }
- else if (double.IsPositiveInfinity(x))
- {
- return JsNumber.DoublePositiveInfinity;
- }
- else if (double.IsNegativeInfinity(x))
- {
- return JsNumber.PositiveZero;
- }
+ return System.Math.Log(n);
+ }
+
+ ///
+ /// https://tc39.es/ecma262/#sec-math.log1p
+ ///
+ [JsFunction]
+ private static JsValue Log1p(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
- return System.Math.Exp(x);
+ if (double.IsNaN(n))
+ {
+ return JsNumber.DoubleNaN;
}
- private static JsValue Expm1(JsValue thisObject, JsValue[] arguments)
+ if (n < -1)
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return JsNumber.DoubleNaN;
+ }
- if (double.IsNaN(x) || NumberInstance.IsPositiveZero(x) || NumberInstance.IsNegativeZero(x) || double.IsPositiveInfinity(x))
- {
- return arguments.At(0);
- }
- if (double.IsNegativeInfinity(x))
- {
- return JsNumber.DoubleNegativeOne;
- }
+ if (n == -1)
+ {
+ return JsNumber.DoubleNegativeInfinity;
+ }
- return System.Math.Exp(x) - 1.0;
+ if (n == 0 || double.IsPositiveInfinity(n))
+ {
+ return x;
}
- private static JsValue Floor(JsValue thisObject, JsValue[] arguments)
+ return System.Math.Log(1 + n);
+ }
+
+ ///
+ /// https://tc39.es/ecma262/#sec-math.log2
+ ///
+ [JsFunction]
+ private static JsValue Log2(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
+
+ if (double.IsNaN(n))
+ {
+ return JsNumber.DoubleNaN;
+ }
+ if (n < 0)
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return JsNumber.DoubleNaN;
+ }
+ else if (n == 0)
+ {
+ return JsNumber.DoubleNegativeInfinity;
+ }
+ else if (double.IsPositiveInfinity(n))
+ {
+ return JsNumber.DoublePositiveInfinity;
+ }
+ else if (n == 1)
+ {
+ return JsNumber.PositiveZero;
+ }
- if (double.IsNaN(x))
- {
- return JsNumber.DoubleNaN;
- }
- else if (NumberInstance.IsPositiveZero(x))
- {
- return JsNumber.PositiveZero;
- }
- else if (NumberInstance.IsNegativeZero(x))
- {
- return JsNumber.NegativeZero;
- }
- else if (double.IsPositiveInfinity(x))
- {
- return JsNumber.DoublePositiveInfinity;
- }
- else if (double.IsNegativeInfinity(x))
- {
- return JsNumber.DoubleNegativeInfinity;
- }
+ return System.Math.Log(n, 2);
+ }
+
+ ///
+ /// https://tc39.es/ecma262/#sec-math.log10
+ ///
+ [JsFunction]
+ private static JsValue Log10(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
- return System.Math.Floor(x);
+ if (double.IsNaN(n))
+ {
+ return JsNumber.DoubleNaN;
+ }
+ if (n < 0)
+ {
+ return JsNumber.DoubleNaN;
+ }
+ else if (n == 0)
+ {
+ return JsNumber.DoubleNegativeInfinity;
+ }
+ else if (double.IsPositiveInfinity(n))
+ {
+ return JsNumber.DoublePositiveInfinity;
+ }
+ else if (n == 1)
+ {
+ return JsNumber.PositiveZero;
}
- private static JsValue Log(JsValue thisObject, JsValue[] arguments)
+ return System.Math.Log10(n);
+ }
+
+ ///
+ /// https://tc39.es/ecma262/#sec-math.max
+ ///
+ [JsFunction]
+ private static JsValue Max(JsValue[] args)
+ {
+ if (args.Length == 0)
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return JsNumber.DoubleNegativeInfinity;
+ }
- if (double.IsNaN(x))
- {
- return JsNumber.DoubleNaN;
- }
- if (x < 0)
+ var highest = double.NegativeInfinity;
+
+ var coerced = args.Length < 128
+ ? stackalloc double[args.Length]
+ : new double[args.Length];
+
+ Coerced(args, coerced);
+
+ foreach (var number in coerced)
+ {
+ if (double.IsNaN(number))
{
return JsNumber.DoubleNaN;
}
- else if (x == 0)
+
+ if (NumberInstance.IsPositiveZero(number) && NumberInstance.IsNegativeZero(highest))
{
- return JsNumber.DoubleNegativeInfinity;
+ highest = 0;
}
- else if (double.IsPositiveInfinity(x))
+
+ if (number > highest)
{
- return JsNumber.DoublePositiveInfinity;
+ highest = number;
}
- else if (x == 1)
- {
- return JsNumber.PositiveZero;
- }
-
- return System.Math.Log(x);
}
- private static JsValue Log1p(JsValue thisObject, JsValue[] arguments)
+ return highest;
+ }
+
+ ///
+ /// https://tc39.es/ecma262/#sec-math.min
+ ///
+ [JsFunction]
+ private static JsValue Min(JsValue[] args)
+ {
+ if (args.Length == 0)
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return JsNumber.DoublePositiveInfinity;
+ }
- if (double.IsNaN(x))
- {
- return JsNumber.DoubleNaN;
- }
+ var coerced = args.Length < 128
+ ? stackalloc double[args.Length]
+ : new double[args.Length];
- if (x < -1)
+ Coerced(args, coerced);
+
+ var lowest = double.PositiveInfinity;
+ foreach (var number in coerced)
+ {
+ if (double.IsNaN(number))
{
return JsNumber.DoubleNaN;
}
- if (x == -1)
+ if (NumberInstance.IsNegativeZero(number) && NumberInstance.IsPositiveZero(lowest))
{
- return JsNumber.DoubleNegativeInfinity;
+ lowest = JsNumber.NegativeZero._value;
}
- if (x == 0 || double.IsPositiveInfinity(x))
+ if (number < lowest)
{
- return arguments.At(0);
+ lowest = number;
}
+ }
- return System.Math.Log(1 + x);
+ return lowest;
+ }
+
+ ///
+ /// https://tc39.es/ecma262/#sec-math.pow
+ ///
+ [JsFunction]
+ private static JsValue Pow(JsValue @base, JsValue exponent)
+ {
+ var x = TypeConverter.ToNumber(@base);
+ var y = TypeConverter.ToNumber(exponent);
+
+ // check easy case where values are valid
+ if (x > 1 && y > 1 && x < int.MaxValue && y < int.MaxValue)
+ {
+ return System.Math.Pow(x, y);
}
- private static JsValue Log2(JsValue thisObject, JsValue[] arguments)
+ if (y == 0)
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return 1;
+ }
- if (double.IsNaN(x))
- {
- return JsNumber.DoubleNaN;
- }
- if (x < 0)
- {
- return JsNumber.DoubleNaN;
- }
- else if (x == 0)
- {
- return JsNumber.DoubleNegativeInfinity;
- }
- else if (double.IsPositiveInfinity(x))
+ return HandlePowUnlikely(y, x);
+ }
+
+ private static JsValue HandlePowUnlikely(double y, double x)
+ {
+ if (double.IsNaN(y))
+ {
+ return JsNumber.DoubleNaN;
+ }
+
+ if (double.IsNaN(x))
+ {
+ return JsNumber.DoubleNaN;
+ }
+
+ var absX = System.Math.Abs(x);
+ if (absX > 1)
+ {
+ if (double.IsPositiveInfinity(y))
{
return JsNumber.DoublePositiveInfinity;
}
- else if (x == 1)
+
+ if (double.IsNegativeInfinity(y))
{
return JsNumber.PositiveZero;
}
-
- return System.Math.Log(x, 2);
}
- private static JsValue Log10(JsValue thisObject, JsValue[] arguments)
+ if (absX == 1)
{
- var x = TypeConverter.ToNumber(arguments.At(0));
-
- if (double.IsNaN(x))
+ if (double.IsInfinity(y))
{
return JsNumber.DoubleNaN;
}
- if (x < 0)
- {
- return JsNumber.DoubleNaN;
- }
- else if (x == 0)
+ }
+
+ if (absX < 1)
+ {
+ if (double.IsPositiveInfinity(y))
{
- return JsNumber.DoubleNegativeInfinity;
+ return 0;
}
- else if (double.IsPositiveInfinity(x))
+
+ if (double.IsNegativeInfinity(y))
{
return JsNumber.DoublePositiveInfinity;
}
- else if (x == 1)
- {
- return JsNumber.PositiveZero;
- }
-
- return System.Math.Log10(x);
}
- ///
- /// https://tc39.es/ecma262/#sec-math.max
- ///
- private static JsValue Max(JsValue thisObject, JsValue[] arguments)
+ if (double.IsPositiveInfinity(x))
{
- if (arguments.Length == 0)
+ if (y > 0)
{
- return JsNumber.DoubleNegativeInfinity;
+ return JsNumber.DoublePositiveInfinity;
}
- var highest = double.NegativeInfinity;
- foreach (var number in Coerced(arguments))
+ if (y < 0)
{
- if (double.IsNaN(number))
- {
- return JsNumber.DoubleNaN;
- }
-
- if (NumberInstance.IsPositiveZero(number) && NumberInstance.IsNegativeZero(highest))
- {
- highest = 0;
- }
-
- if (number > highest)
- {
- highest = number;
- }
+ return JsNumber.PositiveZero;
}
-
- return highest;
}
- ///
- /// https://tc39.es/ecma262/#sec-math.min
- ///
- private static JsValue Min(JsValue thisObject, JsValue[] arguments)
+ if (double.IsNegativeInfinity(x))
{
- if (arguments.Length == 0)
+ if (y > 0)
{
+ if (System.Math.Abs(y % 2).Equals(1))
+ {
+ return JsNumber.DoubleNegativeInfinity;
+ }
+
return JsNumber.DoublePositiveInfinity;
}
- var lowest = double.PositiveInfinity;
- foreach (var number in Coerced(arguments))
+ if (y < 0)
{
- if (double.IsNaN(number))
- {
- return JsNumber.DoubleNaN;
- }
-
- if (NumberInstance.IsNegativeZero(number) && NumberInstance.IsPositiveZero(lowest))
+ if (System.Math.Abs(y % 2).Equals(1))
{
- lowest = JsNumber.NegativeZero._value;
+ return JsNumber.NegativeZero;
}
- if (number < lowest)
- {
- lowest = number;
- }
+ return JsNumber.PositiveZero;
}
-
- return lowest;
}
- private static JsValue Pow(JsValue thisObject, JsValue[] arguments)
+ if (NumberInstance.IsPositiveZero(x))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
- var y = TypeConverter.ToNumber(arguments.At(1));
-
- // check easy case where values are valid
- if (x > 1 && y > 1 && x < int.MaxValue && y < int.MaxValue)
+ // If x is +0 and y>0, the result is +0.
+ if (y > 0)
{
- return System.Math.Pow(x, y);
+ return 0;
}
- if (y == 0)
+ // If x is +0 and y<0, the result is +∞.
+ if (y < 0)
{
- return 1;
+ return JsNumber.DoublePositiveInfinity;
}
-
- return HandlePowUnlikely(y, x);
}
- private static JsValue HandlePowUnlikely(double y, double x)
- {
- if (double.IsNaN(y))
- {
- return JsNumber.DoubleNaN;
- }
-
- if (double.IsNaN(x))
- {
- return JsNumber.DoubleNaN;
- }
- var absX = System.Math.Abs(x);
- if (absX > 1)
+ if (NumberInstance.IsNegativeZero(x))
+ {
+ if (y > 0)
{
- if (double.IsPositiveInfinity(y))
+ // If x is −0 and y>0 and y is an odd integer, the result is −0.
+ if (System.Math.Abs(y % 2).Equals(1))
{
- return JsNumber.DoublePositiveInfinity;
+ return JsNumber.NegativeZero;
}
- if (double.IsNegativeInfinity(y))
- {
- return JsNumber.PositiveZero;
- }
+ // If x is −0 and y>0 and y is not an odd integer, the result is +0.
+ return JsNumber.PositiveZero;
}
- if (absX == 1)
+ if (y < 0)
{
- if (double.IsInfinity(y))
+ // If x is −0 and y<0 and y is an odd integer, the result is −∞.
+ if (System.Math.Abs(y % 2).Equals(1))
{
- return JsNumber.DoubleNaN;
+ return JsNumber.DoubleNegativeInfinity;
}
+
+ // If x is −0 and y<0 and y is not an odd integer, the result is +∞.
+ return JsNumber.DoublePositiveInfinity;
}
+ }
- if (absX < 1)
- {
- if (double.IsPositiveInfinity(y))
- {
- return 0;
- }
+ // If x<0 and x is finite and y is finite and y is not an integer, the result is NaN.
+ if (x < 0 && !double.IsInfinity(x) && !double.IsInfinity(y) && !y.Equals((int) y))
+ {
+ return JsNumber.DoubleNaN;
+ }
- if (double.IsNegativeInfinity(y))
- {
- return JsNumber.DoublePositiveInfinity;
- }
- }
+ return System.Math.Pow(x, y);
+ }
- if (double.IsPositiveInfinity(x))
- {
- if (y > 0)
- {
- return JsNumber.DoublePositiveInfinity;
- }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.random
+ ///
+ [JsFunction]
+#pragma warning disable CA1822 // Mark members as static
+ private JsValue Random()
+ {
+#if NET6_0_OR_GREATER
+ return System.Random.Shared.NextDouble();
+#else
+ if(_random == null)
+ {
+ _random = new Random();
+ }
- if (y < 0)
- {
- return JsNumber.PositiveZero;
- }
- }
+ return _random.NextDouble();
+#endif
+ }
+#pragma warning restore CA1822
- if (double.IsNegativeInfinity(x))
- {
- if (y > 0)
- {
- if (System.Math.Abs(y % 2).Equals(1))
- {
- return JsNumber.DoubleNegativeInfinity;
- }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.round
+ ///
+ [JsFunction]
+ private static JsValue Round(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
+ var round = System.Math.Round(n);
+ if (round.Equals(n - 0.5))
+ {
+ return round + 1;
+ }
- return JsNumber.DoublePositiveInfinity;
- }
+ return round;
+ }
- if (y < 0)
- {
- if (System.Math.Abs(y % 2).Equals(1))
- {
- return JsNumber.NegativeZero;
- }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.fround
+ ///
+ [JsFunction]
+ private static JsValue Fround(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
+ return (double) (float) n;
+ }
- return JsNumber.PositiveZero;
- }
- }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.sin
+ ///
+ [JsFunction]
+ private static JsValue Sin(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
- if (NumberInstance.IsPositiveZero(x))
- {
- // If x is +0 and y>0, the result is +0.
- if (y > 0)
- {
- return 0;
- }
+ if (double.IsNaN(n))
+ {
+ return JsNumber.DoubleNaN;
+ }
+ else if (NumberInstance.IsPositiveZero(n))
+ {
+ return JsNumber.PositiveZero;
+ }
+ else if (NumberInstance.IsNegativeZero(n))
+ {
+ return JsNumber.NegativeZero;
+ }
+ else if (double.IsInfinity(n))
+ {
+ return JsNumber.DoubleNaN;
+ }
- // If x is +0 and y<0, the result is +∞.
- if (y < 0)
- {
- return JsNumber.DoublePositiveInfinity;
- }
- }
+ return System.Math.Sin(n);
+ }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.sinh
+ ///
+ [JsFunction]
+ private static JsValue Sinh(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
- if (NumberInstance.IsNegativeZero(x))
- {
- if (y > 0)
- {
- // If x is −0 and y>0 and y is an odd integer, the result is −0.
- if (System.Math.Abs(y % 2).Equals(1))
- {
- return JsNumber.NegativeZero;
- }
-
- // If x is −0 and y>0 and y is not an odd integer, the result is +0.
- return JsNumber.PositiveZero;
- }
+ if (double.IsNaN(n))
+ {
+ return JsNumber.DoubleNaN;
+ }
+ else if (NumberInstance.IsPositiveZero(n))
+ {
+ return JsNumber.PositiveZero;
+ }
+ else if (NumberInstance.IsNegativeZero(n))
+ {
+ return JsNumber.NegativeZero;
+ }
+ else if (double.IsNegativeInfinity(n))
+ {
+ return JsNumber.DoubleNegativeInfinity;
+ }
+ else if (double.IsPositiveInfinity(n))
+ {
+ return JsNumber.DoublePositiveInfinity;
+ }
- if (y < 0)
- {
- // If x is −0 and y<0 and y is an odd integer, the result is −∞.
- if (System.Math.Abs(y % 2).Equals(1))
- {
- return JsNumber.DoubleNegativeInfinity;
- }
-
- // If x is −0 and y<0 and y is not an odd integer, the result is +∞.
- return JsNumber.DoublePositiveInfinity;
- }
- }
+ return System.Math.Sinh(n);
+ }
- // If x<0 and x is finite and y is finite and y is not an integer, the result is NaN.
- if (x < 0 && !double.IsInfinity(x) && !double.IsInfinity(y) && !y.Equals((int) y))
- {
- return JsNumber.DoubleNaN;
- }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.sqrt
+ ///
+ [JsFunction]
+ private static JsValue Sqrt(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
+ return System.Math.Sqrt(n);
+ }
- return System.Math.Pow(x, y);
- }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.tan
+ ///
+ [JsFunction]
+ private static JsValue Tan(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
+ return System.Math.Tan(n);
+ }
- private JsValue Random(JsValue thisObject, JsValue[] arguments)
- {
- if(_random == null)
- {
- _random = new Random();
- }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.tanh
+ ///
+ [JsFunction]
+ private static JsValue Tanh(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
+ return System.Math.Tanh(n);
+ }
- return _random.NextDouble();
- }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.trunc
+ ///
+ [JsFunction]
+ private static JsValue Trunc(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
- private static JsValue Round(JsValue thisObject, JsValue[] arguments)
+ if (double.IsNaN(n))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
- var round = System.Math.Round(x);
- if (round.Equals(x - 0.5))
- {
- return round + 1;
- }
-
- return round;
+ return JsNumber.DoubleNaN;
}
- private static JsValue Fround(JsValue thisObject, JsValue[] arguments)
+ if (NumberInstance.IsPositiveZero(n) || NumberInstance.IsNegativeZero(n))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
- return (double) (float) x;
+ return n;
}
- private static JsValue Sin(JsValue thisObject, JsValue[] arguments)
+ if (double.IsPositiveInfinity(n))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
-
- if (double.IsNaN(x))
- {
- return JsNumber.DoubleNaN;
- }
- else if (NumberInstance.IsPositiveZero(x))
- {
- return JsNumber.PositiveZero;
- }
- else if (NumberInstance.IsNegativeZero(x))
- {
- return JsNumber.NegativeZero;
- }
- else if (double.IsInfinity(x))
- {
- return JsNumber.DoubleNaN;
- }
-
- return System.Math.Sin(x);
+ return JsNumber.DoublePositiveInfinity;
}
- private static JsValue Sinh(JsValue thisObject, JsValue[] arguments)
+ if (double.IsNegativeInfinity(n))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return JsNumber.DoubleNegativeInfinity;
+ }
- if (double.IsNaN(x))
- {
- return JsNumber.DoubleNaN;
- }
- else if (NumberInstance.IsPositiveZero(x))
- {
- return JsNumber.PositiveZero;
- }
- else if (NumberInstance.IsNegativeZero(x))
- {
- return JsNumber.NegativeZero;
- }
- else if (double.IsNegativeInfinity(x))
- {
- return JsNumber.DoubleNegativeInfinity;
- }
- else if (double.IsPositiveInfinity(x))
- {
- return JsNumber.DoublePositiveInfinity;
- }
+ return System.Math.Truncate(n);
+ }
- return System.Math.Sinh(x);
- }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.sign
+ ///
+ [JsFunction]
+ private static JsValue Sign(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
- private static JsValue Sqrt(JsValue thisObject, JsValue[] arguments)
+ if (double.IsNaN(n))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
- return System.Math.Sqrt(x);
+ return JsNumber.DoubleNaN;
}
- private static JsValue Tan(JsValue thisObject, JsValue[] arguments)
+ if (NumberInstance.IsPositiveZero(n) || NumberInstance.IsNegativeZero(n))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
- return System.Math.Tan(x);
+ return n;
}
- private static JsValue Tanh(JsValue thisObject, JsValue[] arguments)
+ if (double.IsPositiveInfinity(n))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
- return System.Math.Tanh(x);
+ return 1;
}
- private static JsValue Truncate(JsValue thisObject, JsValue[] arguments)
+ if (double.IsNegativeInfinity(n))
{
- var x = TypeConverter.ToNumber(arguments.At(0));
-
- if (double.IsNaN(x))
- {
- return JsNumber.DoubleNaN;
- }
-
- if (NumberInstance.IsPositiveZero(x) || NumberInstance.IsNegativeZero(x))
- {
- return x;
- }
+ return -1;
+ }
- if (double.IsPositiveInfinity(x))
- {
- return JsNumber.DoublePositiveInfinity;
- }
+ return System.Math.Sign(n);
+ }
- if (double.IsNegativeInfinity(x))
- {
- return JsNumber.DoubleNegativeInfinity;
- }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.cbrt
+ ///
+ [JsFunction]
+ private static JsValue Cbrt(JsValue x)
+ {
+ var n = TypeConverter.ToNumber(x);
- return System.Math.Truncate(x);
+ if (double.IsNaN(n))
+ {
+ return JsNumber.DoubleNaN;
+ }
+ else if (NumberInstance.IsPositiveZero(n) || NumberInstance.IsNegativeZero(n))
+ {
+ return n;
+ }
+ else if (double.IsPositiveInfinity(n))
+ {
+ return JsNumber.DoublePositiveInfinity;
+ }
+ else if (double.IsNegativeInfinity(n))
+ {
+ return JsNumber.DoubleNegativeInfinity;
}
- private static JsValue Sign(JsValue thisObject, JsValue[] arguments)
+ if (System.Math.Sign(n) >= 0)
{
- var x = TypeConverter.ToNumber(arguments.At(0));
+ return System.Math.Pow(n, 1.0/3.0);
+ }
- if (double.IsNaN(x))
- {
- return JsNumber.DoubleNaN;
- }
+ return -1 * System.Math.Pow(System.Math.Abs(n), 1.0 / 3.0);
+ }
- if (NumberInstance.IsPositiveZero(x) || NumberInstance.IsNegativeZero(x))
- {
- return x;
- }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.hypot
+ ///
+ [JsFunction]
+ private static JsValue Hypot(JsValue[] args)
+ {
+ var coerced = args.Length < 128
+ ? stackalloc double[args.Length]
+ : new double[args.Length];
- if (double.IsPositiveInfinity(x))
- {
- return 1;
- }
+ Coerced(args, coerced);
- if (double.IsNegativeInfinity(x))
+ foreach (var number in coerced)
+ {
+ if (double.IsInfinity(number))
{
- return -1;
+ return JsNumber.DoublePositiveInfinity;
}
-
- return System.Math.Sign(x);
}
- private static JsValue Cbrt(JsValue thisObject, JsValue[] arguments)
+ var onlyZero = true;
+ double y = 0;
+ foreach (var number in coerced)
{
- var x = TypeConverter.ToNumber(arguments.At(0));
-
- if (double.IsNaN(x))
+ if (double.IsNaN(number))
{
return JsNumber.DoubleNaN;
}
- else if (NumberInstance.IsPositiveZero(x) || NumberInstance.IsNegativeZero(x))
- {
- return x;
- }
- else if (double.IsPositiveInfinity(x))
- {
- return JsNumber.DoublePositiveInfinity;
- }
- else if (double.IsNegativeInfinity(x))
- {
- return JsNumber.DoubleNegativeInfinity;
- }
- if (System.Math.Sign(x) >= 0)
+ if (onlyZero && number != 0)
{
- return System.Math.Pow(x, 1.0/3.0);
+ onlyZero = false;
}
- return -1 * System.Math.Pow(System.Math.Abs(x), 1.0 / 3.0);
+ y += number * number;
}
- ///
- /// https://tc39.es/ecma262/#sec-math.hypot
- ///
- private static JsValue Hypot(JsValue thisObject, JsValue[] arguments)
+ if (onlyZero)
{
- var coerced = Coerced(arguments);
-
- foreach (var number in coerced)
- {
- if (double.IsInfinity(number))
- {
- return JsNumber.DoublePositiveInfinity;
- }
- }
-
- var onlyZero = true;
- double y = 0;
- foreach (var number in coerced)
- {
- if (double.IsNaN(number))
- {
- return JsNumber.DoubleNaN;
- }
-
- if (onlyZero && number != 0)
- {
- onlyZero = false;
- }
+ return JsNumber.PositiveZero;
+ }
- y += number * number;
- }
+ return System.Math.Sqrt(y);
+ }
- if (onlyZero)
- {
- return JsNumber.PositiveZero;
- }
+ ///
+ /// https://tc39.es/ecma262/#sec-math.imul
+ ///
+ [JsFunction]
+ private static JsValue Imul(JsValue x, JsValue y)
+ {
+ var a = TypeConverter.ToInt32(x);
+ var b = TypeConverter.ToInt32(y);
- return System.Math.Sqrt(y);
- }
+ return a * b;
+ }
- private static double[] Coerced(JsValue[] arguments)
+ ///
+ /// https://tc39.es/ecma262/#sec-math.clz32
+ ///
+ [JsFunction]
+ private static JsValue Clz32(JsValue x)
+ {
+ var n = TypeConverter.ToInt32(x);
+ if (n < 0)
{
- // TODO stackalloc
- var coerced = new double[arguments.Length];
- for (var i = 0; i < arguments.Length; i++)
- {
- var argument = arguments[i];
- coerced[i] = TypeConverter.ToNumber(argument);
- }
-
- return coerced;
+ return 0;
}
- private static JsValue Imul(JsValue thisObject, JsValue[] arguments)
+ if (n == 0)
{
- var x = TypeConverter.ToInt32(arguments.At(0));
- var y = TypeConverter.ToInt32(arguments.At(1));
-
- return x * y;
+ return 32;
}
- private static JsValue Clz32(JsValue thisObject, JsValue[] arguments)
+ var res = 0;
+ var shift = 16;
+ while (n > 1)
{
- var x = TypeConverter.ToInt32(arguments.At(0));
- if (x < 0)
- {
- return 0;
- }
-
- if (x == 0)
+ var temp = n >> shift;
+ if (temp != 0)
{
- return 32;
+ n = temp;
+ res += shift;
}
- var res = 0;
- var shift = 16;
- while (x > 1)
- {
- var temp = x >> shift;
- if (temp != 0)
- {
- x = temp;
- res += shift;
- }
+ shift >>= 1;
+ }
- shift >>= 1;
- }
+ return 31 - res;
+ }
- return 31 - res;
+ private static void Coerced(JsValue[] arguments, Span coerced)
+ {
+ for (var i = 0; i < arguments.Length; i++)
+ {
+ var argument = arguments[i];
+ coerced[i] = TypeConverter.ToNumber(argument);
}
}
}
diff --git a/Jint/Runtime/Descriptors/PropertyDescriptor.cs b/Jint/Runtime/Descriptors/PropertyDescriptor.cs
index 3b3f290dd9..9d95f06de8 100644
--- a/Jint/Runtime/Descriptors/PropertyDescriptor.cs
+++ b/Jint/Runtime/Descriptors/PropertyDescriptor.cs
@@ -11,6 +11,7 @@ public class PropertyDescriptor
{
public static readonly PropertyDescriptor Undefined = new UndefinedPropertyDescriptor();
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)]
internal PropertyFlag _flags;
internal JsValue? _value;