Author: cesar
Date: 2005-03-30 20:40:49 -0500 (Wed, 30 Mar 2005)
New Revision: 42408
Modified:
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ArrayConstructor.cs
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ArrayObject.cs
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ArrayPrototype.cs
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/Convert.cs
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/Equality.cs
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/JSFieldInfo.cs
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/JSObject.cs
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/JScriptException.cs
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/LateBinding.cs
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ScriptObject.cs
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/TypeOf.cs
Log:
2005-03-30 Cesar Lopez Nataren <[EMAIL PROTECTED]>
* TypeOf.cs: take into account Objects.
* ArrayConstructor.cs: Implement CreateInstance.
* LateBinding.cs: Initial implementatio of CallValue and
SetIndexedPropertyValueStatic.
* JSFieldInfo.cs: Implement GetValue and SetValue.
* ArrayObject.cs: Implement length, add three ctrs.
* JScriptException.cs: Add error_number field. Implement
ctr. ErrorNumber, Message and StackTrace.
* ArrayPrototype.cs: Implement join and toString.
* JSObject.cs: Remove the ChainHash, we use a simple hashtable
now, the one inherited from ScriptObject.
* ScriptObject.cs: Add a Hashtable here.
Modified:
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ArrayConstructor.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ArrayConstructor.cs
2005-03-31 01:34:40 UTC (rev 42407)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ArrayConstructor.cs
2005-03-31 01:40:49 UTC (rev 42408)
@@ -4,6 +4,7 @@
// Author: Cesar Octavio Lopez Nataren
//
// (C) Cesar Octavio Lopez Nataren, <[EMAIL PROTECTED]>
+// (C) 2005, Novell Inc. (http://novell.com)
//
//
@@ -48,9 +49,14 @@
[JSFunctionAttribute (JSFunctionAttributeEnum.HasVarArgs)]
public new ArrayObject CreateInstance (params Object [] args)
{
- throw new NotImplementedException ();
+ if (args == null || args.Length == 0)
+ return new ArrayObject ();
+ else if (args.Length == 1)
+ return new ArrayObject (args [0]);
+ else
+ return new ArrayObject (args);
}
-
+
[JSFunctionAttribute (JSFunctionAttributeEnum.HasVarArgs)]
public ArrayObject Invoke (params Object [] args)
{
Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ArrayObject.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ArrayObject.cs
2005-03-31 01:34:40 UTC (rev 42407)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ArrayObject.cs
2005-03-31 01:40:49 UTC (rev 42408)
@@ -4,6 +4,7 @@
// Author: Cesar Octavio Lopez Nataren
//
// (C) 2003, Cesar Octavio Lopez Nataren, <[EMAIL PROTECTED]>
+// (C) 2005, Novell Inc, (http://novell.com)
//
//
@@ -28,14 +29,59 @@
//
using System;
-
+using System.Collections;
+
namespace Microsoft.JScript {
public class ArrayObject : JSObject {
- public virtual Object length {
- get { throw new NotImplementedException (); }
- set { throw new NotImplementedException (); }
+ private object _length;
+
+ public virtual object length {
+ get { return _length; }
+ set { _length = value; }
}
+
+ internal ArrayObject ()
+ {
+ length = 0;
+ }
+
+ internal ArrayObject (object o)
+ {
+ IConvertible ic = o as IConvertible;
+ TypeCode tc = ic.GetTypeCode ();
+
+ if (tc == TypeCode.Int32 || ic.ToDouble (null) <
Int32.MaxValue) {
+ int size = ic.ToInt32 (null);
+ if (size > 0)
+ length = o;
+ else
+ throw new JScriptException
(JSError.ArrayLengthConstructIncorrect);
+ } else {
+ elems = new Hashtable ();
+ elems.Add (o, o);
+ }
+ }
+
+ internal ArrayObject (params object [] args)
+ {
+ if (args != null) {
+ int size = args.Length;
+ length = (object) size;
+ elems = new Hashtable ();
+
+ int idx = 0;
+ foreach (object o in args) {
+ elems.Add (idx, o);
+ idx++;
+ }
+ } else
+ throw new Exception ("args can't be null");
+ }
+
+ internal Hashtable Elements {
+ get { return elems; }
+ }
}
-}
\ No newline at end of file
+}
Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ArrayPrototype.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ArrayPrototype.cs
2005-03-31 01:34:40 UTC (rev 42407)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ArrayPrototype.cs
2005-03-31 01:40:49 UTC (rev 42408)
@@ -5,6 +5,7 @@
// Cesar Lopez Nataren ([EMAIL PROTECTED])
//
// (C) 2003, Cesar Lopez Nataren
+// (C) 2005, Novell Inc, (http://novell.com)
//
//
@@ -29,6 +30,8 @@
//
using System;
+using System.Collections;
+using System.Text;
using Microsoft.JScript.Vsa;
namespace Microsoft.JScript {
@@ -50,7 +53,25 @@
[JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject,
JSBuiltin.Array_join)]
public static string join (object thisObj, object separator)
{
- throw new NotImplementedException ();
+ SemanticAnalyser.assert_type (thisObj, typeof
(ArrayObject));
+ ArrayObject array_obj = (ArrayObject) thisObj;
+
+ string _separator;
+ if (separator == null)
+ _separator = ",";
+ else
+ _separator = Convert.ToString (separator);
+
+ Hashtable elems = array_obj.Elements;
+ StringBuilder str = new StringBuilder ();
+ bool first = true;
+ foreach (DictionaryEntry entry in elems) {
+ if (!first)
+ str.Append (_separator);
+ first = false;
+ str.Append (Convert.ToString (entry.Value));
+ }
+ return str.ToString ();
}
[JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject,
JSBuiltin.Array_pop)]
@@ -107,7 +128,7 @@
[JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject,
JSBuiltin.Array_toString)]
public static string toString (object thisObj)
{
- throw new NotImplementedException ();
+ return ArrayPrototype.join (thisObj, null);
}
[JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject |
JSFunctionAttributeEnum.HasVarArgs, JSBuiltin.Array_unshift)]
Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
2005-03-31 01:34:40 UTC (rev 42407)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
2005-03-31 01:40:49 UTC (rev 42408)
@@ -1,3 +1,18 @@
+2005-03-30 Cesar Lopez Nataren <[EMAIL PROTECTED]>
+
+ * TypeOf.cs: take into account Objects.
+ * ArrayConstructor.cs: Implement CreateInstance.
+ * LateBinding.cs: Initial implementatio of CallValue and
+ SetIndexedPropertyValueStatic.
+ * JSFieldInfo.cs: Implement GetValue and SetValue.
+ * ArrayObject.cs: Implement length, add three ctrs.
+ * JScriptException.cs: Add error_number field. Implement
+ ctr. ErrorNumber, Message and StackTrace.
+ * ArrayPrototype.cs: Implement join and toString.
+ * JSObject.cs: Remove the ChainHash, we use a simple hashtable
+ now, the one inherited from ScriptObject.
+ * ScriptObject.cs: Add a Hashtable here.
+
2005-03-29 Cesar Lopez Nataren <[EMAIL PROTECTED]>
* GlobalScope.cs: Set parent and engine in ctr. Return 'this' for
Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/Convert.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/Convert.cs
2005-03-31 01:34:40 UTC (rev 42407)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/Convert.cs
2005-03-31 01:40:49 UTC (rev 42408)
@@ -5,6 +5,7 @@
// Cesar Lopez Nataren ([EMAIL PROTECTED])
//
// (C) 2003, Cesar Lopez Nataren
+// (C) 2005, Novell Inc, (http://novell.com)
//
//
@@ -178,8 +179,10 @@
return RegExpPrototype.toString (value);
else if (value is StringObject)
return StringPrototype.toString (value);
+ Console.WriteLine ("value.GetType = {0}",
value.GetType ());
throw new NotImplementedException ();
default:
+ Console.WriteLine ("tc = {0}", tc);
throw new NotImplementedException ();
}
}
Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/Equality.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/Equality.cs
2005-03-31 01:34:40 UTC (rev 42407)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/Equality.cs
2005-03-31 01:40:49 UTC (rev 42408)
@@ -5,6 +5,7 @@
// Cesar Lopez Nataren ([EMAIL PROTECTED])
//
// (C) 2003, 2004 Cesar Lopez Nataren
+// (C) 2005, Novell Inc, (http://novell.com)
//
//
@@ -83,10 +84,9 @@
Console.WriteLine ("Equality, tc1 = {0}, tc2 =
{1}", tc1, tc2);
break;
}
- throw new NotImplementedException ();
+ throw new Exception ("error: Not an equality operator");
}
-
public static bool JScriptEquals (object v1, object v2)
{
throw new NotImplementedException ();
Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/JSFieldInfo.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/JSFieldInfo.cs
2005-03-31 01:34:40 UTC (rev 42407)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/JSFieldInfo.cs
2005-03-31 01:40:49 UTC (rev 42408)
@@ -36,9 +36,10 @@
public sealed class JSFieldInfo : FieldInfo {
- FieldAttributes attr;
- string name;
-
+ private FieldAttributes attr;
+ private string name;
+ private object value;
+
internal JSFieldInfo (string name)
{
this.name = name;
@@ -78,7 +79,12 @@
public override object GetValue (object obj)
{
- throw new NotImplementedException ();
+ string str_name = Convert.ToString (obj);
+
+ if (str_name == name)
+ return value;
+ else
+ throw new NotImplementedException ();
}
@@ -105,7 +111,11 @@
public new void SetValue (object obj, object value)
{
- throw new NotImplementedException ();
+ string str_name = Convert.ToString (obj);
+ if (str_name == name)
+ this.value = value;
+ else
+ throw new NotImplementedException ();
}
Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/JSObject.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/JSObject.cs
2005-03-31 01:34:40 UTC (rev 42407)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/JSObject.cs
2005-03-31 01:40:49 UTC (rev 42408)
@@ -4,6 +4,7 @@
// Author: Cesar Octavio Lopez Nataren
//
// (C) 2003, Cesar Octavio Lopez Nataren, <[EMAIL PROTECTED]>
+// (C) 2005, Novell Inc, (http://novell.com)
//
//
@@ -36,39 +37,48 @@
public class JSObject : ScriptObject, IEnumerable, IExpando {
- ChainHash ext;
-
public JSObject ()
- {
- ext = new ChainHash (10);
+ {
+ elems = new Hashtable ();
}
public FieldInfo AddField (string name)
{
JSFieldInfo fi = new JSFieldInfo (name);
- ext.Insert (name, fi);
+ elems.Add (name, fi);
return fi;
}
+ internal JSFieldInfo GetField (string name)
+ {
+ object res = elems [name];
+
+ if (res == null)
+ throw new Exception ("JSObject.GetField: search
somewhere else");
+ if (res is JSFieldInfo)
+ return (JSFieldInfo) res;
+ return null;
+ }
+
IEnumerator IEnumerable.GetEnumerator()
{
- return ext.GetEnumerator ();
+ return elems.GetEnumerator ();
}
PropertyInfo IExpando.AddProperty (string name)
{
JSPropertyInfo pi = new JSPropertyInfo (name);
- ext.Insert (name, pi);
+ elems.Add (name, pi);
return pi;
}
MethodInfo IExpando.AddMethod (String name, Delegate method)
{
JSMethodInfo minfo = new JSMethodInfo (name,
method.Method);
- ext.Insert (name, minfo);
+ elems.Add (name, minfo);
return minfo;
}
-
+
public override MemberInfo [] GetMember (string name,
BindingFlags bindFlags)
{
throw new NotImplementedException ();
@@ -77,7 +87,7 @@
public override MemberInfo [] GetMembers (BindingFlags
bindFlags)
{
MemberInfo [] members;
- IEnumerator enumerator = ext.GetEnumerator ();
+ IEnumerator enumerator = elems.GetEnumerator ();
ArrayList tmp = new ArrayList ();
while (enumerator.MoveNext ())
@@ -95,7 +105,7 @@
void IExpando.RemoveMember (MemberInfo m)
{
- ext.Delete (m);
+ elems.Remove (m);
}
public override string ToString ()
@@ -106,10 +116,29 @@
internal string ClassName {
get {
if (this is ObjectPrototype)
- return "Object";
+ return "Object";
else
throw new NotImplementedException ();
}
}
+
+ internal void AddField (object name, object value)
+ {
+ string str_name = Convert.ToString (name);
+
+ if (proper_array_index (str_name)) {
+ JSFieldInfo field = (JSFieldInfo) AddField
(str_name);
+ field.SetValue (str_name, value);
+ } else
+ throw new Exception ("Not a valid index array");
+ }
+
+ //
+ // FIXME:
+ //
+ private bool proper_array_index (object name)
+ {
+ return true;
+ }
}
}
Modified:
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/JScriptException.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/JScriptException.cs
2005-03-31 01:34:40 UTC (rev 42407)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/JScriptException.cs
2005-03-31 01:40:49 UTC (rev 42408)
@@ -5,6 +5,7 @@
// Cesar Lopez Nataren ([EMAIL PROTECTED])
//
// (C) 2003, Cesar Lopez Nataren
+// (C) 2005, Novell Inc, (http://novell.com)
//
//
@@ -35,11 +36,13 @@
namespace Microsoft.JScript {
[Serializable]
- public class JScriptException : ApplicationException, IVsaError
- {
+ public class JScriptException : ApplicationException, IVsaError {
+
+ private JSError error_number;
+
public JScriptException (JSError errorNumber)
{
- throw new NotImplementedException ();
+ error_number = errorNumber;
}
@@ -79,7 +82,7 @@
public int ErrorNumber {
- get { throw new NotImplementedException (); }
+ get { return (int) error_number; }
}
@@ -100,7 +103,12 @@
public override string Message {
- get { throw new NotImplementedException (); }
+ get {
+ if (error_number ==
JSError.ArrayLengthConstructIncorrect)
+ return "Array length must be zero or a
positive integer";
+ else
+ throw new NotImplementedException ();
+ }
}
@@ -115,7 +123,9 @@
public override string StackTrace {
- get { throw new NotImplementedException (); }
+ get {
+ return base.StackTrace;
+ }
}
}
Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/LateBinding.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/LateBinding.cs
2005-03-31 01:34:40 UTC (rev 42407)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/LateBinding.cs
2005-03-31 01:40:49 UTC (rev 42408)
@@ -5,6 +5,7 @@
// Cesar Lopez Nataren ([EMAIL PROTECTED])
//
// (C) 2003, Cesar Lopez Nataren
+// (C) 2005, Novell Inc, (http://novell.com)
//
//
@@ -29,13 +30,15 @@
//
using System;
+using System.Reflection;
using Microsoft.JScript.Vsa;
namespace Microsoft.JScript {
- public sealed class LateBinding
- {
+ public sealed class LateBinding {
+
public object obj;
+ private static BindingFlags bind_flags = BindingFlags.Public;
public LateBinding (string name)
{
@@ -59,7 +62,25 @@
public static object CallValue (object thisObj, object val,
object [] arguments,
bool construct, bool brackets,
VsaEngine engine)
{
- throw new NotImplementedException ();
+ if (construct) {
+ if (brackets) {
+ return null;
+ }
+ return null;
+ } else if (brackets) {
+ if (!(val is JSObject))
+ throw new Exception ("val has to be a
JSObject");
+
+ JSObject js_val = (JSObject) val;
+ object res = js_val.GetField (Convert.ToString
(arguments [0]));
+ if (res is JSFieldInfo)
+ return ((JSFieldInfo) res).GetValue
(arguments [0]);
+ else
+ throw new NotImplementedException ();
+ } else {
+ return null;
+ }
+ return null;
}
@@ -97,7 +118,12 @@
public static void SetIndexedPropertyValueStatic (object obj,
object [] arguments,
object value)
{
- throw new NotImplementedException ();
+ if (!(obj is JSObject))
+ throw new Exception ("obj should be a
JSObject");
+
+ JSObject js_obj = (JSObject) obj;
+ foreach (object o in arguments)
+ js_obj.AddField (o, value);
}
Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ScriptObject.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ScriptObject.cs
2005-03-31 01:34:40 UTC (rev 42407)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ScriptObject.cs
2005-03-31 01:40:49 UTC (rev 42408)
@@ -4,6 +4,7 @@
// Author: Cesar Octavio Lopez Nataren
//
// (C) 2003, Cesar Octavio Lopez Nataren, <[EMAIL PROTECTED]>
+// (C) 2005, Novell Inc, (http://novell.com)
//
//
@@ -28,8 +29,9 @@
//
using System;
+using System.Reflection;
+using System.Collections;
using System.Globalization;
-using System.Reflection;
using Microsoft.JScript.Vsa;
namespace Microsoft.JScript {
@@ -38,6 +40,7 @@
public VsaEngine engine;
protected GlobalScope parent;
+ internal Hashtable elems;
public FieldInfo GetField (string name, BindingFlags bindFlags)
{
Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/TypeOf.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/TypeOf.cs
2005-03-31 01:34:40 UTC (rev 42407)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/TypeOf.cs
2005-03-31 01:40:49 UTC (rev 42408)
@@ -47,6 +47,9 @@
case TypeCode.String:
return "string";
+ case TypeCode.Object:
+ return "object";
+
default:
Console.WriteLine ("TypeOf, tc = {0}", tc);
break;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches