dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/JScript/Vsa BaseVsaEngine.cs,NONE,1.1


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/JScript/Vsa BaseVsaEngine.cs,NONE,1.1 BaseVsaSite.cs,NONE,1.1 BaseVsaStartup.cs,NONE,1.1 COMCharStream.cs,NONE,1.1 IMessageReceiver.cs,NONE,1.1 INeedEngine.cs,NONE,1.1 IRedirectOutput.cs,NONE,1.1 IVsaScriptScope.cs,NONE,1.1 JSError.cs,NONE,1.1 JScriptException.cs,NONE,1.1 Makefile,NONE,1.1 NoContextException.cs,NONE,1.1 ScriptStream.cs,NONE,1.1 VsaCodeItem.cs,NONE,1.1 VsaEngine.cs,NONE,1.1 VsaItem.cs,NONE,1.1 VsaItems.cs,NONE,1.1
Date: Mon, 13 Jan 2003 05:53:25 -0500

Update of /cvsroot/dotgnu-pnet/pnetlib/JScript/Vsa
In directory subversions:/tmp/cvs-serv3129/JScript/Vsa

Added Files:
        BaseVsaEngine.cs BaseVsaSite.cs BaseVsaStartup.cs 
        COMCharStream.cs IMessageReceiver.cs INeedEngine.cs 
        IRedirectOutput.cs IVsaScriptScope.cs JSError.cs 
        JScriptException.cs Makefile NoContextException.cs 
        ScriptStream.cs VsaCodeItem.cs VsaEngine.cs VsaItem.cs 
        VsaItems.cs 
Log Message:


Perform the initial check-in of the JScript implementation (requires
treecc 0.2.0 or higher).


--- NEW FILE ---
/*
 * BaseVsaEngine.cs - front-end interface to the JScript engine.
 *
 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace Microsoft.Vsa
{

using System;
using System.Collections;
using System.Reflection;
using System.Globalization;
using System.Security.Policy;

public abstract class BaseVsaEngine : IVsaEngine
{
        // Accessible internal state.
        protected String applicationPath;
        protected String assemblyVersion;
        protected String compiledRootNamespace;
        protected String engineMoniker;
        protected String engineName;
        protected IVsaSite engineSite;
        protected int errorLocale;
        protected Evidence executionEvidence;
        protected bool failedCompilation;
        protected bool genDebugInfo;
        protected bool haveCompiledState;
        protected bool isClosed;
        protected bool isDebugInfoSupported;
        protected bool isEngineCompiled;
        protected bool isEngineDirty;
        protected bool isEngineInitialized;
        protected bool isEngineRunning;
        protected Assembly loadedAssembly;
        protected String rootNamespace;
        protected String scriptLanguage;
        protected Type startupClass;
        protected BaseVsaStartup startupInstance;
        protected IVsaItems vsaItems;

        // Constructor.
        public BaseVsaEngine(String language, String version, bool supportDebug)
                        {
                                applicationPath = String.Empty;
                                assemblyVersion = version;
                                compiledRootNamespace = null;
                                engineMoniker = String.Empty;
                                engineName = String.Empty;
                                engineSite = null;
                                errorLocale = CultureInfo.CurrentCulture.LCID;
                                executionEvidence = null;
                                failedCompilation = false;
                                genDebugInfo = false;
                                haveCompiledState = false;
                                isClosed = false;
                                isDebugInfoSupported = supportDebug;
                                isEngineCompiled = false;
                                isEngineDirty = false;
                                isEngineInitialized = false;
                                isEngineRunning = false;
                                loadedAssembly = null;
                                rootNamespace = String.Empty;
                                scriptLanguage = language;
                                startupClass = null;
                                startupInstance = null;
                                vsaItems = null;
                        }

        // Implement the IVsaEngine interface.
        public Assembly Assembly
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed | Pre.EngineRunning);
                                                return loadedAssembly;
                                        }
                                }
                        }
        public Evidence Evidence
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.EngineInitialized);
                                                return executionEvidence;
                                        }
                                }
                                set
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.EngineNotRunning |
                                                                          
Pre.EngineInitialized);
                                                executionEvidence = value;
                                        }
                                }
                        }
        public bool GenerateDebugInfo
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.EngineInitialized);
                                                return genDebugInfo;
                                        }
                                }
                                set
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.EngineNotRunning |
                                                                          
Pre.EngineInitialized |
                                                                          
Pre.SupportForDebug);
                                                if(genDebugInfo != value)
                                                {
                                                        isEngineCompiled = 
false;
                                                        isEngineDirty = true;
                                                        genDebugInfo = value;
                                                }
                                        }
                                }
                        }
        public bool IsCompiled
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.EngineInitialized);
                                                return isEngineCompiled;
                                        }
                                }
                        }
        public bool IsDirty
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.EngineInitialized);
                                                return isEngineDirty;
                                        }
                                }
                                set
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed);
                                                isEngineDirty = value;
                                                if(value)
                                                {
                                                        isEngineCompiled = 
false;
                                                }
                                        }
                                }
                        }
        public bool IsRunning
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.EngineInitialized);
                                                return isEngineRunning;
                                        }
                                }
                        }
        public IVsaItems Items
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.EngineInitialized);
                                                return vsaItems;
                                        }
                                }
                        }
        public String Language
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.EngineInitialized);
                                                return scriptLanguage;
                                        }
                                }
                        }
        public int LCID
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.EngineInitialized);
                                                return errorLocale;
                                        }
                                }
                                set
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.EngineNotRunning |
                                                                          
Pre.EngineInitialized);
                                                try
                                                {
                                                        // Validate the culture 
using "CultureInfo".
                                                        CultureInfo culture =
                                                                new 
CultureInfo(value);
                                                }
                                                catch(ArgumentException)
                                                {
                                                        throw new 
VsaException(VsaError.LCIDNotSupported);
                                                }
                                                isEngineDirty = true;
                                                isEngineCompiled = false;
                                                errorLocale = value;
                                        }
                                }
                        }
        public String Name
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.EngineInitialized);
                                                return engineName;
                                        }
                                }
                                set
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.EngineNotRunning |
                                                                          
Pre.EngineInitialized);
                                                if(engineName != value)
                                                {
                                                        // We should check to 
see if the name is in
                                                        // use by some other 
engine, but since we don't
                                                        // use the name for 
anything, and there can only
                                                        // be one instance in 
use at a time, it isn't
                                                        // worth doing the 
check.
                                                        isEngineDirty = true;
                                                        isEngineCompiled = 
false;
                                                        engineName = value;
                                                }
                                        }
                                }
                        }
        public String RootMoniker
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed);
                                                return engineMoniker;
                                        }
                                }
                                set
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.RootMonikerNotSet);
                                                ValidateRootMoniker(value);
                                                engineMoniker = value;
                                        }
                                }
                        }
        public String RootNamespace
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.EngineInitialized);
                                                return rootNamespace;
                                        }
                                }
                                set
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.EngineNotRunning |
                                                                          
Pre.EngineInitialized);
                                                if(IsValidNamespaceName(value))
                                                {
                                                        isEngineDirty = true;
                                                        isEngineCompiled = 
false;
                                                        rootNamespace = value;
                                                }
                                                else
                                                {
                                                        throw new VsaException
                                                                
(VsaError.RootNamespaceInvalid);
                                                }
                                        }
                                }
                        }
        public IVsaSite Site
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.RootMonikerSet);
                                                return engineSite;
                                        }
                                }
                                set
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.SiteNotSet |
                                                                          
Pre.RootMonikerSet);
                                                if(value != null)
                                                {
                                                        engineSite = value;
                                                }
                                                else
                                                {
                                                        throw new 
VsaException(VsaError.SiteInvalid);
                                                }
                                        }
                                }
                        }
        public String Version
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                
Preconditions(Pre.EngineNotClosed |
                                                                          
Pre.EngineInitialized);
                                                return assemblyVersion;
                                        }
                                }
                        }
        public virtual void Close()
                        {
                                lock(this)
                                {
                                        Preconditions(Pre.EngineNotClosed);
                                        if(isEngineRunning)
                                        {
                                                Reset();
                                        }
                                        DoClose();
                                        isClosed = true;
                                }
                        }
        public virtual bool Compile()
                        {
                                lock(this)
                                {
                                        // Make sure that we are in the right 
state.
                                        Preconditions(Pre.EngineNotClosed |
                                                                  
Pre.EngineNotRunning |
                                                                  
Pre.EngineInitialized |
                                                                  
Pre.RootNamespaceSet);

                                        // We need to have at least one code 
item.
                                        int posn;
                                        for(posn = 0; posn < vsaItems.Count; 
++posn)
                                        {
                                                if(vsaItems[posn].ItemType == 
VsaItemType.Code)
                                                {
                                                        break;
                                                }
                                        }
                                        if(posn >= vsaItems.Count)
                                        {
                                                throw new 
VsaException(VsaError.EngineEmpty);
                                        }

                                        // Reset the previous compiled state 
and then compile.
                                        try
                                        {
                                                ResetCompiledState();
                                                isEngineCompiled = DoCompile();
                                        }
                                        catch(VsaException)
                                        {
                                                throw;
                                        }
                                        catch(Exception e)
                                        {
                                                // Wrap the exception and 
re-throw it.
                                                throw new 
VsaException(VsaError.InternalCompilerError,
                                                                                
           e.ToString(), e);
                                        }

                                        // Update the engine state.
                                        if(isEngineCompiled)
                                        {
                                                haveCompiledState = true;
                                                failedCompilation = false;
                                                compiledRootNamespace = 
rootNamespace;
                                        }

                                        // Finished compilation.
                                        return isEngineCompiled;
                                }
                        }
        public virtual Object GetOption(String name)
                        {
                                lock(this)
                                {
                                        Preconditions(Pre.EngineNotClosed |
                                                                  
Pre.EngineInitialized);
                                        return GetCustomOption(name);
                                }
                        }
        public virtual void InitNew()
                        {
                                lock(this)
                                {
                                        Preconditions(Pre.EngineNotClosed |
                                                                  
Pre.EngineNotInitialized |
                                                                  
Pre.RootMonikerSet |
                                                                  Pre.SiteSet);
                                        isEngineInitialized = true;
                                }
                        }
        public abstract bool IsValidIdentifier(String identifier);
        public virtual void LoadSourceState(IVsaPersistSite site)
                        {
                                lock(this)
                                {
                                        Preconditions(Pre.EngineNotClosed |
                                                                  
Pre.EngineNotInitialized |
                                                                  
Pre.RootMonikerSet |
                                                                  Pre.SiteSet);
                                        isEngineInitialized = true;
                                        try
                                        {
                                                DoLoadSourceState(site);
                                        }
                                        catch
                                        {
                                                // Reset the 
"isEngineInitialized" flag.
                                                isEngineInitialized = true;
                                                throw;
                                        }
                                        isEngineDirty = true;
                                }
                        }
        public virtual void Reset()
                        {
                                lock(this)
                                {
                                        Preconditions(Pre.EngineNotClosed |
                                                                  
Pre.EngineRunning);
                                        ResetCompiledState();
                                        isEngineRunning = false;
                                        loadedAssembly = null;
                                }
                        }
        public virtual void RevokeCache()
                        {
                                lock(this)
                                {
                                        // We don't have a cache, so just check 
the preconditions.
                                        Preconditions(Pre.EngineNotClosed |
                                                                  
Pre.RootMonikerSet |
                                                                  
Pre.EngineNotRunning);
                                }
                        }
        public virtual void Run()
                        {
                                lock(this)
                                {
                                        // Check that the engine is in the 
right state.
                                        Preconditions(Pre.EngineNotClosed |
                                                                  
Pre.EngineNotRunning |
                                                                  
Pre.RootMonikerSet |
                                                                  Pre.SiteSet |
                                                                  
Pre.RootNamespaceSet);
                                        if(haveCompiledState)
                                        {
                                                if(rootNamespace != 
compiledRootNamespace)
                                                {
                                                        throw new VsaException
                                                                
(VsaError.RootNamespaceInvalid);
                                                }
                                                loadedAssembly = 
LoadCompiledState();
                                        }
                                        else if(failedCompilation)
                                        {
                                                throw new 
VsaException(VsaError.EngineNotCompiled);
                                        }

                                        // Run the compiled script.
                                        try
                                        {
                                                isEngineRunning = true;
                                                DoRun();
                                        }
                                        catch(VsaException)
                                        {
                                                throw;
                                        }
                                        catch(Exception e)
                                        {
                                                // Wrap the exception and 
re-throw.
                                                throw new 
VsaException(VsaError.UnknownError,
                                                                                
           e.ToString(), e);
                                        }
                                }
                        }
        public virtual void SaveCompiledState(out byte[] pe, out byte[] pdb)
                        {
                                lock(this)
                                {
                                        Preconditions(Pre.EngineNotClosed |
                                                                  
Pre.EngineNotRunning |
                                                                  
Pre.EngineCompiled |
                                                                  
Pre.EngineInitialized);
                                        DoSaveCompiledState(out pe, out pdb);
                                }
                        }
        public virtual void SaveSourceState(IVsaPersistSite site)
                        {
                                lock(this)
                                {
                                        Preconditions(Pre.EngineNotClosed |
                                                                  
Pre.EngineNotRunning |
                                                                  
Pre.EngineInitialized);
                                        if(site != null)
                                        {
                                                try
                                                {
                                                        DoSaveSourceState(site);
                                                }
                                                catch(VsaException)
                                                {
                                                        throw;
                                                }
                                                catch(Exception e)
                                                {
                                                        // Wrap the exception 
and re-throw.
                                                        throw new 
VsaException(VsaError.SaveElementFailed,
                                                                                
                   e.ToString(), e);
                                                }
                                        }
                                        else
                                        {
                                                throw new 
VsaException(VsaError.SiteInvalid);
                                        }
                                }
                        }
        public virtual void SetOption(String name, Object value)
                        {
                                lock(this)
                                {
                                        Preconditions(Pre.EngineNotClosed |
                                                                  
Pre.EngineNotRunning |
                                                                  
Pre.EngineInitialized);
                                        SetCustomOption(name, value);
                                }
                        }

        // Helper method that constructs an error exception.
        protected VsaException Error(VsaError vsaErrorNumber)
                        {
                                return new VsaException(vsaErrorNumber);
                        }

        // Raise an error condition.
        private void Raise(VsaError vsaErrorNumber)
                        {
                                throw Error(vsaErrorNumber);
                        }

        // Pre-conditions that may be tested by the "Preconditions" method.
        protected enum Pre
        {
                None                                    = 0,
                EngineNotClosed                 = (1<<0),
                SupportForDebug                 = (1<<1),
                EngineCompiled                  = (1<<2),
                EngineRunning                   = (1<<3),
                EngineNotRunning                = (1<<4),
                RootMonikerSet                  = (1<<5),
                RootMonikerNotSet               = (1<<6),
                RootNamespaceSet                = (1<<7),
                SiteSet                                 = (1<<8),
                SiteNotSet                              = (1<<9),
                EngineInitialized               = (1<<10),
                EngineInitialised               = (1<<10),
                EngineNotInitialized    = (1<<11),
                EngineNotInitialised    = (1<<11)
        }

        // Test pre-conditions and raise an error if incorrect.
        protected void Preconditions(Pre flags)
                        {
                                // The object must never be closed.
                                if(isClosed)
                                {
                                        Raise(VsaError.EngineClosed);
                                }
                                if(flags == Pre.EngineNotClosed)
                                {
                                        return;
                                }

                                // Test the various conditions.
                                if((flags & Pre.SupportForDebug) != Pre.None)
                                {
                                        if(!isDebugInfoSupported)
                                        {
                                                
Raise(VsaError.DebugInfoNotSupported);
                                        }
                                }
                                if((flags & Pre.EngineCompiled) != Pre.None)
                                {
                                        if(!haveCompiledState)
                                        {
                                                
Raise(VsaError.EngineNotCompiled);
                                        }
                                }
                                if((flags & Pre.EngineRunning) != Pre.None)
                                {
                                        if(!isEngineRunning)
                                        {
                                                
Raise(VsaError.EngineNotRunning);
                                        }
                                }
                                if((flags & Pre.EngineNotRunning) != Pre.None)
                                {
                                        if(isEngineRunning)
                                        {
                                                Raise(VsaError.EngineRunning);
                                        }
                                }
                                if((flags & Pre.RootMonikerSet) != Pre.None)
                                {
                                        if(engineMoniker == String.Empty)
                                        {
                                                
Raise(VsaError.RootMonikerNotSet);
                                        }
                                }
                                if((flags & Pre.RootMonikerNotSet) != Pre.None)
                                {
                                        if(engineMoniker != String.Empty)
                                        {
                                                
Raise(VsaError.RootMonikerAlreadySet);
                                        }
                                }
                                if((flags & Pre.RootNamespaceSet) != Pre.None)
                                {
                                        if(rootNamespace == String.Empty)
                                        {
                                                
Raise(VsaError.RootNamespaceNotSet);
                                        }
                                }
                                if((flags & Pre.SiteSet) != Pre.None)
                                {
                                        if(engineSite == null)
                                        {
                                                Raise(VsaError.SiteNotSet);
                                        }
                                }
                                if((flags & Pre.SiteNotSet) != Pre.None)
                                {
                                        if(engineSite != null)
                                        {
                                                Raise(VsaError.SiteAlreadySet);
                                        }
                                }
                                if((flags & Pre.EngineInitialized) != Pre.None)
                                {
                                        if(!isEngineInitialized)
                                        {
                                                
Raise(VsaError.EngineNotInitialized);
                                        }
                                }
                                if((flags & Pre.EngineNotInitialized) != 
Pre.None)
                                {
                                        if(isEngineInitialized)
                                        {
                                                
Raise(VsaError.EngineInitialized);
                                        }
                                }
                        }

        // Other properties (not used by JScript).
        public _AppDomain AppDomain
                        {
                                get
                                {
                                        Preconditions(Pre.EngineNotClosed);
                                        throw new NotSupportedException();
                                }
                                set
                                {
                                        Preconditions(Pre.EngineNotClosed);
                                        throw new 
VsaException(VsaError.AppDomainCannotBeSet);
                                }
                        }
        public String ApplicationBase
                        {
                                get
                                {
                                        Preconditions(Pre.EngineNotClosed);
                                        throw new NotSupportedException();
                                }
                                set
                                {
                                        Preconditions(Pre.EngineNotClosed);
                                        throw new 
VsaException(VsaError.ApplicationBaseCannotBeSet);
                                }
                        }

        // Load the compiled state into the application domain.
        protected virtual Assembly LoadCompiledState()
                        {
                                // We don't support loading JScript programs as
                                // compiled assemblies just yet.
                                return null;
                        }

        // Validate a root moniker.
        protected virtual void ValidateRootMoniker(String rootMoniker)
                        {
                                // We don't care about root monikers in this 
implementation,
                                // so just verify that it isn't null.
                                if(rootMoniker == null)
                                {
                                        throw new 
VsaException(VsaError.RootMonikerInvalid);
                                }
                        }

        // Internal implementation of "Close"
        protected abstract void DoClose();

        // Internal implementation of "Compile".
        protected abstract bool DoCompile();

        // Internal implementation of "LoadSourceState".
        protected abstract void DoLoadSourceState(IVsaPersistSite site);

        // Internal implementation of "SaveCompiledState".
        protected abstract void DoSaveCompiledState
                        (out byte[] pe, out byte[] debugInfo);

        // Internal implementation of "SaveSourceState".
        protected abstract void DoSaveSourceState(IVsaPersistSite site);

        // Run the compiled script.
        internal virtual void DoRun() {}

        // Get a custom option value.
        protected abstract Object GetCustomOption(String name);

        // Determine if a namespace name is valid.
        protected abstract bool IsValidNamespaceName(String name);

        // Internal implementation of "Reset".
        protected abstract void ResetCompiledState();

        // Set a custom option value.
        protected abstract void SetCustomOption(String name, Object value);

}; // class BaseVsaEngine

}; // namespace Microsoft.Vsa

--- NEW FILE ---
/*
 * BaseVsaSite.cs - Base class that implements IVsaSite.
 *
 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace Microsoft.Vsa
{

using System;

public class BaseVsaSite : IVsaSite
{
        // Fetch the compiled information from this site.
        public virtual byte[] Assembly
                        {
                                get
                                {
                                        return null;
                                }
                        }
        public virtual byte[] DebugInfo
                        {
                                get
                                {
                                        return null;
                                }
                        }

        // Implement the IVsaSite interface.
        public virtual void GetCompiledState(out byte[] pe, out byte[] 
debugInfo)
                        {
                                pe = Assembly;
                                debugInfo = DebugInfo;
                        }
        public virtual Object GetEventSourceInstance
                                (String itemName, String eventSourceName)
                        {
                                throw new 
VsaException(VsaError.CallbackUnexpected);
                        }
        public virtual Object GetGlobalInstance(String name)
                        {
                                throw new 
VsaException(VsaError.CallbackUnexpected);
                        }
        public virtual void Notify(String notify, Object info)
                        {
                                throw new 
VsaException(VsaError.CallbackUnexpected);
                        }
        public virtual bool OnCompilerError(IVsaError error)
                        {
                                return false;
                        }

}; // class BaseVsaSite

internal class ThrowOnErrorVsaSite : BaseVsaSite
{

        public override bool OnCompilerError(IVsaError error)
                        {
                                throw (Exception)error;
                        }

}; // class ThrowOnErrorVsaSite

}; // namespace Microsoft.Vsa

--- NEW FILE ---
/*
 * BaseVsaStartup.cs - Startup/shutdown handling for vsa engines.
 *
 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace Microsoft.Vsa
{

using System;

public abstract class BaseVsaStartup
{
        // Accessible internal state.
        protected IVsaSite site;

        // Set the site.
        public void SetSite(IVsaSite site)
                        {
                                this.site = site;
                        }

        // Startup/shutdown this object.
        public abstract void Startup();
        public abstract void Shutdown();

}; // class BaseVsaStartup

}; // namespace Microsoft.Vsa

--- NEW FILE ---
/*
 * COMCharStream.cs - stream object wrapped around an IMessageReceiver.
 *
 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace Microsoft.JScript
{

using System;
using System.IO;
using System.Text;

public class COMCharStream : Stream
{
        // Internal state.
        private IMessageReceiver messageReceiver;
        private StringBuilder builder;

        // Constructor.
        public COMCharStream(IMessageReceiver messageReceiver)
                        {
                                this.messageReceiver = messageReceiver;
                                this.builder = new StringBuilder();
                        }

        // Close the stream.
        public override void Close()
                        {
                                Flush();
                        }

        // Flush the pending contents in this stream.
        public override void Flush()
                        {
                                messageReceiver.Message(builder.ToString());
                                builder = new StringBuilder();
                        }

        // Read data from this stream.
        public override int Read(byte[] buffer, int offset, int count)
                        {
                                throw new NotSupportedException();
                        }

        // Seek to a new position within this stream.
        public override long Seek(long offset, SeekOrigin origin)
                        {
                                return 0;
                        }

        // Set the length of this stream.
        public override void SetLength(long value)
                        {
                                builder.Length = (int)value;
                        }

        // Write a buffer of bytes to this stream.
        public override void Write(byte[] buffer, int offset, int count)
                        {
                                while(count > 0)
                                {
                                        
builder.Append((char)(buffer[offset++]));
                                        --count;
                                }
                        }

        // Determine if it is possible to read from this stream.
        public override bool CanRead
                        {
                                get
                                {
                                        return false;
                                }
                        }

        // Determine if it is possible to seek within this stream.
        public override bool CanSeek
                        {
                                get
                                {
                                        return false;
                                }
                        }

        // Determine if it is possible to write to this stream.
        public override bool CanWrite
                        {
                                get
                                {
                                        return true;
                                }
                        }

        // Get the length of this stream.
        public override long Length
                        {
                                get
                                {
                                        return builder.Length;
                                }
                        }

        // Get the current position within the stream.
        public override long Position
                        {
                                get
                                {
                                        return builder.Length;
                                }
                                set
                                {
                                        // Nothing to do here.
                                }
                        }

}; // class COMCharStream

}; // namespace Microsoft.JScript.Vsa

--- NEW FILE ---
/*
 * IMessageReceiver.cs - Capture output from the JScript engine.
 *
 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace Microsoft.JScript
{

using System;

public interface IMessageReceiver
{
        // Receive a message.
        void Message(String strValue);

}; // interface IMessageReceiver

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * INeedEngine.cs - Interface for getting or setting an engine.
 *
 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace Microsoft.JScript
{

using System;
using Microsoft.JScript.Vsa;

public interface INeedEngine
{
        // Get the engine in use by this object.
        VsaEngine GetEngine();

        // Set the engine to be used by this object.
        void SetEngine(VsaEngine engine);

}; // interface INeedEngine

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * IRedirectOutput.cs - Capture output from the JScript engine.
 *
 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace Microsoft.JScript
{

using System;

public interface IRedirectOutput
{
        // Set the output stream.
        void SetOutputStream(IMessageReceiver output);

}; // interface IRedirectOutput

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * IVsaScriptScope.cs - Access information within a scripting scope.
 *
 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace Microsoft.JScript
{

using System;
using Microsoft.Vsa;
using Microsoft.JScript.Vsa;

public interface IVsaScriptScope : IVsaItem
{

        IVsaItem AddItem(String itemName, VsaItemType type);
        IVsaItem AddItem(String itemName);
        IVsaItem GetDynamicItem(String itemName, VsaItemType type);
        IVsaItem GetItemAtIndex(int index);
        int GetItemCount();
        IVsaScriptScope Parent { get; }
        void RemoveItem(String itemName);
        void RemoveItem(IVsaItem item);
        void RemoveItemAtIndex(int index);

}; // interface IVsaScriptScope

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * JSError.cs - Error codes for the JScript engine.
 *
 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace Microsoft.JScript
{

public enum JSError
{
        NoError                                                                 
        =    0,
        InvalidCall                                                             
        =    5,
        OutOfMemory                                                             
        =    7,
        TypeMismatch                                                            
=   13,
        OutOfStack                                                              
        =   28,
        InternalError                                                           
=   51,
        FileNotFound                                                            
=   53, 
        NeedObject                                                              
        =  424,
        CantCreateObject                                                        
=  429,
        OLENoPropOrMethod                                                       
=  438,
        ActionNotSupported                                                      
=  445,
        NotCollection                                                           
=  451,
        SyntaxError                                                             
        = 1002,
        NoColon                                                                 
        = 1003,
        NoSemicolon                                                             
        = 1004,
        NoLeftParen                                                             
        = 1005,
        NoRightParen                                                            
= 1006,
        NoRightBracket                                                          
= 1007,
        NoLeftCurly                                                             
        = 1008,
        NoRightCurly                                                            
= 1009,
        NoIdentifier                                                            
= 1010,
        NoEqual                                                                 
        = 1011,
        IllegalChar                                                             
        = 1014,
        UnterminatedString                                                      
= 1015,
        NoCommentEnd                                                            
= 1016,
        BadReturn                                                               
        = 1018,
        BadBreak                                                                
        = 1019,
        BadContinue                                                             
        = 1020,
        BadHexDigit                                                             
        = 1023,
        NoWhile                                                                 
        = 1024,
        BadLabel                                                                
        = 1025,
        NoLabel                                                                 
        = 1026,
        DupDefault                                                              
        = 1027,
        NoMemberIdentifier                                                      
= 1028,
        NoCcEnd                                                                 
        = 1029,
        CcOff                                                                   
        = 1030,
        NotConst                                                                
        = 1031,
        NoAt                                                                    
        = 1032,
        NoCatch                                                                 
        = 1033,
        InvalidElse                                                             
    = 1034,
        NoComma                                                                 
        = 1100,
        DupVisibility                                                           
= 1101,
        IllegalVisibility                                                       
= 1102,
        BadSwitch                                                               
        = 1103,
        CcInvalidEnd                                                            
= 1104,
        CcInvalidElse                                                           
= 1105,
        CcInvalidElif                                                           
= 1106,
        ErrEOF                                                                  
        = 1107,
        IncompatibleVisibility                                          = 1108,
        ClassNotAllowed                                                         
= 1109,
        NeedCompileTimeConstant                                         = 1110,
        DuplicateName                                                           
= 1111,
        NeedType                                                                
        = 1112,
        NotInsideClass                                                          
= 1113,
        InvalidPositionDirective                                        = 1114,
        MustBeEOL                                                               
        = 1115,
        WrongDirective                                                          
= 1118,
        CannotNestPositionDirective                                     = 1119,
        CircularDefinition                                                      
= 1120,
        Deprecated                                                              
        = 1121,
        IllegalUseOfThis                                                        
= 1122,
        NotAccessible                                                           
= 1123,
        CannotUseNameOfClass                                            = 1124,
        MustImplementMethod                                                     
= 1128,
        NeedInterface                                                           
= 1129,
        UnreachableCatch                                                        
= 1133,
        TypeCannotBeExtended                                            = 1134,
        UndeclaredVariable                                                      
= 1135,
        VariableLeftUninitialized                                       = 1136,
        KeywordUsedAsIdentifier                                         = 1137,
        NotAllowedInSuperConstructorCall                        = 1140,
        NotMeantToBeCalledDirectly                                      = 1141,
        GetAndSetAreInconsistent                                        = 1142,
        InvalidCustomAttribute                                          = 1143,
        InvalidCustomAttributeArgument                          = 1144,
        InvalidCustomAttributeClassOrCtor                       = 1146,
        TooManyParameters                                                       
= 1148,
        AmbiguousBindingBecauseOfWith                           = 1149,
        AmbiguousBindingBecauseOfEval                           = 1150,
        NoSuchMember                                                            
= 1151,
        ItemNotAllowedOnExpandoClass                            = 1152,
        MethodNotAllowedOnExpandoClass                          = 1153,
        MethodClashOnExpandoSuperClass                          = 1155,
        BaseClassIsExpandoAlready                                       = 1156,
        AbstractCannotBePrivate                                         = 1157,
        NotIndexable                                                            
= 1158,
        StaticMissingInStaticInit                                       = 1159,
        MissingConstructForAttributes                           = 1160,
        OnlyClassesAllowed                                                      
= 1161,
        ExpandoClassShouldNotImpleEnumerable            = 1162,
        NonCLSCompliantMember                                           = 1163,
        NotDeletable                                                            
= 1164,
        PackageExpected                                                         
= 1165,
        UselessExpression                                                       
= 1169,
        HidesParentMember                                                       
= 1170,
        CannotChangeVisibility                                          = 1171,
        HidesAbstractInBase                                                     
= 1172,
        NewNotSpecifiedInMethodDeclaration                      = 1173,
        MethodInBaseIsNotVirtual                                        = 1174,
        NoMethodInBaseToNew                                                     
= 1175,
        DifferentReturnTypeFromBase                                     = 1176,
        ClashWithProperty                                                       
= 1177,
        OverrideAndHideUsedTogether                                     = 1178,
        InvalidLanguageOption                                           = 1179,
        NoMethodInBaseToOverride                                        = 1180,
        NotValidForConstructor                                          = 1181,
        CannotReturnValueFromVoidFunction                       = 1182,
        AmbiguousMatch                                                          
= 1183,
        AmbiguousConstructorCall                                        = 1184,
        SuperClassConstructorNotAccessible                      = 1185,
        OctalLiteralsAreDeprecated                                      = 1186,
        VariableMightBeUnitialized                                      = 1187,
        NotOKToCallSuper                                                        
= 1188,
        IllegalUseOfSuper                                                       
= 1189,
        BadWayToLeaveFinally                                            = 1190,
        NoCommaOrTypeDefinitionError                            = 1191,
        AbstractWithBody                                                        
= 1192,
        NoRightParenOrComma                                                     
= 1193,
        NoRightBracketOrComma                                           = 1194,
        ExpressionExpected                                                      
= 1195,
        UnexpectedSemicolon                                                     
= 1196,
        TooManyTokensSkipped                                            = 1197,
        BadVariableDeclaration                                          = 1198,
        BadFunctionDeclaration                                          = 1199,
        BadPropertyDeclaration                                          = 1200,
        DoesNotHaveAnAddress                                            = 1203,
        TooFewParameters                                                        
= 1204,
        UselessAssignment                                                       
= 1205,
        SuspectAssignment                                                       
= 1206,
        SuspectSemicolon                                                        
= 1207,
        ImpossibleConversion                                            = 1208,
        FinalPrecludesAbstract                                          = 1209,
        NeedInstance                                                            
= 1210,
        CannotBeAbstract                                                        
= 1212,
        InvalidBaseTypeForEnum                                          = 1213,
        CannotInstantiateAbstractClass                          = 1214,
        ArrayMayBeCopied                                                        
= 1215,
        AbstractCannotBeStatic                                          = 1216,
        StaticIsAlreadyFinal                                            = 1217,
        StaticMethodsCannotOverride                                     = 1218,
        StaticMethodsCannotHide                                         = 1219,
        ExpandoPrecludesOverride                                        = 1220,
        IllegalParamArrayAttribute                                      = 1221,
        ExpandoPrecludesAbstract                                        = 1222,
        ShouldBeAbstract                                                        
= 1223,
        BadModifierInInterface                                          = 1224,
        VarIllegalInInterface                                           = 1226,
        InterfaceIllegalInInterface                                     = 1227,
        NoVarInEnum                                                             
        = 1228,
        InvalidImport                                                           
= 1229,
        EnumNotAllowed                                                          
= 1230,
        InvalidCustomAttributeTarget                            = 1231,
        PackageInWrongContext                                           = 1232,
        ConstructorMayNotHaveReturnType                         = 1233,
        OnlyClassesAndPackagesAllowed                           = 1234,
        InvalidDebugDirective                                           = 1235,
        CustomAttributeUsedMoreThanOnce                         = 1236,
        NestedInstanceTypeCannotBeExtendedByStatic      = 1237,
        PropertyLevelAttributesMustBeOnGetter           = 1238,
        BadThrow                                                                
        = 1239,
        ParamListNotLast                                                        
= 1240,
        NoSuchType                                                              
        = 1241,
        BadOctalLiteral                                                         
= 1242,
        InstanceNotAccessibleFromStatic                         = 1243,
        StaticRequiresTypeName                                          = 1244,
        NonStaticWithTypeName                                           = 1245,
        NoSuchStaticMember                                                      
= 1246,
        SuspectLoopCondition                                            = 1247,
        ExpectedAssembly                                                        
= 1248,
        AssemblyAttributesMustBeGlobal                          = 1249,
        ExpandoPrecludesStatic                                          = 1250,
        DuplicateMethod                                                         
= 1251,
        NotAnExpandoFunction                                            = 1252,
        NotValidVersionString                                           = 1253,
        ExecutablesCannotBeLocalized                            = 1254,
        StringConcatIsSlow                                                      
= 1255,
        CcInvalidInDebugger                                                     
= 1256,
        ExpandoMustBePublic                                                     
= 1257,
        DelegatesShouldNotBeExplicitlyConstructed       = 1258,
        ImplicitlyReferencedAssemblyNotFound            = 1259,
        PossibleBadConversion                                           = 1260,
        PossibleBadConversionFromString                         = 1261,
        InvalidResource                                                         
= 1262,
        WrongUseOfAddressOf                                                     
= 1263,
        NonCLSCompliantType                                                     
= 1264,
        MemberTypeCLSCompliantMismatch                          = 1265,
        TypeAssemblyCLSCompliantMismatch                        = 1266,
        CantAssignThis                                                          
= 5000,
        NumberExpected                                                          
= 5001,
        FunctionExpected                                                        
= 5002,
        CannotAssignToFunctionResult                            = 5003,
        StringExpected                                                          
= 5005,
        DateExpected                                                            
= 5006,
        ObjectExpected                                                          
= 5007,
        IllegalAssignment                                                       
= 5008,
        UndefinedIdentifier                                                     
= 5009,
        BooleanExpected                                                         
= 5010,
        VBArrayExpected                                                         
= 5013,
        EnumeratorExpected                                                      
= 5015,
        RegExpExpected                                                          
= 5016,
        RegExpSyntax                                                            
= 5017,
        UncaughtException                                                       
= 5022,
        InvalidPrototype                                                        
= 5023,
        URIEncodeError                                                          
= 5024,
        URIDecodeError                                                          
= 5025, 
        FractionOutOfRange                                                      
= 5026,
        PrecisionOutOfRange                                                     
= 5027,
        ArrayLengthConstructIncorrect                           = 5029,
        ArrayLengthAssignIncorrect                                      = 5030,
        NeedArrayObject                                                         
= 5031,
        NoConstructor                                                           
= 5032,
        IllegalEval                                                             
        = 5033,
        NotYetImplemented                                                       
= 5034,
        MustProvideNameForNamedParameter                        = 5035,
        DuplicateNamedParameter                                         = 5036,
        MissingNameParameter                                            = 5037,
        MoreNamedParametersThanArguments                        = 5038,
        NonSupportedInDebugger                                          = 5039,
        AssignmentToReadOnly                                            = 5040,
        WriteOnlyProperty                                                       
= 5041,
        IncorrectNumberOfIndices                                        = 5042,
        RefParamsNonSupportedInDebugger                         = 5043,
        CannotCallSecurityMethodLateBound                       = 5044,
        CannotUseStaticSecurityAttribute                        = 5045,
        FuncEvalAborted                                                         
= 6000,
        FuncEvalTimedout                                                        
= 6001,
        FuncEvalThreadSuspended                                         = 6002,
        FuncEvalThreadSleepWaitJoin                                     = 6003,
        FuncEvalBadThreadState                                          = 6004,
        FuncEvalBadThreadNotStarted                                     = 6005,
        NoFuncEvalAllowed                                                       
= 6006, 
        FuncEvalBadLocation                                                     
= 6007,
        FuncEvalWebMethod                                                       
= 6008,
        StaticVarNotAvailable                                           = 6009,
        TypeObjectNotAvailable                                          = 6010,
        ExceptionFromHResult                                            = 6011

}; // enum JSError

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * JScriptException.cs - Exception that may be thrown by the JScript engine.
 *
 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace Microsoft.JScript
{

using System;
using System.Runtime.Serialization;
using Microsoft.Vsa;

[Serializable]
public class JScriptException : ApplicationException, IVsaError
{
        // Internal state.
        internal JSError errorNumber;
        internal Object wrappedException;
        internal Context context;
        internal String message;

        // Constructors.
        internal JScriptException(JSError errorNumber)
                        {
                                this.errorNumber = errorNumber;
                                this.wrappedException = null;
                                this.context = null;
                                this.message = null;
                        }
        internal JScriptException(JSError errorNumber, Context context)
                        {
                                this.errorNumber = errorNumber;
                                this.wrappedException = null;
                                this.context = context;
                                this.message = null;
                        }
        internal JScriptException(Object value)
                        {
                                this.wrappedException = value;
                                if(value is StackOverflowException)
                                {
                                        this.errorNumber = JSError.OutOfStack;
                                }
                                else if(value is OutOfMemoryException)
                                {
                                        this.errorNumber = JSError.OutOfMemory;
                                }
                                else
                                {
                                        this.errorNumber = 
JSError.UncaughtException;
                                }
                                this.context = null;
                                this.message = null;
                        }
#if !ECMA_COMPAT
        protected JScriptException(SerializationInfo info,
                                                           StreamingContext 
context)
                        {
                                // TODO
                        }
        public override void GetObjectData(SerializationInfo info,
                                                                           
StreamingContext context)
                        {
                                // TODO
                        }
#endif

        // Properties.
        public int Column
                        {
                                get
                                {
                                        if(context != null)
                                        {
                                                return context.StartColumn + 1;
                                        }
                                        else
                                        {
                                                return 0;
                                        }
                                }
                        }
        public String Description
                        {
                                get
                                {
                                        return Message;
                                }
                        }
        public int EndColumn
                        {
                                get
                                {
                                        if(context != null)
                                        {
                                                return context.EndColumn + 1;
                                        }
                                        else
                                        {
                                                return 0;
                                        }
                                }
                        }
        public int EndLine
                        {
                                get
                                {
                                        if(context != null)
                                        {
                                                return context.endLine;
                                        }
                                        else
                                        {
                                                return 0;
                                        }
                                }
                        }
        public int ErrorNumber
                        {
                                get
                                {
                                        return unchecked(((int)errorNumber) + 
(int)0x800A0000);
                                }
                        }
        public int Line
                        {
                                get
                                {
                                        if(context != null)
                                        {
                                                return context.StartLine;
                                        }
                                        else
                                        {
                                                return 0;
                                        }
                                }
                        }
        public String LineText
                        {
                                get
                                {
                                        if(context != null)
                                        {
                                                return context.GetCode();
                                        }
                                        else
                                        {
                                                return String.Empty;
                                        }
                                }
                        }
        public override String Message
                        {
                                get
                                {
                                        if(message != null)
                                        {
                                                if(context != null)
                                                {
                                                        if(context.codebase != 
null &&
                                                           
context.codebase.name != null)
                                                        {
                                                                return 
String.Format
                                                                        ("{0}: 
line {1}, column {2}: {3}",
                                                                     
context.codebase.name,
                                                                         Line, 
Column, message);
                                                        }
                                                        else
                                                        {
                                                                return 
String.Format
                                                                        ("line 
{0}, column {1}: {2}",
                                                                     Line, 
Column, message);
                                                        }
                                                }
                                                else
                                                {
                                                        return message;
                                                }
                                        }
                                        else
                                        {
                                                return errorNumber.ToString();
                                        }
                                }
                        }
        public int Number
                        {
                                get
                                {
                                        return ErrorNumber;
                                }
                        }
        public int Severity
                        {
                                get
                                {
                                        switch(errorNumber)
                                        {
                                                case JSError.ArrayMayBeCopied:
                                                case 
JSError.AssignmentToReadOnly:
                                                case JSError.BadOctalLiteral:
                                                case 
JSError.BaseClassIsExpandoAlready:
                                                case 
JSError.DifferentReturnTypeFromBase:
                                                case JSError.DuplicateName:
                                                case JSError.DupVisibility:
                                                case 
JSError.GetAndSetAreInconsistent:
                                                case JSError.HidesParentMember:
                                                case 
JSError.IncompatibleVisibility:
                                                case 
JSError.NewNotSpecifiedInMethodDeclaration:
                                                case JSError.NotDeletable:
                                                case 
JSError.NotMeantToBeCalledDirectly:
                                                case 
JSError.PossibleBadConversion:
                                                case JSError.ShouldBeAbstract:
                                                case JSError.SuspectAssignment:
                                                case 
JSError.SuspectLoopCondition:
                                                case JSError.SuspectSemicolon:
                                                case JSError.TooFewParameters:
                                                case JSError.TooManyParameters:
                                                case JSError.UselessAssignment:
                                                case JSError.UselessExpression:
                                                        return 1;

                                                case JSError.Deprecated:
                                                case 
JSError.KeywordUsedAsIdentifier:
                                                case 
JSError.OctalLiteralsAreDeprecated:
                                                        return 2;

                                                case 
JSError.BadWayToLeaveFinally:
                                                case JSError.StringConcatIsSlow:
                                                case JSError.UndeclaredVariable:
                                                case 
JSError.VariableLeftUninitialized:
                                                case 
JSError.VariableMightBeUnitialized:
                                                        return 3;

                                                case 
JSError.AmbiguousBindingBecauseOfWith:
                                                case 
JSError.AmbiguousBindingBecauseOfEval:
                                                case 
JSError.PossibleBadConversionFromString:
                                                        return 4;

                                                default: break;
                                        }
                                        return 0;
                                }
                        }
        public IVsaItem SourceItem
                        {
                                get
                                {
                                        if(context != null && context.codebase 
!= null)
                                        {
                                                return context.codebase.item;
                                        }
                                        else
                                        {
                                                throw new NoContextException();
                                        }
                                }
                        }
        public String SourceMoniker
                        {
                                get
                                {
                                        if(context != null && context.codebase 
!= null)
                                        {
                                                return context.codebase.name;
                                        }
                                        else
                                        {
                                                return "no source";
                                        }
                                }
                        }
        public override String StackTrace
                        {
                                get
                                {
                                        return Message + Environment.NewLine + 
base.StackTrace;
                                }
                        }
        public int StartColumn
                        {
                                get
                                {
                                        return Column;
                                }
                        }

}; // class JScriptException

}; // namespace Microsoft.JScript

--- NEW FILE ---

# The build is done in "runtime", so cd up and use that Makefile.

all:
        (cd ..;make)

clean:
        (cd ..;make clean)

--- NEW FILE ---
/*
 * NoContextException.cs - No context available to perform operation.
 *
 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace Microsoft.JScript
{

using System;

public class NoContextException : ApplicationException
{
        // Constructors.
        internal NoContextException()
                        : base("The source context is not available")
                        {
                                // Nothing to do here.
                        }

}; // class NoContextException

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * ScriptStream.cs - capture stream output from an engine.
 *
 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace Microsoft.JScript.Vsa
{

using System;
using System.IO;

public class ScriptStream
{
        // Global stdout and stderr streams.
        public static TextWriter Out = Console.Out;
        public static TextWriter Error = Console.Error;

        // Print an exception stack trace.
        public static void PrintStackTrace(Exception e)
                        {
                                Out.WriteLine(e.StackTrace);
                                Out.Flush();
                        }
        public static void PrintStackTrace()
                        {
                                // Get the stack trace for the current method
                                // by throwing a dummy exception.
                                try
                                {
                                        throw new Exception();
                                }
                                catch(Exception e)
                                {
                                        PrintStackTrace(e);
                                }
                        }

        // Write a string to stdout.
        public static void Write(String str)
                        {
                                Out.Write(str);
                        }
        public static void WriteLine(String str)
                        {
                                Out.WriteLine(str);
                        }

}; // class ScriptStream

}; // namespace Microsoft.JScript.Vsa

--- NEW FILE ---
/*
 * VsaCodeItem.cs - script code item for an engine.
 *
 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace Microsoft.JScript
{

using System;
using System.CodeDom;
using Microsoft.JScript.Vsa;
using Microsoft.Vsa;

internal sealed class VsaCodeItem : VsaItem, IVsaCodeItem
{
        // Internal state.
        private String sourceText;
        private JNode parsed;

        // Constructor.
        internal VsaCodeItem(VsaEngine engine, String name, VsaItemFlag flag)
                        : base(engine, name, VsaItemType.Code, flag)
                        {
                                sourceText = null;
                                parsed = null;
                        }

        // Implement the "IVsaCodeItem" interface.
#if !ECMA_COMPAT
        public CodeObject CodeDOM
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                CheckForClosed();
                                                throw new 
VsaException(VsaError.CodeDOMNotAvailable);
                                        }
                                }
                        }
#endif
        public String SourceText
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                CheckForClosed();
                                                return sourceText;
                                        }
                                }
                                set
                                {
                                        lock(this)
                                        {
                                                CheckForClosed();
                                                sourceText = value;
                                        }
                                }
                        }
        public void AddEventSource(String eventSourceName, String 
eventSourceType)
                        {
                                lock(this)
                                {
                                        CheckForClosed();
                                        throw new NotSupportedException();
                                }
                        }
        public void AppendSourceText(String text)
                        {
                                lock(this)
                                {
                                        CheckForClosed();
                                        sourceText += text;
                                }
                        }
        public void RemoveEventSource(String eventSourceName)
                        {
                                lock(this)
                                {
                                        CheckForClosed();
                                        throw new NotSupportedException();
                                }
                        }

        // Reset the compiled state of this item.
        internal override void Reset()
                        {
                                parsed = null;
                        }

        // Compile this item.
        internal override bool Compile()
                        {
                                if(parsed == null && sourceText != null)
                                {
                                        Context context = new 
Context(sourceText);
                                        context.codebase = new 
CodeBase(codebaseOption, this);
                                        context.codebase.site = engine.Site;
                                        JSParser parser = new JSParser(context);
                                        try
                                        {
                                                parsed = 
parser.ParseSource(false);
                                        }
                                        catch(JScriptException e)
                                        {
                                                // Parse error that wasn't 
caught internally.
                                                return false;
                                        }
                                        if(parser.numErrors > 0)
                                        {
                                                // There were errors that were 
partially recovered.
                                                parsed = null;
                                                return false;
                                        }
                                }
                                return true;
                        }

        // Run this item.
        internal override void Run()
                        {
                                if(parsed != null)
                                {
                                        int size = 
engine.ScriptObjectStackSize();
                                        try
                                        {
                                                parsed.Eval(engine);
                                        }
                                        finally
                                        {
                                                // Make sure we return to the 
global level, even if
                                                // some aberrant exception 
caused us to miss any
                                                // of the scope pops.  This is 
just paranoia.
                                                
engine.ScriptObjectStackSetSize(size);
                                        }
                                }
                        }

}; // class VsaCodeItem

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * VsaEngine.cs - front-end interface to the JScript engine.
 *
 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace Microsoft.JScript.Vsa
{

using System;
using System.IO;
using System.Text;
using System.Reflection;
using Microsoft.JScript;
using Microsoft.Vsa;

public class VsaEngine : BaseVsaEngine, IRedirectOutput
{
        // Internal state.
        private static VsaEngine primaryEngine;
        private bool detached;
        private bool printSupported;
        internal EngineInstance engineInstance;
        private LenientGlobalObject lenientGlobalObject;
        private GlobalScope globalScope;
        private Object[] scopeStack;
        private int scopeStackSize;
        private Object currentScope;

        // Constructors.
        public VsaEngine() : this(true) {}
        public VsaEngine(bool fast)
                        : base("JScript", "7.0.3300", true)
                        {
                                vsaItems = new VsaItems(this);
                                detached = false;
                                printSupported = false;
                                engineInstance = new EngineInstance(this);
                                engineInstance.Init();

                                // Set the global context to this engine if we 
are
                                // the only engine instance in the system.
                                Globals.SetContextEngine(this);

                                // Create the global object that contains all of
                                // the definitions in the engine's global scope.
                                lenientGlobalObject = new 
LenientGlobalObject(this);

                                // Create the global scope object.
                                globalScope = new GlobalScope
                                        (null, 
lenientGlobalObject.globalObject);

                                // Initialize the scope stack.
                                scopeStack = new Object [8];
                                scopeStack[0] = globalScope;
                                scopeStackSize = 1;
                                currentScope = globalScope;
                        }

        // Clone an application domain's engine.
        public virtual IVsaEngine Clone(AppDomain domain)
                        {
                                throw new NotImplementedException();
                        }

        // Run this engine in a specified application domain.
        public virtual void Run(AppDomain domain)
                        {
                                throw new NotImplementedException();
                        }

        // Compile an "empty" script context.
        public virtual bool CompileEmpty()
                        {
                                lock(this)
                                {
                                        return DoCompile();
                                }
                        }

        // Run an "empty" script context.
        public virtual void RunEmpty()
                        {
                                // Let the base class do the work.
                                base.Run();
                        }

        // Connect up the events in use by this engine.
        public virtual void ConnectEvents()
                        {
                                // Noting to do here.
                        }

        // Disconnect the events in use by this engine.
        public virtual void DisconnectEvents()
                        {
                                // Noting to do here.
                        }

        // Register an event source with this engine.
        public virtual void RegisterEventSource(String name)
                        {
                                // Nothing to do here.
                        }

        // Get the assembly or assembly builder in use.
        public virtual Assembly GetAssembly()
                        {
                                // We don't use assemblies in this 
implementation.
                                return null;
                        }

        // Get the module or module builder in use.
        public virtual Module GetModule()
                        {
                                // We don't use modules in this implementation.
                                return null;
                        }

        // Get the global script scope for this engine.
        public virtual IVsaScriptScope GetGlobalScope()
                        {
                                // As far as we can tell, this API is obsolete 
or it was
                                // never actually used for anything.  Let us 
know if you
                                // find something important that depends upon 
it.
                                return null;
                        }

        // Get the main scope.
        public virtual GlobalScope GetMainScope()
                        {
                                return globalScope;
                        }

        // Interrupt the engine if it is running in a separate thread.
        public virtual void Interrupt()
                        {
                                // We don't support threading yet.
                        }

        // Determine if an identifier is valid for this engine.
        public override bool IsValidIdentifier(String identifier)
                        {
                                if(identifier == null)
                                {
                                        return false;
                                }
                                JSScanner scanner = new JSScanner(identifier);
                                if(scanner.FetchIdentifier() == null)
                                {
                                        return false;
                                }
                                return (scanner.Fetch() == -1);
                        }

        // Internal implementation of "Close"
        protected override void DoClose()
                        {
                                // Close all code items in the engine.
                                ((VsaItems)vsaItems).Close();
                                vsaItems = null;

                                // Clear the engine site, which will no longer 
be required.
                                engineSite = null;

                                // Reset global variables that may refer to 
this instance.
                                lock(typeof(VsaEngine))
                                {
                                        if(primaryEngine == this)
                                        {
                                                primaryEngine = null;
                                        }
                                        if(Globals.contextEngine == this)
                                        {
                                                Globals.contextEngine = null;
                                                ScriptStream.Out = Console.Out;
                                                ScriptStream.Error = 
Console.Error;
                                        }
                                }

                                // Force a garbage collection to clean 
everything up.
                                GC.Collect();
                        }

        // Internal implementation of "Compile".
        protected override bool DoCompile()
                        {
                                failedCompilation = false;
                                if(vsaItems != null)
                                {
                                        failedCompilation = 
!(((VsaItems)vsaItems).Compile());
                                }
                                return !failedCompilation;
                        }

        // Load the compiled state into the application domain.
        protected override Assembly LoadCompiledState()
                        {
                                return base.LoadCompiledState();
                        }

        // Internal implementation of "LoadSourceState".
        protected override void DoLoadSourceState(IVsaPersistSite site)
                        {
                                // Nothing to do here - source loading is not 
supported.
                        }

        // Internal implementation of "SaveCompiledState".
        protected override void DoSaveCompiledState
                                (out byte[] pe, out byte[] debugInfo)
                        {
                                // Saving scripts to assembly form is not 
supported.
                                throw new 
VsaException(VsaError.SaveCompiledStateFailed);
                        }

        // Internal implementation of "SaveSourceState".
        protected override void DoSaveSourceState(IVsaPersistSite site)
                        {
                                // Nothing to do here - source saving is not 
supported.
                        }

        // Run the compiled script.
        internal override void DoRun()
                        {
                                if(vsaItems != null)
                                {
                                        ((VsaItems)vsaItems).Run();
                                }
                        }

        // Get a custom option value.
        protected override Object GetCustomOption(String name)
                        {
                                // Check options that we understand.
                                if(String.Compare(name, "detach", true) == 0)
                                {
                                        return detached;
                                }
                                else if(String.Compare(name, "print", true) == 
0)
                                {
                                        return printSupported;
                                }

                                // The option was not understood.
                                throw new 
VsaException(VsaError.OptionNotSupported);
                        }

        // Determine if a namespace name is valid.
        protected override bool IsValidNamespaceName(String name)
                        {
                                if(name == null)
                                {
                                        return false;
                                }
                                JSScanner scanner = new JSScanner(name);
                                if(scanner.FetchIdentifier() == null)
                                {
                                        return false;
                                }
                                while(scanner.Peek() == '.')
                                {
                                        scanner.Fetch();
                                        if(scanner.FetchIdentifier() == null)
                                        {
                                                return false;
                                        }
                                }
                                return (scanner.Fetch() == -1);
                        }

        // Internal implementation of "Reset".
        protected override void ResetCompiledState()
                        {
                                compiledRootNamespace = null;
                                failedCompilation = true;
                                haveCompiledState = false;
                                ((VsaItems)vsaItems).Reset();
                                isEngineCompiled = false;
                                isEngineRunning = false;
                        }

        // Set a custom option value.
        protected override void SetCustomOption(String name, Object value)
                        {
                                // Handle the "detach" option, which allows us 
to support
                                // more than one engine instance per process.
                                if(String.Compare(name, "detach", true) == 0)
                                {
                                        if(value is Boolean && ((bool)value) && 
!detached)
                                        {
                                                DetachEngine();
                                        }
                                        return;
                                }
                                else if(String.Compare(name, "print", true) == 
0)
                                {
                                        printSupported = (value is Boolean && 
((bool)value));
                                        return;
                                }

                                // The option is not understood.
                                throw new 
VsaException(VsaError.OptionNotSupported);
                        }

        // Validate a root moniker.
        protected override void ValidateRootMoniker(String rootMoniker)
                        {
                                base.ValidateRootMoniker(rootMoniker);
                        }

        // Implement the IRedirectOutput interface.
        public virtual void SetOutputStream(IMessageReceiver output)
                        {
                                // Wrap up the receiver to turn it into a 
stream.
                                COMCharStream stream = new 
COMCharStream(output);
                                StreamWriter writer = new StreamWriter
                                                (stream, Encoding.Default);

                                // Do a flush after every write operation.
                                writer.AutoFlush = true;

                                // Set the stdout and stderr streams for the 
script.
                                lock(typeof(VsaEngine))
                                {
                                        if(Globals.contextEngine != this)
                                        {
                                                // This instance has been 
detached, so set its
                                                // local output streams.
                                                
engineInstance.SetOutputStreams(writer, writer);
                                        }
                                        else
                                        {
                                                // Use the global 
"ScriptStream" class for the
                                                // default engine instance.
                                                ScriptStream.Out = writer;
                                                ScriptStream.Error = writer;
                                        }
                                }
                        }

        // Make a new engine instance and set it up for stand-alone operation.
        internal static VsaEngine MakeNewEngine()
                        {
                                VsaEngine engine = new VsaEngine(true);
                                engine.InitVsaEngine
                                        
("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa",
                                         new ThrowOnErrorVsaSite());
                                return engine;
                        }

        // Create the primary engine instance.
        public static VsaEngine CreateEngine()
                        {
                                lock(typeof(VsaEngine))
                                {
                                        if(primaryEngine == null)
                                        {
                                                primaryEngine = MakeNewEngine();
                                        }
                                        return primaryEngine;
                                }
                        }

        // Detach this engine from the primary position.
        private void DetachEngine()
                        {
                                lock(typeof(VsaEngine))
                                {
                                        if(this == primaryEngine)
                                        {
                                                primaryEngine = null;
                                        }
                                        if(this == Globals.contextEngine)
                                        {
                                                Globals.contextEngine = null;
                                        }
                                        engineInstance.DetachOutputStreams();
                                        detached = true;
                                }
                        }

        // Create the primary engine instance for a given DLL type.
        public static VsaEngine CreateEngineWithType
                                (RuntimeTypeHandle callingTypeHandle)
                        {
                                // Use the primary engine in the current 
process.
                                return CreateEngine();
                        }

        // Create an engine and get its global scope.
        public static GlobalScope CreateEngineAndGetGlobalScope
                                (bool fast, String[] AssemblyNames)
                        {
                                // We don't support assembly-based JScript 
executions.
                                throw new NotSupportedException();
                        }

        // Create an engine and get its global scope.
        public static GlobalScope CreateEngineAndGetGlobalScopeWithType
                                (bool fast, String[] AssemblyNames,
                                 RuntimeTypeHandle callingTypeHandle)
                        {
                                // We don't support assembly-based JScript 
executions.
                                throw new NotSupportedException();
                        }

        // Initialize a VSA engine in a non-VSA mode manually.
        // Use "CreateEngine" instead of this.
        public void InitVsaEngine(String rootMoniker, IVsaSite site)
                        {
                                rootNamespace = "JScript.DefaultNamespace";
                                engineMoniker = rootMoniker;
                                engineSite = site;
                                isEngineDirty = true;
                                isEngineCompiled = false;
                                isEngineInitialized = true;
                        }

        // Get the original constructors for various types.
        public ObjectConstructor GetOriginalObjectConstructor()
                        {
                                return engineInstance.GetObjectConstructor();
                        }
        public ArrayConstructor GetOriginalArrayConstructor()
                        {
                                return engineInstance.GetArrayConstructor();
                        }
#if false
        public RegExpConstructor GetOriginalRegExpConstructor()
                        {
                                // TODO
                                return null;
                        }
#endif

        // Get the lenient global object associated with this engine.
        public LenientGlobalObject LenientGlobalObject
                        {
                                get
                                {
                                        return lenientGlobalObject;
                                }
                        }

        // Push an object onto the script object stack.
        public void PushScriptObject(ScriptObject obj)
                        {
                                if(scopeStackSize >= scopeStack.Length)
                                {
                                        Object[] stack = new Object 
[scopeStackSize + 8];
                                        Array.Copy(scopeStack, 0, stack, 0, 
scopeStackSize);
                                        scopeStack = stack;
                                }
                                scopeStack[scopeStackSize++] = obj;
                                currentScope = obj;
                        }

        // Push an object onto the script object stack, and check for overflow.
        internal void PushScriptObjectChecked(ScriptObject obj)
                        {
                                if(scopeStackSize > 500)
                                {
                                        throw new 
JScriptException(JSError.OutOfStack);
                                }
                                else
                                {
                                        PushScriptObject(obj);
                                }
                        }

        // Pop an object from the script object stack.
        public void PopScriptObject()
                        {
                                // Never pop the global object.
                                if(scopeStackSize > 1)
                                {
                                        --scopeStackSize;
                                        currentScope = 
scopeStack[scopeStackSize - 1];
                                }
                        }

        // Get the object at the top of the script object stack.
        public ScriptObject ScriptObjectStackTop()
                        {
                                return (ScriptObject)currentScope;
                        }

        // Get the current size of the script object stack.
        internal int ScriptObjectStackSize()
                        {
                                return scopeStackSize;
                        }

        // Reset the script object stack to a particular size.
        internal void ScriptObjectStackSetSize(int size)
                        {
                                if(size < scopeStackSize)
                                {
                                        scopeStackSize = size;
                                }
                        }

        // Reset the engine.
        public override void Reset()
                        {
                                // Let the base class do the work.
                                base.Reset();
                        }

        // Debugger entry point: restart the engine for another expression.
        public virtual void Restart()
                        {
                                // Nothing to do here - debugging not yet 
supported.
                        }

}; // class VsaEngine

}; // namespace Microsoft.JScript.Vsa

--- NEW FILE ---
/*
 * VsaItem.cs - script item for an engine.
 *
 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace Microsoft.JScript
{

using System;
using Microsoft.JScript.Vsa;
using Microsoft.Vsa;

public abstract class VsaItem : IVsaItem
{
        // Internal state.
        internal VsaEngine engine;
        internal String codebaseOption;
        protected bool isDirty;
        protected VsaItemType type;
        protected String name;
        protected VsaItemFlag flag;

        // Constructor.
        internal VsaItem(VsaEngine engine, String name, VsaItemType type,
                                         VsaItemFlag flag)
                        {
                                this.engine = engine;
                                this.codebaseOption = null;
                                this.isDirty = false;
                                this.type = type;
                                this.name = name;
                                this.flag = flag;
                        }

        // Check this object to see if the engine is closed.
        internal void CheckForClosed()
                        {
                                if(engine == null)
                                {
                                        throw new 
VsaException(VsaError.EngineClosed);
                                }
                        }

        // Validate an item name.
        internal static void ValidateName(VsaEngine engine, String name)
                        {
                                // Validate the name with the engine.
                                if(!engine.IsValidIdentifier(name))
                                {
                                        throw new 
VsaException(VsaError.ItemNameInvalid);
                                }

                                // Make sure that there are no items with this 
name.
                                foreach(VsaItem item in engine.Items)
                                {
                                        if(item.Name == name)
                                        {
                                                throw new 
VsaException(VsaError.ItemNameInUse);
                                        }
                                }
                        }

        // Implement the "IVsaItem" interface;
        public virtual bool IsDirty
                        {
                                get
                                {
                                        CheckForClosed();
                                        return isDirty;
                                }
                                set
                                {
                                        CheckForClosed();
                                        isDirty = value;
                                }
                        }
        public VsaItemType ItemType
                        {
                                get
                                {
                                        CheckForClosed();
                                        return type;
                                }
                        }
        public virtual String Name
                        {
                                get
                                {
                                        CheckForClosed();
                                        return name;
                                }
                                set
                                {
                                        CheckForClosed();
                                        if(name != value)
                                        {
                                                ValidateName(engine, name);
                                        }
                                        name = value;
                                        isDirty = true;
                                        engine.IsDirty = true;
                                }
                        }
        public virtual Object GetOption(String name)
                        {
                                CheckForClosed();
                                if(String.Compare(name, "codebase", true) == 0)
                                {
                                        return codebaseOption;
                                }
                                else
                                {
                                        throw new 
VsaException(VsaError.OptionNotSupported);
                                }
                        }
        public virtual void SetOption(String name, Object value)
                        {
                                CheckForClosed();
                                if(String.Compare(name, "codebase", true) == 0)
                                {
                                        codebaseOption = (String)value;
                                        isDirty = true;
                                        engine.IsDirty = true;
                                }
                                else
                                {
                                        throw new 
VsaException(VsaError.OptionNotSupported);
                                }
                        }

        // Close this item.
        internal virtual void Close()
                        {
                                engine = null;
                        }

        // Notify this item that it is being removed from the item list.
        internal virtual void RemovingItem()
                        {
                                Close();
                        }

        // Reset the compiled state of this item.
        internal virtual void Reset()
                        {
                                // Nothing to do here.
                        }

        // Compile this item.
        internal virtual bool Compile()
                        {
                                // Nothing to do here.
                                return true;
                        }

        // Run this item.
        internal virtual void Run()
                        {
                                // Nothing to do here.
                        }

}; // class VsaItem

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * VsaItems.cs - script item list for an engine.
 *
 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace Microsoft.JScript
{

using System;
using System.Collections;
using Microsoft.JScript.Vsa;
using Microsoft.Vsa;

public class VsaItems : IVsaItems
{
        // Internal state.
        private VsaEngine engine;
        private bool isClosed;
        private ArrayList itemList;

        // Constructor.
        public VsaItems(VsaEngine engine)
                        {
                                this.engine = engine;
                                this.isClosed = false;
                                this.itemList = new ArrayList();
                        }

        // Check this object to see if the engine is closed.
        private void CheckForClosed()
                        {
                                if(isClosed)
                                {
                                        throw new 
VsaException(VsaError.EngineClosed);
                                }
                        }

        // Implement the "IVsaItems" interface.
        public virtual int Count
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                CheckForClosed();
                                                return itemList.Count;
                                        }
                                }
                        }
        public IVsaItem this[int index]
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                CheckForClosed();
                                                if(index >= 0 && index < 
itemList.Count)
                                                {
                                                        return 
(IVsaItem)(itemList[index]);
                                                }
                                                else
                                                {
                                                        throw new 
VsaException(VsaError.ItemNotFound);
                                                }
                                        }
                                }
                        }
        public IVsaItem this[String name]
                        {
                                get
                                {
                                        lock(this)
                                        {
                                                CheckForClosed();
                                                if(name != null)
                                                {
                                                        foreach(IVsaItem item 
in itemList)
                                                        {
                                                                if(item.Name == 
name)
                                                                {
                                                                        return 
item;
                                                                }
                                                        }
                                                }
                                                throw new 
VsaException(VsaError.ItemNotFound);
                                        }
                                }
                        }
        public virtual IVsaItem CreateItem
                                (String name, VsaItemType itemType, VsaItemFlag 
itemFlag)
                        {
                                lock(this)
                                {
                                        CheckForClosed();
                                        if(engine.IsRunning)
                                        {
                                                throw new 
VsaException(VsaError.EngineRunning);
                                        }
                                        if(itemType != VsaItemType.Code)
                                        {
                                                // We only support code items 
in this implementation.
                                                throw new 
VsaException(VsaError.ItemTypeNotSupported);
                                        }
                                        if(itemFlag == VsaItemFlag.Class)
                                        {
                                                // We don't support class flags.
                                                throw new 
VsaException(VsaError.ItemFlagNotSupported);
                                        }
                                        VsaItem.ValidateName(engine, name);
                                        VsaItem item = new VsaCodeItem(engine, 
name, itemFlag);
                                        itemList.Add(item);
                                        return item;
                                }
                        }
        public virtual void Remove(int index)
                        {
                                lock(this)
                                {
                                        CheckForClosed();
                                        if(index >= 0 && index < itemList.Count)
                                        {
                                                VsaItem item = 
(VsaItem)(itemList[index]);
                                                item.RemovingItem();
                                                itemList.RemoveAt(index);
                                                engine.IsDirty = true;
                                        }
                                        else
                                        {
                                                throw new 
VsaException(VsaError.ItemNotFound);
                                        }
                                }
                        }
        public virtual void Remove(String name)
                        {
                                lock(this)
                                {
                                        CheckForClosed();
                                        if(name == null)
                                        {
                                                throw new 
ArgumentNullException("name");
                                        }
                                        foreach(VsaItem item in itemList)
                                        {
                                                if(item.Name == name)
                                                {
                                                        item.RemovingItem();
                                                        itemList.Remove(item);
                                                        engine.IsDirty = true;
                                                }
                                        }
                                        throw new 
VsaException(VsaError.ItemNotFound);
                                }
                        }

        // Implement the "IEnumerable" interface.
        public virtual IEnumerator GetEnumerator()
                        {
                                lock(this)
                                {
                                        CheckForClosed();
                                        return itemList.GetEnumerator();
                                }
                        }

        // Close this item list.
        public virtual void Close()
                        {
                                lock(this)
                                {
                                        CheckForClosed();
                                        foreach(VsaItem item in itemList)
                                        {
                                                item.Close();
                                        }
                                        isClosed = true;
                                        itemList = null;
                                        engine = null;
                                }
                        }

        // Reset the compiled state of all of the items.
        internal void Reset()
                        {
                                lock(this)
                                {
                                        CheckForClosed();
                                        foreach(VsaItem item in itemList)
                                        {
                                                item.Reset();
                                        }
                                }
                        }

        // Compile all items.
        internal bool Compile()
                        {
                                lock(this)
                                {
                                        CheckForClosed();
                                        foreach(VsaItem item in itemList)
                                        {
                                                if(!item.Compile())
                                                {
                                                        return false;
                                                }
                                        }
                                        return true;
                                }
                        }

        // Run all items.
        internal void Run()
                        {
                                lock(this)
                                {
                                        CheckForClosed();
                                        foreach(VsaItem item in itemList)
                                        {
                                                item.Run();
                                        }
                                }
                        }

}; // class VsaItems

}; // namespace Microsoft.JScript





reply via email to

[Prev in Thread] Current Thread [Next in Thread]