public void CreateFunctionWithTextEvaluationResult() { // Arrange var variable = new MockNodeVariable { Id = 23, Parent = null, StackFrame = null, Name = "v_function", TypeName = "function", Value = "55", Class = null, Text = "function(){...}" }; var factory = new EvaluationResultFactory(); // Act NodeEvaluationResult result = factory.Create(variable); // Assert Assert.IsNotNull(result); Assert.AreEqual(variable.Name, result.Expression); Assert.IsNull(result.Frame); Assert.AreEqual(variable.Name, result.FullName); Assert.AreEqual(variable.Id, result.Handle); Assert.IsNull(result.HexValue); Assert.AreEqual(variable.Text, result.StringValue); Assert.AreEqual(NodeExpressionType.Function | NodeExpressionType.Expandable, result.Type); Assert.AreEqual(NodeVariableType.Function, result.TypeName); }
private static string GetFullName(NodeEvaluationResult parent, string fullName, ref string name) { if (parent == null) { return(fullName); } // Generates a parent name const string prototypeSuffix = "." + NodeVariableType.Prototype; var parentName = parent.FullName; if (parentName.EndsWith(prototypeSuffix, StringComparison.Ordinal)) { parentName = parentName.Remove(parentName.Length - prototypeSuffix.Length); } // Generates a full name fullName = string.Format(CultureInfo.InvariantCulture, VariableNameValidator.IsMatch(name) ? @"{0}.{1}" : @"{0}[""{1}""]", parentName, name); if (parent.TypeName != NodeVariableType.Object) { return(fullName); } // Checks whether name points on array element if (int.TryParse(name, out var indexer)) { name = string.Format(CultureInfo.InvariantCulture, "[{0}]", indexer); fullName = parent.FullName + name; } return(fullName); }
public void CreateNumberEvaluationResult() { // Arrange var variable = new MockNodeVariable { Id = 20, Parent = null, StackFrame = null, Name = "v_number", TypeName = "number", Value = "55", Class = null, Text = null }; var factory = new EvaluationResultFactory(); // Act NodeEvaluationResult result = factory.Create(variable); // Assert Assert.IsNotNull(result); Assert.AreEqual(variable.Name, result.Expression); Assert.IsNull(result.Frame); Assert.AreEqual(variable.Name, result.FullName); Assert.AreEqual(variable.Id, result.Handle); Assert.AreEqual(string.Format("0x{0:x}", int.Parse(variable.Value)), result.HexValue); Assert.AreEqual(variable.Value.Length, result.StringLength); Assert.AreEqual(variable.Value, result.StringValue); Assert.AreEqual(NodeExpressionType.None, result.Type); Assert.AreEqual(NodeVariableType.Number, result.TypeName); }
public void CreateErrorEvaluationResult() { // Arrange var variable = new MockNodeVariable { Id = 26, Parent = null, StackFrame = null, Name = "v_error", TypeName = "error", Value = "Error: dsfdsf", Class = null, Text = null }; var factory = new EvaluationResultFactory(); // Act NodeEvaluationResult result = factory.Create(variable); // Assert Assert.IsNotNull(result); Assert.AreEqual(variable.Name, result.Expression); Assert.IsNull(result.Frame); Assert.AreEqual(variable.Name, result.FullName); Assert.AreEqual(variable.Id, result.Handle); Assert.IsNull(result.HexValue); Assert.AreEqual(variable.Value.Substring(7), result.StringValue); Assert.AreEqual(result.Type, NodeExpressionType.Expandable); Assert.AreEqual(NodeVariableType.Error, result.TypeName); }
public void CreateUnknownEvaluationResultWithEmptyValue() { // Arrange var variable = new MockNodeVariable { Id = 26, Parent = null, StackFrame = null, Name = "v_unknown", TypeName = "unknown", Value = null, Class = null, Text = "Unknown" }; var factory = new EvaluationResultFactory(); // Act NodeEvaluationResult result = factory.Create(variable); // Assert Assert.IsNotNull(result); Assert.AreEqual(variable.Name, result.Expression); Assert.IsNull(result.Frame); Assert.AreEqual(variable.Name, result.FullName); Assert.AreEqual(variable.Id, result.Handle); Assert.IsNull(result.HexValue); Assert.AreEqual(variable.Text, result.StringValue); Assert.AreEqual(NodeExpressionType.None, result.Type); Assert.AreEqual(NodeVariableType.Unknown, result.TypeName); }
public void CreateArrayEvaluationResult() { // Arrange var variable = new MockNodeVariable { Id = 19, Parent = null, StackFrame = null, Name = "v_array", TypeName = "object", Value = null, Class = "Array", Text = null }; var factory = new EvaluationResultFactory(); // Act NodeEvaluationResult result = factory.Create(variable); // Assert Assert.IsNotNull(result); Assert.AreEqual(variable.Name, result.Expression); Assert.IsNull(result.Frame); Assert.AreEqual(variable.Name, result.FullName); Assert.AreEqual(variable.Id, result.Handle); Assert.IsNull(result.HexValue); Assert.AreEqual(string.Format("{{{0}}}", variable.Class), result.StringValue); Assert.AreEqual(result.Type, NodeExpressionType.Expandable); Assert.AreEqual(NodeVariableType.Object, result.TypeName); }
public void CreateObjectElementWithInvalidIdentifierEvaluationResult() { // Arrange var variable = new MockNodeVariable { Id = 19, Parent = new NodeEvaluationResult(0, null, null, "Object", "v_object", "v_object", NodeExpressionType.Expandable, null), StackFrame = null, Name = "123name", TypeName = "number", Value = "0", Class = "Number", Text = null }; var factory = new EvaluationResultFactory(); // Act NodeEvaluationResult result = factory.Create(variable); // Assert Assert.IsNotNull(result); Assert.AreEqual(variable.Name, result.Expression); Assert.IsNull(result.Frame); Assert.AreEqual(string.Format(@"{0}[""{1}""]", variable.Parent.Expression, variable.Name), result.FullName); Assert.AreEqual(variable.Id, result.Handle); Assert.AreEqual(string.Format("0x{0:x}", int.Parse(variable.Value)), result.HexValue); Assert.AreEqual(variable.Value, result.StringValue); Assert.AreEqual(result.Type, NodeExpressionType.None); Assert.AreEqual(NodeVariableType.Number, result.TypeName); }
public void CreateBooleanEvaluationResult() { // Arrange var variable = new MockNodeVariable { Id = 21, Parent = null, StackFrame = null, Name = "v_boolean", TypeName = "boolean", Value = "false", Class = null, Text = null }; var factory = new EvaluationResultFactory(); // Act NodeEvaluationResult result = factory.Create(variable); // Assert Assert.IsNotNull(result); Assert.AreEqual(variable.Name, result.Expression); Assert.IsNull(result.Frame); Assert.AreEqual(variable.Name, result.FullName); Assert.AreEqual(variable.Id, result.Handle); Assert.IsNull(result.HexValue); Assert.AreEqual(variable.Value.Length, result.StringLength); Assert.AreEqual(variable.Value, result.StringValue); Assert.AreEqual(NodeExpressionType.Boolean, result.Type); Assert.AreEqual(NodeVariableType.Boolean, result.TypeName); }
public override void ProcessResponse(JObject response) { base.ProcessResponse(response); var variableProvider = new NodeSetValueVariable(this._stackFrame, this._name, response); this.Result = this._resultFactory.Create(variableProvider); }
public override void ProcessResponse(JObject response) { base.ProcessResponse(response); var variableProvider = new NodeEvaluationVariable(this._stackFrame, this._expression, response["body"]); this.Result = this._resultFactory.Create(variableProvider); }
public override void Execute(object[] arguments) { if (arguments.Length != 1) { throw new ArgumentOutOfRangeException("arguments"); } var variable = arguments[0] as NodeEvaluationResult; if (variable == null) { string message = string.Format("Invalid arguments: {0}", arguments); throw new ArgumentException(message, "arguments"); } // Retrieve references var refs = (JArray)_message["refs"]; var references = new Dictionary <int, JToken>(refs.Count); for (int i = 0; i < refs.Count; i++) { JToken reference = refs[i]; var id = (int)reference["handle"]; references.Add(id, reference); } // Retrieve properties var variableId = variable.Id.ToString(CultureInfo.InvariantCulture); var objectData = _message["body"][variableId]; var properties = new List <NodeEvaluationResult>(); var props = (JArray)objectData["properties"]; if (props != null) { for (int i = 0; i < props.Count; i++) { var variableProvider = new LookupVariableProvider(props[i], references, variable); NodeEvaluationResult result = NodeMessageFactory.CreateVariable(variableProvider); properties.Add(result); } } // Try to get prototype var prototype = objectData["protoObject"]; if (prototype != null) { var variableProvider = new LookupPrototypeProvider(prototype, references, variable); NodeEvaluationResult result = NodeMessageFactory.CreateVariable(variableProvider); properties.Add(result); } Children = properties.OrderBy(p => p.Name).ToList(); }
private List <NodeEvaluationResult> GetVariables(NodeStackFrame stackFrame, JsonArray variables) { var results = new List <NodeEvaluationResult>(variables.Count); for (int i = 0; i < variables.Count; i++) { var variableProvider = new NodeBacktraceVariable(stackFrame, variables[i]); NodeEvaluationResult result = _evaluationResultFactory.Create(variableProvider); results.Add(result); } return(results.ToList()); }
private static List <NodeEvaluationResult> GetVariables(JArray variables, IDebuggerManager debugger, NodeStackFrame stackFrame) { var results = new List <NodeEvaluationResult>(variables.Count); for (int j = 0; j < variables.Count; j++) { JToken variable = variables[j]; var variableProvider = new BacktraceVariableProvider(variable, debugger, stackFrame); NodeEvaluationResult result = NodeMessageFactory.CreateVariable(variableProvider); results.Add(result); } return(results); }
public LookupPrototypeProvider(JToken prototype, Dictionary<int, JToken> references, NodeEvaluationResult variable) { Id = (int) prototype["ref"]; JToken reference = references[Id]; Debugger = variable.Debugger; StackFrame = variable.StackFrame; Parent = variable; Name = "[prototype]"; TypeName = (string) reference["type"]; Value = (string) reference["value"]; Class = (string) reference["className"]; Text = (string) reference["text"]; Attributes = PropertyAttribute.DontEnum; }
public LookupPrototypeProvider(JToken prototype, Dictionary <int, JToken> references, NodeEvaluationResult variable) { Id = (int)prototype["ref"]; JToken reference = references[Id]; Debugger = variable.Debugger; StackFrame = variable.StackFrame; Parent = variable; Name = "[prototype]"; TypeName = (string)reference["type"]; Value = (string)reference["value"]; Class = (string)reference["className"]; Text = (string)reference["text"]; Attributes = PropertyAttribute.DontEnum; }
/// <summary> /// Handles lookup response message. /// </summary> /// <param name="parent">Parent variable.</param> /// <param name="message">Message.</param> /// <returns>Array of evaluation results.</returns> public NodeEvaluationResult[] ProcessLookup(NodeEvaluationResult parent, JsonValue message) { Utilities.ArgumentNotNull("parent", parent); Utilities.ArgumentNotNull("message", message); // Retrieve references JsonArray refs = message.GetArray("refs"); var references = new Dictionary <int, JsonValue>(refs.Count); for (int i = 0; i < refs.Count; i++) { JsonValue reference = refs[i]; var id = reference.GetValue <int>("handle"); references.Add(id, reference); } // Retrieve properties JsonValue body = message["body"]; string handle = parent.Handle.ToString(CultureInfo.InvariantCulture); JsonValue objectData = body[handle]; var properties = new List <NodeEvaluationResult>(); JsonArray props = objectData.GetArray("properties"); if (props != null) { for (int i = 0; i < props.Count; i++) { JsonValue property = props[i]; var variableProvider = new NodeLookupVariable(parent, property, references); NodeEvaluationResult result = _evaluationResultFactory.Create(variableProvider); properties.Add(result); } } // Try to get prototype JsonValue prototype = objectData["protoObject"]; if (prototype != null) { var variableProvider = new NodePrototypeVariable(parent, prototype, references); NodeEvaluationResult result = _evaluationResultFactory.Create(variableProvider); properties.Add(result); } return(properties.ToArray()); }
public LookupVariableProvider(JToken property, Dictionary<int, JToken> references, NodeEvaluationResult variable) { Id = (int) property["ref"]; JToken reference = references[Id]; Debugger = variable.Debugger; StackFrame = variable.StackFrame; Parent = variable; Name = (string) property["name"]; TypeName = (string) reference["type"]; Value = (string) reference["value"]; Class = (string) reference["className"]; Text = (string) reference["text"]; Attributes = (PropertyAttribute)((int?)property["attributes"] ?? 0); Type = (PropertyType) ((int?) property["propertyType"] ?? 0); }
public LookupVariableProvider(JToken property, Dictionary <int, JToken> references, NodeEvaluationResult variable) { Id = (int)property["ref"]; JToken reference = references[Id]; Debugger = variable.Debugger; StackFrame = variable.StackFrame; Parent = variable; Name = (string)property["name"]; TypeName = (string)reference["type"]; Value = (string)reference["value"]; Class = (string)reference["className"]; Text = (string)reference["text"]; Attributes = (PropertyAttribute)((int?)property["attributes"] ?? 0); Type = (PropertyType)((int?)property["propertyType"] ?? 0); }
public override void ProcessResponse(JObject response) { base.ProcessResponse(response); // Retrieve references var refs = (JArray)response["refs"] ?? new JArray(); var references = new Dictionary <int, JToken>(refs.Count); foreach (var reference in refs) { var id = (int)reference["handle"]; references.Add(id, reference); } // Retrieve properties var body = response["body"]; this.Results = new Dictionary <int, List <NodeEvaluationResult> >(this._handles.Length); foreach (var handle in this._handles) { var id = handle.ToString(CultureInfo.InvariantCulture); var data = body[id]; if (data == null) { continue; } NodeEvaluationResult parent = null; if (this._parents != null) { this._parents.TryGetValue(handle, out parent); } var properties = GetProperties(data, parent, references); if (properties.Count == 0) { // Primitive javascript type var variable = new NodeEvaluationVariable(null, id, data); var property = this._resultFactory.Create(variable); properties.Add(property); } this.Results.Add(handle, properties); } }
public override void Execute(object[] arguments) { if (arguments.Length != 3) { throw new ArgumentOutOfRangeException("arguments"); } var debugger = arguments[0] as IDebuggerManager; var stackFrame = arguments[1] as NodeStackFrame; var name = arguments[2] as string; if (debugger == null || stackFrame == null) { string message = string.Format("Invalid arguments: {0}", arguments); throw new ArgumentException(message, "arguments"); } var variableProvider = new NewValueVariableProvider(_message, debugger, stackFrame, name); Result = NodeMessageFactory.CreateVariable(variableProvider); }
public async Task <NodeEvaluationResult> EvaluateVariableAsync(NodeEvaluationResult variable) { IResponseMessage response = await _client.SendMessage("evaluate", new { expression = variable.FullName, frame = variable.StackFrame.Id, maxStringLength = -1 }, this, variable.StackFrame, variable.Name).ConfigureAwait(false); var evaluateMessage = response as EvaluateMessage; if (evaluateMessage == null || !evaluateMessage.IsSuccessful) { return(null); } IsRunning = response.IsRunning; return(evaluateMessage.Result); }
/// <summary> /// Gets a collection of descentants for a variable. /// </summary> /// <param name="variable">Variable.</param> /// <param name="stackFrame">Stack frame.</param> /// <returns>Collection of descendants.</returns> public async Task <IList <NodeEvaluationResult> > GetChildrenAsync(NodeEvaluationResult variable, NodeStackFrame stackFrame) { IResponseMessage response = await _client.SendMessage("lookup", new { handles = new[] { variable.Id }, includeSource = false }, variable).ConfigureAwait(false); var lookupMessage = response as LookupMessage; if (lookupMessage == null || !lookupMessage.IsSuccessful) { string message = string.Format("Invalid lookup response: {0}", response); throw new InvalidOperationException(message); } IsRunning = response.IsRunning; return(lookupMessage.Children); }
public NodeLookupVariable(NodeEvaluationResult parent, JToken property, Dictionary<int, JToken> references) { Utilities.ArgumentNotNull("property", property); Utilities.ArgumentNotNull("references", references); Id = (int)property["ref"]; JToken reference; if (!references.TryGetValue(Id, out reference)) { reference = property; } Parent = parent; StackFrame = parent != null ? parent.Frame : null; Name = (string)property["name"]; TypeName = (string)reference["type"]; Value = (string)reference["value"]; Class = (string)reference["className"]; Text = (string)reference["text"]; Attributes = (NodePropertyAttributes)property.Value<int>("attributes"); Type = (NodePropertyType)property.Value<int>("propertyType"); }
public NodePrototypeVariable(NodeEvaluationResult parent, JToken prototype, Dictionary<int, JToken> references) { Utilities.ArgumentNotNull("prototype", prototype); Utilities.ArgumentNotNull("references", references); Id = (int)prototype["ref"]; JToken reference; if (!references.TryGetValue(Id, out reference)) { reference = prototype; } Parent = parent; StackFrame = parent != null ? parent.Frame : null; Name = NodeVariableType.Prototype; TypeName = (string)reference["type"]; Value = (string)reference["value"]; Class = (string)reference["className"]; Text = (string)reference["text"]; Attributes = NodePropertyAttributes.DontEnum; Type = NodePropertyType.Normal; }
internal void ExecTest( NodeThread thread, int frameIndex = 0, string expression = null, string expectedType = null, string expectedValue = null, string expectedException = null, string expectedFrame = null ) { var frame = thread.Frames[frameIndex]; NodeEvaluationResult evaluationResult = null; Exception exception = null; try { evaluationResult = frame.ExecuteTextAsync(expression).WaitAndUnwrapExceptions(); } catch (Exception ex) { exception = ex; } if (expectedType != null) { Assert.IsNotNull(evaluationResult); Assert.AreEqual(expectedType, evaluationResult.TypeName); } if (expectedValue != null) { Assert.IsNotNull(evaluationResult); Assert.AreEqual(expectedValue, evaluationResult.StringValue); } if (expectedException != null) { Assert.IsNotNull(exception); Assert.AreEqual(expectedException, exception.Message); } if (expectedFrame != null) { Assert.AreEqual(expectedFrame, frame.FunctionName); } }
public NodeLookupVariable(NodeEvaluationResult parent, JToken property, Dictionary <int, JToken> references) { Utilities.ArgumentNotNull(nameof(property), property); Utilities.ArgumentNotNull(nameof(references), references); this.Id = (int)property["ref"]; if (!references.TryGetValue(this.Id, out var reference)) { reference = property; } this.Parent = parent; this.StackFrame = parent != null ? parent.Frame : null; this.Name = (string)property["name"]; this.TypeName = (string)reference["type"]; this.Value = (string)reference["value"]; this.Class = (string)reference["className"]; this.Text = (string)reference["text"]; this.Attributes = (NodePropertyAttributes)property.Value <int>("attributes"); this.Type = (NodePropertyType)property.Value <int>("propertyType"); }
public NodePrototypeVariable(NodeEvaluationResult parent, JToken prototype, Dictionary <int, JToken> references) { Utilities.ArgumentNotNull("prototype", prototype); Utilities.ArgumentNotNull("references", references); this.Id = (int)prototype["ref"]; if (!references.TryGetValue(this.Id, out var reference)) { reference = prototype; } this.Parent = parent; this.StackFrame = parent != null ? parent.Frame : null; this.Name = NodeVariableType.Prototype; this.TypeName = (string)reference["type"]; this.Value = (string)reference["value"]; this.Class = (string)reference["className"]; this.Text = (string)reference["text"]; this.Attributes = NodePropertyAttributes.DontEnum; this.Type = NodePropertyType.Normal; }
public void CreateLookupVariableWithNullJsonReferences() { // Arrange var parent = new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null); JObject json = SerializationTestData.GetLookupJsonPrototype(); Exception exception = null; NodePrototypeVariable result = null; // Act try { result = new NodePrototypeVariable(parent, json, null); } catch (Exception e) { exception = e; } // Assert Assert.IsNull(result); Assert.IsNotNull(exception); Assert.IsInstanceOfType(exception, typeof(ArgumentNullException)); }
public int GetStringChars(uint buflen, ushort[] rgString, out uint pceltFetched) { pceltFetched = buflen; if (!_stringValueLoaded) { NodeEvaluationResult result = _variable.Debugger.EvaluateVariableAsync(_variable).Result; if (result == null) { pceltFetched = 0; return(VSConstants.E_FAIL); } _variable.StringValue = result.StringValue; _stringValueLoaded = true; } _variable.StringValue.ToCharArray().CopyTo(rgString, 0); return(VSConstants.S_OK); }
public override void Execute(object[] arguments) { if (arguments.Length != 3) { throw new ArgumentOutOfRangeException("arguments"); } var debugger = arguments[0] as IDebuggerManager; var stackFrame = arguments[1] as NodeStackFrame; var name = arguments[2] as string; if (debugger == null || stackFrame == null) { string message = string.Format("Invalid arguments: {0}", arguments); throw new ArgumentException(message, "arguments"); } var variableProvider = new NewValueVariableProvider(_message, debugger, stackFrame, name); Result = NodeMessageFactory.CreateVariable(variableProvider); }
public NodeLookupVariable(NodeEvaluationResult parent, JToken property, Dictionary <int, JToken> references) { Utilities.ArgumentNotNull("property", property); Utilities.ArgumentNotNull("references", references); Id = (int)property["ref"]; JToken reference; if (!references.TryGetValue(Id, out reference)) { reference = property; } Parent = parent; StackFrame = parent != null ? parent.Frame : null; Name = (string)property["name"]; TypeName = (string)reference["type"]; Value = (string)reference["value"]; Class = (string)reference["className"]; Text = (string)reference["text"]; Attributes = (NodePropertyAttributes)property.Value <int>("attributes"); Type = (NodePropertyType)property.Value <int>("propertyType"); }
public void CreateEvaluationResultForPrototypeChild() { // Arrange const string parentName = "parent"; var variable = new MockNodeVariable { Id = 19, Parent = new NodeEvaluationResult( 0, null, null, "Object", NodeVariableType.Prototype, parentName + "." + NodeVariableType.Prototype, NodeExpressionType.Expandable, null), StackFrame = null, Name = "name", TypeName = "number", Value = "0", Class = "Number", Text = null }; var factory = new EvaluationResultFactory(); // Act NodeEvaluationResult result = factory.Create(variable); // Assert Assert.IsNotNull(result); Assert.AreEqual(variable.Name, result.Expression); Assert.IsNull(result.Frame); Assert.AreEqual(string.Format(@"{0}.{1}", parentName, variable.Name), result.FullName); Assert.AreEqual(variable.Id, result.Handle); Assert.AreEqual(string.Format("0x{0:x}", int.Parse(variable.Value)), result.HexValue); Assert.AreEqual(variable.Value, result.StringValue); Assert.AreEqual(result.Type, NodeExpressionType.None); Assert.AreEqual(NodeVariableType.Number, result.TypeName); }
public void CreateLookupVariable() { // Arrange var parent = new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null); JObject json = SerializationTestData.GetLookupJsonProperty(); Dictionary <int, JToken> references = SerializationTestData.GetLookupJsonReferences(); // Act var result = new NodeLookupVariable(parent, json, references); // Assert Assert.IsNotNull(result); Assert.AreEqual(NodePropertyAttributes.None, result.Attributes); Assert.IsNull(result.Class); Assert.AreEqual(54, result.Id); Assert.AreEqual("first", result.Name); Assert.AreEqual(parent, result.Parent); Assert.IsNull(result.StackFrame); Assert.AreEqual("1", result.Text); Assert.AreEqual(NodePropertyType.Field, result.Type); Assert.AreEqual("number", result.TypeName); Assert.AreEqual("1", result.Value); }
public void CreatePrototypeVariable() { // Arrange var parent = new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null); JObject json = SerializationTestData.GetLookupJsonPrototype(); Dictionary <int, JToken> references = SerializationTestData.GetLookupJsonReferences(); // Act var result = new NodePrototypeVariable(parent, json, references); // Assert Assert.IsNotNull(result); Assert.AreEqual(NodePropertyAttributes.DontEnum, result.Attributes); Assert.AreEqual(NodeVariableType.Object, result.Class); Assert.AreEqual(4, result.Id); Assert.AreEqual(NodeVariableType.Prototype, result.Name); Assert.AreEqual(parent, result.Parent); Assert.IsNull(result.StackFrame); Assert.AreEqual("#<Object>", result.Text); Assert.AreEqual(NodePropertyType.Normal, result.Type); Assert.AreEqual("object", result.TypeName); Assert.IsNull(result.Value); }
private List <NodeEvaluationResult> GetProperties(JToken data, NodeEvaluationResult parent, Dictionary <int, JToken> references) { var properties = new List <NodeEvaluationResult>(); var props = (JArray)data["properties"]; if (props != null) { properties.AddRange(props.Select(property => new NodeLookupVariable(parent, property, references)) .Select(variableProvider => this._resultFactory.Create(variableProvider))); } // Try to get prototype var prototype = data["protoObject"]; if (prototype != null) { var variableProvider = new NodePrototypeVariable(parent, prototype, references); var result = this._resultFactory.Create(variableProvider); properties.Add(result); } return(properties); }
public override void ProcessResponse(JObject response) { base.ProcessResponse(response); var variableProvider = new NodeSetValueVariable(_stackFrame, _name, response); Result = _resultFactory.Create(variableProvider); }
private static string GetFullName(NodeEvaluationResult parent, string fullName, ref string name) { if (parent == null) { return fullName; } // Generates a parent name const string prototypeSuffix = "." + NodeVariableType.Prototype; var parentName = parent.FullName; if (parentName.EndsWith(prototypeSuffix, StringComparison.Ordinal)) { parentName = parentName.Remove(parentName.Length - prototypeSuffix.Length); } // Generates a full name fullName = string.Format(CultureInfo.InvariantCulture, VariableNameValidator.IsMatch(name) ? @"{0}.{1}" : @"{0}[""{1}""]", parentName, name); if (parent.TypeName != NodeVariableType.Object) { return fullName; } // Checks whether name points on array element int indexer; if (int.TryParse(name, out indexer)) { name = string.Format(CultureInfo.InvariantCulture, "[{0}]", indexer); fullName = parent.FullName + name; } return fullName; }
private static string GetFullName(NodeEvaluationResult parent, string fullName, ref string name) { if (parent == null) { return fullName; } fullName = string.Format(@"{0}[""{1}""]", parent.FullName, name); if (parent.TypeName != "Object") { return fullName; } int indexer; if (int.TryParse(name, out indexer)) { name = string.Format("[{0}]", indexer); fullName = parent.FullName + name; } return fullName; }
public async Task<NodeEvaluationResult> SetVariableValueAsync(NodeEvaluationResult variable, string value) { if (_v8EngineVersion < new Version(3, 15, 8)) { throw new NotSupportedException("Changing variable values available in node.js v0.11.0 and higher."); } IResponseMessage response = await _client.SendMessage("setVariableValue", new { name = variable.FullName, newValue = new RawValue(value), scope = new {number = 0, frameNumber = variable.StackFrame.Id} }, this, variable.StackFrame, variable.Name).ConfigureAwait(false); var setVariableValueMessage = response as SetVariableValueMessage; if (setVariableValueMessage == null || !setVariableValueMessage.IsSuccessful) { return null; } IsRunning = response.IsRunning; return setVariableValueMessage.Result; }
/// <summary> /// Gets a collection of descentants for a variable. /// </summary> /// <param name="variable">Variable.</param> /// <param name="stackFrame">Stack frame.</param> /// <returns>Collection of descendants.</returns> public async Task<IList<NodeEvaluationResult>> GetChildrenAsync(NodeEvaluationResult variable, NodeStackFrame stackFrame) { IResponseMessage response = await _client.SendMessage("lookup", new { handles = new[] {variable.Id}, includeSource = false }, variable).ConfigureAwait(false); var lookupMessage = response as LookupMessage; if (lookupMessage == null || !lookupMessage.IsSuccessful) { string message = string.Format("Invalid lookup response: {0}", response); throw new InvalidOperationException(message); } IsRunning = response.IsRunning; return lookupMessage.Children; }
/// <summary> /// Handles lookup response message. /// </summary> /// <param name="parent">Parent variable.</param> /// <param name="message">Message.</param> /// <returns>Array of evaluation results.</returns> public NodeEvaluationResult[] ProcessLookup(NodeEvaluationResult parent, JsonValue message) { Utilities.ArgumentNotNull("parent", parent); Utilities.ArgumentNotNull("message", message); // Retrieve references JsonArray refs = message.GetArray("refs"); var references = new Dictionary<int, JsonValue>(refs.Count); for (int i = 0; i < refs.Count; i++) { JsonValue reference = refs[i]; var id = reference.GetValue<int>("handle"); references.Add(id, reference); } // Retrieve properties JsonValue body = message["body"]; string handle = parent.Handle.ToString(CultureInfo.InvariantCulture); JsonValue objectData = body[handle]; var properties = new List<NodeEvaluationResult>(); JsonArray props = objectData.GetArray("properties"); if (props != null) { for (int i = 0; i < props.Count; i++) { JsonValue property = props[i]; var variableProvider = new NodeLookupVariable(parent, property, references); NodeEvaluationResult result = _evaluationResultFactory.Create(variableProvider); properties.Add(result); } } // Try to get prototype JsonValue prototype = objectData["protoObject"]; if (prototype != null) { var variableProvider = new NodePrototypeVariable(parent, prototype, references); NodeEvaluationResult result = _evaluationResultFactory.Create(variableProvider); properties.Add(result); } return properties.ToArray(); }
public AD7Property(AD7StackFrame frame, NodeEvaluationResult evaluationResult, AD7Property parent = null) { _evaluationResult = evaluationResult; _parent = parent; _frame = frame; }
public async Task<NodeEvaluationResult> EvaluateVariableAsync(NodeEvaluationResult variable) { IResponseMessage response = await _client.SendMessage("evaluate", new { expression = variable.FullName, frame = variable.StackFrame.Id, maxStringLength = -1 }, this, variable.StackFrame, variable.Name).ConfigureAwait(false); var evaluateMessage = response as EvaluateMessage; if (evaluateMessage == null || !evaluateMessage.IsSuccessful) { return null; } IsRunning = response.IsRunning; return evaluateMessage.Result; }
public override void ProcessResponse(JObject response) { base.ProcessResponse(response); var variableProvider = new NodeEvaluationVariable(_stackFrame, _expression, response["body"]); Result = _resultFactory.Create(variableProvider); }