Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Handles response message.
        /// </summary>
        /// <param name="message">Message.</param>
        private void HandleResponseMessage(JObject message)
        {
            IResponseMessage response = NodeMessageFactory.CreateResponseMessage(message);
            Tuple <TaskCompletionSource <IResponseMessage>, object[]> promise;

            if (!_messages.TryGetValue(response.MessageId, out promise))
            {
                Debug.Print("Invalid response message identifier {0}: {1}", response.MessageId, message);
                return;
            }

            if (response.IsSuccessful)
            {
                response.Execute(promise.Item2);
            }

            promise.Item1.SetResult(response);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Handles event message.
        /// </summary>
        /// <param name="message">Message.</param>
        private void HandleEventMessage(JObject message)
        {
            switch ((string)message["event"])
            {
            case "afterCompile":
            {
                IEventMessage messageData          = NodeMessageFactory.CreateEventMessage(message);
                var           compileScriptMessage = messageData as CompileScriptMessage;
                if (messageData == null || !messageData.IsSuccessful)
                {
                    string errorMessage = string.Format("Invalid event message: {0}", message);
                    Debug.Fail(errorMessage);
                    break;
                }

                EventHandler <CompileScriptMessageEventArgs> compileEvent = CompileEvent;
                if (compileEvent != null)
                {
                    compileEvent(this, new CompileScriptMessageEventArgs(compileScriptMessage));
                }
            }
            break;

            case "break":
            {
                IEventMessage messageData       = NodeMessageFactory.CreateEventMessage(message);
                var           breakPointMessage = messageData as BreakpointMessage;
                if (messageData == null || !messageData.IsSuccessful)
                {
                    string errorMessage = string.Format("Invalid event message: {0}", message);
                    Debug.Fail(errorMessage);
                    break;
                }

                EventHandler <BreakpointMessageEventArgs> breakpointEvent = BreakpointEvent;
                if (breakpointEvent != null)
                {
                    breakpointEvent(this, new BreakpointMessageEventArgs(breakPointMessage));
                }
            }
            break;

            case "exception":
            {
                IEventMessage messageData      = NodeMessageFactory.CreateEventMessage(message);
                var           exceptionMessage = messageData as ExceptionMessage;
                if (messageData == null || !messageData.IsSuccessful)
                {
                    string errorMessage = string.Format("Invalid event message: {0}", message);
                    Debug.Fail(errorMessage);
                    break;
                }

                EventHandler <ExceptionMessageEventArgs> exceptionEvent = ExceptionEvent;
                if (exceptionEvent != null)
                {
                    exceptionEvent(this, new ExceptionMessageEventArgs(exceptionMessage));
                }
            }
            break;

            default:
            {
                var errorMessage = (string)message["message"];
                Dictionary <int, Tuple <TaskCompletionSource <IResponseMessage>, object[]> > messages =
                    Interlocked.Exchange(ref _messages, new Dictionary <int, Tuple <TaskCompletionSource <IResponseMessage>, object[]> >());

                foreach (var kv in messages)
                {
                    kv.Value.Item1.SetException(new Exception(errorMessage));
                }

                messages.Clear();

                Debug.Print("Unrecognized event type: {0}", message);
            }
            break;
            }
        }