/// <summary>
 /// Creates an evaluation result for an expression which successfully returned a value.
 /// </summary>
 public NodeEvaluationResult(int handle, string stringValue, string hexValue, string typeName, string expression, string fullName, NodeExpressionType type, NodeStackFrame frame) {
     Handle = handle;
     Frame = frame;
     Expression = expression;
     StringValue = stringValue;
     HexValue = hexValue;
     TypeName = typeName;
     FullName = fullName;
     Type = type;
 }
Exemple #2
0
 /// <summary>
 /// Creates an evaluation result for an expression which successfully returned a value.
 /// </summary>
 public NodeEvaluationResult(int handle, string stringValue, string hexValue, string typeName, string expression, string fullName, NodeExpressionType type, NodeStackFrame frame)
 {
     Handle      = handle;
     Frame       = frame;
     Expression  = expression;
     StringValue = stringValue;
     HexValue    = hexValue;
     TypeName    = typeName;
     FullName    = fullName;
     Type        = type;
 }
        public void ProcessEvaluateResponse() {
            // Arrange
            const int commandId = 3;
            var resultFactoryMock = new Mock<IEvaluationResultFactory>();
            resultFactoryMock.Setup(factory => factory.Create(It.IsAny<INodeVariable>()))
                .Returns(() => new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null));
            const string expression = "expression";
            var stackFrame = new NodeStackFrame(0);
            var evaluateCommand = new EvaluateCommand(commandId, resultFactoryMock.Object, expression, stackFrame);

            // Act
            evaluateCommand.ProcessResponse(SerializationTestData.GetEvaluateResponse());

            // Assert
            Assert.AreEqual(commandId, evaluateCommand.Id);
            Assert.IsNotNull(evaluateCommand.Result);
            resultFactoryMock.Verify(factory => factory.Create(It.IsAny<INodeVariable>()), Times.Once);
        }
        public void ProcessSetVariableValueResponse() {
            // Arrange
            const int commandId = 3;
            var resultFactoryMock = new Mock<IEvaluationResultFactory>();
            resultFactoryMock.Setup(factory => factory.Create(It.IsAny<INodeVariable>()))
                .Returns(() => new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null));
            var stackFrame = new NodeStackFrame(0);
            const string variableName = "port";
            const int handle = 40;
            var setVariableValueCommand = new SetVariableValueCommand(commandId, resultFactoryMock.Object, stackFrame, variableName, handle);

            // Act
            setVariableValueCommand.ProcessResponse(SerializationTestData.GetSetVariableValueResponse());

            // Assert
            Assert.AreEqual(commandId, setVariableValueCommand.Id);
            Assert.IsNotNull(setVariableValueCommand.Result);
            resultFactoryMock.Verify(factory => factory.Create(It.IsAny<INodeVariable>()), Times.Once);
        }
        public void CreateSetVariableValueCommand() {
            // Arrange
            const int commandId = 3;
            const int frameId = 1;
            var resultFactoryMock = new Mock<IEvaluationResultFactory>();
            var stackFrame = new NodeStackFrame(frameId);
            const string variableName = "port";
            const int handle = 40;

            // Act
            var setVariableValueCommand = new SetVariableValueCommand(commandId, resultFactoryMock.Object, stackFrame, variableName, handle);

            // Assert
            Assert.AreEqual(commandId, setVariableValueCommand.Id);
            Assert.AreEqual(
                string.Format("{{\"command\":\"setVariableValue\",\"seq\":{0},\"type\":\"request\",\"arguments\":{{\"name\":\"{1}\",\"newValue\":{{\"handle\":{2}}},\"scope\":{{\"frameNumber\":{3},\"number\":0}}}}}}",
                    commandId, variableName, handle, frameId),
                setVariableValueCommand.ToString());
        }
        public void CreateBacktraceVariableWithNullName() {
            // Arrange
            JObject json = SerializationTestData.GetBacktraceJsonObjectWithNullName();
            var stackFrame = new NodeStackFrame(0);

            // Act
            var result = new NodeBacktraceVariable(stackFrame, json);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(NodePropertyAttributes.None, result.Attributes);
            Assert.IsNull(result.Class);
            Assert.AreEqual(21, result.Id);
            Assert.AreEqual(NodeVariableType.AnonymousVariable, result.Name);
            Assert.IsNull(result.Parent);
            Assert.AreEqual(stackFrame, result.StackFrame);
            Assert.IsNull(result.Text);
            Assert.AreEqual(NodePropertyType.Normal, result.Type);
            Assert.AreEqual("boolean", result.TypeName);
        }
        public void CreateEvaluationVariable() {
            // Arrange
            JObject json = SerializationTestData.GetEvaluationJsonObject();
            var stackFrame = new NodeStackFrame(0);
            const string name = "name";

            // Act
            var result = new NodeEvaluationVariable(stackFrame, name, json);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(NodePropertyAttributes.None, result.Attributes);
            Assert.IsNull(result.Class);
            Assert.AreEqual(16, result.Id);
            Assert.AreEqual(name, result.Name);
            Assert.IsNull(result.Parent);
            Assert.AreEqual(stackFrame, result.StackFrame);
            Assert.AreEqual("<tag>Value</tag>", result.Text);
            Assert.AreEqual(NodePropertyType.Normal, result.Type);
            Assert.AreEqual("string", result.TypeName);
            Assert.AreEqual("<tag>Value</tag>", result.Value);
        }
        public void CreateSetVariableValue() {
            // Arrange
            JObject json = SerializationTestData.GetSetVariableValueResponse();
            const int frameId = 3;
            var stackFrame = new NodeStackFrame(frameId);
            const string name = "name";

            // Act
            var result = new NodeSetValueVariable(stackFrame, name, json);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(NodePropertyAttributes.None, result.Attributes);
            Assert.IsNull(result.Class);
            Assert.AreEqual(44, result.Id);
            Assert.AreEqual(name, result.Name);
            Assert.IsNull(result.Parent);
            Assert.AreEqual(stackFrame, result.StackFrame);
            Assert.AreEqual("55", result.Text);
            Assert.AreEqual(NodePropertyType.Normal, result.Type);
            Assert.AreEqual("number", result.TypeName);
            Assert.AreEqual("55", result.Value);
        }
        /// <summary>
        /// Gets or adds a new module.
        /// </summary>
        /// <param name="module">New module.</param>
        /// <param name="value">Existing module.</param>
        /// <param name="stackFrame">The stack frame linked to the module.</param>
        /// <returns>True if module was added otherwise false.</returns>
        private bool GetOrAddModule(NodeModule module, out NodeModule value, NodeStackFrame stackFrame = null) {
            value = null;
            string javaScriptFileName = module.JavaScriptFileName;
            int? line = null, column = null;

            if (string.IsNullOrEmpty(javaScriptFileName) ||
                javaScriptFileName == NodeVariableType.UnknownModule ||
                javaScriptFileName.StartsWith("binding:")) {
                return false;
            }

            // Get local JS file name
            javaScriptFileName = FileNameMapper.GetLocalFileName(javaScriptFileName);

            // Try to get mapping for JS file
            if(stackFrame != null) {
                line = stackFrame.Line;
                column = stackFrame.Column;
            }
            string originalFileName = SourceMapper.GetOriginalFileName(javaScriptFileName, line, column);

            if (originalFileName == null) {
                module = new NodeModule(module.Id, javaScriptFileName);
            } else {
                string directoryName = Path.GetDirectoryName(javaScriptFileName) ?? string.Empty;
                string fileName = CommonUtils.GetAbsoluteFilePath(directoryName, originalFileName.Replace('/', '\\'));

                module = new NodeModule(module.Id, fileName, javaScriptFileName);
            }

            // Check whether module already exits
            if (_modules.TryGetValue(module.FileName, out value)) {
                return false;
            }

            value = module;

            // Add module
            _modules[module.FileName] = module;

            return true;
        }
        internal async Task<NodeEvaluationResult> SetVariableValueAsync(
            NodeStackFrame stackFrame,
            string name,
            string value,
            CancellationToken cancellationToken = new CancellationToken()) {
            DebugWriteCommand("Set Variable Value");

            // Create a new value
            var evaluateValueCommand = new EvaluateCommand(CommandId, _resultFactory, value, stackFrame);
            await _client.SendRequestAsync(evaluateValueCommand, cancellationToken).ConfigureAwait(false);
            int handle = evaluateValueCommand.Result.Handle;

            // Set variable value
            var setVariableValueCommand = new SetVariableValueCommand(CommandId, _resultFactory, stackFrame, name, handle);
            await _client.SendRequestAsync(setVariableValueCommand, cancellationToken).ConfigureAwait(false);
            return setVariableValueCommand.Result;
        }
        internal async Task<NodeEvaluationResult> ExecuteTextAsync(
            NodeStackFrame stackFrame,
            string text,
            CancellationToken cancellationToken = new CancellationToken()) {
            DebugWriteCommand("Execute Text Async");

            var evaluateCommand = new EvaluateCommand(CommandId, _resultFactory, text, stackFrame);
            await _client.SendRequestAsync(evaluateCommand, cancellationToken).ConfigureAwait(false);
            return evaluateCommand.Result;
        }
Exemple #12
0
 /// <summary>
 /// Creates an evaluation result for an expression which successfully returned a value.
 /// </summary>
 public NodeEvaluationResult(int handle, string stringValue, string hexValue, string typeName, string expression, string fullName, NodeExpressionType type, NodeStackFrame frame)
 {
     this.Handle      = handle;
     this.Frame       = frame;
     this.Expression  = expression;
     this.StringValue = stringValue;
     this.HexValue    = hexValue;
     this.TypeName    = typeName;
     this.FullName    = fullName;
     this.Type        = type;
 }
        public void CreateBacktraceVariableWithNullJson() {
            // Arrange
            var stackFrame = new NodeStackFrame(0);
            Exception exception = null;
            NodeBacktraceVariable result = null;

            // Act
            try {
                result = new NodeBacktraceVariable(stackFrame, null);
            } catch (Exception e) {
                exception = e;
            }

            // Assert
            Assert.IsNull(result);
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof (ArgumentNullException));
        }
        public void ProcessEvaluateResponseWithReferenceError() {
            // Arrange
            const int commandId = 3;
            var resultFactoryMock = new Mock<IEvaluationResultFactory>();
            resultFactoryMock.Setup(factory => factory.Create(It.IsAny<INodeVariable>()));
            const string expression = "hello";
            var stackFrame = new NodeStackFrame(0);
            var evaluateCommand = new EvaluateCommand(commandId, resultFactoryMock.Object, expression, stackFrame);
            Exception exception = null;

            // Act
            try {
                evaluateCommand.ProcessResponse(SerializationTestData.GetEvaluateResponseWithReferenceError());
            } catch (Exception e) {
                exception = e;
            }

            // Assert
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof (DebuggerCommandException));
            Assert.AreEqual("ReferenceError: hello is not defined", exception.Message);
            Assert.IsNull(evaluateCommand.Result);
            resultFactoryMock.Verify(factory => factory.Create(It.IsAny<INodeVariable>()), Times.Never);
        }