Sfoglia il codice sorgente

Splitting configuration in another step

Sebastien Ros 12 anni fa
parent
commit
01ae03bfdf

+ 42 - 20
Jint/Engine.cs

@@ -37,10 +37,13 @@ namespace Jint
         {
             _executionContexts = new Stack<ExecutionContext>();
 
-            Object = ObjectConstructor.CreateObjectConstructor(this);
-
             Global = GlobalObject.CreateGlobalObject(this);
+
+            Object = ObjectConstructor.CreateObjectConstructor(this);
             Function = FunctionConstructor.CreateFunctionConstructor(this);
+
+            
+
             Array = ArrayConstructor.CreateArrayConstructor(this);
             String = StringConstructor.CreateStringConstructor(this);
             Number = NumberConstructor.CreateNumberConstructor(this);
@@ -57,23 +60,42 @@ namespace Jint
             TypeError = ErrorConstructor.CreateErrorConstructor(this, "TypeError");
             UriError = ErrorConstructor.CreateErrorConstructor(this, "URIError");
 
-            Global.FastAddProperty("Object", Object, true, false, true);
-            Global.FastAddProperty("Function", Function, true, false, true);
-            Global.FastAddProperty("Array", Array, true, false, true);
-            Global.FastAddProperty("String", String, true, false, true);
-            Global.FastAddProperty("Number", Number, true, false, true);
-            Global.FastAddProperty("Boolean", Boolean, true, false, true);
-            Global.FastAddProperty("Date", Date, true, false, true);
-            Global.FastAddProperty("Math", Math, true, false, true);
-            Global.FastAddProperty("JSON", Json, true, false, true);
-
-            Global.FastAddProperty("Error", Error, true, false, true);
-            Global.FastAddProperty("EvalError", EvalError, true, false, true);
-            Global.FastAddProperty("RangeError", RangeError, true, false, true);
-            Global.FastAddProperty("ReferenceError", ReferenceError, true, false, true);
-            Global.FastAddProperty("SyntaxError", SyntaxError, true, false, true);
-            Global.FastAddProperty("TypeError", TypeError, true, false, true);
-            Global.FastAddProperty("URIError", UriError, true, false, true);
+            // Because the properties might need some of the built-in object
+            // their configuration is delayed to a later step
+
+            Global.Configure();
+
+            Object.Configure();
+            Object.PrototypeObject.Configure();
+
+            Function.Configure();
+            Function.PrototypeObject.Configure();
+
+            Array.Configure();
+            Array.PrototypeObject.Configure();
+
+            String.Configure();
+            String.PrototypeObject.Configure();
+
+            Number.Configure();
+            Number.PrototypeObject.Configure();
+
+            Boolean.Configure();
+            Boolean.PrototypeObject.Configure();
+
+            Date.Configure();
+            Date.PrototypeObject.Configure();
+
+            Math.Configure();
+            Json.Configure();
+
+            Error.Configure();
+            EvalError.Configure();
+            RangeError.Configure();
+            ReferenceError.Configure();
+            SyntaxError.Configure();
+            TypeError.Configure();
+            UriError.Configure();
 
             // create the global environment http://www.ecma-international.org/ecma-262/5.1/#sec-10.2.3
             GlobalEnvironment = LexicalEnvironment.NewObjectEnvironment(this, Global, null, true);
@@ -105,7 +127,7 @@ namespace Jint
 
         public LexicalEnvironment GlobalEnvironment;
 
-        public ObjectInstance Global { get; private set; }
+        public GlobalObject Global { get; private set; }
         public ObjectConstructor Object { get; private set; }
         public FunctionConstructor Function { get; private set; }
         public ArrayConstructor Array { get; private set; }

+ 3 - 9
Jint/Native/Argument/ArgumentsObject.cs

@@ -24,7 +24,7 @@ namespace Jint.Native.Argument
             var len = args.Length;
             var obj = new ArgumentsInstance(engine);
             obj.Prototype = engine.Object.PrototypeObject;
-            obj.DefineOwnProperty("length", new DataDescriptor(len) { Writable = true, Enumerable = false, Configurable = true }, false);
+            obj.FastAddProperty("length", len, true, false, true);
             var map = engine.Object.Construct(Arguments.Empty);
             var mappedNamed = new List<string>();
             var indx = len - 1;
@@ -32,7 +32,7 @@ namespace Jint.Native.Argument
             {
                 var indxStr = TypeConverter.ToString(indx);
                 var val = args[indx];
-                obj.DefineOwnProperty(indxStr, new DataDescriptor(val) { Writable = true, Enumerable = false, Configurable = true }, false);
+                obj.FastAddProperty(indxStr, val, true, true, true);
                 if (indx < names.Length)
                 {
                     var name = names[indx];
@@ -53,13 +53,7 @@ namespace Jint.Native.Argument
             }
             if (!strict)
             {
-                obj.DefineOwnProperty("callee",
-                                      new DataDescriptor(func)
-                                      {
-                                          Writable = true,
-                                          Enumerable = false,
-                                          Configurable = false
-                                      }, false);
+                obj.FastAddProperty("callee",func, true, false, true);
             }
             else
             {

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

@@ -11,7 +11,7 @@ namespace Jint.Native.Array
         {
         }
 
-        public ObjectInstance PrototypeObject { get; private set; }
+        public ArrayPrototype PrototypeObject { get; private set; }
 
         public static ArrayConstructor CreateArrayConstructor(Engine engine)
         {
@@ -30,6 +30,11 @@ namespace Jint.Native.Array
             return obj;
         }
 
+        public void Configure()
+        {
+            
+        }
+
         public override object Call(object thisObject, object[] arguments)
         {
             return Construct(arguments);

+ 7 - 4
Jint/Native/Array/ArrayPrototype.cs

@@ -19,13 +19,16 @@ namespace Jint.Native.Array
 
             obj.FastAddProperty("constructor", arrayConstructor, false, false, false);
 
-            // Array prototype functions
-            obj.FastAddProperty("push", new ClrFunctionInstance<ArrayInstance, object>(engine, obj.Push), false, false, false);
-            obj.FastAddProperty("pop", new ClrFunctionInstance<ArrayInstance, object>(engine, obj.Pop), false, false, false);
-
             return obj;
         }
 
+        public void Configure()
+        {
+            // Array prototype functions
+            FastAddProperty("push", new ClrFunctionInstance<ArrayInstance, object>(Engine, Push), false, false, false);
+            FastAddProperty("pop", new ClrFunctionInstance<ArrayInstance, object>(Engine, Pop), false, false, false);
+        }
+            
 
         public object Push(object thisObject, object[] arguments)
         {

+ 6 - 1
Jint/Native/Boolean/BooleanConstructor.cs

@@ -29,6 +29,11 @@ namespace Jint.Native.Boolean
             return obj;
         }
 
+        public void Configure()
+        {
+
+        }
+
         public override object Call(object thisObject, object[] arguments)
         {
             if (arguments.Length == 0)
@@ -49,7 +54,7 @@ namespace Jint.Native.Boolean
             return Construct(TypeConverter.ToBoolean(arguments[0]));
         }
 
-        public ObjectInstance PrototypeObject { get; private set; }
+        public BooleanPrototype PrototypeObject { get; private set; }
 
         public BooleanInstance Construct(bool value)
         {

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

@@ -20,6 +20,10 @@
             return obj;
         }
 
+        public void Configure()
+        {
+            
+        }
 
     }
 }

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

@@ -28,6 +28,11 @@ namespace Jint.Native.Date
             return obj;
         }
 
+        public void Configure()
+        {
+
+        }
+
         public override object Call(object thisObject, object[] arguments)
         {
             return Construct(arguments);
@@ -77,7 +82,7 @@ namespace Jint.Native.Date
             }
         }
 
-        public ObjectInstance PrototypeObject { get; private set; }
+        public DatePrototype PrototypeObject { get; private set; }
 
         public DateInstance Construct(DateTime value)
         {

+ 4 - 1
Jint/Native/Date/DatePrototype.cs

@@ -20,6 +20,9 @@
             return obj;
         }
 
-
+        public void Configure()
+        {
+            
+        }
     }
 }

+ 6 - 1
Jint/Native/Error/ErrorConstructor.cs

@@ -27,6 +27,11 @@ namespace Jint.Native.Error
             return obj;
         }
 
+        public void Configure()
+        {
+            
+        }
+
         public override object Call(object thisObject, object[] arguments)
         {
             return Construct(arguments);
@@ -46,7 +51,7 @@ namespace Jint.Native.Error
             return instance;
         }
 
-        public ObjectInstance PrototypeObject { get; private set; }
+        public ErrorPrototype PrototypeObject { get; private set; }
 
 
     }

+ 9 - 6
Jint/Native/Error/ErrorPrototype.cs

@@ -19,15 +19,18 @@ namespace Jint.Native.Error
 
             obj.FastAddProperty("constructor", errorConstructor, false, false, false);
 
-            // Error prototype properties
-            obj.DefineOwnProperty("message", new ClrAccessDescriptor<ErrorInstance>(engine, x => x.Message), false);
-            obj.DefineOwnProperty("name", new ClrAccessDescriptor<ErrorInstance>(engine, x => x.Name), false);
 
-            // Error prototype functions
-            obj.DefineOwnProperty("toString", new ClrDataDescriptor<ErrorInstance, object>(engine, ToErrorString), false);
+            return obj;
+        }
 
+        public void Configure()
+        {
+            // Error prototype properties
+            DefineOwnProperty("message", new ClrAccessDescriptor<ErrorInstance>(Engine, x => x.Message), false);
+            DefineOwnProperty("name", new ClrAccessDescriptor<ErrorInstance>(Engine, x => x.Name), false);
 
-            return obj;
+            // Error prototype functions
+            DefineOwnProperty("toString", new ClrDataDescriptor<ErrorInstance, object>(Engine, ToErrorString), false);
         }
 
         private static object ToErrorString(ErrorInstance thisObject, object[] arguments)

+ 12 - 5
Jint/Native/Function/FunctionConstructor.cs

@@ -21,19 +21,26 @@ namespace Jint.Native.Function
         {
             var obj = new FunctionConstructor(engine);
 
-            // The value of the [[Prototype]] internal property of the Function constructor is the standard built-in Function prototype object 
-            obj.Prototype = FunctionPrototype.CreatePrototypeObject(engine);
 
             // The initial value of Function.prototype is the standard built-in Function prototype object
-            obj.PrototypeObject = obj.Prototype;
+            obj.PrototypeObject = FunctionPrototype.CreatePrototypeObject(engine);
+            
+            // The value of the [[Prototype]] internal property of the Function constructor is the standard built-in Function prototype object 
+            obj.Prototype = obj.PrototypeObject;
+            
             obj.FastAddProperty("prototype", obj.PrototypeObject, false, false, false);
 
             obj.FastAddProperty("length", 1, false, false, false);
 
             return obj;
         }
-        
-        public ObjectInstance PrototypeObject { get; private set; }
+
+        public void Configure()
+        {
+
+        }
+
+        public FunctionPrototype PrototypeObject { get; private set; }
 
         public override object Call(object thisObject, object[] arguments)
         {

+ 5 - 5
Jint/Native/Function/FunctionInstance.cs

@@ -43,15 +43,15 @@ namespace Jint.Native.Function
         /// </summary>
         /// <param name="instance"></param>
         /// <returns></returns>
-        public bool HasInstance(object instance)
+        public bool HasInstance(object v)
         {
-            var v = instance as ObjectInstance;
-            if (v == null)
+            var vObj = v as ObjectInstance;
+            if (vObj == null)
             {
                 return false;
             }
 
-            var o = v.Get("prototype") as ObjectInstance;
+            var o = Get("prototype") as ObjectInstance;
             
             if (o == null)
             {
@@ -60,7 +60,7 @@ namespace Jint.Native.Function
 
             while (true)
             {
-                v = v.Prototype;
+                v = vObj.Prototype;
 
                 if (v == null)
                 {

+ 5 - 4
Jint/Native/Function/FunctionPrototype.cs

@@ -2,7 +2,6 @@
 using System.Collections.Generic;
 using Jint.Native.Object;
 using Jint.Runtime;
-using Jint.Runtime.Descriptors.Specialized;
 using Jint.Runtime.Interop;
 
 namespace Jint.Native.Function
@@ -14,7 +13,6 @@ namespace Jint.Native.Function
     {
         private FunctionPrototype(Engine engine):base(engine, null, null, false)
         {
-
         }
 
         public static FunctionPrototype CreatePrototypeObject(Engine engine)
@@ -26,11 +24,14 @@ namespace Jint.Native.Function
 
             obj.FastAddProperty("length", 0, false, false, false);
 
-            obj.FastAddProperty("apply", new ClrFunctionInstance<object, object>(engine, obj.Apply), false, false, false);
-
             return obj;
         }
 
+        public void Configure()
+        {
+            FastAddProperty("apply", new ClrFunctionInstance<object, object>(Engine, Apply), false, false, false);
+        }
+
         public object Apply(object thisObject, object[] arguments)
         {
             if (arguments.Length != 2)

+ 35 - 15
Jint/Native/Global/GlobalObject.cs

@@ -2,8 +2,7 @@
 using System.Globalization;
 using Jint.Native.Object;
 using Jint.Runtime;
-using Jint.Runtime.Descriptors;
-using Jint.Runtime.Descriptors.Specialized;
+using Jint.Runtime.Interop;
 
 namespace Jint.Native.Global
 {
@@ -19,22 +18,43 @@ namespace Jint.Native.Global
             global.Prototype = null;
             global.Extensible = true;
             
+                        return global;
+        }
+
+        public void Configure()
+        {
             // Global object properties
-            global.DefineOwnProperty("NaN", new DataDescriptor(double.NaN), false);
-            global.DefineOwnProperty("Infinity", new DataDescriptor(double.PositiveInfinity), false);
-            global.DefineOwnProperty("undefined", new DataDescriptor(Undefined.Instance), false);
+            FastAddProperty("Object", Engine.Object, true, false, true);
+            FastAddProperty("Function", Engine.Function, true, false, true);
+            FastAddProperty("Array", Engine.Array, true, false, true);
+            FastAddProperty("String", Engine.String, true, false, true);
+            FastAddProperty("Number", Engine.Number, true, false, true);
+            FastAddProperty("Boolean", Engine.Boolean, true, false, true);
+            FastAddProperty("Date", Engine.Date, true, false, true);
+            FastAddProperty("Math", Engine.Math, true, false, true);
+            FastAddProperty("JSON", Engine.Json, true, false, true);
+
+            FastAddProperty("Error", Engine.Error, true, false, true);
+            FastAddProperty("EvalError", Engine.EvalError, true, false, true);
+            FastAddProperty("RangeError", Engine.RangeError, true, false, true);
+            FastAddProperty("ReferenceError", Engine.ReferenceError, true, false, true);
+            FastAddProperty("SyntaxError", Engine.SyntaxError, true, false, true);
+            FastAddProperty("TypeError", Engine.TypeError, true, false, true);
+            FastAddProperty("URIError", Engine.UriError, true, false, true);
+
+            FastAddProperty("NaN", double.NaN, false, false, false);
+            FastAddProperty("Infinity", double.PositiveInfinity, false, false, false);
+            FastAddProperty("undefined", Undefined.Instance, false, false, false);
 
             // Global object functions
-            global.DefineOwnProperty("parseInt", new ClrDataDescriptor<object, object>(engine, ParseInt), false);
-            global.DefineOwnProperty("parseFloat", new ClrDataDescriptor<object, object>(engine, ParseFloat), false);
-            global.DefineOwnProperty("isNaN", new ClrDataDescriptor<object, bool>(engine, IsNaN), false);
-            global.DefineOwnProperty("isFinite", new ClrDataDescriptor<object, bool>(engine, IsFinite), false);
-            global.DefineOwnProperty("decodeURI", new ClrDataDescriptor<object, string>(engine, DecodeUri), false);
-            global.DefineOwnProperty("decodeURIComponent", new ClrDataDescriptor<object, string>(engine, DecodeUriComponent), false);
-            global.DefineOwnProperty("encodeURI", new ClrDataDescriptor<object, string>(engine, EncodeUri), false);
-            global.DefineOwnProperty("encodeURIComponent", new ClrDataDescriptor<object, string>(engine, EncodeUriComponent), false);
-
-            return global;
+            FastAddProperty("parseInt", new ClrFunctionInstance<object, object>(Engine, ParseInt), false, false, false);
+            FastAddProperty("parseFloat", new ClrFunctionInstance<object, object>(Engine, ParseFloat), false, false, false);
+            FastAddProperty("isNaN", new ClrFunctionInstance<object, bool>(Engine, IsNaN), false, false, false);
+            FastAddProperty("isFinite", new ClrFunctionInstance<object, bool>(Engine, IsFinite), false, false, false);
+            FastAddProperty("decodeURI", new ClrFunctionInstance<object, string>(Engine, DecodeUri), false, false, false);
+            FastAddProperty("decodeURIComponent", new ClrFunctionInstance<object, string>(Engine, DecodeUriComponent), false, false, false);
+            FastAddProperty("encodeURI", new ClrFunctionInstance<object, string>(Engine, EncodeUri), false, false, false);
+            FastAddProperty("encodeURIComponent", new ClrFunctionInstance<object, string>(Engine, EncodeUriComponent), false, false, false);
         }
 
         /// <summary>

+ 0 - 2
Jint/Native/IConstructor.cs

@@ -6,7 +6,5 @@ namespace Jint.Native
     {
         object Call(object thisObject, object[] arguments);
         ObjectInstance Construct(object[] arguments);
-
-        ObjectInstance PrototypeObject { get; }
     }
 }

+ 7 - 4
Jint/Native/Json/JsonInstance.cs

@@ -1,5 +1,5 @@
 using Jint.Native.Object;
-using Jint.Runtime.Descriptors.Specialized;
+using Jint.Runtime.Interop;
 
 namespace Jint.Native.Json
 {
@@ -25,12 +25,15 @@ namespace Jint.Native.Json
         public static JsonInstance CreateJsonObject(Engine engine)
         {
             var json = new JsonInstance(engine);
-            json.DefineOwnProperty("parse", new ClrDataDescriptor<JsonInstance, object>(engine, json.Parse), false);
-            json.DefineOwnProperty("stringify", new ClrDataDescriptor<JsonInstance, object>(engine, json.Stringify), false);
-
             return json;
         }
 
+        public void Configure()
+        {
+            FastAddProperty("parse", new ClrFunctionInstance<JsonInstance, object>(Engine, Parse), false, false, false);
+            FastAddProperty("stringify", new ClrFunctionInstance<JsonInstance, object>(Engine, Stringify), false, false, false);
+        }
+
         public object Parse(JsonInstance thisObject, object[] arguments)
         {
             var parser = new JsonParser(_engine);

+ 34 - 29
Jint/Native/Math/MathInstance.cs

@@ -1,7 +1,7 @@
 using System;
 using Jint.Native.Object;
 using Jint.Runtime;
-using Jint.Runtime.Descriptors.Specialized;
+using Jint.Runtime.Interop;
 
 namespace Jint.Native.Math
 {
@@ -25,37 +25,42 @@ namespace Jint.Native.Math
             math.Extensible = true;
             math.Prototype = engine.Object.Prototype;
 
-            math.DefineOwnProperty("abs", new ClrDataDescriptor<object, double>(engine, Abs), false);
-            math.DefineOwnProperty("acos", new ClrDataDescriptor<object, double>(engine, Acos), false);
-            math.DefineOwnProperty("asin", new ClrDataDescriptor<object, double>(engine, Asin), false);
-            math.DefineOwnProperty("atan", new ClrDataDescriptor<object, double>(engine, Atan), false);
-            math.DefineOwnProperty("atan2", new ClrDataDescriptor<object, double>(engine, Atan2), false);
-            math.DefineOwnProperty("ceil", new ClrDataDescriptor<object, double>(engine, Ceil), false);
-            math.DefineOwnProperty("cos", new ClrDataDescriptor<object, double>(engine, Cos), false);
-            math.DefineOwnProperty("exp", new ClrDataDescriptor<object, double>(engine, Exp), false);
-            math.DefineOwnProperty("floor", new ClrDataDescriptor<object, double>(engine, Floor), false);
-            math.DefineOwnProperty("log", new ClrDataDescriptor<object, double>(engine, Log), false);
-            math.DefineOwnProperty("max", new ClrDataDescriptor<object, double>(engine, Max), false);
-            math.DefineOwnProperty("min", new ClrDataDescriptor<object, double>(engine, Min), false);
-            math.DefineOwnProperty("pow", new ClrDataDescriptor<object, double>(engine, Pow), false);
-            math.DefineOwnProperty("random", new ClrDataDescriptor<object, double>(engine, Random), false);
-            math.DefineOwnProperty("round", new ClrDataDescriptor<object, double>(engine, Round), false);
-            math.DefineOwnProperty("sin", new ClrDataDescriptor<object, double>(engine, Sin), false);
-            math.DefineOwnProperty("sqrt", new ClrDataDescriptor<object, double>(engine, Sqrt), false);
-            math.DefineOwnProperty("tan", new ClrDataDescriptor<object, double>(engine, Tan), false);
-
-            math.FastAddProperty("E", System.Math.E, false, false, false);
-            math.FastAddProperty("LN10", System.Math.Log(10), false, false, false);
-            math.FastAddProperty("LN2", System.Math.Log(2), false, false, false);
-            math.FastAddProperty("LOG2E", System.Math.Log(System.Math.E, 2), false, false, false);
-            math.FastAddProperty("LOG10E", System.Math.Log(System.Math.E, 10), false, false, false);
-            math.FastAddProperty("PI", System.Math.PI, false, false, false);
-            math.FastAddProperty("SQRT1_2", System.Math.Sqrt(0.5), false, false, false);
-            math.FastAddProperty("SQRT2", System.Math.Sqrt(2), false, false, false);
-
+            
             return math;
         }
 
+        public void Configure()
+        {
+            FastAddProperty("abs", new ClrFunctionInstance<object, double>(Engine, Abs), false, false, false);
+            FastAddProperty("acos", new ClrFunctionInstance<object, double>(Engine, Acos), false, false, false);
+            FastAddProperty("asin", new ClrFunctionInstance<object, double>(Engine, Asin), false, false, false);
+            FastAddProperty("atan", new ClrFunctionInstance<object, double>(Engine, Atan), false, false, false);
+            FastAddProperty("atan2", new ClrFunctionInstance<object, double>(Engine, Atan2), false, false, false);
+            FastAddProperty("ceil", new ClrFunctionInstance<object, double>(Engine, Ceil), false, false, false);
+            FastAddProperty("cos", new ClrFunctionInstance<object, double>(Engine, Cos), false, false, false);
+            FastAddProperty("exp", new ClrFunctionInstance<object, double>(Engine, Exp), false, false, false);
+            FastAddProperty("floor", new ClrFunctionInstance<object, double>(Engine, Floor), false, false, false);
+            FastAddProperty("log", new ClrFunctionInstance<object, double>(Engine, Log), false, false, false);
+            FastAddProperty("max", new ClrFunctionInstance<object, double>(Engine, Max), false, false, false);
+            FastAddProperty("min", new ClrFunctionInstance<object, double>(Engine, Min), false, false, false);
+            FastAddProperty("pow", new ClrFunctionInstance<object, double>(Engine, Pow), false, false, false);
+            FastAddProperty("random", new ClrFunctionInstance<object, double>(Engine, Random), false, false, false);
+            FastAddProperty("round", new ClrFunctionInstance<object, double>(Engine, Round), false, false, false);
+            FastAddProperty("sin", new ClrFunctionInstance<object, double>(Engine, Sin), false, false, false);
+            FastAddProperty("sqrt", new ClrFunctionInstance<object, double>(Engine, Sqrt), false, false, false);
+            FastAddProperty("tan", new ClrFunctionInstance<object, double>(Engine, Tan), false, false, false);
+
+            FastAddProperty("E", System.Math.E, false, false, false);
+            FastAddProperty("LN10", System.Math.Log(10), false, false, false);
+            FastAddProperty("LN2", System.Math.Log(2), false, false, false);
+            FastAddProperty("LOG2E", System.Math.Log(System.Math.E, 2), false, false, false);
+            FastAddProperty("LOG10E", System.Math.Log(System.Math.E, 10), false, false, false);
+            FastAddProperty("PI", System.Math.PI, false, false, false);
+            FastAddProperty("SQRT1_2", System.Math.Sqrt(0.5), false, false, false);
+            FastAddProperty("SQRT2", System.Math.Sqrt(2), false, false, false);
+
+        }
+
         private static double Abs(object thisObject, object[] arguments)
         {
             var x = TypeConverter.ToNumber(arguments[0]);

+ 6 - 1
Jint/Native/Number/NumberConstructor.cs

@@ -31,6 +31,11 @@ namespace Jint.Native.Number
             return obj;
         }
 
+        public void Configure()
+        {
+
+        }
+
         public override object Call(object thisObject, object[] arguments)
         {
             if (arguments.Length == 0)
@@ -51,7 +56,7 @@ namespace Jint.Native.Number
             return Construct(arguments.Length > 0 ? TypeConverter.ToNumber(arguments[0]) : 0);
         }
 
-        public ObjectInstance PrototypeObject { get; private set; }
+        public NumberPrototype PrototypeObject { get; private set; }
 
         public NumberInstance Construct(double value)
         {

+ 21 - 7
Jint/Native/Number/NumberPrototype.cs

@@ -1,4 +1,7 @@
-namespace Jint.Native.Number
+using Jint.Runtime;
+using Jint.Runtime.Interop;
+
+namespace Jint.Native.Number
 {
     /// <summary>
     /// http://www.ecma-international.org/ecma-262/5.1/#sec-15.7.4
@@ -18,15 +21,26 @@
 
             obj.FastAddProperty("constructor", numberConstructor, false, false, false);
 
-            obj.FastAddProperty("NaN", double.NaN, false, false, false);
-            obj.FastAddProperty("MAX_VALUE", double.MaxValue, false, false, false);
-            obj.FastAddProperty("MIN_VALUE", double.MinValue, false, false, false);
-            obj.FastAddProperty("POSITIVE_INFINITY", double.PositiveInfinity, false, false, false);
-            obj.FastAddProperty("NEGATIVE_INFINITY", double.NegativeInfinity, false, false, false);
-
             return obj;
         }
 
+        public void Configure()
+        {
+
+
+            FastAddProperty("NaN", double.NaN, false, false, false);
+            FastAddProperty("MAX_VALUE", double.MaxValue, false, false, false);
+            FastAddProperty("MIN_VALUE", double.MinValue, false, false, false);
+            FastAddProperty("POSITIVE_INFINITY", double.PositiveInfinity, false, false, false);
+            FastAddProperty("NEGATIVE_INFINITY", double.NegativeInfinity, false, false, false);
+
+            FastAddProperty("toString", new ClrFunctionInstance<object, object>(Engine, ToNumberString), false, false, false);
+        }
+
+        private static object ToNumberString(object thisObject, object[] arguments)
+        {
+            return TypeConverter.ToString(thisObject);
+        }
 
     }
 }

+ 20 - 16
Jint/Native/Object/ObjectConstructor.cs

@@ -17,30 +17,34 @@ namespace Jint.Native.Object
         public static ObjectConstructor CreateObjectConstructor(Engine engine)
         {
             var obj = new ObjectConstructor(engine);
-            // obj.Prototype = engine.Function.PrototypeObject;
             obj.PrototypeObject = ObjectPrototype.CreatePrototypeObject(engine, obj);
 
             obj.FastAddProperty("length", 1, false, false, false);
             obj.FastAddProperty("prototype", obj.PrototypeObject, false, false, false);
 
-            obj.FastAddProperty("getPrototypeOf", new ClrFunctionInstance<object, object>(engine, obj.GetPrototypeOf), false, false, false);
-            obj.FastAddProperty("getOwnPropertyDescriptor", new ClrFunctionInstance<object, object>(engine, obj.GetOwnPropertyDescriptor), false, false, false);
-            obj.FastAddProperty("getOwnPropertyNames", new ClrFunctionInstance<object, object>(engine, obj.GetOwnPropertyNames), false, false, false);
-            obj.FastAddProperty("create", new ClrFunctionInstance<object, object>(engine, obj.Create), false, false, false);
-            obj.FastAddProperty("defineProperty", new ClrFunctionInstance<object, object>(engine, obj.DefineProperty), false, false, false);
-            obj.FastAddProperty("defineProperties", new ClrFunctionInstance<object, object>(engine, obj.DefineProperties), false, false, false);
-            obj.FastAddProperty("seal", new ClrFunctionInstance<object, object>(engine, obj.Seal), false, false, false);
-            obj.FastAddProperty("freeze", new ClrFunctionInstance<object, object>(engine, obj.Freeze), false, false, false);
-            obj.FastAddProperty("preventExtensions", new ClrFunctionInstance<object, object>(engine, obj.PreventExtensions), false, false, false);
-            obj.FastAddProperty("isSealed", new ClrFunctionInstance<object, object>(engine, obj.IsSealed), false, false, false);
-            obj.FastAddProperty("isFrozen", new ClrFunctionInstance<object, object>(engine, obj.IsFrozen), false, false, false);
-            obj.FastAddProperty("isExtensible", new ClrFunctionInstance<object, object>(engine, obj.IsExtensible), false, false, false);
-            obj.FastAddProperty("keys", new ClrFunctionInstance<object, object>(engine, obj.Keys), false, false, false);
-
             return obj;
         }
 
-        public ObjectInstance PrototypeObject { get; private set; }
+        public void Configure()
+        {
+            Prototype = Engine.Function.PrototypeObject;
+
+            FastAddProperty("getPrototypeOf", new ClrFunctionInstance<object, object>(Engine, GetPrototypeOf), false, false, false);
+            FastAddProperty("getOwnPropertyDescriptor", new ClrFunctionInstance<object, object>(Engine, GetOwnPropertyDescriptor), false, false, false);
+            FastAddProperty("getOwnPropertyNames", new ClrFunctionInstance<object, object>(Engine, GetOwnPropertyNames), false, false, false);
+            FastAddProperty("create", new ClrFunctionInstance<object, object>(Engine, Create), false, false, false);
+            FastAddProperty("defineProperty", new ClrFunctionInstance<object, object>(Engine, DefineProperty), false, false, false);
+            FastAddProperty("defineProperties", new ClrFunctionInstance<object, object>(Engine, DefineProperties), false, false, false);
+            FastAddProperty("seal", new ClrFunctionInstance<object, object>(Engine, Seal), false, false, false);
+            FastAddProperty("freeze", new ClrFunctionInstance<object, object>(Engine, Freeze), false, false, false);
+            FastAddProperty("preventExtensions", new ClrFunctionInstance<object, object>(Engine, PreventExtensions), false, false, false);
+            FastAddProperty("isSealed", new ClrFunctionInstance<object, object>(Engine, IsSealed), false, false, false);
+            FastAddProperty("isFrozen", new ClrFunctionInstance<object, object>(Engine, IsFrozen), false, false, false);
+            FastAddProperty("isExtensible", new ClrFunctionInstance<object, object>(Engine, IsExtensible), false, false, false);
+            FastAddProperty("keys", new ClrFunctionInstance<object, object>(Engine, Keys), false, false, false);
+        }
+
+        public ObjectPrototype PrototypeObject { get; private set; }
 
         /// <summary>
         /// http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.1.1

+ 6 - 2
Jint/Native/Object/ObjectPrototype.cs

@@ -15,12 +15,16 @@ namespace Jint.Native.Object
             var obj = new ObjectPrototype(engine) { Extensible = true };
 
             obj.FastAddProperty("constructor", objectConstructor, false, false, false);
-            obj.FastAddProperty("toString", new ClrFunctionInstance<object, string>(engine, obj.ToString), false, false, false);
-            obj.FastAddProperty("hasOwnProperty", new ClrFunctionInstance<object, bool>(engine, obj.HasOwnProperty), false, false, false);
 
             return obj;
         }
 
+        public void Configure()
+        {
+            FastAddProperty("toString", new ClrFunctionInstance<object, string>(Engine, ToString), false, false, false);
+            FastAddProperty("hasOwnProperty", new ClrFunctionInstance<object, bool>(Engine, HasOwnProperty), false, false, false);
+        }
+
         /// <summary>
         /// http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.4.2
         /// </summary>

+ 7 - 1
Jint/Native/String/StringConstructor.cs

@@ -27,6 +27,12 @@ namespace Jint.Native.String
 
             return obj;
         }
+
+        public void Configure()
+        {
+
+        }
+
         public override object Call(object thisObject, object[] arguments)
         {
             if (arguments.Length == 0)
@@ -47,7 +53,7 @@ namespace Jint.Native.String
             return Construct(arguments.Length > 0 ? TypeConverter.ToString(arguments[0]) : "");
         }
 
-        public ObjectInstance PrototypeObject { get; private set; }
+        public StringPrototype PrototypeObject { get; private set; }
 
         public StringInstance Construct(string value)
         {

+ 3 - 0
Jint/Native/String/StringPrototype.cs

@@ -21,6 +21,9 @@
             return obj;
         }
 
+        public void Configure()
+        {
 
+        }
     }
 }

+ 1 - 3
Jint/Runtime/Arguments.cs

@@ -1,6 +1,4 @@
-using Jint.Native;
-
-namespace Jint.Runtime
+namespace Jint.Runtime
 {
     public static class Arguments
     {

+ 3 - 7
Jint/Runtime/ExpressionIntepreter.cs

@@ -567,19 +567,15 @@ namespace Jint.Runtime
 
         public object EvaluateCallExpression(CallExpression callExpression)
         {
-            var callee = EvaluateExpression(callExpression.Callee) as Reference;
-
-            if (callee == null)
-            {
-                throw new ArgumentException("Callee should be a reference");    
-            }
+            var callee = EvaluateExpression(callExpression.Callee);
 
             var func = _engine.GetValue(callee);
 
             if (func == Undefined.Instance)
             {
-                throw new JavaScriptException(_engine.TypeError, "object has no method '" + callee.GetReferencedName() + "'" );
+                throw new JavaScriptException(_engine.TypeError);
             }
+
             object thisObject;
 
             // todo: implement as in http://www.ecma-international.org/ecma-262/5.1/#sec-11.2.4

+ 1 - 0
Jint/Runtime/Interop/ClrFunctionInstance.cs

@@ -14,6 +14,7 @@ namespace Jint.Runtime.Interop
             : base(engine, null, null, false)
         {
             _func = func;
+            Prototype = engine.Function.PrototypeObject;
         }
 
         public override object Call(object thisObject, object[] arguments)