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 FunctionScope.cs,NON


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/JScript/Execute FunctionScope.cs,NONE,1.1 NullEnumerator.cs,NONE,1.1 ActivationObject.cs,1.3,1.4 BlockScope.cs,1.1,1.2 Convert.cs,1.2,1.3 IVariableAccess.cs,1.2,1.3 JSObject.cs,1.2,1.3 PropertyAttributes.cs,1.1,1.2 ScriptObject.cs,1.2,1.3 WithScope.cs,1.2,1.3
Date: Tue, 21 Jan 2003 17:11:51 -0500

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

Modified Files:
        ActivationObject.cs BlockScope.cs Convert.cs 
        IVariableAccess.cs JSObject.cs PropertyAttributes.cs 
        ScriptObject.cs WithScope.cs 
Added Files:
        FunctionScope.cs NullEnumerator.cs 
Log Message:


Implement function calls; "for-in" statements; variable declarations;
property enums.


--- NEW FILE ---
/*
 * FunctionScope.cs - Structure of an activation object for local
 *                                        variables within a function 
activation.
 *
 * 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 FunctionScope : ActivationObject
{
        // Internal state.
        private Object thisObject;

        // Constructor.
        internal FunctionScope(ScriptObject parent, JFormalParams fparams,
                                                   Object thisObject, Object[] 
args)
                        : base(parent, new JSObject())
                        {
                                this.thisObject = thisObject;
                                if(fparams != null)
                                {
                                        JExprListElem param = fparams.first;
                                        int posn = 0;
                                        while(param != null && posn < 
args.Length)
                                        {
                                                
((IVariableAccess)this).SetVariable
                                                        
(Convert.ToString(param.name), args[posn++]);
                                                param = param.next;
                                        }
                                        while(param != null)
                                        {
                                                
((IVariableAccess)this).SetVariable
                                                        
(Convert.ToString(param.name), null);
                                                param = param.next;
                                        }
                                }
                        }

        // Get the "this" object for this function scope.
        public override Object GetDefaultThisObject()
                        {
                                return thisObject;
                        }

}; // class FunctionScope

}; // namespace Microsoft.JScript

--- NEW FILE ---
/*
 * NullEnumerator.cs - Enumerator class that returns no elements.
 *
 * 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;

internal sealed class NullEnumerator : IEnumerator
{
        // Constructor.
        public NullEnumerator() {}

        // Implement the IEnumerator interface.
        public bool MoveNext()
                        {
                                return false;
                        }
        public void Reset()
                        {
                                // Nothing to do here.
                        }
        public Object Current
                        {
                                get
                                {
                                        // Not positioned on an element.
                                        throw new InvalidOperationException();
                                }
                        }

}; // class NullEnumerator

}; // namespace Microsoft.JScript

Index: ActivationObject.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/JScript/Execute/ActivationObject.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** ActivationObject.cs 17 Jan 2003 06:34:46 -0000      1.3
--- ActivationObject.cs 21 Jan 2003 22:11:49 -0000      1.4
***************
*** 119,122 ****
--- 119,129 ----
                                storage.Put(name, value);
                        }
+       void IVariableAccess.DeclareVariable(String name)
+                       {
+                               if(!storage.HasOwnProperty(name))
+                               {
+                                       storage.Put(name, null);
+                               }
+                       }
        IVariableAccess IVariableAccess.GetParentScope()
                        {

Index: BlockScope.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/JScript/Execute/BlockScope.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** BlockScope.cs       13 Jan 2003 10:53:19 -0000      1.1
--- BlockScope.cs       21 Jan 2003 22:11:49 -0000      1.2
***************
*** 39,44 ****
                                (String name, Object value, FieldAttributes 
attributes)
                        {
!                               // TODO
!                               return null;
                        }
  
--- 39,43 ----
                                (String name, Object value, FieldAttributes 
attributes)
                        {
!                               return base.CreateField(name, value, 
attributes);
                        }
  

Index: Convert.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/JScript/Execute/Convert.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** Convert.cs  17 Jan 2003 06:34:46 -0000      1.2
--- Convert.cs  21 Jan 2003 22:11:49 -0000      1.3
***************
*** 299,303 ****
                                if(value is ScriptObject)
                                {
!                                       return 
((ScriptObject)value).Normalize();
                                }
                                else if(value is DateTime)
--- 299,304 ----
                                if(value is ScriptObject)
                                {
!                                       return 
((ScriptObject)value).DefaultValue
!                                                               
(DefaultValueHint.None);
                                }
                                else if(value is DateTime)

Index: IVariableAccess.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/JScript/Execute/IVariableAccess.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** IVariableAccess.cs  17 Jan 2003 06:34:46 -0000      1.2
--- IVariableAccess.cs  21 Jan 2003 22:11:49 -0000      1.3
***************
*** 36,39 ****
--- 36,43 ----
        void SetVariable(String name, Object value);
  
+       // Declare a specific variable in this scope if it isn't already 
present.
+       // If it is present, then its current value is left unmodified.
+       void DeclareVariable(String name);
+ 
        // Get the parent variable scope.
        IVariableAccess GetParentScope();

Index: JSObject.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/JScript/Execute/JSObject.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** JSObject.cs 14 Jan 2003 10:35:50 -0000      1.2
--- JSObject.cs 21 Jan 2003 22:11:49 -0000      1.3
***************
*** 130,134 ****
                                        if(prop != null)
                                        {
!                                               return prop.value;
                                        }
                                        else
--- 130,141 ----
                                        if(prop != null)
                                        {
!                                               if((prop.attrs & 
PropertyAttributes.Deferred) == 0)
!                                               {
!                                                       return prop.value;
!                                               }
!                                               else
!                                               {
!                                                       return 
((FieldInfo)(prop.value)).GetValue(this);
!                                               }
                                        }
                                        else
***************
*** 144,148 ****
                                        if(prop.name == name)
                                        {
!                                               return prop.value;
                                        }
                                        prop = prop.next;
--- 151,162 ----
                                        if(prop.name == name)
                                        {
!                                               if((prop.attrs & 
PropertyAttributes.Deferred) == 0)
!                                               {
!                                                       return prop.value;
!                                               }
!                                               else
!                                               {
!                                                       return 
((FieldInfo)(prop.value)).GetValue(this);
!                                               }
                                        }
                                        prop = prop.next;
***************
*** 240,244 ****
                                        else if((prop.attrs & 
PropertyAttributes.ReadOnly) == 0)
                                        {
!                                               prop.value = value;
                                        }
                                        return;
--- 254,265 ----
                                        else if((prop.attrs & 
PropertyAttributes.ReadOnly) == 0)
                                        {
!                                               if((prop.attrs & 
PropertyAttributes.Deferred) == 0)
!                                               {
!                                                       prop.value = value;
!                                               }
!                                               else
!                                               {
!                                                       
((FieldInfo)(prop.value)).SetValue(this, value);
!                                               }
                                        }
                                        return;
***************
*** 255,259 ****
                                                if((prop.attrs & 
PropertyAttributes.ReadOnly) == 0)
                                                {
!                                                       prop.value = value;
                                                }
                                                return;
--- 276,287 ----
                                                if((prop.attrs & 
PropertyAttributes.ReadOnly) == 0)
                                                {
!                                                       if((prop.attrs & 
PropertyAttributes.Deferred) == 0)
!                                                       {
!                                                               prop.value = 
value;
!                                                       }
!                                                       else
!                                                       {
!                                                               
((FieldInfo)(prop.value)).SetValue(this, value);
!                                                       }
                                                }
                                                return;
***************
*** 342,345 ****
--- 370,386 ----
                        }
  
+       // Get an enumerator for the properties in this object.
+       internal override IEnumerator GetPropertyEnumerator()
+                       {
+                               if(overflow != null)
+                               {
+                                       return new 
HashKeyEnumerator(overflow.GetEnumerator());
+                               }
+                               else
+                               {
+                                       return new PropertyEnumerator(this);
+                               }
+                       }
+ 
        // Add a builtin method to a prototype.
        internal void AddBuiltin(EngineInstance inst, String name)
***************
*** 352,356 ****
  
        // Storage for a property.
!       private class Property
        {
                // Accessible internal state.
--- 393,397 ----
  
        // Storage for a property.
!       private sealed class Property
        {
                // Accessible internal state.
***************
*** 370,373 ****
--- 411,506 ----
  
        }; // class Property
+ 
+       // Enumerator class for properties in this object.
+       private sealed class PropertyEnumerator : IEnumerator
+       {
+               // Internal state.
+               private JSObject obj;
+               private Property prop;
+               private Property current;
+ 
+               // Constructor.
+               public PropertyEnumerator(JSObject obj)
+                               {
+                                       this.obj = obj;
+                                       this.prop = obj.properties;
+                                       this.current = null;
+                               }
+ 
+               // Implement the IEnumerator interface.
+               public bool MoveNext()
+                               {
+                                       while(prop != null)
+                                       {
+                                               current = prop;
+                                               prop = prop.next;
+                                               if((current.attrs & 
PropertyAttributes.DontEnum) == 0)
+                                               {
+                                                       return true;
+                                               }
+                                       }
+                                       return false;
+                               }
+               public void Reset()
+                               {
+                                       prop = obj.properties;
+                                       current = null;
+                               }
+               public Object Current
+                               {
+                                       get
+                                       {
+                                               if(current != null)
+                                               {
+                                                       return current.name;
+                                               }
+                                               else
+                                               {
+                                                       throw new 
InvalidOperationException();
+                                               }
+                                       }
+                               }
+ 
+       }; // class PropertyEnumerator
+ 
+       // Enumerator class for keys in a hash table.
+       private sealed class HashKeyEnumerator : IEnumerator
+       {
+               // Internal state.
+               private IDictionaryEnumerator e;
+ 
+               // Constructor.
+               public HashKeyEnumerator(IDictionaryEnumerator e)
+                               {
+                                       this.e = e;
+                               }
+ 
+               // Implement the IEnumerator interface.
+               public bool MoveNext()
+                               {
+                                       Property prop;
+                                       while(e.MoveNext())
+                                       {
+                                               prop = (Property)(e.Value);
+                                               if((prop.attrs & 
PropertyAttributes.DontEnum) == 0)
+                                               {
+                                                       return true;
+                                               }
+                                       }
+                                       return false;
+                               }
+               public void Reset()
+                               {
+                                       e.Reset();
+                               }
+               public Object Current
+                               {
+                                       get
+                                       {
+                                               return e.Key;
+                                       }
+                               }
+ 
+       }; // class HashKeyEnumerator
  
  }; // class JSObject

Index: PropertyAttributes.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/JScript/Execute/PropertyAttributes.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** PropertyAttributes.cs       13 Jan 2003 10:53:19 -0000      1.1
--- PropertyAttributes.cs       21 Jan 2003 22:11:49 -0000      1.2
***************
*** 29,33 ****
        ReadOnly   = 0x01,
        DontEnum   = 0x02,
!       DontDelete = 0x04
  
  }; // enum PropertyAttributes
--- 29,34 ----
        ReadOnly   = 0x01,
        DontEnum   = 0x02,
!       DontDelete = 0x04,
!       Deferred   = 0x08
  
  }; // enum PropertyAttributes

Index: ScriptObject.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/JScript/Execute/ScriptObject.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ScriptObject.cs     14 Jan 2003 10:35:50 -0000      1.2
--- ScriptObject.cs     21 Jan 2003 22:11:49 -0000      1.3
***************
*** 23,26 ****
--- 23,27 ----
  
  using System;
+ using System.Collections;
  using System.Reflection;
  using System.Globalization;
***************
*** 436,444 ****
                        }
  
!       // Normalize this object to remove object wrappers.
!       internal virtual Object Normalize()
                        {
!                               // By default, no normalization is applied.
!                               return this;
                        }
  
--- 437,444 ----
                        }
  
!       // Get an enumerator for the properties in this object.
!       internal virtual IEnumerator GetPropertyEnumerator()
                        {
!                               return new NullEnumerator();
                        }
  

Index: WithScope.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/JScript/Execute/WithScope.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** WithScope.cs        17 Jan 2003 06:34:46 -0000      1.2
--- WithScope.cs        21 Jan 2003 22:11:49 -0000      1.3
***************
*** 98,101 ****
--- 98,108 ----
                                ((ScriptObject)withObject).Put(name, value);
                        }
+       void IVariableAccess.DeclareVariable(String name)
+                       {
+                               
if(!((ScriptObject)withObject).HasProperty(name))
+                               {
+                                       ((ScriptObject)withObject).Put(name, 
null);
+                               }
+                       }
        IVariableAccess IVariableAccess.GetParentScope()
                        {





reply via email to

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