diff --git a/Nodejs/Product/Nodejs/Debugger/Serialization/NodeBacktraceVariable.cs b/Nodejs/Product/Nodejs/Debugger/Serialization/NodeBacktraceVariable.cs index 5d52667c6..2f566ddb4 100644 --- a/Nodejs/Product/Nodejs/Debugger/Serialization/NodeBacktraceVariable.cs +++ b/Nodejs/Product/Nodejs/Debugger/Serialization/NodeBacktraceVariable.cs @@ -1,55 +1,76 @@ -//*********************************************************// -// Copyright (c) Microsoft. All rights reserved. -// -// Apache 2.0 License -// -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. -// -//*********************************************************// - -using System; -using Microsoft.VisualStudioTools.Project; -using Newtonsoft.Json.Linq; - -namespace Microsoft.NodejsTools.Debugger.Serialization { - sealed class NodeBacktraceVariable : INodeVariable { - public NodeBacktraceVariable(NodeStackFrame stackFrame, JToken parameter) { - Utilities.ArgumentNotNull("stackFrame", stackFrame); - Utilities.ArgumentNotNull("parameter", parameter); - - JToken value = parameter["value"]; - Id = (int)value["ref"]; - Parent = null; - StackFrame = stackFrame; - Name = (string)parameter["name"] ?? NodeVariableType.AnonymousVariable; - TypeName = (string)value["type"]; - Value = (string)value["value"]; - Class = (string)value["className"]; - try { - Text = (string)value["text"]; - } catch (ArgumentException) { - Text = String.Empty; - } - Attributes = NodePropertyAttributes.None; - Type = NodePropertyType.Normal; - } - - public int Id { get; private set; } - public NodeEvaluationResult Parent { get; private set; } - public string Name { get; private set; } - public string TypeName { get; private set; } - public string Value { get; private set; } - public string Class { get; private set; } - public string Text { get; private set; } - public NodePropertyAttributes Attributes { get; private set; } - public NodePropertyType Type { get; private set; } - public NodeStackFrame StackFrame { get; private set; } - } +//*********************************************************// +// Copyright (c) Microsoft. All rights reserved. +// +// Apache 2.0 License +// +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. +// +//*********************************************************// + +using System; +using Microsoft.VisualStudioTools.Project; +using Newtonsoft.Json.Linq; + +namespace Microsoft.NodejsTools.Debugger.Serialization { + sealed class NodeBacktraceVariable : INodeVariable { + public NodeBacktraceVariable(NodeStackFrame stackFrame, JToken parameter) { + Utilities.ArgumentNotNull("stackFrame", stackFrame); + Utilities.ArgumentNotNull("parameter", parameter); + + JToken value = parameter["value"]; + Id = (int)value["ref"]; + Parent = null; + StackFrame = stackFrame; + Name = (string)parameter["name"] ?? NodeVariableType.AnonymousVariable; + TypeName = (string)value["type"]; + Value = GetValue((JValue)value["value"]); + Class = (string)value["className"]; + try { + Text = (string)value["text"]; + } catch (ArgumentException) { + Text = String.Empty; + } + Attributes = NodePropertyAttributes.None; + Type = NodePropertyType.Normal; + } + + public int Id { get; private set; } + public NodeEvaluationResult Parent { get; private set; } + public string Name { get; private set; } + public string TypeName { get; private set; } + public string Value { get; private set; } + public string Class { get; private set; } + public string Text { get; private set; } + public NodePropertyAttributes Attributes { get; private set; } + public NodePropertyType Type { get; private set; } + public NodeStackFrame StackFrame { get; private set; } + + /// + /// Converts the JValue to string. + /// + /// Value which has to be converted to string representation. + /// String which represents the value. + private static string GetValue(JValue value) { + if (value == null) { + return null; + } + + if (value.Type == JTokenType.Date) { + var parentValue = value.Parent.ToString(); + return parentValue.Replace("\"value\": \"", string.Empty) + .Replace("\"", string.Empty); + // var dateTimeValue = (DateTime)value.Value; + // return dateTimeValue.ToUniversalTime().ToString("s") + "Z"; + } + + return (string)value; + } + } } \ No newline at end of file diff --git a/Nodejs/Tests/Core/Debugger/DebuggerTests.cs b/Nodejs/Tests/Core/Debugger/DebuggerTests.cs index f71dae06b..30bb34ab0 100644 --- a/Nodejs/Tests/Core/Debugger/DebuggerTests.cs +++ b/Nodejs/Tests/Core/Debugger/DebuggerTests.cs @@ -240,9 +240,9 @@ public void TimeStringLocalsTest() { LocalsTest( "TimeStringLocalsTest.js", - 3, - expectedLocals: new string[] { "time" }, - expectedValues: new string[] { "2015-05-07T22:00:00.000Z" } + 6, + expectedLocals: new string[] { "time", "time1", "time2" }, + expectedValues: new string[] { "2015-05-07T22:00:00.000Z", "2015-05-07T22:00:00.000", "2015-05-07 22:00:00.000" } ); } diff --git a/Nodejs/Tests/TestData/DebuggerProject/TimeStringLocalsTest.js b/Nodejs/Tests/TestData/DebuggerProject/TimeStringLocalsTest.js index 4c3310eb5..b91760f46 100644 --- a/Nodejs/Tests/TestData/DebuggerProject/TimeStringLocalsTest.js +++ b/Nodejs/Tests/TestData/DebuggerProject/TimeStringLocalsTest.js @@ -1,5 +1,8 @@ function TimeStringLocals() { var time = "2015-05-07T22:00:00.000Z"; + var time1 = "2015-05-07T22:00:00.000"; + var time2 = "2015-05-07 22:00:00.000"; + console.log("TimeStringLocals() done"); }