DateTime came back from JavaScript as a V8ScriptObject. Why? #633
Answered
by
ClearScriptLib
AnsisMalins
asked this question in
Q&A
-
|
The following unit test fails because result is not a DateTime but a V8ScriptObject. But why? ClearScript has code specifically for DateTime. [Test]
public void GetDateTime()
{
var csDate = DateTime.Parse("2010-10-10T20:30:00Z");
hostObject.GetNamedProperty = (StdString name, V8Value value) =>
{
Assert.That(name.Equals("getDateTime"));
value.SetDateTime(csDate);
};
object result = engine.Evaluate(@"{
let csDate = hostObject.getDateTime;
assert(csDate instanceof Date); // <== succeeds
let jsDate = new Date('2010-10-10T20:30:00Z');
assert(csDate.getTime() === jsDate.getTime()); // <== succeeds
csDate;
}");
Assert.That(result is DateTime dateTime && dateTime == csDate); // <== fails
} |
Beta Was this translation helpful? Give feedback.
Answered by
ClearScriptLib
Feb 3, 2025
Replies: 1 comment 3 replies
-
|
Hi @AnsisMalins, The JavaScript code that you're passing to Thanks! |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. Since
csDate instanceof Dateis true, we can assume thatcsDateis a JavaScriptDateinstance. For such an object to be automatically converted toDateTime, you must construct the engine withV8ScriptEngineFlags.EnableDateTimeConversion.