Pārlūkot izejas kodu

Defining more standard properties

Sebastien Ros 12 gadi atpakaļ
vecāks
revīzija
5ec68fd7fb

+ 7 - 1
Jint/Native/Array/ArrayConstructor.cs

@@ -2,6 +2,7 @@
 using Jint.Native.Function;
 using Jint.Native.Object;
 using Jint.Runtime;
+using Jint.Runtime.Interop;
 
 namespace Jint.Native.Array
 {
@@ -32,7 +33,12 @@ namespace Jint.Native.Array
 
         public void Configure()
         {
-            
+            FastAddProperty("isArray", new ClrFunctionInstance<object, object>(Engine, IsArray), false, false, false);
+        }
+
+        private object IsArray(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
         }
 
         public override object Call(object thisObject, object[] arguments)

+ 129 - 16
Jint/Native/Array/ArrayPrototype.cs

@@ -1,11 +1,12 @@
-using Jint.Native.Object;
+using System;
+using Jint.Native.Object;
 using Jint.Runtime;
 using Jint.Runtime.Interop;
 
 namespace Jint.Native.Array
 {
     /// <summary>
-    /// http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4
+    ///     http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4
     /// </summary>
     public sealed class ArrayPrototype : ObjectInstance
     {
@@ -15,7 +16,7 @@ namespace Jint.Native.Array
 
         public static ArrayPrototype CreatePrototypeObject(Engine engine, ArrayConstructor arrayConstructor)
         {
-            var obj = new ArrayPrototype(engine) { Extensible = true };
+            var obj = new ArrayPrototype(engine) {Extensible = true};
 
             obj.FastAddProperty("constructor", arrayConstructor, false, false, false);
 
@@ -24,18 +25,130 @@ namespace Jint.Native.Array
 
         public void Configure()
         {
-            // Array prototype functions
-            FastAddProperty("push", new ClrFunctionInstance<ArrayInstance, object>(Engine, Push), false, false, false);
+            FastAddProperty("toString", new ClrFunctionInstance<object, object>(Engine, ToArrayString), false, false, false);
+            FastAddProperty("toLocaleString", new ClrFunctionInstance<object, object>(Engine, ToLocaleString), false, false, false);
+            FastAddProperty("concat", new ClrFunctionInstance<object, object>(Engine, Concat), false, false, false);
+            FastAddProperty("join", new ClrFunctionInstance<object, object>(Engine, Join), false, false, false);
             FastAddProperty("pop", new ClrFunctionInstance<ArrayInstance, object>(Engine, Pop), false, false, false);
+            FastAddProperty("push", new ClrFunctionInstance<ArrayInstance, object>(Engine, Push), false, false, false);
+            FastAddProperty("reverse", new ClrFunctionInstance<object, object>(Engine, Reverse), false, false, false);
+            FastAddProperty("shift", new ClrFunctionInstance<ArrayInstance, object>(Engine, Shift), false, false, false);
+            FastAddProperty("slice", new ClrFunctionInstance<ArrayInstance, object>(Engine, Slice), false, false, false);
+            FastAddProperty("sort", new ClrFunctionInstance<ArrayInstance, object>(Engine, Sort), false, false, false);
+            FastAddProperty("splice", new ClrFunctionInstance<ArrayInstance, object>(Engine, Splice), false, false, false);
+            FastAddProperty("unshift", new ClrFunctionInstance<ArrayInstance, object>(Engine, Unshift), false, false, false);
+            FastAddProperty("indexOf", new ClrFunctionInstance<ArrayInstance, object>(Engine, IndexOf), false, false, false);
+            FastAddProperty("lastIndexOf", new ClrFunctionInstance<ArrayInstance, object>(Engine, LastIndexOf), false, false, false);
+            FastAddProperty("every", new ClrFunctionInstance<ArrayInstance, object>(Engine, Every), false, false, false);
+            FastAddProperty("some", new ClrFunctionInstance<ArrayInstance, object>(Engine, Some), false, false, false);
+            FastAddProperty("forEach", new ClrFunctionInstance<ArrayInstance, object>(Engine, ForEach), false, false, false);
+            FastAddProperty("map", new ClrFunctionInstance<ArrayInstance, object>(Engine, Map), false, false, false);
+            FastAddProperty("filter", new ClrFunctionInstance<ArrayInstance, object>(Engine, Filter), false, false, false);
+            FastAddProperty("reduce", new ClrFunctionInstance<ArrayInstance, object>(Engine, Reduce), false, false, false);
+            FastAddProperty("reduceRight", new ClrFunctionInstance<ArrayInstance, object>(Engine, ReduceRight), false, false, false);
+        }
+
+        private object LastIndexOf(ArrayInstance arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object Reduce(ArrayInstance arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object Filter(ArrayInstance arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object Map(ArrayInstance arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object ForEach(ArrayInstance arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object Some(ArrayInstance arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object Every(ArrayInstance arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object IndexOf(ArrayInstance arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object Splice(ArrayInstance arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object Unshift(ArrayInstance arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object Sort(ArrayInstance arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object Slice(ArrayInstance arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object Shift(ArrayInstance arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object Reverse(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object Join(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object ToLocaleString(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object Concat(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object ToArrayString(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object ReduceRight(ArrayInstance arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
         }
-            
 
         public object Push(object thisObject, object[] arguments)
         {
-            var o = TypeConverter.ToObject(Engine, thisObject);
-            var lenVal = o.Get("length");
-            var n = TypeConverter.ToUint32(lenVal);
-            foreach (var e in arguments)
+            ObjectInstance o = TypeConverter.ToObject(Engine, thisObject);
+            object lenVal = o.Get("length");
+            uint n = TypeConverter.ToUint32(lenVal);
+            foreach (object e in arguments)
             {
                 o.Put(TypeConverter.ToString(n), e, true);
                 n++;
@@ -47,9 +160,9 @@ namespace Jint.Native.Array
 
         public object Pop(object thisObject, object[] arguments)
         {
-            var o = TypeConverter.ToObject(Engine, thisObject);
-            var lenVal = o.Get("length");
-            var len = TypeConverter.ToUint32(lenVal);
+            ObjectInstance o = TypeConverter.ToObject(Engine, thisObject);
+            object lenVal = o.Get("length");
+            uint len = TypeConverter.ToUint32(lenVal);
             if (len == 0)
             {
                 o.Put("length", 0, true);
@@ -57,12 +170,12 @@ namespace Jint.Native.Array
             }
             else
             {
-                var indx = TypeConverter.ToString(len - 1);
-                var element = o.Get(indx);
+                string indx = TypeConverter.ToString(len - 1);
+                object element = o.Get(indx);
                 o.Delete(indx, true);
                 o.Put("length", indx, true);
                 return element;
             }
         }
     }
-}
+}

+ 17 - 4
Jint/Native/Boolean/BooleanPrototype.cs

@@ -1,7 +1,10 @@
-namespace Jint.Native.Boolean
+using System;
+using Jint.Runtime.Interop;
+
+namespace Jint.Native.Boolean
 {
     /// <summary>
-    /// http://www.ecma-international.org/ecma-262/5.1/#sec-15.6.4
+    ///     http://www.ecma-international.org/ecma-262/5.1/#sec-15.6.4
     /// </summary>
     public sealed class BooleanPrototype : BooleanInstance
     {
@@ -22,8 +25,18 @@
 
         public void Configure()
         {
-            
+            FastAddProperty("toString", new ClrFunctionInstance<object, object>(Engine, ToBooleanString), false, false, false);
+            FastAddProperty("valueOf", new ClrFunctionInstance<object, object>(Engine, ValueOf), false, false, false);
+        }
+
+        private object ValueOf(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
         }
 
+        private object ToBooleanString(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
     }
-}
+}

+ 1 - 1
Jint/Native/Date/DateConstructor.cs

@@ -22,7 +22,7 @@ namespace Jint.Native.Date
 
             obj.FastAddProperty("length", 1, false, false, false);
 
-            // The initial value of Date.prototype is the Boolean prototype object
+            // The initial value of Date.prototype is the Date prototype object
             obj.FastAddProperty("prototype", obj.PrototypeObject, false, false, false);
 
             return obj;

+ 22 - 9
Jint/Native/Function/FunctionPrototype.cs

@@ -7,11 +7,11 @@ using Jint.Runtime.Interop;
 namespace Jint.Native.Function
 {
     /// <summary>
-    /// http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.4
+    ///     http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.4
     /// </summary>
     public sealed class FunctionPrototype : FunctionInstance
     {
-        private FunctionPrototype(Engine engine):base(engine, null, null, false)
+        private FunctionPrototype(Engine engine) : base(engine, null, null, false)
         {
         }
 
@@ -29,7 +29,20 @@ namespace Jint.Native.Function
 
         public void Configure()
         {
+            FastAddProperty("toString", new ClrFunctionInstance<object, object>(Engine, ToFunctionString), false, false, false);
             FastAddProperty("apply", new ClrFunctionInstance<object, object>(Engine, Apply), false, false, false);
+            FastAddProperty("call", new ClrFunctionInstance<object, object>(Engine, Call), false, false, false);
+            FastAddProperty("bind", new ClrFunctionInstance<object, object>(Engine, Bind), false, false, false);
+        }
+
+        private object Bind(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+
+        private object ToFunctionString(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
         }
 
         public object Apply(object thisObject, object[] arguments)
@@ -40,8 +53,8 @@ namespace Jint.Native.Function
             }
 
             var func = thisObject as ICallable;
-            var thisArg = arguments[0];
-            var argArray = arguments[1];
+            object thisArg = arguments[0];
+            object argArray = arguments[1];
 
             if (func == null)
             {
@@ -59,13 +72,13 @@ namespace Jint.Native.Function
                 throw new JavaScriptException(Engine.TypeError);
             }
 
-            var len = argArrayObj.Get("length");
-            var n = TypeConverter.ToUint32(len);
+            object len = argArrayObj.Get("length");
+            uint n = TypeConverter.ToUint32(len);
             var argList = new List<object>();
-            for (var index = 0; index < n; index++)
+            for (int index = 0; index < n; index++)
             {
-                var indexName = index.ToString();
-                var nextArg = argArrayObj.Get(indexName);
+                string indexName = index.ToString();
+                object nextArg = argArrayObj.Get(indexName);
                 argList.Add(nextArg);
             }
             return func.Call(thisArg, argList.ToArray());

+ 22 - 1
Jint/Native/Object/ObjectPrototype.cs

@@ -1,4 +1,5 @@
-using Jint.Runtime;
+using System;
+using Jint.Runtime;
 using Jint.Runtime.Descriptors;
 using Jint.Runtime.Interop;
 
@@ -22,7 +23,27 @@ namespace Jint.Native.Object
         public void Configure()
         {
             FastAddProperty("toString", new ClrFunctionInstance<object, string>(Engine, ToString), false, false, false);
+            FastAddProperty("toLocaleString", new ClrFunctionInstance<object, string>(Engine, ToLocaleString), false, false, false);
+            FastAddProperty("valueOf", new ClrFunctionInstance<object, object>(Engine, ValueOf), false, false, false);
             FastAddProperty("hasOwnProperty", new ClrFunctionInstance<object, bool>(Engine, HasOwnProperty), false, false, false);
+            FastAddProperty("isPrototypeOf", new ClrFunctionInstance<object, bool>(Engine, IsPrototypeOf), false, false, false);
+            FastAddProperty("propertyIsEnumerable", new ClrFunctionInstance<object, bool>(Engine, PropertyIsEnumerable), false, false, false);
+        }
+        private bool PropertyIsEnumerable(object thisObject, object[] arguments)
+        {
+            throw new NotImplementedException();
+        }
+        private object ValueOf(object thisObject, object[] arguments)
+        {
+            throw new NotImplementedException();
+        }
+        private bool IsPrototypeOf(object thisObject, object[] arguments)
+        {
+            throw new NotImplementedException();
+        }
+        private string ToLocaleString(object thisObject, object[] arguments)
+        {
+            throw new NotImplementedException();
         }
 
         /// <summary>

+ 99 - 2
Jint/Native/String/StringPrototype.cs

@@ -1,4 +1,7 @@
-namespace Jint.Native.String
+using System;
+using Jint.Runtime.Interop;
+
+namespace Jint.Native.String
 {
     /// <summary>
     /// http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4
@@ -23,7 +26,101 @@
 
         public void Configure()
         {
-
+            FastAddProperty("toString", new ClrFunctionInstance<object, object>(Engine, ToStringString), false, false, false);
+            FastAddProperty("valueOf", new ClrFunctionInstance<object, object>(Engine, ValueOf), false, false, false);
+            FastAddProperty("charAt", new ClrFunctionInstance<object, object>(Engine, CharAt), false, false, false);
+            FastAddProperty("charCodeAt", new ClrFunctionInstance<object, object>(Engine, CharCodeAt), false, false, false);
+            FastAddProperty("concat", new ClrFunctionInstance<object, object>(Engine, Concat), false, false, false);
+            FastAddProperty("indexOf", new ClrFunctionInstance<object, object>(Engine, IndexOf), false, false, false);
+            FastAddProperty("lastIndexOf", new ClrFunctionInstance<object, object>(Engine, LastIndexOf), false, false, false);
+            FastAddProperty("localeCompare", new ClrFunctionInstance<object, object>(Engine, LocaleCompare), false, false, false);
+            FastAddProperty("match", new ClrFunctionInstance<object, object>(Engine, Match), false, false, false);
+            FastAddProperty("replace", new ClrFunctionInstance<object, object>(Engine, Replace), false, false, false);
+            FastAddProperty("search", new ClrFunctionInstance<object, object>(Engine, Search), false, false, false);
+            FastAddProperty("slice", new ClrFunctionInstance<object, object>(Engine, Slice), false, false, false);
+            FastAddProperty("split", new ClrFunctionInstance<object, object>(Engine, Split), false, false, false);
+            FastAddProperty("substring", new ClrFunctionInstance<object, object>(Engine, Substring), false, false, false);
+            FastAddProperty("toLowerCase", new ClrFunctionInstance<object, object>(Engine, ToLowerCase), false, false, false);
+            FastAddProperty("toLocaleLowerCase", new ClrFunctionInstance<object, object>(Engine, ToLocaleLowerCase), false, false, false);
+            FastAddProperty("toUpperCase", new ClrFunctionInstance<object, object>(Engine, ToUpperCase), false, false, false);
+            FastAddProperty("toLocaleUpperCase", new ClrFunctionInstance<object, object>(Engine, ToLocaleUpperCase), false, false, false);
+            FastAddProperty("trim", new ClrFunctionInstance<object, object>(Engine, Trim), false, false, false);
+        }
+        private object Trim(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object ToLocaleUpperCase(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object ToUpperCase(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object ToLocaleLowerCase(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object ToLowerCase(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object Substring(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object Split(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object Slice(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object Search(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object Replace(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object Match(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object LocaleCompare(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object LastIndexOf(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object IndexOf(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object Concat(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object CharCodeAt(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object CharAt(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object ValueOf(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
+        }
+        private object ToStringString(object arg1, object[] arg2)
+        {
+            throw new NotImplementedException();
         }
     }
 }