Beispiel #1
0
        /// <summary>
        /// eventListener.emit(eventName, args...)
        ///
        /// Returns bool indicating if event was raised.
        /// </summary>
        private static IAnalysisSet EventEmitterEmit(FunctionValue func, Node node, AnalysisUnit unit, IAnalysisSet @this, IAnalysisSet[] args)
        {
            if (args.Length >= 1)
            {
                if (@this != null)
                {
                    foreach (var thisArg in @this)
                    {
                        ExpandoValue expando = @thisArg.Value as ExpandoValue;
                        if (expando != null)
                        {
                            foreach (var arg in args[0])
                            {
                                var strValue = arg.Value.GetStringValue();
                                if (strValue != null)
                                {
                                    VariableDef events;
                                    if (expando.TryGetMetadata <VariableDef>(new EventListenerKey(strValue), out events))
                                    {
                                        foreach (var type in events.GetTypesNoCopy(unit))
                                        {
                                            type.Call(node, unit, @this, args.Skip(1).ToArray());
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(func.ProjectState._trueInst.Proxy);
        }
Beispiel #2
0
        /// <summary>
        /// this.addListener(name, handler)
        ///
        /// returns the event listener
        /// </summary>
        private static IAnalysisSet EventEmitterAddListener(FunctionValue func, Node node, AnalysisUnit unit, IAnalysisSet @this, IAnalysisSet[] args)
        {
            if (args.Length >= 2 && args[1].Count > 0)
            {
                if (@this != null)
                {
                    foreach (var thisArg in @this)
                    {
                        ExpandoValue expando = @thisArg.Value as ExpandoValue;
                        if (expando != null)
                        {
                            foreach (var arg in args[0])
                            {
                                var strValue = arg.Value.GetStringValue();
                                if (strValue != null)
                                {
                                    var         key = new EventListenerKey(strValue);
                                    VariableDef events;
                                    if (!expando.TryGetMetadata(key, out events))
                                    {
                                        expando.SetMetadata(key, events = new VariableDef());
                                    }

                                    events.AddTypes(unit, args[1]);
                                }
                            }
                        }
                    }
                }
            }
            return(@this ?? AnalysisSet.Empty);
        }