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/Builtins ArrayConstructor.cs


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/JScript/Builtins ArrayConstructor.cs,NONE,1.1 ArrayObject.cs,NONE,1.1 ArrayPrototype.cs,NONE,1.1 BuiltinFunction.cs,NONE,1.1 ErrorObject.cs,NONE,1.1 FunctionConstructor.cs,NONE,1.1 FunctionPrototype.cs,NONE,1.1 GlobalObject.cs,NONE,1.1 JSBuiltin.cs,NONE,1.1 JSFunctionAttribute.cs,NONE,1.1 JSFunctionAttributeEnum.cs,NONE,1.1 Makefile,NONE,1.1 ObjectConstructor.cs,NONE,1.1ObjectPrototype.cs,NONE,1.1
Date: Mon, 13 Jan 2003 05:53:22 -0500

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

Added Files:
        ArrayConstructor.cs ArrayObject.cs ArrayPrototype.cs 
        BuiltinFunction.cs ErrorObject.cs FunctionConstructor.cs 
        FunctionPrototype.cs GlobalObject.cs JSBuiltin.cs 
        JSFunctionAttribute.cs JSFunctionAttributeEnum.cs Makefile 
        ObjectConstructor.cs ObjectPrototype.cs 
Log Message:


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


--- NEW FILE ---
/*
 * ArrayConstructor.cs - Object that represents the "Array" constructor.
 *
 * 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 sealed class ArrayConstructor : ScriptFunction
{
        // Constructor.
        internal ArrayConstructor(FunctionPrototype parent)
                        : base(parent, "Array", 1) {}

        // Construct a new array from a list of elements.
        public ArrayObject ConstructArray(Object[] args)
                        {
                                // TODO
                                return null;
                        }

        // Construct a new "Array" instance.
        [JSFunction(JSFunctionAttributeEnum.HasVarArgs)]
        public new ArrayObject CreateInstance(params Object[] args)
                        {
                                // TODO
                                return null;
                        }

        // Invoke this constructor.
        [JSFunction(JSFunctionAttributeEnum.HasVarArgs)]
        public ArrayObject Invoke(params Object[] args)
                        {
                                if(args.Length == 1 && args[0] is Array)
                                {
                                        // TODO: wrap the normal array in a 
JScript array object.
                                        return null;
                                }
                                else
                                {
                                        return CreateInstance(args);
                                }
                        }

        // Perform a call on this object.
        internal override Object Call(Object thisob, Object[] args)
                        {
                                return Invoke(args);
                        }

        // Perform a constructor call on this object.
        internal override Object CallConstructor(Object[] args)
                        {
                                return CreateInstance(args);
                        }

}; // class ArrayConstructor

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * ArrayObject.cs - Implementation of array 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 ArrayObject : JSObject
{
        // Internal state.
        private Object[] array;
        private uint arrayLen;
        private bool isSparse;

        // Constructor.
        internal ArrayObject(ScriptObject prototype)
                        : base(prototype)
                        {
                                array = null;
                                arrayLen = 0;
                                isSparse = false;
                        }

        // Get or set the length of the array.
        public virtual Object length
                        {
                                get
                                {
                                        if(arrayLen <= (uint)(Int32.MaxValue))
                                        {
                                                return (int)arrayLen;
                                        }
                                        else
                                        {
                                                return (double)arrayLen;
                                        }
                                }
                                set
                                {
                                        // TODO
                                }
                        }

        // Splice the array slowly.
        protected void SpliceSlowly(uint start, uint deleteCount,
                                                                Object[] args, 
ArrayObject outArray,
                                                                uint oldLength, 
uint newLength)
                        {
                                // This exists for backwards-compatibility, but 
there
                                // is actually no way to call it from user code.
                        }

}; // class ArrayObject

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * ArrayPrototype.cs - Prototype object for "Array" 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.Text;
using Microsoft.JScript.Vsa;

public class ArrayPrototype : ArrayObject
{
        // Constructor.
        internal ArrayPrototype(ObjectPrototype parent, EngineInstance inst)
                        : base(parent)
                        {
                                // Add the builtin "Array" properties to the 
prototype.
                                SetProperty("constructor", 
inst.GetArrayConstructor(),
                                                        
PropertyAttributes.None);
                                AddBuiltin(inst, "concat");
                                AddBuiltin(inst, "join");
                                AddBuiltin(inst, "pop");
                                AddBuiltin(inst, "push");
                                AddBuiltin(inst, "reverse");
                                AddBuiltin(inst, "shift");
                                AddBuiltin(inst, "slice");
                                AddBuiltin(inst, "sort");
                                AddBuiltin(inst, "splice");
                                AddBuiltin(inst, "toLocaleString");
                                AddBuiltin(inst, "toString");
                                AddBuiltin(inst, "unshift");
                        }

        // Get the "Array" class constructor.  Don't use this.
        public static ArrayConstructor constructor
                        {
                                get
                                {
                                        return 
EngineInstance.Default.GetArrayConstructor();
                                }
                        }

        // Concatenate arrays together.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject |
                                JSFunctionAttributeEnum.HasVarArgs |
                                JSFunctionAttributeEnum.HasEngine, 
JSBuiltin.Array_concat)]
        public static ArrayObject concat(Object thisob, VsaEngine engine,
                                                                         params 
Object[] args)
                        {
                                // TODO
                                return null;
                        }

        // Join the elements together into a string.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject, 
JSBuiltin.Array_join)]
        public static String join(Object thisob, Object separator)
                        {
                                String sep;
                                StringBuilder builder;
                                if(separator is Missing)
                                {
                                        sep = ",";
                                }
                                else
                                {
                                        sep = Convert.ToString(separator);
                                }
                                builder = new StringBuilder();
                                // TODO
                                return builder.ToString();
                        }

        // Pop an element from the end of an array.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Array_pop)]
        public static Object pop(Object thisob)
                        {
                                // TODO
                                return thisob;
                        }

        // Push elements onto the end of an array.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject |
                                JSFunctionAttributeEnum.HasVarArgs, 
JSBuiltin.Array_push)]
        public static long push(Object thisob, params Object[] args)
                        {
                                // TODO
                                return 0;
                        }

        // Reverse the elements in an array.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject,
                                JSBuiltin.Array_reverse)]
        public static Object reverse(Object thisob)
                        {
                                // TODO
                                return thisob;
                        }

        // Shift the elements in an array down one, returning the first.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject, 
JSBuiltin.Array_shift)]
        public static Object shift(Object thisob)
                        {
                                // TODO
                                return null;
                        }

        // Slice a sub-array out of an array.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject |
                                JSFunctionAttributeEnum.HasEngine, 
JSBuiltin.Array_slice)]
        public static ArrayObject slice(Object thisob, VsaEngine engine,
                                                                    double 
start, Object end)
                        {
                                // TODO
                                return null;
                        }

        // Sort the contents of an array.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject, 
JSBuiltin.Array_sort)]
        public static Object sort(Object thisob, Object function)
                        {
                                // TODO
                                return thisob;
                        }

        // Split an array into the middle of another array.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject |
                                JSFunctionAttributeEnum.HasVarArgs |
                                JSFunctionAttributeEnum.HasEngine, 
JSBuiltin.Array_splice)]
        public static ArrayObject splice(Object thisob, VsaEngine engine,
                                                                         double 
start, double deleteCnt,
                                                                         params 
Object[] args)
                        {
                                // TODO
                                return null;
                        }

        // Convert the contents of an array into a locale-based string.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject,
                                JSBuiltin.Array_toLocaleString)]
        public static String toLocaleString(Object thisob)
                        {
                                // TODO
                                return null;
                        }

        // Convert the contents of an array into an invariant string.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject,
                                JSBuiltin.Array_toString)]
        public static String toString(Object thisob)
                        {
                                if(thisob is ArrayObject)
                                {
                                        return join(thisob, ",");
                                }
                                else
                                {
                                        throw new 
JScriptException(JSError.NeedArrayObject);
                                }
                        }

        // Unshift elements back into an array.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject |
                                JSFunctionAttributeEnum.HasEngine, 
JSBuiltin.Array_unshift)]
        public static Object unshift(Object thisob, params Object[] args)
                        {
                                // TODO
                                return null;
                        }

}; // class ArrayPrototype

// "Lenient" version of the above class which exports all of the
// prototype's properties to the user level.
public class LenientArrayPrototype : ArrayPrototype
{
        // Accessible properties.
        public new Object constructor;
        public new Object concat;
        public new Object join;
        public new Object pop;
        public new Object push;
        public new Object reverse;
        public new Object shift;
        public new Object slice;
        public new Object sort;
        public new Object splice;
        public new Object toLocaleString;
        public new Object toString;
        public new Object unshift;

        // Constructor.
        internal LenientArrayPrototype(ObjectPrototype parent, EngineInstance 
inst)
                        : base(parent, inst)
                        {
                                constructor = inst.GetArrayConstructor();
                                concat = GetProperty("concat");
                                join = GetProperty("join");
                                pop = GetProperty("pop");
                                push = GetProperty("push");
                                reverse = GetProperty("reverse");
                                shift = GetProperty("shift");
                                slice = GetProperty("slice");
                                sort = GetProperty("sort");
                                splice = GetProperty("splice");
                                toLocaleString = GetProperty("toLocaleString");
                                toString = GetProperty("toString");
                                unshift = GetProperty("unshift");
                        }

}; // class LenientArrayPrototype

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * BuiltinFunction.cs - Wrapper for builtin functions.
 *
 * 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;

internal sealed class BuiltinFunction : ScriptFunction
{
        // Internal state.
        private MethodInfo method;
        private JSFunctionAttributeEnum flags;
        private int requiredParameters;

        // Constructor.
        public BuiltinFunction(ScriptObject prototype, String name,
                                                   MethodInfo method)
                        : base(prototype, name)
                        {
                                this.method = method;
                                Object[] attrs = method.GetCustomAttributes
                                                (typeof(JSFunctionAttribute), 
false);
                                if(attrs == null || attrs.Length == 0)
                                {
                                        this.flags = (JSFunctionAttributeEnum)0;
                                }
                                else
                                {
                                        this.flags = 
((JSFunctionAttribute)(attrs[0]))
                                                        .GetAttributeValue();
                                }
                                requiredParameters = 
method.GetParameters().Length;
                                lengthValue = requiredParameters;
                                if((flags & 
JSFunctionAttributeEnum.HasThisObject) != 0)
                                {
                                        --lengthValue;
                                }
                                if((flags & JSFunctionAttributeEnum.HasEngine) 
!= 0)
                                {
                                        --lengthValue;
                                }
                                if((flags & JSFunctionAttributeEnum.HasVarArgs) 
!= 0)
                                {
                                        --lengthValue;
                                }
                        }

        // Perform a call on this object.
        internal override Object Call(Object thisob, Object[] args)
                        {
                                // Invoke the builtin method using reflection.
                                if((flags & 
(JSFunctionAttributeEnum.HasThisObject |
                                                         
JSFunctionAttributeEnum.HasVarArgs |
                                                         
JSFunctionAttributeEnum.HasEngine)) ==
                                                (JSFunctionAttributeEnum)0)
                                {
                                        return method.Invoke(null, args);
                                }
                                else
                                {
                                        Object[] tempArgs = new Object 
[requiredParameters];
                                        int posn = 0;
                                        if((flags & 
JSFunctionAttributeEnum.HasThisObject) != 0)
                                        {
                                                tempArgs[posn++] = thisob;
                                        }
                                        if((flags & 
JSFunctionAttributeEnum.HasEngine) != 0)
                                        {
                                                tempArgs[posn++] = engine;
                                        }
                                        if((flags & 
JSFunctionAttributeEnum.HasVarArgs) != 0)
                                        {
                                                tempArgs[posn] = args;
                                        }
                                        else
                                        {
                                                Array.Copy(args, 0, tempArgs, 
posn, args.Length);
                                        }
                                        return method.Invoke(null, tempArgs);
                                }
                        }

}; // class BuiltinFunction

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * ErrorObject.cs - Implementation of error 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 ErrorObject : JSObject
{
        // Accessible internal state.
        public Object message;
        public Object number;
        public Object description;

        // Private internal state.
        private Object wrapped;

        // Constructor.
        internal ErrorObject(ScriptObject prototype)
                        : base(prototype)
                        {
                                // TODO
                        }

        // Extract the wrapped-up exception inside the error object.
        public static explicit operator Exception(ErrorObject err)
                        {
                                return (err.wrapped as Exception);
                        }

}; // class ErrorObject

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * FunctionConstructor.cs - Object that represents the "Function" constructor.
 *
 * 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 sealed class FunctionConstructor : ScriptFunction
{
        // Constructor.
        internal FunctionConstructor() : base(null, "Function", 1) {}

        // Initialize this object, after all dependencies have been created.
        internal void Init(VsaEngine engine, ScriptObject parent)
                        {
                                // Set the prototype and engine.
                                this.parent = parent;
                                this.engine = engine;

                                // Set the "prototype" property value.
                                ScriptObject prototype =
                                        EngineInstance.GetEngineInstance(engine)
                                                .GetObjectPrototype();
                                SetProperty("prototype", prototype,
                                                    PropertyAttributes.ReadOnly 
|
                                                        
PropertyAttributes.DontEnum |
                                                        
PropertyAttributes.DontDelete);
                        }

        // Construct a new "Function" instance.
        [JSFunction(JSFunctionAttributeEnum.HasVarArgs)]
        public new ScriptFunction CreateInstance(params Object[] args)
                        {
                                // TODO
                                return null;
                        }

        // Invoke this constructor.
        [JSFunction(JSFunctionAttributeEnum.HasVarArgs)]
        public ScriptFunction Invoke(params Object[] args)
                        {
                                return CreateInstance(args);
                        }

        // Perform a call on this object.
        internal override Object Call(Object thisob, Object[] args)
                        {
                                return CreateInstance(args);
                        }

        // Perform a constructor call on this object.
        internal override Object CallConstructor(Object[] args)
                        {
                                return CreateInstance(args);
                        }

}; // class FunctionConstructor

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * FunctionPrototype.cs - JScript function prototype 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 Microsoft.JScript.Vsa;

public class FunctionPrototype : ScriptFunction
{
        // Constructor.
        internal FunctionPrototype() : base(null, "Function.prototype") {}

        // Initialize this object, after all dependencies have been created.
        internal virtual void Init(VsaEngine engine, ScriptObject parent)
                        {
                                // Set the prototype and engine.
                                this.parent = parent;
                                this.engine = engine;
                                InitPrototype(parent);

                                // Add the builtin "Function" properties to the 
prototype.
                                EngineInstance inst = 
EngineInstance.GetEngineInstance(engine);
                                SetProperty("constructor", 
inst.GetFunctionConstructor(),
                                                        
PropertyAttributes.None);
                                AddBuiltin(inst, "apply");
                                AddBuiltin(inst, "call");
                                AddBuiltin(inst, "toString");
                        }

        // Get the "Function" class constructor.  Don't use this.
        public static FunctionConstructor constructor
                        {
                                get
                                {
                                        return 
EngineInstance.Default.GetFunctionConstructor();
                                }
                        }

        // Implement the builtin "Function.apply" function.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject,
                                JSBuiltin.Function_apply)]
        public static Object apply(Object thisob, Object thisarg, Object 
argArray)
                        {
                                // TODO
                                return null;
                        }

        // Implement the builtin "Function.call" function.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject |
                                JSFunctionAttributeEnum.HasVarArgs,
                                JSBuiltin.Function_call)]
        public static Object call(Object thisob, Object thisarg,
                                                          params Object[] args)
                        {
                                // TODO
                                return null;
                        }

        // Implement the builtin "Function.toString" function.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject,
                                JSBuiltin.Function_toString)]
        public static String toString(Object thisob)
                        {
                                if(thisob is ScriptFunction)
                                {
                                        return thisob.ToString();
                                }
                                else
                                {
                                        throw new 
JScriptException(JSError.FunctionExpected);
                                }
                        }

}; // class FunctionPrototype

// "Lenient" version of the above class which exports all of the
// prototype's properties to the user level.
public class LenientFunctionPrototype : FunctionPrototype
{
        // Accessible properties.
        public new Object constructor;
        public new Object apply;
        public new Object call;
        public new Object toString;

        // Constructor.
        internal LenientFunctionPrototype() : base() {}

        // Initialize this object, after all dependencies have been created.
        internal override void Init(VsaEngine engine, ScriptObject parent)
                        {
                                base.Init(engine, parent);
                                constructor = GetProperty("constructor");
                                apply = GetProperty("apply");
                                call = GetProperty("call");
                                toString = GetProperty("toString");
                        }

}; // class LenientFunctionPrototype

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * GlobalObject.cs - Implementation of the global JScript 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
 */
[...985 lines suppressed...]
                                                   vbArray is Missing)
                                                {
                                                        vbArray = 
GlobalObject.VBArray;
                                                }
                                                return vbArray;
                                        }
                                }
                                set
                                {
                                        lock(this)
                                        {
                                                vbArray = value;
                                        }
                                }
                        }
#endif

}; // class LenientGlobalObject

}; // namespace Microsoft.JScript

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

public enum JSBuiltin
{
        Array_concat                                    =   1,
        Array_join                                              =   2,
        Array_pop                                               =   3,
        Array_push                                              =   4,
        Array_reverse                                   =   5,
        Array_shift                                             =   6,
        Array_slice                                             =   7,
        Array_sort                                              =   8,
        Array_splice                                    =   9,
        Array_toLocaleString                    =  10,
        Array_toString                                  =  11,
        Array_unshift                                   =  12,
        Boolean_toString                                =  13,
        Boolean_valueOf                                 =  14,
        Date_getDate                                    =  15,
        Date_getDay                                             =  16,
        Date_getFullYear                                =  17,
        Date_getHours                                   =  18,
        Date_getMilliseconds                    =  19,
        Date_getMinutes                                 =  20,
        Date_getMonth                                   =  21,
        Date_getSeconds                                 =  22,
        Date_getTime                                    =  23,
        Date_getTimezoneOffset                  =  24,
        Date_getUTCDate                                 =  25,
        Date_getUTCDay                                  =  26,
        Date_getUTCFullYear                             =  27,
        Date_getUTCHours                                =  28,
        Date_getUTCMilliseconds                 =  29,
        Date_getUTCMinutes                              =  30,
        Date_getUTCMonth                                =  31,
        Date_getUTCSeconds                              =  32,
        Date_getVarDate                                 =  33,
        Date_getYear                                    =  34,
        Date_parse                                              =  35,
        Date_setDate                                    =  36,
        Date_setFullYear                                =  37,
        Date_setHours                                   =  38,
        Date_setMinutes                                 =  39,
        Date_setMilliseconds                    =  40,
        Date_setMonth                                   =  41,
        Date_setSeconds                                 =  42,
        Date_setTime                                    =  43,
        Date_setUTCDate                                 =  44,
        Date_setUTCFullYear                             =  45,
        Date_setUTCHours                                =  46,
        Date_setUTCMinutes                              =  47,
        Date_setUTCMilliseconds                 =  48,
        Date_setUTCMonth                                =  49,
        Date_setUTCSeconds                              =  50,
        Date_setYear                                    =  51,
        Date_toDateString                               =  52,
        Date_toGMTString                                =  53,
        Date_toLocaleDateString                 =  54,
        Date_toLocaleString                             =  55,
        Date_toLocaleTimeString                 =  56,
        Date_toString                                   =  57,
        Date_toTimeString                               =  58,
        Date_toUTCString                                =  59,
        Date_UTC                                                =  60,
        Date_valueOf                                    =  61,
        Enumerator_atEnd                                =  62,
        Enumerator_item                                 =  63,
        Enumerator_moveFirst                    =  64,
        Enumerator_moveNext                             =  65,
        Error_toString                                  =  66,
        Function_apply                                  =  67,
        Function_call                                   =  68,
        Function_toString                               =  69,
        Global_CollectGarbage                   =  70,
        Global_decodeURI                                =  71,
        Global_decodeURIComponent               =  72,
        Global_encodeURI                                =  73,
        Global_encodeURIComponent               =  74,
        Global_escape                                   =  75,
        Global_eval                                             =  76,
        Global_isNaN                                    =  77,
        Global_isFinite                                 =  78,
        Global_parseFloat                               =  79,
        Global_parseInt                                 =  80,
        Global_ScriptEngine                             =  81,
        Global_ScriptEngineBuildVersion =  82,
        Global_ScriptEngineMajorVersion =  83,
        Global_ScriptEngineMinorVersion =  84,
        Global_unescape                                 =  85,
        Math_abs                                                =  86,
        Math_acos                                               =  87,
        Math_asin                                               =  88,
        Math_atan                                               =  89,
        Math_atan2                                              =  90,
        Math_ceil                                               =  91,
        Math_cos                                                =  92,
        Math_exp                                                =  93,
        Math_floor                                              =  94,
        Math_log                                                =  95,
        Math_max                                                =  96,
        Math_min                                                =  97,
        Math_pow                                                =  98,
        Math_random                                             =  99,
        Math_round                                              = 100,
        Math_sin                                                = 101,
        Math_sqrt                                               = 102,
        Math_tan                                                = 103,
        Number_toExponential                    = 104,
        Number_toFixed                                  = 105,
        Number_toLocaleString                   = 106,
        Number_toPrecision                              = 107,
        Number_toString                                 = 108,
        Number_valueOf                                  = 109,
        Object_hasOwnProperty                   = 110,
        Object_isPrototypeOf                    = 111,
        Object_propertyIsEnumerable             = 112,
        Object_toLocaleString                   = 113,
        Object_toString                                 = 114,
        Object_valueOf                                  = 115,
        RegExp_compile                                  = 116,
        RegExp_exec                                             = 117,
        RegExp_test                                             = 118,
        RegExp_toString                                 = 119,
        String_anchor                                   = 120,
        String_big                                              = 121,
        String_blink                                    = 122,
        String_bold                                             = 123,
        String_charAt                                   = 124,
        String_charCodeAt                               = 125,
        String_concat                                   = 126,
        String_fixed                                    = 127,
        String_fontcolor                                = 128,
        String_fontsize                                 = 129,
        String_fromCharCode                             = 130,
        String_indexOf                                  = 131,
        String_italics                                  = 132,
        String_lastIndexOf                              = 133,
        String_link                                             = 134,
        String_localeCompare                    = 135,
        String_match                                    = 136,
        String_replace                                  = 137,
        String_search                                   = 138,
        String_slice                                    = 139,
        String_small                                    = 140,
        String_split                                    = 141,
        String_strike                                   = 142,
        String_sub                                              = 143,
        String_substr                                   = 144,
        String_substring                                = 145,
        String_sup                                              = 146,
        String_toLocaleLowerCase                = 147,
        String_toLocaleUpperCase                = 148,
        String_toLowerCase                              = 149,
        String_toString                                 = 150,
        String_toUpperCase                              = 151,
        String_valueOf                                  = 152,
        VBArray_dimensions                              = 153,
        VBArray_getItem                                 = 154,
        VBArray_lbound                                  = 155,
        VBArray_toArray                                 = 156,
        VBArray_ubound                                  = 157

}; // enum JSBuiltin

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * JSFunctionAttribute.cs - Mark a method with JScript-specific attributes.
 *
 * 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.Constructor)]
public class JSFunctionAttribute : Attribute
{
        // Internal state.
        private JSFunctionAttributeEnum value;
        private JSBuiltin builtinFunction;

        // Constructors.
        public JSFunctionAttribute(JSFunctionAttributeEnum value)
                        {
                                this.value = value;
                                this.builtinFunction = (JSBuiltin)0;
                        }
        public JSFunctionAttribute
                                (JSFunctionAttributeEnum value, JSBuiltin 
builtinFunction)
                        {
                                this.value = value;
                                this.builtinFunction = builtinFunction;
                        }

        // Get the attribute's value.
        public JSFunctionAttributeEnum GetAttributeValue()
                        {
                                return value;
                        }

}; // class Expando

}; // namespace Microsoft.JScript

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

public enum JSFunctionAttributeEnum
{
        HasArguments                            = 0x0001,
        HasThisObject                           = 0x0002,
        IsNested                                        = 0x0004,
        HasStackFrame                           = 0x0008,
        HasVarArgs                                      = 0x0010,
        HasEngine                                       = 0x0020,
        IsExpandoMethod                         = 0x0040,
        IsNestedClassConstructor        = 0x0080,
        ClassicFunction                         = 0x0023,
        NestedFunction                          = 0x002C,
        ClassicNestedFunction           = 0x002F

}; // enum JSFunctionAttributeEnum

}; // 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 ---
/*
 * ObjectConstructor.cs - Object that represents the "Object" constructor.
 *
 * 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 sealed class ObjectConstructor : ScriptFunction
{
        // Constructor.
        internal ObjectConstructor() : base(null, "Object", 1) {}

        // Initialize this object, after all dependencies have been created.
        internal void Init(VsaEngine engine, ScriptObject parent)
                        {
                                // Set the prototype and engine.
                                this.parent = parent;
                                this.engine = engine;
                                InitPrototype(parent);

                                // Set the "prototype" property value.
                                ScriptObject prototype =
                                        EngineInstance.GetEngineInstance(engine)
                                                .GetObjectPrototype();
                                SetProperty("prototype", prototype,
                                                    PropertyAttributes.ReadOnly 
|
                                                        
PropertyAttributes.DontEnum |
                                                        
PropertyAttributes.DontDelete);
                        }

        // Construct a new "Object" instance.
        public JSObject ConstructObject()
                        {
                                ScriptObject prototype =
                                        EngineInstance.GetEngineInstance(engine)
                                                .GetObjectPrototype();
                                return new JSObject(prototype);
                        }
        [JSFunction(JSFunctionAttributeEnum.HasVarArgs)]
        public new Object CreateInstance(params Object[] args)
                        {
                                if(args.Length == 0)
                                {
                                        return ConstructObject();
                                }
                                else if(args[0] == null || args[0] == 
DBNull.Value)
                                {
                                        return ConstructObject();
                                }
                                else
                                {
                                        // TODO
                                        return args[0];
                                }
                        }

        // Invoke this constructor.
        [JSFunction(JSFunctionAttributeEnum.HasVarArgs)]
        public Object Invoke(params Object[] args)
                        {
                                return Call(null, args);
                        }

        // Perform a call on this object.
        internal override Object Call(Object thisob, Object[] args)
                        {
                                if(args.Length == 0)
                                {
                                        return ConstructObject();
                                }
                                else if(args[0] == null || args[0] == 
DBNull.Value)
                                {
                                        return CreateInstance(args);
                                }
                                else
                                {
                                        // TODO
                                        return this;
                                }
                        }

        // Perform a constructor call on this object.
        internal override Object CallConstructor(Object[] args)
                        {
                                return CreateInstance(args);
                        }

}; // class ObjectConstructor

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * ObjectPrototype.cs - Common base for JScript prototype 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 Microsoft.JScript.Vsa;

public class ObjectPrototype : JSObject
{
        // Constructor.
        internal ObjectPrototype() : base(null) {}

        // Initialize this object, after all dependencies have been created.
        internal virtual void Init(VsaEngine engine)
                        {
                                // Set the engine.
                                this.engine = engine;

                                // Add the builtin "Object" properties to the 
prototype.
                                EngineInstance inst = 
EngineInstance.GetEngineInstance(engine);
                                SetProperty("constructor", 
inst.GetObjectConstructor(),
                                                        
PropertyAttributes.None);
                                AddBuiltin(inst, "toString");
                                AddBuiltin(inst, "toLocaleString");
                                AddBuiltin(inst, "valueOf");
                                AddBuiltin(inst, "hasOwnProperty");
                                AddBuiltin(inst, "isPrototypeOf");
                                AddBuiltin(inst, "propertyIsEnumerable");
                        }

        // Get the "Object" class constructor.  Don't use this.
        public static ObjectConstructor constructor
                        {
                                get
                                {
                                        return 
EngineInstance.Default.GetObjectConstructor();
                                }
                        }

        // Implement the builtin "Object.hasOwnProperty" function.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject,
                                JSBuiltin.Object_hasOwnProperty)]
        public static bool hasOwnProperty(Object thisob, Object name)
                        {
                                String cname = Convert.ToString(name);
                                if(thisob is JSObject)
                                {
                                        
if(((JSObject)thisob).GetProperty(cname) != null)
                                        {
                                                return true;
                                        }
                                }
                                return false;
                        }

        // Implement the builtin "Object.isPrototypeOf" function.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject,
                                JSBuiltin.Object_isPrototypeOf)]
        public static bool isPrototypeOf(Object thisob, Object ob)
                        {
                                if(thisob is ScriptObject && ob is ScriptObject)
                                {
                                        while(ob != null)
                                        {
                                                if(ob == thisob)
                                                {
                                                        return true;
                                                }
                                                ob = 
((ScriptObject)ob).GetParent();
                                        }
                                }
                                return false;
                        }

        // Implement the builtin "Object.propertyIsEnumerable" function.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject,
                                JSBuiltin.Object_propertyIsEnumerable)]
        public static bool propertyIsEnumerable(Object thisob, Object name)
                        {
                                String cname = Convert.ToString(name);
                                if(thisob is JSObject)
                                {
                                        return 
((JSObject)thisob).IsEnumerable(cname);
                                }
                                return false;
                        }

        // Implement the builtin "Object.toLocaleString" function.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject,
                                JSBuiltin.Object_toLocaleString)]
        public static String toLocaleString(Object thisob)
                        {
                                // Let "JSObject.ToString" take care of 
redirecting
                                // to the JScript "toString" method on the 
object.
                                return thisob.ToString();
                        }

        // Implement the builtin "Object.toString" function.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject,
                                JSBuiltin.Object_toString)]
        public static String toString(Object thisob)
                        {
                                String className;
                                if(thisob is JSObject)
                                {
                                        className = 
((JSObject)thisob).ClassName;
                                }
                                else
                                {
                                        className = thisob.GetType().Name;
                                }
                                return "[object " + className + "]";
                        }

        // Implement the builtin "Object.valueOf" function.
        [JSFunction(JSFunctionAttributeEnum.HasThisObject,
                                JSBuiltin.Object_valueOf)]
        public static Object valueOf(Object thisob)
                        {
                                return thisob;
                        }

}; // class ObjectPrototype

// "Lenient" version of the above class which exports all of the
// prototype's properties to the user level.
public class LenientObjectPrototype : ObjectPrototype
{
        // Accessible properties.
        public new Object constructor;
        public new Object hasOwnProperty;
        public new Object isPrototypeOf;
        public new Object propertyIsEnumerable;
        public new Object toLocaleString;
        public new Object toString;
        public new Object valueOf;

        // Constructor.
        internal LenientObjectPrototype() : base() {}

        // Initialize this object, after all dependencies have been created.
        internal override void Init(VsaEngine engine)
                        {
                                base.Init(engine);
                                constructor = GetProperty("constructor");
                                hasOwnProperty = GetProperty("hasOwnProperty");
                                isPrototypeOf = GetProperty("isPrototypeOf");
                                propertyIsEnumerable = 
GetProperty("propertyIsEnumerable");
                                toLocaleString = GetProperty("toLocaleString");
                                toString = GetProperty("toString");
                                valueOf = GetProperty("valueOf");
                        }

}; // class LenientObjectPrototype

}; // namespace Microsoft.JScript





reply via email to

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