コード例 #1
0
ファイル: TypeMarkerPhase.cs プロジェクト: pvginkel/Jint2
                public void Dispose()
                {
                    if (!_disposed)
                    {
                        if (_marker != null)
                        {
                            _marker.Dispose();
                            _marker = null;
                        }

                        _disposed = true;
                    }
                }
コード例 #2
0
ファイル: TypeMarkerPhase.cs プロジェクト: pvginkel/Jint2
                public Scope(BoundBody body, Scope parent)
                {
                    Parent = parent;

                    _marker = body.TypeManager.CreateTypeMarker();

                    foreach (var argument in body.Arguments)
                    {
                        if (argument.Closure != null)
                            MarkWrite(body.Closure.Fields[argument.Name], BoundValueType.Unknown);
                    }

                    if (body.MappedArguments != null)
                        _arguments = body.MappedArguments.ToDictionary(p => p.Argument, p => p.Mapped);

                    if (body.MappedArguments != null)
                    {
                        foreach (var mapping in body.MappedArguments)
                        {
                            MarkWrite(mapping.Mapped, BoundValueType.Unknown);
                        }
                    }

                    if (body.Closure != null)
                    {
                        var argumentsClosureField = body.Closure.Fields.SingleOrDefault(p => p.Name == BoundClosure.ArgumentsFieldName);
                        if (argumentsClosureField != null)
                            MarkWrite(argumentsClosureField, BoundValueType.Object);
                    }

                    _magicTypes = body.TypeManager.MagicTypes.ToDictionary(p => p.MagicType, p => p.Type);

                    foreach (var item in _magicTypes)
                    {
                        switch (item.Key)
                        {
                            case BoundMagicVariableType.Arguments:
                            case BoundMagicVariableType.Global:
                                _marker.SpeculateType(item.Value, SpeculatedType.Object, true);
                                _marker.MarkWrite(item.Value, BoundValueType.Object);
                                break;

                            case BoundMagicVariableType.This:
                                _marker.MarkWrite(item.Value, BoundValueType.Unknown);
                                break;

                            default:
                                throw new InvalidOperationException();
                        }
                    }
                }