Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 59 additions & 3 deletions Unity/Package/Runtime/V8/SplitProxy/V8SplitProxyHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ internal StdV8ValueArray(Ptr pArray)
{
ptr = pArray;
owns = false;

data = pArray != Ptr.Null
? V8SplitProxyNative.Instance.StdV8ValueArray_GetData(ptr) : V8Value.Ptr.Null;
}
Expand Down Expand Up @@ -962,6 +962,15 @@ public Decoded Decode()
});
}

/// <summary>
/// Store a <see cref="BigInteger"/> in the wrapped V8Value as a <see cref="Type.BigInt"/>.
/// </summary>
/// <param name="value">The value to store.</param>
public void SetBigInt(BigInteger value)
{
SetBigInt(ptr, value);
}

/// <summary>
/// Store a <see cref="bool"/> in the wrapped V8Value as a <see cref="Type.Boolean"/>.
/// </summary>
Expand All @@ -971,6 +980,15 @@ public void SetBoolean(bool value)
SetBoolean(ptr, value);
}

/// <summary>
/// Store a <see cref="DateTime"/> in the wrapped V8Value as a <see cref="Type.DateTime"/>.
/// </summary>
/// <param name="value">The value to store.</param>
public void SetDateTime(DateTime value)
{
SetDateTime(ptr, value);
}

/// <summary>
/// Store a pointer to a host object in the wrapped V8Value as a <see cref="Type.HostObject"/>
/// or <see cref="Type.Null"/>.
Expand Down Expand Up @@ -1010,6 +1028,15 @@ public void SetNull()
SetNull(ptr);
}

/// <summary>
/// Store a <see cref="double"/> in the wrapped V8Value as a <see cref="Type.Number"/>.
/// </summary>
/// <param name="value">The value to store.</param>
public void SetNumber(double value)
{
SetNumeric(ptr, value);
}

/// <summary>
/// Store a <see cref="string"/> in the wrapped V8Value as a <see cref="Type.String"/> or
/// <see cref="Type.Null"/>.
Expand All @@ -1023,6 +1050,15 @@ public void SetString(string value)
SetNull(ptr);
}

/// <summary>
/// Store a <see cref="uint"/> in the wrapped V8Value as a <see cref="Type.UInt32"/>.
/// </summary>
/// <param name="value">The value to store.</param>
public void SetUInt32(uint value)
{
SetNumeric(ptr, value);
}

internal const int Size = 16;

internal static IScope<Ptr> CreateScope()
Expand Down Expand Up @@ -1602,7 +1638,7 @@ public void Dispose()
if (Type == Type.V8Object)
V8SplitProxyNative.Instance.V8Entity_DestroyHandle((V8Entity.Handle)PtrOrHandle);
}

/// <summary>
/// Check that the value is a <see cref="Type.Boolean"/> and return it as a
/// <see cref="bool"/>.
Expand All @@ -1617,6 +1653,26 @@ public readonly bool GetBoolean()
return Int32Value != 0;
}

/// <summary>
/// Chech that the value is a <see cref="Type.DateTime"/> and return it as a
/// <see cref="DateTime"/>.
/// </summary>
/// <returns>The <see cref="Type.DateTime"/> value as a <see cref="DateTime"/>.</returns>
/// <remarks>
/// The <see cref="V8ScriptEngine"/> must have been created with the
/// <see cref="V8ScriptEngineFlags.EnableDateTimeConversion"/> flag set for this method to
/// work. Else, the Date object will be passed from JavaScript as a
/// <see cref="Type.V8Object"/>.
/// </remarks>
public readonly DateTime GetDateTime()
{
if (Type != Type.DateTime)
throw new InvalidCastException($"Tried to get a DateTime out of a {GetTypeName()}");

return new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)
+ TimeSpan.FromMilliseconds(DoubleValue);
}

/// <summary>
/// Check that the value is a <see cref="Type.HostObject"/> and return it as a
/// <see cref="decimal"/>.
Expand Down Expand Up @@ -2173,7 +2229,7 @@ public void Invoke(StdV8ValueArray args, V8Value result, bool asConstructor = fa
V8Value.Ptr pResult = result.ptr;
V8SplitProxyNative.Invoke(instance => instance.V8Object_Invoke(hObject, asConstructor, pArgs, pResult));
}

#region Nested type: Handle

internal readonly struct Handle
Expand Down
8 changes: 4 additions & 4 deletions Unity/Package/Runtime/V8/V8ScriptEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,14 +1482,14 @@ internal override void AddHostItem(string itemName, HostItemFlags flags, object

ScriptInvoke(() =>
{
object marshaledItem;
object marshaledItem;

#if NETCOREAPP || NETSTANDARD
if (item is SplitProxy.IV8HostObject)
if (item is SplitProxy.IV8HostObject or SplitProxy.InvokeHostObject)
{
marshaledItem = item;
}
else
else
#endif
{
marshaledItem = MarshalToScript(item, flags);
Expand Down
8 changes: 8 additions & 0 deletions Unity/Package/Tests.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Unity/Package/Tests/Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Unity/Package/Tests/Runtime/Decentraland.ClearScript.Tests.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "Decentraland.ClearScript.Tests",
"rootNamespace": "Microsoft.ClearScript.Tests",
"references": [
"GUID:9659fcb6593e30b46909c1245ed056df"
],
"includePlatforms": [
"Editor",
"LinuxStandalone64",
"macOSStandalone",
"WindowsStandalone64"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"Microsoft.CodeAnalysis.dll",
"Microsoft.CSharp.dll",
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": true
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading