Skip to content

Commit dee9e03

Browse files
committed
Added Number object.
Further improvement to this. Small clean-up.
1 parent 3d89a79 commit dee9e03

File tree

5 files changed

+129
-32
lines changed

5 files changed

+129
-32
lines changed

CSharpToJavaScript/APIs/JS/Ecma/Date.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
using CSharpToJavaScript.Utils;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
7-
using static CSharpToJavaScript.APIs.JS.Date;
8-
using static System.Runtime.InteropServices.JavaScript.JSType;
92

103
namespace CSharpToJavaScript.APIs.JS
114
{
@@ -33,7 +26,7 @@ public static float Parse(string str)
3326
}
3427

3528
[To(ToAttribute.Default)]
36-
public static float UTC(float year, float month = 0,float date = 1, float hours = 0, float minutes = 0, float seconds = 0, float ms = 0)
29+
public static float UTC(float year, float month = 0, float date = 1, float hours = 0, float minutes = 0, float seconds = 0, float ms = 0)
3730
{
3831
throw new System.NotImplementedException();
3932
}

CSharpToJavaScript/APIs/JS/Ecma/GlobalObject.cs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
using CSharpToJavaScript.Utils;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.ComponentModel;
5-
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
2+
83

94
namespace CSharpToJavaScript.APIs.JS
105
{
6+
[To(ToAttribute.FirstCharToLowerCase)]
117
//https://262.ecma-international.org/14.0/#sec-global-object
12-
public class GlobalObject
8+
public partial class GlobalObject
139
{
1410
[To(ToAttribute.FirstCharToLowerCase)]
15-
public class GlobalThis
11+
public class GlobalThis : GlobalObject
1612
{
17-
public static Window Window { get; set; } = new();
13+
public static Window Window { get; } = new();
1814
public static console Console { get; set; } = new();
15+
16+
[To(ToAttribute.Default)]
17+
public static string Date(string x)
18+
{
19+
throw new System.NotImplementedException();
20+
}
1921
}
2022

2123
[To(ToAttribute.Default)]
@@ -37,14 +39,25 @@ public class Undefined
3739

3840
//Do I need this? TODO!
3941
//https://262.ecma-international.org/14.0/#sec-constructor-properties-of-the-global-object
42+
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
4043
//
44+
//DO THIS IN !GlobalThis!
45+
//As far as I can understand, you can only access Global Object through GlobalThis in Classes.
46+
//It's only beneficial! We can emulate construction without "new" like GlobalThis.Date()
47+
//DO THIS IN !GlobalThis!
48+
//
49+
//[To(ToAttribute.Default)]
50+
//public static string Date(string x)
51+
//{
52+
//throw new System.NotImplementedException();
53+
//}
4154

4255
[To(ToAttribute.FirstCharToLowerCase)]
4356
public static dynamic Eval(string x)
4457
{
4558
throw new System.NotImplementedException();
4659
}
47-
60+
4861
[To(ToAttribute.FirstCharToLowerCase)]
4962
public static bool IsFinite(float number)
5063
{

CSharpToJavaScript/APIs/JS/Ecma/Math.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
using CSharpToJavaScript.Utils;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
2+
73

84
namespace CSharpToJavaScript.APIs.JS
95
{
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using CSharpToJavaScript.Utils;
2+
3+
namespace CSharpToJavaScript.APIs.JS
4+
{
5+
//https://262.ecma-international.org/14.0/#sec-number-objects
6+
[To(ToAttribute.Default)]
7+
public partial class Number : NumberPrototype
8+
{
9+
public dynamic Value { get; set; }
10+
public static implicit operator Number(double value) { return new Number { Value = value }; }
11+
public static implicit operator double(Number value) { return new Number { Value = value }; }
12+
13+
[To(ToAttribute.FirstCharToLowerCase)]
14+
public static NumberPrototype Prototype { get; } = new();
15+
16+
public const double EPSILON = 2.2204460492503130808472633361816 * 10-16;
17+
public const double MAX_SAFE_INTEGER = 9007199254740992;
18+
public const double MAX_VALUE = 1.7976931348623157 * 10308;
19+
public const double MIN_SAFE_INTEGER = -9007199254740991;
20+
public const double MIN_VALUE = 5 * 10 -324;
21+
public GlobalObject.NaN NaN = new();
22+
public const double NEGATIVE_INFINITY = double.NegativeInfinity;
23+
public const double POSITIVE_INFINITY = double.PositiveInfinity;
24+
25+
public Number() { }
26+
public Number(double value) { }
27+
28+
[To(ToAttribute.FirstCharToLowerCase)]
29+
public bool IsFinite(double number)
30+
{
31+
throw new System.NotImplementedException();
32+
}
33+
34+
[To(ToAttribute.FirstCharToLowerCase)]
35+
public bool IsInteger(double number)
36+
{
37+
throw new System.NotImplementedException();
38+
}
39+
40+
[To(ToAttribute.FirstCharToLowerCase)]
41+
public bool IsNaN(double number)
42+
{
43+
throw new System.NotImplementedException();
44+
}
45+
46+
[To(ToAttribute.FirstCharToLowerCase)]
47+
public bool IsSafeInteger(double number)
48+
{
49+
throw new System.NotImplementedException();
50+
}
51+
52+
[To(ToAttribute.FirstCharToLowerCase)]
53+
public float ParseFloat(string str)
54+
{
55+
throw new System.NotImplementedException();
56+
}
57+
58+
[To(ToAttribute.FirstCharToLowerCase)]
59+
public int ParseInt(string str, dynamic radix)
60+
{
61+
throw new System.NotImplementedException();
62+
}
63+
}
64+
[To(ToAttribute.FirstCharToLowerCase)]
65+
public class NumberPrototype
66+
{
67+
public string ToExponential(dynamic fractionDigits)
68+
{
69+
throw new System.NotImplementedException();
70+
}
71+
public string ToFixed(dynamic fractionDigits)
72+
{
73+
throw new System.NotImplementedException();
74+
}
75+
public string ToLocaleString(dynamic? reserved1 = null, dynamic? reserved2 = null)
76+
{
77+
throw new System.NotImplementedException();
78+
}
79+
public string ToPrecision(dynamic precision)
80+
{
81+
throw new System.NotImplementedException();
82+
}
83+
public string ToString(dynamic? radix = null)
84+
{
85+
throw new System.NotImplementedException();
86+
}
87+
public float ValueOf()
88+
{
89+
throw new System.NotImplementedException();
90+
}
91+
}
92+
}

CSharpToJavaScript/Walker.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ where n.IsKind(SyntaxKind.ClassDeclaration)
16451645

16461646
foreach (MemberDeclarationSyntax item in mem)
16471647
{
1648-
SyntaxToken _sT = default;
1648+
SyntaxToken? _sT = null;
16491649
if (item is MethodDeclarationSyntax m)
16501650
{
16511651
_sT = m.Identifier;
@@ -1665,7 +1665,7 @@ where e.IsKind(SyntaxKind.IdentifierToken)
16651665
_sT = d3.Last();
16661666
}
16671667

1668-
if (_aes.Left.ToString().Contains(_sT.Text))
1668+
if (_sT != null && _aes.Left.ToString() == _sT?.Text)
16691669
{
16701670
//Todo?
16711671
//VariableDeclarationSyntax s = item.DescendantNodes().First(e => e.IsKind(SyntaxKind.VariableDeclaration)) as VariableDeclarationSyntax;
@@ -1734,6 +1734,12 @@ where e.IsKind(SyntaxKind.IdentifierToken)
17341734
break;
17351735
}
17361736

1737+
//TODO??? Test??
1738+
if (syntaxNode.IsKind(SyntaxKind.PredefinedType))
1739+
{
1740+
break;
1741+
}
1742+
17371743
if (CustomCSNamesToJS(syntaxNode) == false)
17381744
{
17391745
JSSB.Append(' ');
@@ -2057,8 +2063,9 @@ where e.IsKind(SyntaxKind.GenericName)
20572063

20582064
if (_iSymbol != null && _iSymbol.Kind == SymbolKind.Local)
20592065
{
2060-
//base.VisitIdentifierName(node);
2061-
return false;
2066+
//TODO! TEST THIS!
2067+
//DO NOT REMOVE BREAKPOINT TEST THIS!
2068+
//return false;
20622069
}
20632070

20642071
ClassDeclarationSyntax _class = (ClassDeclarationSyntax)node.Ancestors().First(n => n.Kind() == SyntaxKind.ClassDeclaration);
@@ -2074,7 +2081,7 @@ where e.IsKind(SyntaxKind.IdentifierToken)
20742081
select e;
20752082
_sT = d3.First();*/
20762083

2077-
_sT = m.Identifier;
2084+
_sT = m.Identifier;
20782085
}
20792086

20802087
if (item is PropertyDeclarationSyntax p)
@@ -2113,7 +2120,6 @@ where e.IsKind(SyntaxKind.IdentifierToken)
21132120
}
21142121
}
21152122

2116-
//base.VisitIdentifierName(node);
21172123
return false;
21182124
}
21192125

@@ -2234,9 +2240,6 @@ where e.IsKind(SyntaxKind.IdentifierToken)
22342240
}
22352241
_CSTOJS.Log("WARNING! Diagnostics ends ---");
22362242
}
2237-
//_CSTOJS.Log($"WARNING! !-{node}-! By reaching this means, a name did not convert to JS. CHECK FOR UPPERCASE CHARACTERS IN NAMES IN THE JS FILE!");
2238-
2239-
//base.VisitIdentifierName(node);
22402243
return false;
22412244
}
22422245
}

0 commit comments

Comments
 (0)