示例#1
0
        internal override void AnalyzeNode()
        {
            // throw a warning discouraging the use of this statement
            Context.HandleError(JSError.WithNotRecommended, false);

            // hold onto the with-scope in case we need to do something with it
            BlockScope withScope = (m_block == null ? null : m_block.BlockScope);

            if (Parser.Settings.StripDebugStatements &&
                Parser.Settings.IsModificationAllowed(TreeModifications.StripDebugStatements) &&
                m_block != null &&
                m_block.IsDebuggerStatement)
            {
                m_block = null;
            }

            // recurse
            base.AnalyzeNode();

            // we'd have to know what the object (obj) evaluates to before we
            // can figure out what to add to the scope -- not possible without actually
            // running the code. This could throw a whole bunch of 'undefined' errors.
            if (m_block != null && m_block.Count == 0)
            {
                m_block = null;
            }

            // we got rid of the block -- tidy up the no-longer-needed scope
            if (m_block == null && withScope != null)
            {
                // because the scope is empty, we now know it (it does nothing)
                withScope.IsKnownAtCompileTime = true;
            }
        }
示例#2
0
        private void WriteBlockHeader(BlockScope blockScope, string blockType)
        {
            string scopeFlags = null;
            var    sb         = StringBuilderPool.Acquire();

            try
            {
                if (!blockScope.IsKnownAtCompileTime)
                {
                    sb.Append('[');
                    sb.Append(AjaxMin.NotKnown);
                    sb.Append(']');
                }

                if (blockScope.UseStrict)
                {
                    sb.Append(AjaxMin.ScopeIsStrictFlag);
                }

                scopeFlags = sb.ToString();
            }
            finally
            {
                sb.Release();
            }

            WriteProgress();
            WriteProgress(AjaxMin.BlockScopeHeader.FormatInvariant(
                              blockType,
                              blockScope.Owner.Context.StartLineNumber,
                              blockScope.Owner.Context.StartColumn + 1,
                              scopeFlags));
        }
示例#3
0
        private void WriteScopeReport(FunctionObject funcObj, ActivationObject scope)
        {
            // output the function header
            if (scope is GlobalScope)
            {
                WriteProgress(StringMgr.GetString("GlobalObjectsHeader"));
            }
            else
            {
                FunctionScope functionScope = scope as FunctionScope;
                if (functionScope != null && funcObj != null)
                {
                    WriteFunctionHeader(funcObj, scope.IsKnownAtCompileTime);
                }
                else
                {
                    BlockScope blockScope = scope as BlockScope;
                    if (blockScope is CatchScope)
                    {
                        WriteBlockHeader(blockScope, StringMgr.GetString("BlockTypeCatch"));
                    }
                    else if (blockScope is WithScope)
                    {
                        WriteBlockHeader(blockScope, StringMgr.GetString("BlockTypeWith"));
                    }
                    else
                    {
                        WriteProgress();
                        WriteProgress(StringMgr.GetString("UnknownScopeType", scope.GetType().ToString()));
                    }
                }
            }

            // get all the fields in the scope
            JSVariableField[] scopeFields = scope.GetFields();
            // sort the fields
            Array.Sort(scopeFields, FieldComparer.Instance);

            // iterate over all the fields
            foreach (JSVariableField variableField in scopeFields)
            {
                // don't report placeholder fields
                if (!variableField.IsPlaceholder)
                {
                    WriteMemberReport(variableField, scope);
                }
            }
        }
示例#4
0
            private static Context GetContext(ActivationObject obj)
            {
                FunctionScope funcScope = obj as FunctionScope;

                if (funcScope != null && funcScope.FunctionObject != null)
                {
                    return(funcScope.FunctionObject.Context);
                }
                else
                {
                    BlockScope blockScope = obj as BlockScope;
                    if (blockScope != null)
                    {
                        return(blockScope.Context);
                    }
                }
                return(null);
            }
示例#5
0
        private void WriteBlockHeader(BlockScope blockScope, string blockType)
        {
            string knownMarker = string.Empty;

            if (!blockScope.IsKnownAtCompileTime)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append('[');
                sb.Append(StringMgr.GetString("NotKnown"));
                sb.Append(']');
                knownMarker = sb.ToString();
            }

            WriteProgress();
            WriteProgress(StringMgr.GetString(
                              "BlockScopeHeader",
                              blockType,
                              blockScope.Context.StartLineNumber,
                              blockScope.Context.StartColumn,
                              knownMarker
                              ));
        }