[Top][All Lists]
[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,1.2,1.3 ArrayObject.cs,1.2,1.3 |
Date: |
Thu, 06 Mar 2003 22:52:51 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/JScript/Builtins
In directory subversions:/tmp/cvs-serv17338/JScript/Builtins
Modified Files:
ArrayConstructor.cs ArrayObject.cs
Log Message:
Implement parts of the JScript "Array" class.
Index: ArrayConstructor.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/JScript/Builtins/ArrayConstructor.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ArrayConstructor.cs 7 Mar 2003 01:08:35 -0000 1.2
--- ArrayConstructor.cs 7 Mar 2003 03:52:46 -0000 1.3
***************
*** 36,41 ****
public ArrayObject ConstructArray(Object[] args)
{
! // TODO
! return null;
}
--- 36,49 ----
public ArrayObject ConstructArray(Object[] args)
{
! ArrayObject obj = new ArrayObject
!
(EngineInstance.GetEngineInstance(engine)
! .GetArrayPrototype());
! int index, len;
! len = args.Length;
! for(index = 0; index < len; ++index)
! {
! obj.PutIndex(index, args[index]);
! }
! return obj;
}
***************
*** 44,49 ****
public new ArrayObject CreateInstance(params Object[] args)
{
! // TODO
! return null;
}
--- 52,56 ----
public new ArrayObject CreateInstance(params Object[] args)
{
! return (ArrayObject)Construct(engine, args);
}
***************
*** 52,64 ****
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);
! }
}
--- 59,63 ----
public ArrayObject Invoke(params Object[] args)
{
! return (ArrayObject)Construct(engine, args);
}
***************
*** 67,71 ****
(VsaEngine engine, Object thisob, Object[] args)
{
! return Invoke(args);
}
--- 66,70 ----
(VsaEngine engine, Object thisob, Object[] args)
{
! return Construct(engine, args);
}
***************
*** 73,77 ****
internal override Object Construct(VsaEngine engine, Object[] args)
{
! return CreateInstance(args);
}
--- 72,143 ----
internal override Object Construct(VsaEngine engine, Object[] args)
{
! ArrayObject obj;
! int index, len;
! if(args.Length != 1)
! {
! // Construct an array from a list of
values.
! obj = new ArrayObject
!
(EngineInstance.GetEngineInstance(engine)
!
.GetArrayPrototype(), (uint)(args.Length));
! len = args.Length;
! for(index = 0; index < len; ++index)
! {
! obj.PutIndex(index,
args[index]);
! }
! }
! else if(args[0] is Array)
! {
! // Wrap an existing array.
! Array array = (Array)(args[0]);
! if(array.Rank != 1)
! {
! throw new
JScriptException(JSError.TypeMismatch);
! }
! obj = new ArrayObject.Wrapper
!
(EngineInstance.GetEngineInstance(engine)
!
.GetArrayPrototype(), (Array)(args[0]));
! }
! else
! {
! // Construct an array from a length
value.
!
switch(Support.TypeCodeForObject(args[0]))
! {
! case TypeCode.Byte:
! case TypeCode.SByte:
! case TypeCode.Char:
! 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:
! {
! double num =
Convert.ToNumber(args[0]);
! uint inum =
Convert.ToUInt32(args[0]);
! if(num == (double)inum)
! {
! return new
ArrayObject
!
(EngineInstance.GetEngineInstance(engine)
!
.GetArrayPrototype(), inum);
! }
! else
! {
! throw new
JScriptException
!
(JSError.ArrayLengthConstructIncorrect);
! }
! }
! // Not reached.
! }
!
! // The length is not numeric, so it is
actually a value.
! obj = new ArrayObject
!
(EngineInstance.GetEngineInstance(engine)
!
.GetArrayPrototype());
! obj.PutIndex(0, args[0]);
! }
! return obj;
}
Index: ArrayObject.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/JScript/Builtins/ArrayObject.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ArrayObject.cs 21 Jan 2003 22:11:49 -0000 1.2
--- ArrayObject.cs 7 Mar 2003 03:52:46 -0000 1.3
***************
*** 28,34 ****
{
// Internal state.
! private Object[] array;
! private uint arrayLen;
! private bool isSparse;
// Constructor.
--- 28,33 ----
{
// Internal state.
! internal Array array;
! internal uint arrayLen;
// Constructor.
***************
*** 38,42 ****
array = null;
arrayLen = 0;
! isSparse = false;
}
--- 37,46 ----
array = null;
arrayLen = 0;
! }
! internal ArrayObject(ScriptObject prototype, uint len)
! : base(prototype)
! {
! array = null;
! arrayLen = len;
}
***************
*** 57,61 ****
set
{
! // TODO
}
}
--- 61,86 ----
set
{
! double num = Convert.ToNumber(value);
! uint inum = Convert.ToUInt32(value);
! if(num != (double)inum)
! {
! throw new JScriptException
!
(JSError.ArrayLengthAssignIncorrect);
! }
! if(array != null && inum < arrayLen &&
! inum < (uint)(array.Length))
! {
! if(arrayLen <
(uint)(array.Length))
! {
! Array.Clear(array,
(int)inum,
!
(int)(arrayLen - inum));
! }
! else
! {
! Array.Clear(array,
(int)inum,
!
array.Length - (int)inum);
! }
! }
! arrayLen = inum;
}
}
***************
*** 79,83 ****
else
{
! return base.Get(name);
}
}
--- 104,122 ----
else
{
! double num = Convert.ToNumber(name);
! uint inum = Convert.ToUInt32(name);
! if(num != (double)inum)
! {
! return base.Get(name);
! }
! else if(inum < arrayLen && array !=
null &&
! inum <
(uint)(array.Length))
! {
! return
array.GetValue((int)inum);
! }
! else
! {
! return null;
! }
}
}
***************
*** 86,92 ****
internal override Object GetIndex(int index)
{
! if(!isSparse && index >= 0 && ((uint)index) <
arrayLen)
{
! return array[index];
}
else
--- 125,132 ----
internal override Object GetIndex(int index)
{
! if(index >= 0 && ((uint)index) < arrayLen &&
! array != null && index < array.Length)
{
! return array.GetValue(index);
}
else
***************
*** 103,107 ****
length = value;
}
! else
{
// TODO
--- 143,147 ----
length = value;
}
! else if(CanPut(name))
{
// TODO
***************
*** 142,145 ****
--- 182,257 ----
return null;
}
+
+ // Wrapper class for wrapping up a native array.
+ internal sealed class Wrapper : ArrayObject
+ {
+ // Constructor.
+ public Wrapper(ScriptObject prototype, Array array)
+ : base(prototype, (uint)(array.Length))
+ {
+ this.array = array;
+ }
+
+ // Get or set the length of the array.
+ public override Object length
+ {
+ get
+ {
+ return array.Length;
+ }
+ set
+ {
+ throw new JScriptException
+
(JSError.AssignmentToReadOnly);
+ }
+ }
+
+ // Get a property from this object by numeric index.
+ internal override Object GetIndex(int index)
+ {
+ if(index >= 0 && index < array.Length)
+ {
+ return array.GetValue(index);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ // Put a property to this object.
+ internal override void Put(String name, Object value)
+ {
+ if(name == "length")
+ {
+ length = value;
+ }
+ else if(CanPut(name))
+ {
+ double num =
Convert.ToNumber(name);
+ uint inum =
Convert.ToUInt32(name);
+ if(num != (double)inum)
+ {
+ // Force an array index
exception.
+ inum =
(uint)(array.Length);
+ }
+ array.SetValue(value,
(int)inum);
+ }
+ }
+
+ // Put a property to this object by numeric index.
+ internal override void PutIndex(int index, Object value)
+ {
+ array.SetValue(value, index);
+ }
+
+ // Delete a property from this object.
+ internal override bool Delete(String name)
+ {
+ // Deletions are not allowed on native
arrays.
+ return false;
+ }
+
+ }; // class Wrapper
}; // class ArrayObject
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/JScript/Builtins ArrayConstructor.cs,1.2,1.3 ArrayObject.cs,1.2,1.3,
Rhys Weatherley <address@hidden> <=