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/Execute ActivationObject.cs,


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/JScript/Execute ActivationObject.cs,NONE,1.1 BlockScope.cs,NONE,1.1 BreakJumpOut.cs,NONE,1.1 ContinueJumpOut.cs,NONE,1.1 Convert.cs,NONE,1.1 DBNull.cs,NONE,1.1 Empty.cs,NONE,1.1 EngineInstance.cs,NONE,1.1 GlobalField.cs,NONE,1.1 GlobalScope.cs,NONE,1.1 Hide.cs,NONE,1.1 IActivationObject.cs,NONE,1.1 IVariableAccess.cs,NONE,1.1 IWrappedMember.cs,NONE,1.1 JSField.cs,NONE,1.1 JSObject.cs,NONE,1.1 JSPrototypeObject.cs,NONE,1.1 JSVariableField.cs,NONE,1.1 JumpOut.cs,NONE,1.1 Makefile,NONE,1.1 Missing.cs,NONE,1.1 NotRecommended.cs,NONE,1.1 Override.cs,NONE,1.1 PropertyAttributes.cs,NONE,1.1 ReturnJumpOut.cs,NONE,1.1 ScriptFunction.cs,NONE,1.1 ScriptObject.cs,NONE,1.1 SimpleHashtable.cs,NONE,1.1 Support.cs,NONE,1.1WithScope.cs,NONE,1.1
Date: Mon, 13 Jan 2003 05:53:22 -0500

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

Added Files:
        ActivationObject.cs BlockScope.cs BreakJumpOut.cs 
        ContinueJumpOut.cs Convert.cs DBNull.cs Empty.cs 
        EngineInstance.cs GlobalField.cs GlobalScope.cs Hide.cs 
        IActivationObject.cs IVariableAccess.cs IWrappedMember.cs 
        JSField.cs JSObject.cs JSPrototypeObject.cs JSVariableField.cs 
        JumpOut.cs Makefile Missing.cs NotRecommended.cs Override.cs 
        PropertyAttributes.cs ReturnJumpOut.cs ScriptFunction.cs 
        ScriptObject.cs SimpleHashtable.cs Support.cs WithScope.cs 
Log Message:


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


--- NEW FILE ---
/*
 * ActivationObject.cs - Structure of an activation object.
 *
 * 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 System.Reflection;

public abstract class ActivationObject : ScriptObject, IActivationObject,
                                                                                
 IVariableAccess
{
        // Internal state.
        private ScriptObject storage;

        // Constructor.
        internal ActivationObject(ScriptObject parent, ScriptObject storage)
                        : base(parent)
                        {
                                this.storage = storage;
                        }

        // Implement the IActivationObject interface.
        public virtual Object GetDefaultThisObject()
                        {
                                return 
((IActivationObject)parent).GetDefaultThisObject();
                        }
        public virtual GlobalScope GetGlobalScope()
                        {
                                return 
((IActivationObject)parent).GetGlobalScope();
                        }
        public virtual FieldInfo GetLocalField(String name)
                        {
                                return storage.GetField(name, 
BindingFlags.Instance |
                                                                                
          BindingFlags.Static |
                                                                                
          BindingFlags.Public |
                                                                                
          BindingFlags.DeclaredOnly);
                        }
        public virtual Object GetMemberValue(String name, int lexlevel)
                        {
                                if(lexlevel > 0)
                                {
                                        if(storage.HasOwnProperty(name))
                                        {
                                                return 
storage.GetProperty(name);
                                        }
                                        else if(parent != null)
                                        {
                                                return 
((IActivationObject)parent).GetMemberValue
                                                                        (name, 
lexlevel - 1);
                                        }
                                }
                                return Missing.Value;
                        }
        public virtual FieldInfo GetField(String name, int lexlevel)
                        {
                                throw new 
JScriptException(JSError.InternalError);
                        }

        // Create a new field within this activation object.
        protected virtual JSVariableField CreateField
                                (String name, Object value, FieldAttributes 
attributes)
                        {
                                // TODO
                                return null;
                        }

        // Get a specific member.
        public override MemberInfo GetMember(String name, BindingFlags 
bindingAttr)
                        {
                                // TODO
                                return null;
                        }

        // Get all members that match specific binding conditions.
        public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
                        {
                                // TODO
                                return null;
                        }

        // Implement the internal "IVariableAccess" interface.
        bool IVariableAccess.HasVariable(String name)
                        {
                                return storage.HasOwnProperty(name);
                        }
        Object IVariableAccess.GetVariable(String name)
                        {
                                if(storage.HasOwnProperty(name))
                                {
                                        return storage.GetProperty(name);
                                }
                                else
                                {
                                        storage.SetProperty(name, null, 
PropertyAttributes.None);
                                        return null;
                                }
                        }
        void IVariableAccess.SetVariable(String name, Object value)
                        {
                                storage.SetProperty(name, value, 
PropertyAttributes.None);
                        }

}; // class ActivationObject

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * BlockScope.cs - Structure of an activation object for a simple block.
 *
 * 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 System.Reflection;

public class BlockScope : ActivationObject
{
        // Constructor.
        internal BlockScope(ScriptObject parent, ScriptObject storage)
                        : base(parent, storage)
                        {
                                // Nothing to do here.
                        }

        // Create a new field within this scope.
        protected override JSVariableField CreateField
                                (String name, Object value, FieldAttributes 
attributes)
                        {
                                // TODO
                                return null;
                        }

}; // class BlockScope

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * BreakJumpOut.cs - Exception that is used to implement "break".
 *
 * 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;

// Jump-out that resulted from a "break".
internal sealed class BreakJumpOut : JumpOut
{
        // Constructor.
        public BreakJumpOut(String label, Context context)
                        : base(label, null, context) {}

}; // class BreakJumpOut

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * ContinueJumpOut.cs - Exception that is used to implement "continue".
 *
 * 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;

// Jump-out that resulted from a "continue".
internal sealed class ContinueJumpOut : JumpOut
{
        // Constructor.
        public ContinueJumpOut(String label, Context context)
                        : base(label, null, context) {}

}; // class ContinueJumpOut

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * Convert.cs - Convert between various script types.
 *
 * 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.Globalization;
using Microsoft.JScript.Vsa;

public sealed class Convert
{

        // Check to see if a floating-point value is actually an integer.
        public static double CheckIfDoubleIsInteger(double d)
                        {
                                if(d == Math.Round(d))
                                {
                                        return d;
                                }
                                else
                                {
                                        throw new 
JScriptException(JSError.TypeMismatch);
                                }
                        }
        public static float CheckIfSingleIsInteger(float s)
                        {
                                if(s == Math.Round(s))
                                {
                                        return s;
                                }
                                else
                                {
                                        throw new 
JScriptException(JSError.TypeMismatch);
                                }
                        }

        // Coerce a value to a new type, throwing an exception if not possible.
        public static Object Coerce(Object value, Object type)
                        {
                                // TODO
                                return value;
                        }

        // Coerce to an explicit type.
        public static Object CoerceT(Object value, Type t, bool explicitOK)
                        {
                                // TODO
                                return value;
                        }

        // Coerce to a type that is specified using a type code.
        public static Object Coerce2(Object value, TypeCode target,
                                                                 bool 
truncationPermitted)
                        {
                                // TODO
                                return value;
                        }

        // Determine if an abstract syntax tree is a bad index.
        // Not used - for backwards-compatibility only.
        public static bool IsBadIndex(AST ast)
                        {
                                throw new NotImplementedException();
                        }

        // Throw a type mismatch exception.
        public static void ThrowTypeMismatch(Object val)
                        {
                                throw new JScriptException(JSError.TypeMismatch,
                                                                                
   new Context(val.ToString()));
                        }

        // Extract values of various types from an object that is known
        // to have a specific type code.
        internal static bool ExtractBoolean(Object value)
                        {
                        #if ECMA_COMPAT
                                return (bool)value;
                        #else
                                return ((IConvertible)value).ToBoolean(null);
                        #endif
                        }
        internal static char ExtractChar(Object value)
                        {
                        #if ECMA_COMPAT
                                return (char)value;
                        #else
                                return ((IConvertible)value).ToChar(null);
                        #endif
                        }
        internal static int ExtractInt32Smaller(Object value)
                        {
                        #if ECMA_COMPAT
                                if(value is SByte)
                                {
                                        return (int)(sbyte)value;
                                }
                                else if(value is Byte)
                                {
                                        return (int)(byte)value;
                                }
                                else if(value is Int16)
                                {
                                        return (int)(short)value;
                                }
                                else if(value is UInt16)
                                {
                                        return (int)(ushort)value;
                                }
                                else
                                {
                                        return (int)(char)value;
                                }
                        #else
                                return ((IConvertible)value).ToInt32(null);
                        #endif
                        }
        internal static int ExtractInt32(Object value)
                        {
                        #if ECMA_COMPAT
                                return (int)value;
                        #else
                                return ((IConvertible)value).ToInt32(null);
                        #endif
                        }
        internal static long ExtractInt64(Object value)
                        {
                        #if ECMA_COMPAT
                                if(value is long)
                                {
                                        return (long)value;
                                }
                                else
                                {
                                        return (long)(uint)value;
                                }
                        #else
                                return ((IConvertible)value).ToInt64(null);
                        #endif
                        }
        internal static ulong ExtractUInt64(Object value)
                        {
                        #if ECMA_COMPAT
                                return (ulong)value;
                        #else
                                return ((IConvertible)value).ToUInt64(null);
                        #endif
                        }
        internal static double ExtractDouble(Object value)
                        {
                        #if ECMA_COMPAT
                                if(value is Double)
                                {
                                        return (double)value;
                                }
                                else
                                {
                                        return (double)(float)value;
                                }
                        #else
                                return ((IConvertible)value).ToDouble(null);
                        #endif
                        }
        internal static Decimal ExtractDecimal(Object value)
                        {
                        #if ECMA_COMPAT
                                return (Decimal)value;
                        #else
                                return ((IConvertible)value).ToDecimal(null);
                        #endif
                        }
        internal static String ExtractString(Object value)
                        {
                        #if ECMA_COMPAT
                                return (String)value;
                        #else
                                return ((IConvertible)value).ToString(null);
                        #endif
                        }
        internal static DateTime ExtractDateTime(Object value)
                        {
                        #if ECMA_COMPAT
                                return (DateTime)value;
                        #else
                                return ((IConvertible)value).ToDateTime(null);
                        #endif
                        }

        // Convert a value to boolean.
        public static bool ToBoolean(Object value)
                        {
                                if(value is Boolean)
                                {
                                        return (bool)value;
                                }
                                switch(Support.TypeCodeForObject(value))
                                {
                                        case TypeCode.Empty:
                                        case TypeCode.DBNull:           return 
false;

                                        case TypeCode.Object:
                                        {
                                                if(value is Missing ||
                                                   value is 
System.Reflection.Missing)
                                                {
                                                        return false;
                                                }
                                                // TODO: look for "op_True" and 
use that if present
                                                return true;
                                        }
                                        // Not reached.

                                        case TypeCode.Boolean:
                                                return ExtractBoolean(value);
                                        case TypeCode.Char:
                                                return (ExtractChar(value) != 
'\0');

                                        case TypeCode.SByte:
                                        case TypeCode.Byte:
                                        case TypeCode.Int16:
                                        case TypeCode.UInt16:
                                                return 
(ExtractInt32Smaller(value) != 0);

                                        case TypeCode.Int32:
                                                return (ExtractInt32(value) != 
0);

                                        case TypeCode.UInt32:
                                        case TypeCode.Int64:
                                                return (ExtractInt64(value) != 
(long)0);

                                        case TypeCode.UInt64:
                                                return (ExtractUInt64(value) != 
(ulong)0);

                                        case TypeCode.Single:
                                        case TypeCode.Double:
                                        {
                                                double dvalue = 
ExtractDouble(value);
                                                if(Double.IsNaN(dvalue) || 
dvalue == 0.0)
                                                {
                                                        return false;
                                                }
                                                else
                                                {
                                                        return true;
                                                }
                                        }
                                        // Not reached.

                                        case TypeCode.Decimal:
                                                return (ExtractDecimal(value) 
!= 0.0m);

                                        case TypeCode.DateTime: return true;

                                        case TypeCode.String:
                                                return 
(ExtractString(value).Length != 0);

                                        default: return true;
                                }
                        }
        public static bool ToBoolean(Object value, bool explicitConversion)
                        {
                        #if false
                                if(!explicitConversion && value is 
BooleanObject)
                                {
                                        return ((BooleanObject)value).value;
                                }
                        #endif
                                return ToBoolean(value);
                        }

        // Convert a value into an object suitable for "for ... in".
        public static Object ToForInObject(Object value, VsaEngine engine)
                        {
                                // TODO
                                return value;
                        }

        // Normalize a value, to remove JScript object wrappers.
        private static Object Normalize(Object value)
                        {
                                if(value is ScriptObject)
                                {
                                        return 
((ScriptObject)value).Normalize();
                                }
                                else if(value is DateTime)
                                {
                                        return ((DateTime)value).ToString();
                                }
                                else
                                {
                                        return value;
                                }
                        }

        // Convert a value into an int32 value.
        public static int ToInt32(Object value)
                        {
                                Object nvalue;
                                if(value is Int32)
                                {
                                        return (int)value;
                                }
                                else if(value is Double)
                                {
                                        return (int)(double)value;
                                }
                                switch(Support.TypeCodeForObject(value))
                                {
                                        case TypeCode.Empty:
                                        case TypeCode.DBNull:           return 
0;

                                        case TypeCode.Object:
                                        {
                                                nvalue = Normalize(value);
                                                if(nvalue != value)
                                                {
                                                        return ToInt32(nvalue);
                                                }
                                                else
                                                {
                                                        return 0;
                                                }
                                        }
                                        // Not reached.

                                        case TypeCode.Boolean:
                                                return (ExtractBoolean(value) ? 
1 : 0);

                                        case TypeCode.SByte:
                                        case TypeCode.Byte:
                                        case TypeCode.Int16:
                                        case TypeCode.UInt16:
                                        case TypeCode.Char:
                                                return 
ExtractInt32Smaller(value);

                                        case TypeCode.Int32:
                                                return ExtractInt32(value);

                                        case TypeCode.UInt32:
                                        case TypeCode.Int64:
                                                return 
(int)(ExtractInt64(value));

                                        case TypeCode.UInt64:
                                                return 
(int)(ExtractUInt64(value));

                                        case TypeCode.Single:
                                        case TypeCode.Double:
                                                return 
(int)(ExtractDouble(value));

                                        case TypeCode.Decimal:
                                                return 
(int)(double)(ExtractDecimal(value));

                                        case TypeCode.DateTime:
                                        {
                                                value = ExtractDateTime(value);
                                                nvalue = Normalize(value);
                                                if(nvalue != value)
                                                {
                                                        return ToInt32(nvalue);
                                                }
                                                else
                                                {
                                                        return 0;
                                                }
                                        }
                                        // Not reached

                                        case TypeCode.String:
                                                return 
(int)(ToNumber(ExtractString(value)));

                                        default: return 0;
                                }
                        }

        // Convert a value into a UInt32 value.
        internal static uint ToUInt32(Object value)
                        {
                                Object nvalue;
                                if(value is UInt32)
                                {
                                        return (uint)value;
                                }
                                else if(value is Int32)
                                {
                                        return (uint)(int)value;
                                }
                                else if(value is Double)
                                {
                                        return (uint)(double)value;
                                }
                                switch(Support.TypeCodeForObject(value))
                                {
                                        case TypeCode.Empty:
                                        case TypeCode.DBNull:           return 
0;

                                        case TypeCode.Object:
                                        {
                                                nvalue = Normalize(value);
                                                if(nvalue != value)
                                                {
                                                        return ToUInt32(nvalue);
                                                }
                                                else
                                                {
                                                        return 0;
                                                }
                                        }
                                        // Not reached.

                                        case TypeCode.Boolean:
                                                return (ExtractBoolean(value) ? 
(uint)1 : (uint)0);

                                        case TypeCode.SByte:
                                        case TypeCode.Byte:
                                        case TypeCode.Int16:
                                        case TypeCode.UInt16:
                                        case TypeCode.Char:
                                                return 
(uint)(ExtractInt32Smaller(value));

                                        case TypeCode.Int32:
                                                return 
(uint)(ExtractInt32(value));

                                        case TypeCode.UInt32:
                                        case TypeCode.Int64:
                                                return 
(uint)(ExtractInt64(value));

                                        case TypeCode.UInt64:
                                                return 
(uint)(ExtractUInt64(value));

                                        case TypeCode.Single:
                                        case TypeCode.Double:
                                                return 
(uint)(ExtractDouble(value));

                                        case TypeCode.Decimal:
                                                return 
(uint)(double)(ExtractDecimal(value));

                                        case TypeCode.DateTime:
                                        {
                                                value = ExtractDateTime(value);
                                                nvalue = Normalize(value);
                                                if(nvalue != value)
                                                {
                                                        return ToUInt32(nvalue);
                                                }
                                                else
                                                {
                                                        return 0;
                                                }
                                        }
                                        // Not reached.

                                        case TypeCode.String:
                                                return 
(uint)(ToNumber(ExtractString(value)));

                                        default: return 0;
                                }
                        }

        // Convert a JScript array object into a native array.
        public static Object ToNativeArray(Object value, RuntimeTypeHandle 
handle)
                        {
                                // TODO
                                return value;
                        }

        // Convert a value into a number.
        public static double ToNumber(Object value)
                        {
                                Object nvalue;
                                if(value is Double)
                                {
                                        return (double)value;
                                }
                                else if(value is Int32)
                                {
                                        return (double)(int)value;
                                }
                                switch(Support.TypeCodeForObject(value))
                                {
                                        case TypeCode.Empty:            return 
Double.NaN;
                                        case TypeCode.DBNull:           return 
0.0;

                                        case TypeCode.Object:
                                        {
                                                nvalue = Normalize(value);
                                                if(nvalue != value)
                                                {
                                                        return ToNumber(nvalue);
                                                }
                                                else
                                                {
                                                        return Double.NaN;
                                                }
                                        }
                                        // Not reached.

                                        case TypeCode.Boolean:
                                                return (ExtractBoolean(value) ? 
1.0 : 0.0);

                                        case TypeCode.SByte:
                                        case TypeCode.Byte:
                                        case TypeCode.Int16:
                                        case TypeCode.UInt16:
                                        case TypeCode.Char:
                                                return 
(double)(ExtractInt32Smaller(value));

                                        case TypeCode.Int32:
                                                return 
(double)(ExtractInt32(value));

                                        case TypeCode.UInt32:
                                        case TypeCode.Int64:
                                                return 
(double)(ExtractInt64(value));

                                        case TypeCode.UInt64:
                                                return 
(double)(ExtractUInt64(value));

                                        case TypeCode.Single:
                                        case TypeCode.Double:
                                                return ExtractDouble(value);

                                        case TypeCode.Decimal:
                                                return 
(double)(ExtractDecimal(value));

                                        case TypeCode.DateTime:
                                        {
                                                value = ExtractDateTime(value);
                                                nvalue = Normalize(value);
                                                if(nvalue != value)
                                                {
                                                        return ToNumber(nvalue);
                                                }
                                                else
                                                {
                                                        return Double.NaN;
                                                }
                                        }
                                        // Not reached

                                        case TypeCode.String:
                                                return 
ToNumber(ExtractString(value));

                                        default: return 0.0;
                                }
                        }
        public static double ToNumber(String value)
                        {
                                // TODO
                                return 0;
                        }

        // Convert a value into a JScript object, throwing an exception
        // if the conversion is not possible.
        public static Object ToObject(Object value, VsaEngine engine)
                        {
                                // TODO
                                return value;
                        }

        // Convert a value into a JScript object, returning "null"
        // if the conversion is not possible.
        public static Object ToObject2(Object value, VsaEngine engine)
                        {
                                // TODO
                                return value;
                        }

        // Convert an object into a string.
        public static String ToString(Object value, bool explicitOK)
                        {
                                // TODO
                                return value.ToString();
                        }
        internal static String ToString(Object value)
                        {
                                return ToString(value, true);
                        }

        // Convert primitive values into strings.
        public static String ToString(bool b)
                        {
                                return (b ? "true" : "false");
                        }
        public static String ToString(double d)
                        {
                                long longValue = (long)d;
                                if(d == (double)longValue)
                                {
                                        return longValue.ToString();
                                }
                                else if(Double.IsNaN(d))
                                {
                                        return "NaN";
                                }
                                else if(Double.IsPositiveInfinity(d))
                                {
                                        return "Infinity";
                                }
                                else if(Double.IsNegativeInfinity(d))
                                {
                                        return "-Infinity";
                                }
                                else
                                {
                                        return d.ToString("e", 
CultureInfo.InvariantCulture);
                                }
                        }

}; // class Convert

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * DBNull.cs - Replacement for "System.DBNull" on ECMA systems.
 *
 * 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;

// This is a non-standard JScript class, but is needed to work around
// the missing "System.DBNull" class in ECMA-compatibility modes.

public sealed class DBNull
{
        // The only DBNull object in the system.
#if ECMA_COMPAT
        public readonly static DBNull Value = new DBNull();
#else
        public readonly static System.DBNull Value = System.DBNull.Value;
#endif

        // Constructors.
        private DBNull() {}

        // Override inherited methods.
        public override String ToString() { return String.Empty; }

}; // class DBNull

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * Empty.cs - Representation of the empty value.
 *
 * 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 sealed class Empty
{
        // Public state.
        public static readonly Empty Value = null;

        // Constructor.
        private Empty() {}

}; // class Empty

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * EngineInstance.cs - Information that is specific to an engine instance.
 *
 * 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 Microsoft.JScript.Vsa;

// This class exists to support multiple engine instances within a
// single application process.  It keeps track of objects that would
// otherwise be global, and hence a re-entrancy problem.

internal sealed class EngineInstance
{
        // Internal state.
        private VsaEngine engine;
        private ObjectPrototype objectPrototype;
        private ObjectConstructor objectConstructor;
        private FunctionPrototype functionPrototype;
        private FunctionConstructor functionConstructor;
        private ArrayPrototype arrayPrototype;
        private ArrayConstructor arrayConstructor;
        private TextWriter outStream;
        private TextWriter errorStream;

        // Constructor.
        public EngineInstance(VsaEngine engine)
                        {
                                // Initialize the local state.
                                this.engine = engine;
                                this.outStream = null;
                                this.errorStream = null;
                        }
        
        // Initialize the engine instance after construction.  Needed
        // to resolve circularity issues at startup time.
        public void Init()
                        {
                                // Initialize the basic "Object" and "Function" 
objects,
                                // which must be created carefully to avoid 
circularities.
                                objectPrototype = new LenientObjectPrototype();
                                functionPrototype = new 
LenientFunctionPrototype();
                                objectConstructor = new ObjectConstructor();
                                functionConstructor = new FunctionConstructor();
                                objectPrototype.Init(engine);
                                functionPrototype.Init(engine, objectPrototype);
                                objectConstructor.Init(engine, 
functionPrototype);
                                functionConstructor.Init(engine, 
functionPrototype);
                        }
        
        // Get the default engine instance.
        public static EngineInstance Default
                        {
                                get
                                {
                                        return 
Globals.GetContextEngine().engineInstance;
                                }
                        }

        // Get the engine instance for a specific engine.
        public static EngineInstance GetEngineInstance(VsaEngine engine)
                        {
                                return engine.engineInstance;
                        }

        // Get standard prototypes and constructors.
        public ObjectPrototype GetObjectPrototype()
                        {
                                return objectPrototype;
                        }
        public ObjectConstructor GetObjectConstructor()
                        {
                                return objectConstructor;
                        }
        public FunctionPrototype GetFunctionPrototype()
                        {
                                return functionPrototype;
                        }
        public FunctionConstructor GetFunctionConstructor()
                        {
                                return functionConstructor;
                        }
        public ArrayPrototype GetArrayPrototype()
                        {
                                lock(this)
                                {
                                        if(arrayPrototype == null)
                                        {
                                                arrayPrototype = new 
LenientArrayPrototype
                                                                
(GetObjectPrototype(), this);
                                        }
                                        return arrayPrototype;
                                }
                        }
        public ArrayConstructor GetArrayConstructor()
                        {
                                lock(this)
                                {
                                        if(arrayConstructor == null)
                                        {
                                                arrayConstructor = new 
ArrayConstructor
                                                                
(GetFunctionPrototype());
                                        }
                                        return arrayConstructor;
                                }
                        }

        // Get the output streams for this engine instance.
        public TextWriter Out
                        {
                                get
                                {
                                        if(outStream != null)
                                        {
                                                return outStream;
                                        }
                                        else
                                        {
                                                return ScriptStream.Out;
                                        }
                                }
                        }
        public TextWriter Error
                        {
                                get
                                {
                                        if(errorStream != null)
                                        {
                                                return errorStream;
                                        }
                                        else
                                        {
                                                return ScriptStream.Error;
                                        }
                                }
                        }

        // Set the output stream for this engine instance.
        public void SetOutputStreams(TextWriter output, TextWriter error)
                        {
                                outStream = output;
                                errorStream = error;
                        }

        // Detach the output streams from the global state.
        public void DetachOutputStreams()
                        {
                                if(outStream == null)
                                {
                                        outStream = Console.Out;
                                }
                                if(errorStream == null)
                                {
                                        errorStream = Console.Error;
                                }
                        }

}; // class EngineInstance

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * GlobalField.cs - JScript global variable, as a field.
 *
 * 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.Globalization;
using System.Reflection;

internal sealed class GlobalField : JSVariableField
{
        // Constructor.
        public GlobalField(FieldAttributes attributes, String name,
                                           ScriptObject obj, Object value)
                        : this(attributes, name, obj, value)
                        {
                                // Nothing to do here.
                        }

        // Get the value of this field.
        public override Object GetValue(Object obj)
                        {
                                return value;
                        }

        // Set the value of this field.
        public override void SetValue(Object obj, Object value,
                                                                  BindingFlags 
invokeAttr, Binder binder,
                                                                  CultureInfo 
culture)
                        {
                                if((IsLiteral || IsInitOnly) && !(this.value is 
Missing))
                                {
                                        throw new JScriptException
                                                (JSError.AssignmentToReadOnly);
                                }
                                // TODO: typed fields
                                this.value = value;
                        }

}; // class GlobalField

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * GlobalScope.cs - Structure of the global activation object.
 *
 * 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 System.Reflection;
using System.Runtime.InteropServices.Expando;
using Microsoft.JScript.Vsa;

public class GlobalScope : ActivationObject
#if !ECMA_COMPAT
        , IExpando
#endif
{
        // Constructor.
        public GlobalScope(GlobalScope parent, ScriptObject storage)
                        : base(parent, storage)
                        {
                                // Nothing else to do here.
                        }

        // Override methods in the IActivationObject interface.
        public override Object GetDefaultThisObject()
                        {
                                return this;
                        }
        public override GlobalScope GetGlobalScope()
                        {
                                return this;
                        }
        public override FieldInfo GetLocalField(String name)
                        {
                                return GetField(name, BindingFlags.Instance |
                                                                          
BindingFlags.Static |
                                                                          
BindingFlags.Public |
                                                                          
BindingFlags.DeclaredOnly);
                        }
        public override FieldInfo GetField(String name, int lexlevel)
                        {
                                return GetField(name, BindingFlags.Instance |
                                                                          
BindingFlags.Static |
                                                                          
BindingFlags.Public |
                                                                          
BindingFlags.DeclaredOnly);
                        }

        // Override methods in the IReflect interface.
        public override FieldInfo[] GetFields(BindingFlags bindingAttr)
                        {
                                return base.GetFields(bindingAttr | 
BindingFlags.DeclaredOnly);
                        }
        public override MemberInfo[] GetMember
                                (String name, BindingFlags bindingAttr)
                        {
                                // TODO
                                return null;
                        }
        public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
                        {
                                // TODO
                                return null;
                        }
        public override MethodInfo[] GetMethods(BindingFlags bindingAttr)
                        {
                                return base.GetMethods(bindingAttr | 
BindingFlags.DeclaredOnly);
                        }
        public override PropertyInfo[] GetProperties(BindingFlags bindingAttr)
                        {
                                return base.GetProperties
                                        (bindingAttr | 
BindingFlags.DeclaredOnly);
                        }

        // Implement the IExpando interface.
        public FieldInfo AddField(String name)
                        {
                                return CreateField(name, null, 
FieldAttributes.Public);
                        }
#if !ECMA_COMPAT
        MethodInfo IExpando.AddMethod(String name, Delegate method)
                        {
                                // Not used by JScript.
                                return null;
                        }
        PropertyInfo IExpando.AddProperty(String name)
                        {
                                // Not used by JScript.
                                return null;
                        }
        void IExpando.RemoveMember(MemberInfo m)
                        {
                                // TODO
                        }
#endif

}; // class GlobalScope

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * Hide.cs - Mark a method or field as hidden.
 *
 * 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;

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Field)]
public class Hide : Attribute
{
        // Constructor.
        public Hide() {}

}; // class Hide

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * IActivationObject.cs - Activation object information 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
{

using System;
using System.Reflection;

public interface IActivationObject
{
        // Get the default "this" object for this activation.
        Object GetDefaultThisObject();

        // Find the global scope.  Never returns null.
        GlobalScope GetGlobalScope();

        // Look up a local field.
        FieldInfo GetLocalField(String name);

        // Get the value of a specific member in this activation.
        Object GetMemberValue(String name, int lexlevel);

        // Get the field for a specific member in this activation.
        FieldInfo GetField(String name, int lexlevel);

}; // interface IActivationObject

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * IVariableAccess.cs - Short-cut for variable declaration access.
 *
 * 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.Reflection;

internal interface IVariableAccess
{
        // Determine if this scope has a specific variable.
        bool HasVariable(String name);

        // Declare a specific variable in this scope and get its value.
        Object GetVariable(String name);

        // Declare a specific variable in this scope and set its value.
        void SetVariable(String name, Object value);

}; // interface IVariableAccess

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * IWrappedMember.cs - Interface for wrapped reflection member objects.
 *
 * 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 IWrappedMember
{

        // Get the member that is wrapped by this object.
        Object GetWrappedMember();

}; // interface IWrappedMember

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * JSField.cs - Extended information for a JScript field.
 *
 * 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.Reflection;

public abstract class JSField : FieldInfo
{

        // Get the field's attributes.
        public override FieldAttributes Attributes
                        {
                                get
                                {
                                        return (FieldAttributes)0;
                                }
                        }

        // Get the declaring type.
        public override Type DeclaringType
                        {
                                get
                                {
                                        return null;
                                }
                        }

        // Get the handle for the underlying "real" field.
        public override RuntimeFieldHandle FieldHandle
                        {
                                get
                                {
                                        return GetRealField().FieldHandle;
                                }
                        }

        // Get the type of this field's value.
        public override Type FieldType
                        {
                                get
                                {
                                        return typeof(Object);
                                }
                        }

        // Get the member type.
        public override MemberTypes MemberType
                        {
                                get
                                {
                                        return MemberTypes.Field;
                                }
                        }

        // Get the name of this field.
        public override String Name
                        {
                                get
                                {
                                        return String.Empty;
                                }
                        }

        // Get the reflected type.
        public override Type ReflectedType
                        {
                                get
                                {
                                        return DeclaringType;
                                }
                        }

        // Get the custom attributes that are attached to this field.
        public override Object[] GetCustomAttributes(bool inherit)
                        {
                                return new Object[0];
                        }
        public override Object[] GetCustomAttributes(Type type, bool inherit)
                        {
                                return new Object[0];
                        }
        public override bool IsDefined(Type type, bool inherit)
                        {
                                return false;
                        }

        // Get the "real" field that underlies this one.
        internal virtual FieldInfo GetRealField()
                        {
                                throw new 
JScriptException(JSError.InternalError);
                        }

}; // class JSField

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * JSObject.cs - Common base for JScript objects.
 *
 * 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.Reflection;
using System.Collections;
using System.Globalization;
using System.Runtime.InteropServices.Expando;
using Microsoft.JScript.Vsa;

public class JSObject : ScriptObject, IEnumerable
#if !ECMA_COMPAT
        , IExpando
#endif
{
        // Internal state.
        private Property properties;
        private Hashtable overflow;

        // Constructors.
        public JSObject() : this(null) {}
        internal JSObject(ScriptObject parent)
                        : base(parent)
                        {
                                properties = null;
                                overflow = null;
                        }
        internal JSObject(ScriptObject parent, VsaEngine engine)
                        : this(parent)
                        {
                                this.engine = engine;
                        }

        // Implement the IEnumerable interface.
        IEnumerator IEnumerable.GetEnumerator()
                        {
                                return ForIn.JScriptGetEnumerator(this);
                        }

        // Get member information for this object.
        public override MemberInfo GetMember(String name, BindingFlags 
bindingAttr)
                        {
                                // TODO
                                return null;
                        }
        public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
                        {
                                // TODO
                                return null;
                        }

        // Implement the IExpando interface.
        public FieldInfo AddField(String name)
                        {
                                // TODO
                                return null;
                        }
#if !ECMA_COMPAT
        MethodInfo IExpando.AddMethod(String name, Delegate method)
                        {
                                // Not used by JScript.
                                return null;
                        }
        PropertyInfo IExpando.AddProperty(String name)
                        {
                                // Not used by JScript.
                                return null;
                        }
        void IExpando.RemoveMember(MemberInfo m)
                        {
                                // TODO
                        }
#endif

        // Set the value of a field member.
        public void SetMemberValue2(String name, Object value)
                        {
                                // TODO
                        }

        // Convert this object into a string.
        public override String ToString()
                        {
                                // Find the "toString" method on the object or 
its prototype.
                                JSObject temp = this;
                                ScriptFunction toStr;
                                do
                                {
                                        toStr = (temp.GetProperty("toString") 
as ScriptFunction);
                                        if(toStr != null)
                                        {
                                                // Invoke the "toString" method.
                                                return 
(toStr.Invoke(this)).ToString();
                                        }
                                        temp = (temp.GetParent() as JSObject);
                                }
                                while(temp != null);
                                return String.Empty;
                        }

        // Get the internal "[[Class]]" property for this object.
        internal virtual String ClassName
                        {
                                get
                                {
                                        return "Object";
                                }
                        }

        // Get a property from this object.  Null if not present.
        internal override Object GetProperty(String name)
                        {
                                Property prop;

                                // Check the overflow hash table first, if it 
exists.
                                if(overflow != null)
                                {
                                        prop = (Property)(overflow[name]);
                                        if(prop != null)
                                        {
                                                return prop.value;
                                        }
                                        else
                                        {
                                                return null;
                                        }
                                }

                                // Scan the property list.
                                prop = properties;
                                while(prop != null)
                                {
                                        if(prop.name == name)
                                        {
                                                return prop.value;
                                        }
                                        prop = prop.next;
                                }

                                // Could not find the property.
                                return null;
                        }

        // Determine if a property is enumerable.
        internal bool IsEnumerable(String name)
                        {
                                Property prop;

                                // Check the overflow hash table first, if it 
exists.
                                if(overflow != null)
                                {
                                        prop = (Property)(overflow[name]);
                                        if(prop != null)
                                        {
                                                return (prop.attrs & 
PropertyAttributes.DontEnum) == 0;
                                        }
                                        else
                                        {
                                                return false;
                                        }
                                }

                                // Scan the property list.
                                prop = properties;
                                while(prop != null)
                                {
                                        if(prop.name == name)
                                        {
                                                return (prop.attrs & 
PropertyAttributes.DontEnum) == 0;
                                        }
                                        prop = prop.next;
                                }

                                // Could not find the property.
                                return false;
                        }

        // Determine if this object has a specific property.
        internal override bool HasOwnProperty(String name)
                        {
                                Property prop;

                                // Check the overflow hash table first, if it 
exists.
                                if(overflow != null)
                                {
                                        prop = (Property)(overflow[name]);
                                        return (prop != null);
                                }

                                // Scan the property list.
                                prop = properties;
                                while(prop != null)
                                {
                                        if(prop.name == name)
                                        {
                                                return true;
                                        }
                                        prop = prop.next;
                                }

                                // Could not find the property.
                                return false;
                        }

        // Set a property in this object.
        internal override void SetProperty(String name, Object value,
                                                                           
PropertyAttributes attrs)
                        {
                                Property prop, prev;
                                int num;

                                // Normalize null values.
                                if(value == null)
                                {
                                        value = DBNull.Value;
                                }

                                // Check the overflow hash table first, if it 
exists.
                                if(overflow != null)
                                {
                                        prop = (Property)(overflow[name]);
                                        if(prop == null)
                                        {
                                                overflow[name] = new 
Property(name, value, attrs);
                                        }
                                        else if((prop.attrs & 
PropertyAttributes.ReadOnly) == 0)
                                        {
                                                prop.value = value;
                                        }
                                        return;
                                }

                                // Scan for a property with the given name.
                                prop = properties;
                                prev = null;
                                num = 0;
                                while(prop != null)
                                {
                                        if(prop.name == name)
                                        {
                                                if((prop.attrs & 
PropertyAttributes.ReadOnly) == 0)
                                                {
                                                        prop.value = value;
                                                }
                                                return;
                                        }
                                        prev = prop;
                                        prop = prop.next;
                                        ++num;
                                }

                                // Add a new property to the list.
                                if(num < 8)
                                {
                                        prop = new Property(name, value, attrs);
                                        if(prev != null)
                                        {
                                                prev.next = prop;
                                        }
                                        else
                                        {
                                                properties = prop;
                                        }
                                        return;
                                }

                                // The list is too big, so switch to a hash 
table.
                                overflow = new Hashtable(32);
                                prop = properties;
                                while(prop != null)
                                {
                                        overflow[prop.name] = prop;
                                        prev = prop;
                                        prop = prop.next;
                                        prev.next = null;
                                }
                                properties = null;
                                overflow[name] = new Property(name, value, 
attrs);
                        }

        // Add a builtin method to a prototype.
        internal void AddBuiltin(EngineInstance inst, String name)
                        {
                                MethodInfo method = GetType().GetMethod(name);
                                SetProperty(name, new BuiltinFunction
                                        (inst.GetFunctionPrototype(), name, 
method),
                                        PropertyAttributes.None);
                        }

        // Storage for a property.
        private class Property
        {
                // Accessible internal state.
                public Property next;
                public String name;
                public Object value;
                public PropertyAttributes attrs;

                // Constructor.
                public Property(String name, Object value, PropertyAttributes 
attrs)
                                {
                                        this.next = null;
                                        this.name = name;
                                        this.value = value;
                                        this.attrs = attrs;
                                }

        }; // class Property

}; // class JSObject

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * JSPrototypeObject.cs - Prototype wrapper objects.
 *
 * 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 JSPrototypeObject : JSObject
{
        // Accessible internal state.
        public Object constructor;

        // Constructor.
        internal JSPrototypeObject(ScriptObject parent, Object constructor)
                        : base(parent)
                        {
                                this.constructor = constructor;
                        }

}; // class JSPrototypeObject

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * JSVariableField.cs - JScript variable, as a field.
 *
 * 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.Reflection;

public abstract class JSVariableField : JSField
{
        // Internal state.
        private FieldAttributes attributes;
        private String name;
        private FieldInfo realField;
        private Object[] customAttributes;
        protected ScriptObject obj;
        protected Object value;

        // Constructor.
        internal JSVariableField(FieldAttributes attributes, String name,
                                                         ScriptObject obj, 
Object value)
                        {
                                if((attributes & 
FieldAttributes.FieldAccessMask) ==
                                                (FieldAttributes)0)
                                {
                                        attributes |= FieldAttributes.Public;
                                }
                                this.attributes = attributes;
                                this.name = name;
                                this.realField = null;
                                this.customAttributes = null;
                                this.obj = obj;
                                this.value = value;
                        }

        // Get the field's attributes.
        public override FieldAttributes Attributes
                        {
                                get
                                {
                                        return attributes;
                                }
                        }

        // Get the declaring type.
        public override Type DeclaringType
                        {
                                get
                                {
                                        // TODO
                                        return null;
                                }
                        }

        // Get the type of this field's value.
        public override Type FieldType
                        {
                                get
                                {
                                        // TODO
                                        return typeof(Object);
                                }
                        }

        // Get the name of this field.
        public override String Name
                        {
                                get
                                {
                                        return name;
                                }
                        }

        // Get the custom attributes that are attached to this field.
        public override Object[] GetCustomAttributes(bool inherit)
                        {
                                if(customAttributes != null)
                                {
                                        return customAttributes;
                                }
                                return new Object[0];
                        }

        // Get the "real" field that underlies this one.
        internal override FieldInfo GetRealField()
                        {
                                return realField;
                        }

}; // class JSVariableField

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * JumpOut.cs - Exception that is used to implement jump-outs.
 *
 * 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;

// Base class for all jump-outs.
internal abstract class JumpOut : Exception
{
        // Accessible internal state.
        public String label;
        public Object value;
        public Context context;

        // Constructor.
        public JumpOut(String label, Object value, Context context)
                        {
                                this.label = label;
                                this.value = value;
                                this.context = context;
                        }

}; // class JumpOut

}; // 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 ---
/*
 * Missing.cs - Representation of the "Missing" value.
 *
 * 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 sealed class Missing
{
        // Public state.
        public static readonly Missing Value = new Missing();

        // Constructor.
        private Missing() {}

}; // class Missing

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * NotRecommended.cs - Mark a construct as not recommended for use.
 *
 * 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;

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Field)]
public class NotRecommended : Attribute
{
        // Internal state.
        private String message;

        // Constructor.
        public NotRecommended(String message)
                        {
                                this.message = message;
                        }

        // Determine if this attribute is an error indication.
        public bool IsError
                        {
                                get
                                {
                                        return false;
                                }
                        }

        // Get the message.
        public String Message
                        {
                                get
                                {
                                        return message;
                                }
                        }

}; // class NotRecommended

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * Override.cs - Mark a method or field as an override.
 *
 * 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;

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Field)]
public class Override : Attribute
{
        // Constructor.
        public Override() {}

}; // class Override

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * PropertyAttributes.cs - Attributes that may be attached to a property.
 *
 * 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;

internal enum PropertyAttributes
{
        None       = 0x00,
        ReadOnly   = 0x01,
        DontEnum   = 0x02,
        DontDelete = 0x04

}; // enum PropertyAttributes

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * ReturnJumpOut.cs - Exception that is used to implement "return".
 *
 * 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;

// Jump-out that resulted from a "return".
internal sealed class ReturnJumpOut : JumpOut
{
        // Constructor.
        public ReturnJumpOut(Object value, Context context)
                        : base(null, value, context) {}

}; // class ReturnJumpOut

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * ScriptFunction.cs - Object that represents a script function.
 *
 * 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.Reflection;
using System.Globalization;

public abstract class ScriptFunction : JSObject
{
        // Internal state.
        private String name;
        internal int lengthValue;
        private Object prototypeValue;

        // Constructors.
        protected ScriptFunction(ScriptObject parent, String name)
                        : base(parent)
                        {
                                this.name = name;
                                this.lengthValue = length;
                                if(parent != null)
                                {
                                        this.prototypeValue =
                                                new 
JSPrototypeObject(parent.GetParent(), this);
                                }
                                else
                                {
                                        this.prototypeValue = Missing.Value;
                                }
                        }
        internal ScriptFunction(ScriptObject parent, String name, int numParams)
                        : base(parent)
                        {
                                this.name = name;
                                this.lengthValue = numParams;
                                if(parent != null)
                                {
                                        this.prototypeValue =
                                                new 
JSPrototypeObject(parent.GetParent(), this);
                                }
                                else
                                {
                                        this.prototypeValue = Missing.Value;
                                }
                        }

        // Initialize the prototype value from a subclass.
        internal void InitPrototype(ScriptObject parent)
                        {
                                this.prototypeValue =
                                        new 
JSPrototypeObject(parent.GetParent(), this);
                        }

        // Create an instance of this function.
        [JSFunction(JSFunctionAttributeEnum.HasVarArgs)]
        public Object CreateInstance(params Object[] args)
                        {
                                return CallConstructor(args);
                        }

        // Get the prototype for a constructed function object.
        protected ScriptObject GetPrototypeForConstructedObject()
                        {
                                return (ScriptObject)prototypeValue;
                        }

        // Invoke this script function.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject |
                                JSFunctionAttributeEnum.HasVarArgs)]
        public Object Invoke(Object thisob, params Object[] args)
                        {
                                return Call(thisob, args);
                        }

        // Invoke a member object.
        public override Object InvokeMember
                                           (String name, BindingFlags 
invokeAttr,
                                                Binder binder, Object target, 
Object[] args,
                                                ParameterModifier[] modifiers,
                                                CultureInfo culture, String[] 
namedParameters)
                        {
                                // Bail out if the wrong object was used to 
invoke.
                                if(target != this)
                                {
                                        throw new TargetException();
                                }

                                // TODO: find the member and invoke it.
                                return null;
                        }

        // Get or set the length of the script function argument list.
        public virtual int length
                        {
                                get
                                {
                                        return lengthValue;
                                }
                                set
                                {
                                        // Nothing to do here.
                                }
                        }

        // Get or set the prototype that underlies this script function.
        public Object prototype
                        {
                                get
                                {
                                        return prototypeValue;
                                }
                                set
                                {
                                        prototypeValue = value;
                                }
                        }

        // Convert this script function into a string.
        public override String ToString()
                        {
                                return "function " + name + "() {\n" +
                                           "    [native code]\n" +
                                           "}";
                        }

        // Perform a call on this object.
        internal abstract Object Call(Object thisob, Object[] args);

        // Perform a constructor call on this object.
        internal virtual Object CallConstructor(Object[] args)
                        {
                                JSObject obj = new 
JSObject(GetPrototypeForConstructedObject());
                                Object result = Call(obj, args);
                                if(result is ScriptObject)
                                {
                                        return result;
                                }
                                else
                                {
                                        return obj;
                                }
                        }

        // Get the internal "[[Class]]" property for this object.
        internal override String ClassName
                        {
                                get
                                {
                                        return "Function";
                                }
                        }

}; // class ScriptFunction

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * ScriptObject.cs - Root of the "script object" hierarchy.
 *
 * 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.Reflection;
using System.Globalization;
using Microsoft.JScript.Vsa;

public abstract class ScriptObject : IReflect
{
        // Accessible internal state.
        protected ScriptObject parent;
        public VsaEngine engine;

        // Constructor.
        internal ScriptObject(ScriptObject parent)
                        {
                                this.parent = parent;
                                if(parent != null)
                                {
                                        this.engine = parent.engine;
                                }
                                else
                                {
                                        this.engine = null;
                                }
                        }

        // Strip a list of members down to just those of a specific type.
        private Array StripMemberList(BindingFlags bindingAttr,
                                                                  MemberTypes 
memberType,
                                                                  Type 
arrayElementType)
                        {
                                // Get the members.
                                MemberInfo[] members = GetMembers(bindingAttr);
                                if(members == null)
                                {
                                        return 
Array.CreateInstance(arrayElementType, 0);
                                }

                                // Count the number of members of the requested 
type.
                                int posn;
                                int count = 0;
                                for(posn = 0; posn < members.Length; ++posn)
                                {
                                        if(members[posn].MemberType == 
memberType)
                                        {
                                                ++count;
                                        }
                                }

                                // Create the final member array.
                                Array array = 
Array.CreateInstance(arrayElementType, count);

                                // Populate the array and return it.
                                count = 0;
                                for(posn = 0; posn < members.Length; ++posn)
                                {
                                        if(members[posn].MemberType == 
memberType)
                                        {
                                                array.SetValue(members[posn], 
count++);
                                        }
                                }
                                return array;
                        }

        // Implement the IReflect interface.
        public FieldInfo GetField(String name, BindingFlags bindingAttr)
                        {
                                MemberInfo[] members = GetMember(name, 
bindingAttr);
                                foreach(MemberInfo member in members)
                                {
                                        if(member.MemberType == 
MemberTypes.Field)
                                        {
                                                return (FieldInfo)member;
                                        }
                                }
                                return null;
                        }
        public virtual FieldInfo[] GetFields(BindingFlags bindingAttr)
                        {
                                return (FieldInfo[])StripMemberList(bindingAttr,
                                                                                
                        MemberTypes.Field,
                                                                                
                        typeof(FieldInfo));
                        }
        public abstract MemberInfo[] GetMember
                                (String name, BindingFlags bindingAttr);
        public abstract MemberInfo[] GetMembers(BindingFlags bindingAttr);
        public MethodInfo GetMethod(String name, BindingFlags bindingAttr)
                        {
                                return GetMethod(name, bindingAttr, null,
                                                                 
Type.EmptyTypes, null);
                        }
        public MethodInfo GetMethod(String name, BindingFlags bindingAttr,
                                                                Binder binder, 
Type[] types,
                                                                
ParameterModifier[] modifiers)
                        {
                                // TODO
                                return null;
                        }
        public virtual MethodInfo[] GetMethods(BindingFlags bindingAttr)
                        {
                                return 
(MethodInfo[])StripMemberList(bindingAttr,
                                                                                
                         MemberTypes.Method,
                                                                                
                         typeof(MethodInfo));
                        }
        public PropertyInfo GetProperty(String name, BindingFlags bindingAttr)
                        {
                                return GetProperty(name, bindingAttr, null,
                                                                   null, 
Type.EmptyTypes, null);
                        }
        public PropertyInfo GetProperty(String name, BindingFlags bindingAttr,
                                                                        Binder 
binder, Type returnType,
                                                                        Type[] 
types, ParameterModifier[] modifiers)
                        {
                                // TODO
                                return null;
                        }
        public virtual PropertyInfo[] GetProperties(BindingFlags bindingAttr)
                        {
                                return 
(PropertyInfo[])StripMemberList(bindingAttr,
                                                                                
                           MemberTypes.Property,
                                                                                
                           typeof(PropertyInfo));
                        }
        public virtual Object InvokeMember
                                           (String name, BindingFlags 
invokeAttr,
                                                Binder binder, Object target, 
Object[] args,
                                                ParameterModifier[] modifiers,
                                                CultureInfo culture, String[] 
namedParameters)
                        {
                                // Can only invoke on ourselves.
                                if(target != this)
                                {
                                        throw new TargetException();
                                }

                                // TODO
                                return null;
                        }
        public virtual Type UnderlyingSystemType
                        {
                                get
                                {
                                        return GetType();
                                }
                        }

        // Get the parent of this script object.
        public ScriptObject GetParent()
                        {
                                return parent;
                        }

        // Indexers for this script object.
        public Object this[int index]
                        {
                                get
                                {
                                        Object value;
                                        if(index >= 0)
                                        {
                                                value = 
GetPropertyByIndex(index);
                                        }
                                        else
                                        {
                                                value = 
GetProperty(Convert.ToString(index));
                                        }
                                        if(!(value is Missing))
                                        {
                                                return value;
                                        }
                                        else
                                        {
                                                return null;
                                        }
                                }
                                set
                                {
                                        if(index >= 0)
                                        {
                                                SetPropertyByIndex(index, 
value);
                                        }
                                        else
                                        {
                                                
SetProperty(Convert.ToString(index), value,
                                                                        
PropertyAttributes.None);
                                        }
                                }
                        }
        public Object this[double index]
                        {
                                get
                                {
                                        Object value;
                                        if(index >= 0.0 && index <= 
(double)(Int32.MaxValue) &&
                                           Math.Round(index) == index)
                                        {
                                                value = 
GetPropertyByIndex((int)index);
                                        }
                                        else
                                        {
                                                value = 
GetProperty(Convert.ToString(index));
                                        }
                                        if(!(value is Missing))
                                        {
                                                return value;
                                        }
                                        else
                                        {
                                                return null;
                                        }
                                }
                                set
                                {
                                        if(index >= 0.0 && index <= 
(double)(Int32.MaxValue) &&
                                           Math.Round(index) == index)
                                        {
                                                SetPropertyByIndex((int)index, 
value);
                                        }
                                        else
                                        {
                                                
SetProperty(Convert.ToString(index), value,
                                                                        
PropertyAttributes.None);
                                        }
                                }
                        }
        public Object this[String name]
                        {
                                get
                                {
                                        Object value = GetProperty(name);
                                        if(!(value is Missing))
                                        {
                                                return value;
                                        }
                                        else
                                        {
                                                return null;
                                        }
                                }
                                set
                                {
                                        SetProperty(name, value, 
PropertyAttributes.None);
                                }
                        }
        public Object this[params Object[] pars]
                        {
                                get
                                {
                                        if(pars.Length == 0)
                                        {
                                                if(!(this is ScriptFunction))
                                                {
                                                        throw new 
JScriptException
                                                                
(JSError.TooFewParameters);
                                                }
                                                else
                                                {
                                                        throw new 
JScriptException
                                                                
(JSError.FunctionExpected);
                                                }
                                        }
                                        Object index = pars[pars.Length - 1];
                                        if(index is Int32)
                                        {
                                                return this[(int)index];
                                        }
                                        else if(index is Double)
                                        {
                                                return this[(double)index];
                                        }
                                        else
                                        {
                                                return 
this[Convert.ToString(index)];
                                        }
                                }
                                set
                                {
                                        if(pars.Length == 0)
                                        {
                                                if(!(this is ScriptFunction))
                                                {
                                                        throw new 
JScriptException
                                                                
(JSError.TooFewParameters);
                                                }
                                                else
                                                {
                                                        throw new 
JScriptException
                                                                
(JSError.CannotAssignToFunctionResult);
                                                }
                                        }
                                        Object index = pars[pars.Length - 1];
                                        if(index is Int32)
                                        {
                                                this[(int)index] = value;
                                        }
                                        else if(index is Double)
                                        {
                                                this[(double)index] = value;
                                        }
                                        else
                                        {
                                                this[Convert.ToString(index)] = 
value;
                                        }
                                }
                        }

        // Wrap members to turn them into script objects.
        protected static MemberInfo[] WrapMembers
                                (MemberInfo[] members, Object obj)
                        {
                                // TODO
                                return null;
                        }
        protected static MemberInfo[] WrapMembers(MemberInfo member, Object obj)
                        {
                                // TODO
                                return null;
                        }
        protected static MemberInfo[] WrapMembers
                                (MemberInfo[] members, Object obj, 
SimpleHashtable cache)
                        {
                                // TODO
                                return null;
                        }

        // Get a property from this object.  Null if not present.
        internal virtual Object GetProperty(String name)
                        {
                                // TODO
                                return null;
                        }

        // Set a property in this object.
        internal virtual void SetProperty(String name, Object value,
                                                                          
PropertyAttributes attrs)
                        {
                                // TODO
                        }

        // Determine if this object has a specific property.
        internal virtual bool HasOwnProperty(String name)
                        {
                                // TODO
                                return false;
                        }

        // Get a property from this object by numeric index.
        internal virtual Object GetPropertyByIndex(int index)
                        {
                                return GetProperty(Convert.ToString(index));
                        }

        // Get a property from this object by numeric index.
        internal virtual void SetPropertyByIndex(int index, Object value)
                        {
                                SetProperty(Convert.ToString(index), value,
                                                        
PropertyAttributes.None);
                        }

        // Normalize this object to remove object wrappers.
        internal virtual Object Normalize()
                        {
                                // By default, no normalization is applied.
                                return this;
                        }

}; // class ScriptObject

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * SimpleHashtable.cs - Simple hash table class.
 *
 * 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;

// In this implementation, we just wrap up a "Hashtable".  That's simple.

public sealed class SimpleHashtable
{
        // Internal state.
        private Hashtable table;

        // Constructor.
        public SimpleHashtable(uint threshold)
                        {
                                table = new Hashtable((int)threshold);
                        }

        // Get an enumerator for the hash table.
        public IDictionaryEnumerator GetEnumerator()
                        {
                                return table.GetEnumerator();
                        }

        // Remove an entry from the hash table.
        public void Remove(Object key)
                        {
                                table.Remove(key);
                        }

        // Indexer for the hash table.
        public Object this[Object key]
                        {
                                get
                                {
                                        return table[key];
                                }
                                set
                                {
                                        table[key] = value;
                                }
                        }

}; // class SimpleHashtable

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * Support.cs - Random support routines.
 *
 * 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.Reflection;

internal sealed class Support
{
        // Get the type code for an object value.
        public static TypeCode TypeCodeForObject(Object value)
                        {
                                if(value == null)
                                {
                                        return TypeCode.Empty;
                                }
                        #if !ECMA_COMPAT
                                if(value is IConvertible)
                                {
                                        return 
((IConvertible)value).GetTypeCode();
                                }
                                else
                                {
                                        return TypeCode.Object;
                                }
                        #else
                                if(value is DBNull)
                                {
                                        return TypeCode.DBNull;
                                }
                                else if(value is Boolean)
                                {
                                        return TypeCode.Boolean;
                                }
                                else if(value is Char)
                                {
                                        return TypeCode.Char;
                                }
                                else if(value is SByte)
                                {
                                        return TypeCode.SByte;
                                }
                                else if(value is Byte)
                                {
                                        return TypeCode.Byte;
                                }
                                else if(value is Int16)
                                {
                                        return TypeCode.Int16;
                                }
                                else if(value is UInt16)
                                {
                                        return TypeCode.UInt16;
                                }
                                else if(value is Int32)
                                {
                                        return TypeCode.Int32;
                                }
                                else if(value is UInt32)
                                {
                                        return TypeCode.UInt32;
                                }
                                else if(value is Int64)
                                {
                                        return TypeCode.Int64;
                                }
                                else if(value is UInt64)
                                {
                                        return TypeCode.UInt64;
                                }
                                else if(value is Single)
                                {
                                        return TypeCode.Single;
                                }
                                else if(value is Double)
                                {
                                        return TypeCode.Double;
                                }
                                else if(value is Decimal)
                                {
                                        return TypeCode.Decimal;
                                }
                                else if(value is DateTime)
                                {
                                        return TypeCode.DateTime;
                                }
                                else if(value is String)
                                {
                                        return TypeCode.String;
                                }
                                else
                                {
                                        return TypeCode.Object;
                                }
                        #endif
                        }

        // Get the type of an object, in JScript parlance.
        public static String Typeof(Object value)
                        {
                                switch(TypeCodeForObject(value))
                                {
                                        case TypeCode.Empty:    break;

                                        case TypeCode.Object:
                                        {
                                                if(value is 
Microsoft.JScript.Missing ||
                                                   value is 
System.Reflection.Missing)
                                                {
                                                        return "undefined";
                                                }
                                                else if(value is ScriptFunction)
                                                {
                                                        return "function";
                                                }
                                                else if(value is JSObject)
                                                {
                                                        return 
((JSObject)value).ClassName.ToLower();
                                                }
                                                else
                                                {
                                                        return "object";
                                                }
                                        }
                                        // Not reached.

                                        case TypeCode.DBNull:   return "object";
                                        case TypeCode.Boolean:  return 
"boolean";
                                        case TypeCode.SByte:
                                        case TypeCode.Byte:
                                        case TypeCode.Int16:
                                        case TypeCode.UInt16:
                                        case TypeCode.Int32:
                                        case TypeCode.UInt32:
                                        case TypeCode.Int64:
                                        case TypeCode.UInt64:
                                        case TypeCode.Single:
                                        case TypeCode.Double:
                                        case TypeCode.Decimal:  return "number";
                                        case TypeCode.DateTime: return "date";
                                        case TypeCode.Char:
                                        case TypeCode.String:   return "string";
                                }
                                return "undefined";
                        }

        // Determine if a statement label matches a label list.  The null
        // label always matches.
        public static bool LabelMatch(String label, String[] labels)
                        {
                                if(label == null)
                                {
                                        return true;
                                }
                                else if(labels == null)
                                {
                                        return false;
                                }
                                foreach(String lab in labels)
                                {
                                        if(label == lab)
                                        {
                                                return true;
                                        }
                                }
                                return false;
                        }

        // Create a compound statement node.  We do this carefully to
        // reduce the depth of the resulting node tree.
        public static JNode CreateCompound(JNode left, JNode right)
                        {
                                JCompound node;
                                JCompound prev;
                                if(left == null || left is JEmpty)
                                {
                                        return right;
                                }
                                else if(right == null || right is JEmpty)
                                {
                                        return left;
                                }
                                if(!(left is JCompound))
                                {
                                        node = new JCompound(Context.BuildRange
                                                                                
        (left.context, right.context));
                                        node.stmt1 = left;
                                        node.stmt2 = right;
                                        return node;
                                }
                                node = (JCompound)left;
                                prev = null;
                                do
                                {
                                        if(node.stmt1 == null)
                                        {
                                                node.stmt1 = right;
                                                return left;
                                        }
                                        if(node.stmt2 == null)
                                        {
                                                node.stmt2 = right;
                                                return left;
                                        }
                                        if(node.stmt3 == null)
                                        {
                                                node.stmt3 = right;
                                                return left;
                                        }
                                        if(node.stmt4 == null)
                                        {
                                                node.stmt4 = right;
                                                return left;
                                        }
                                        prev = node;
                                        node = node.next;
                                }
                                while(node != null);
                                prev.next = new 
JCompound(right.context.MakeCopy());
                                prev.next.stmt1 = right;
                                left.context.endLine = right.context.endLine;
                                left.context.endLinePosition = 
right.context.endLinePosition;
                                return left;
                        }

        // Add a label to a statement.
        public static void AddLabel(String label, JNode node)
                        {
                                JStatement stmt = (node as JStatement);
                                if(stmt != null)
                                {
                                        if(stmt.labels == null)
                                        {
                                                stmt.labels = new String [] 
{label};
                                        }
                                        else
                                        {
                                                String[] newLabels =
                                                        new String 
[stmt.labels.Length + 1];
                                                Array.Copy(stmt.labels, 
newLabels,
                                                                   
stmt.labels.Length);
                                                newLabels[stmt.labels.Length] = 
label;
                                                stmt.labels = newLabels;
                                        }
                                }
                        }

        // Add an expression to a list.
        public static void AddExprToList(JExprList list, Object name, JNode 
expr)
                        {
                                JExprListElem elem = new JExprListElem
                                        (null, name, expr, null);
                                if(list.last != null)
                                {
                                        list.last.next = elem;
                                }
                                else
                                {
                                        list.first = elem;
                                }
                                list.last = elem;
                        }

}; // class Support

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * WithScope.cs - Structure of an activation object for "with" contexts.
 *
 * 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.Reflection;

internal sealed class WithScope : ScriptObject, IActivationObject
{
        // Internal state.
        private Object withObject;

        // Constructor.
        internal WithScope(ScriptObject parent, Object withObject)
                        : base(parent)
                        {
                                this.withObject = withObject;
                        }

        // Implement the IActivationObject interface.
        public virtual Object GetDefaultThisObject()
                        {
                                return withObject;
                        }
        public virtual GlobalScope GetGlobalScope()
                        {
                                return 
((IActivationObject)parent).GetGlobalScope();
                        }
        public virtual FieldInfo GetLocalField(String name)
                        {
                                // This method is not used.
                                return null;
                        }
        public virtual Object GetMemberValue(String name, int lexlevel)
                        {
                                // TODO
                                return Missing.Value;
                        }
        public virtual FieldInfo GetField(String name, int lexlevel)
                        {
                                // TODO
                                return null;
                        }

        // Get a specific member.
        public override MemberInfo GetMember(String name, BindingFlags 
bindingAttr)
                        {
                                // TODO
                                return null;
                        }

        // Get all members that match specific binding conditions.
        public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
                        {
                                // TODO
                                return null;
                        }

}; // class WithScope

}; // namespace Microsoft.JScript





reply via email to

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