Example #1
0
        /// <summary>
        /// Initializes the prototype properties.
        /// </summary>
        /// <param name="obj"> The object to set the properties on. </param>
        /// <param name="constructor"> A reference to the constructor that owns the prototype. </param>
        internal static void InitializePrototypeProperties(ObjectInstance obj, FunctionConstructor constructor)
        {
            var engine     = obj.Engine;
            var properties = GetDeclarativeProperties(engine);

            properties.Add(new PropertyNameAndValue("constructor", constructor, PropertyAttributes.NonEnumerable));
            properties.Add(new PropertyNameAndValue("name", "Empty", PropertyAttributes.Configurable));
            properties.Add(new PropertyNameAndValue("length", 0, PropertyAttributes.Configurable));
            obj.InitializeProperties(properties);
        }
Example #2
0
        //     SERIALIZATION
        //_________________________________________________________________________________________

#if !SILVERLIGHT
        /// <summary>
        /// Initializes a new instance of the ObjectInstance class with serialized data.
        /// </summary>
        /// <param name="info"> The SerializationInfo that holds the serialized object data about
        /// the exception being thrown. </param>
        /// <param name="context"> The StreamingContext that contains contextual information about
        /// the source or destination. </param>
        private ScriptEngine(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
        {
            // Set the DeserializationEnvironment to this script engine.
            ScriptEngine.DeserializationEnvironment = this;

            // Create the initial hidden class schema.  This must be done first.
            this.emptySchema = HiddenClassSchema.CreateEmptySchema();

            // Deserialize the compatibility mode.
            this.compatibilityMode = (CompatibilityMode)info.GetInt32("compatibilityMode");

            // Deserialize the ForceStrictMode flag.
            this.ForceStrictMode = info.GetBoolean("forceStrictMode");

            // Deserialize the built-in objects.
            this.globalObject        = (GlobalObject)info.GetValue("globalObject", typeof(GlobalObject));
            this.arrayConstructor    = (ArrayConstructor)info.GetValue("arrayConstructor", typeof(ArrayConstructor));
            this.booleanConstructor  = (BooleanConstructor)info.GetValue("booleanConstructor", typeof(BooleanConstructor));
            this.dateConstructor     = (DateConstructor)info.GetValue("dateConstructor", typeof(DateConstructor));
            this.functionConstructor = (FunctionConstructor)info.GetValue("functionConstructor", typeof(FunctionConstructor));
            this.jsonObject          = (JSONObject)info.GetValue("jsonObject", typeof(JSONObject));
            this.mathObject          = (MathObject)info.GetValue("mathObject", typeof(MathObject));
            this.numberConstructor   = (NumberConstructor)info.GetValue("numberConstructor", typeof(NumberConstructor));
            this.objectConstructor   = (ObjectConstructor)info.GetValue("objectConstructor", typeof(ObjectConstructor));
            this.regExpConstructor   = (RegExpConstructor)info.GetValue("regExpConstructor", typeof(RegExpConstructor));
            this.stringConstructor   = (StringConstructor)info.GetValue("stringConstructor", typeof(StringConstructor));

            // Deserialize the built-in error objects.
            this.errorConstructor          = (ErrorConstructor)info.GetValue("errorConstructor", typeof(ErrorConstructor));
            this.rangeErrorConstructor     = (ErrorConstructor)info.GetValue("rangeErrorConstructor", typeof(ErrorConstructor));
            this.typeErrorConstructor      = (ErrorConstructor)info.GetValue("typeErrorConstructor", typeof(ErrorConstructor));
            this.syntaxErrorConstructor    = (ErrorConstructor)info.GetValue("syntaxErrorConstructor", typeof(ErrorConstructor));
            this.uriErrorConstructor       = (ErrorConstructor)info.GetValue("uriErrorConstructor", typeof(ErrorConstructor));
            this.evalErrorConstructor      = (ErrorConstructor)info.GetValue("evalErrorConstructor", typeof(ErrorConstructor));
            this.referenceErrorConstructor = (ErrorConstructor)info.GetValue("referenceErrorConstructor", typeof(ErrorConstructor));
        }
Example #3
0
        public Engine(Action <Options> options)
        {
            _executionContexts = new Stack <ExecutionContext>();

            Global = GlobalObject.CreateGlobalObject(this);

            Object   = ObjectConstructor.CreateObjectConstructor(this);
            Function = FunctionConstructor.CreateFunctionConstructor(this);

            Array   = ArrayConstructor.CreateArrayConstructor(this);
            String  = StringConstructor.CreateStringConstructor(this);
            RegExp  = RegExpConstructor.CreateRegExpConstructor(this);
            Number  = NumberConstructor.CreateNumberConstructor(this);
            Boolean = BooleanConstructor.CreateBooleanConstructor(this);
            Date    = DateConstructor.CreateDateConstructor(this);
            Math    = MathInstance.CreateMathObject(this);
            Json    = JsonInstance.CreateJsonObject(this);

            Error          = ErrorConstructor.CreateErrorConstructor(this, "Error");
            EvalError      = ErrorConstructor.CreateErrorConstructor(this, "EvalError");
            RangeError     = ErrorConstructor.CreateErrorConstructor(this, "RangeError");
            ReferenceError = ErrorConstructor.CreateErrorConstructor(this, "ReferenceError");
            SyntaxError    = ErrorConstructor.CreateErrorConstructor(this, "SyntaxError");
            TypeError      = ErrorConstructor.CreateErrorConstructor(this, "TypeError");
            UriError       = ErrorConstructor.CreateErrorConstructor(this, "URIError");

            // 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();

            RegExp.Configure();
            RegExp.PrototypeObject.Configure();

            Number.Configure();
            Number.PrototypeObject.Configure();

            Boolean.Configure();
            Boolean.PrototypeObject.Configure();

            Date.Configure();
            Date.PrototypeObject.Configure();

            Math.Configure();
            Json.Configure();

            Error.Configure();
            Error.PrototypeObject.Configure();

            // create the global environment http://www.ecma-international.org/ecma-262/5.1/#sec-10.2.3
            GlobalEnvironment = new LexicalEnvironment();
            GlobalEnvironment.Setup(new ObjectEnvironmentRecord(this, Global, false), null);

            // create the global execution context http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.1.1
            EnterExecutionContext(GlobalEnvironment, GlobalEnvironment, Global);

            Options = new Options();

            if (options != null)
            {
                options(Options);
            }

            Eval = new EvalFunctionInstance(this, new string[0], LexicalEnvironment.NewDeclarativeEnvironment(this, ExecutionContext.LexicalEnvironment), StrictModeScope.IsStrictModeCode);
            Global.FastAddProperty("eval", Eval, true, false, true);

            _statements  = new StatementInterpreter(this);
            _expressions = new ExpressionInterpreter(this);

            if (Options._IsClrAllowed)
            {
                Global.FastAddProperty("System", new NamespaceReference(this, "System"), false, false, false);
                Global.FastAddProperty("importNamespace", new ClrFunctionInstance(this, (thisObj, arguments) =>
                {
                    return(new NamespaceReference(this, TypeConverter.ToString(arguments.At(0))));
                }), false, false, false);
            }

            ClrTypeConverter = new DefaultTypeConverter(this);
            BreakPoints      = new List <BreakPoint>();
            DebugHandler     = new DebugHandler(this);
        }
Example #4
0
        private void Initialize_impl(Type type, string methodName, List <MethodBase> methods)
        {
            m_Type       = type;
            m_IsClass    = type.IsClass;
            m_MethodName = methodName;
            List <FunctionBase> functionMethod = new List <FunctionBase>();
            List <FunctionBase> genericMethods = new List <FunctionBase>();
            bool Params    = false;                                 //是否是不定参函数
            Type ParamType = null;                                  //不定参类型

            ParameterInfo[] Parameters;                             //所有参数
            List <Type>     parameterTypes   = new List <Type>();   //参数类型
            List <object>   defaultParameter = new List <object>(); //默认参数
            int             length           = methods.Count;       //总数量
            MethodBase      method           = null;
            FunctionBase    functionBase;

            for (int i = 0; i < length; ++i)
            {
                method    = methods[i];
                Params    = false;
                ParamType = null;
                parameterTypes.Clear();
                defaultParameter.Clear();
                Parameters = method.GetParameters();
                if (Util.IsExtensionMethod(method))
                {
                    for (int j = 1; j < Parameters.Length; ++j)
                    {
                        var par = Parameters[j];
                        parameterTypes.Add(par.ParameterType);
                        if (par.DefaultValue != DBNull.Value)
                        {
                            defaultParameter.Add(par.DefaultValue);
                        }
                        Params = Util.IsParamArray(par);
                        if (Params)
                        {
                            ParamType = par.ParameterType.GetElementType();
                        }
                    }
                    functionBase = new ExtensionMethod(method as MethodInfo, parameterTypes.ToArray(), defaultParameter.ToArray(), ParamType, Params, "");
                }
                else
                {
                    foreach (ParameterInfo par in Parameters)
                    {
                        parameterTypes.Add(par.ParameterType);
                        if (par.DefaultValue != DBNull.Value)
                        {
                            defaultParameter.Add(par.DefaultValue);
                        }
                        Params = Util.IsParamArray(par);
                        if (Params)
                        {
                            ParamType = par.ParameterType.GetElementType();
                        }
                    }
                    if (method is MethodInfo)
                    {
                        functionBase = new FunctionMethod(method as MethodInfo, parameterTypes.ToArray(), defaultParameter.ToArray(), ParamType, Params, "");
                    }
                    else
                    {
                        functionBase = new FunctionConstructor(method as ConstructorInfo, parameterTypes.ToArray(), defaultParameter.ToArray(), ParamType, Params, "");
                    }
                }
                if (functionBase.IsGeneric)
                {
                    genericMethods.Add(functionBase);
                }
                else
                {
                    functionMethod.Add(functionBase);
                }
            }
            m_Methods        = functionMethod.ToArray();
            m_Count          = m_Methods.Length;
            m_GenericMethods = genericMethods.ToArray();
            m_GenericCount   = m_GenericMethods.Length;
        }
 private void Initialize_impl(Type type, string methodName, List<MethodBase> methods)
 {
     m_Type = type;
     m_MethodName = methodName;
     List<FunctionBase> functionMethod = new List<FunctionBase>();
     List<FunctionBase> genericMethods = new List<FunctionBase>();
     bool Params = false;                                    //是否是不定参函数
     Type ParamType = null;                                  //不定参类型
     ParameterInfo[] Parameters;                             //所有参数
     List<Type> parameterTypes = new List<Type>();           //参数类型
     List<object> defaultParameter = new List<object>();     //默认参数
     int length = methods.Count;                             //总数量
     MethodBase method = null;
     FunctionBase functionBase;
     for (int i = 0; i < length; ++i) {
         method = methods[i];
         Params = false;
         ParamType = null;
         parameterTypes.Clear();
         defaultParameter.Clear();
         Parameters = method.GetParameters();
         if (Util.IsExtensionMethod(method)) {
             for (int j = 1; j < Parameters.Length; ++j) {
                 var par = Parameters[j];
                 parameterTypes.Add(par.ParameterType);
                 if (par.DefaultValue != DBNull.Value) { defaultParameter.Add(par.DefaultValue); }
                 Params = Util.IsParamArray(par);
                 if (Params) ParamType = par.ParameterType.GetElementType();
             }
             functionBase = new ExtensionMethod(method as MethodInfo, parameterTypes.ToArray(), defaultParameter.ToArray(), ParamType, Params, "");
         } else {
             foreach (ParameterInfo par in Parameters) {
                 parameterTypes.Add(par.ParameterType);
                 if (par.DefaultValue != DBNull.Value) { defaultParameter.Add(par.DefaultValue); }
                 Params = Util.IsParamArray(par);
                 if (Params) ParamType = par.ParameterType.GetElementType();
             }
             if (method is MethodInfo)
                 functionBase = new FunctionMethod(method as MethodInfo, parameterTypes.ToArray(), defaultParameter.ToArray(), ParamType, Params, "");
             else
                 functionBase = new FunctionConstructor(method as ConstructorInfo, parameterTypes.ToArray(), defaultParameter.ToArray(), ParamType, Params, "");
         }
         if (functionBase.IsGeneric)
             genericMethods.Add(functionBase);
         else
             functionMethod.Add(functionBase);
     }
     m_Methods = functionMethod.ToArray();
     m_Count = m_Methods.Length;
     m_GenericMethods = genericMethods.ToArray();
     m_GenericCount = m_GenericMethods.Length;
 }
Example #6
0
        public Engine(Action <Options> options)
        {
            _executionContexts = new ExecutionContextStack();

            Global = GlobalObject.CreateGlobalObject(this);

            Object   = ObjectConstructor.CreateObjectConstructor(this);
            Function = FunctionConstructor.CreateFunctionConstructor(this);

            Symbol   = SymbolConstructor.CreateSymbolConstructor(this);
            Array    = ArrayConstructor.CreateArrayConstructor(this);
            Map      = MapConstructor.CreateMapConstructor(this);
            Set      = SetConstructor.CreateSetConstructor(this);
            Iterator = IteratorConstructor.CreateIteratorConstructor(this);
            String   = StringConstructor.CreateStringConstructor(this);
            RegExp   = RegExpConstructor.CreateRegExpConstructor(this);
            Number   = NumberConstructor.CreateNumberConstructor(this);
            Boolean  = BooleanConstructor.CreateBooleanConstructor(this);
            //            Date = DateConstructor.CreateDateConstructor(this);
            Math = MathInstance.CreateMathObject(this);
            Json = JsonInstance.CreateJsonObject(this);

            Error          = ErrorConstructor.CreateErrorConstructor(this, "Error");
            EvalError      = ErrorConstructor.CreateErrorConstructor(this, "EvalError");
            RangeError     = ErrorConstructor.CreateErrorConstructor(this, "RangeError");
            ReferenceError = ErrorConstructor.CreateErrorConstructor(this, "ReferenceError");
            SyntaxError    = ErrorConstructor.CreateErrorConstructor(this, "SyntaxError");
            TypeError      = ErrorConstructor.CreateErrorConstructor(this, "TypeError");
            UriError       = ErrorConstructor.CreateErrorConstructor(this, "URIError");

            GlobalSymbolRegistry = new GlobalSymbolRegistry();

            // 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();

            Symbol.Configure();
            Symbol.PrototypeObject.Configure();

            Function.Configure();
            Function.PrototypeObject.Configure();

            Array.Configure();
            Array.PrototypeObject.Configure();

            Map.Configure();
            Map.PrototypeObject.Configure();

            Set.Configure();
            Set.PrototypeObject.Configure();

            Iterator.Configure();
            Iterator.PrototypeObject.Configure();

            String.Configure();
            String.PrototypeObject.Configure();

            RegExp.Configure();
            RegExp.PrototypeObject.Configure();

            Number.Configure();
            Number.PrototypeObject.Configure();

            Boolean.Configure();
            Boolean.PrototypeObject.Configure();

            //            Date.Configure();
            //            Date.PrototypeObject.Configure();

            Math.Configure();
            Json.Configure();

            Error.Configure();
            Error.PrototypeObject.Configure();

            // create the global environment http://www.ecma-international.org/ecma-262/5.1/#sec-10.2.3
            GlobalEnvironment = LexicalEnvironment.NewObjectEnvironment(this, Global, null, false);

            // create the global execution context http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.1.1
            EnterExecutionContext(GlobalEnvironment, GlobalEnvironment, Global);

            Options = new Options();

            options?.Invoke(Options);

            // gather some options as fields for faster checks
            _isDebugMode = Options.IsDebugMode;

            if (_isDebugMode)
            {
                MyAPIGateway.Utilities.ShowMessage("SpaceJS", "Debug mode enabled.");
            }

            _isStrict                 = Options.IsStrict;
            _maxStatements            = Options._MaxStatements;
            _referenceResolver        = Options.ReferenceResolver;
            _memoryLimit              = Options._MemoryLimit;
            _runBeforeStatementChecks = (_maxStatements > 0 && _maxStatements < int.MaxValue) ||
                                        Options._TimeoutInterval.Ticks > 0 ||
                                        _memoryLimit > 0 ||
                                        _isDebugMode;

            _referencePool         = new ReferencePool();
            _argumentsInstancePool = new ArgumentsInstancePool(this);
            _jsValueArrayPool      = new JsValueArrayPool();

            Eval = new EvalFunctionInstance(this, System.ArrayExt.Empty <string>(), LexicalEnvironment.NewDeclarativeEnvironment(this, ExecutionContext.LexicalEnvironment), StrictModeScope.IsStrictModeCode);
            Global.FastAddProperty("eval", Eval, true, false, true);

            _statements  = new StatementInterpreter(this);
            _expressions = new ExpressionInterpreter(this);

            /*            if (Options._IsClrAllowed)
             *          {
             *              Global.FastAddProperty("System", new NamespaceReference(this, "System"), false, false, false);
             *              Global.FastAddProperty("importNamespace", new ClrFunctionInstance(
             *                  this,
             *                  "importNamespace",
             *                  (thisObj, arguments) => new NamespaceReference(this, TypeConverter.ToString(arguments.At(0)))), false, false, false);
             *          }
             */
            //            ClrTypeConverter = new DefaultTypeConverter(this);
        }
Example #7
0
        /// <summary>
        /// Constructs a new engine instance and allows customizing options.
        /// </summary>
        /// <remarks>The provided engine instance in callback is not guaranteed to be fully configured</remarks>
        public Engine(Action <Engine, Options> options)
        {
            _executionContexts = new ExecutionContextStack(2);

            Global = GlobalObject.CreateGlobalObject(this);

            Object   = ObjectConstructor.CreateObjectConstructor(this);
            Function = FunctionConstructor.CreateFunctionConstructor(this);
            _callerCalleeArgumentsThrowerConfigurable    = new GetSetPropertyDescriptor.ThrowerPropertyDescriptor(this, PropertyFlag.Configurable | PropertyFlag.CustomJsValue, "'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them");
            _callerCalleeArgumentsThrowerNonConfigurable = new GetSetPropertyDescriptor.ThrowerPropertyDescriptor(this, PropertyFlag.CustomJsValue, "'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them");

            Symbol   = SymbolConstructor.CreateSymbolConstructor(this);
            Array    = ArrayConstructor.CreateArrayConstructor(this);
            Map      = MapConstructor.CreateMapConstructor(this);
            Set      = SetConstructor.CreateSetConstructor(this);
            Iterator = IteratorConstructor.CreateIteratorConstructor(this);
            String   = StringConstructor.CreateStringConstructor(this);
            RegExp   = RegExpConstructor.CreateRegExpConstructor(this);
            Number   = NumberConstructor.CreateNumberConstructor(this);
            Boolean  = BooleanConstructor.CreateBooleanConstructor(this);
            Date     = DateConstructor.CreateDateConstructor(this);
            Math     = MathInstance.CreateMathObject(this);
            Json     = JsonInstance.CreateJsonObject(this);
            Proxy    = ProxyConstructor.CreateProxyConstructor(this);
            Reflect  = ReflectInstance.CreateReflectObject(this);

            GlobalSymbolRegistry = new GlobalSymbolRegistry();

            // Because the properties might need some of the built-in object
            // their configuration is delayed to a later step

            // trigger initialization
            Global.GetProperty(JsString.Empty);

            // this is implementation dependent, and only to pass some unit tests
            Global._prototype = Object.PrototypeObject;
            Object._prototype = Function.PrototypeObject;

            // create the global environment http://www.ecma-international.org/ecma-262/5.1/#sec-10.2.3
            GlobalEnvironment = LexicalEnvironment.NewGlobalEnvironment(this, Global);

            // create the global execution context http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.1.1
            EnterExecutionContext(GlobalEnvironment, GlobalEnvironment);

            Eval = new EvalFunctionInstance(this);
            Global.SetProperty(CommonProperties.Eval, new PropertyDescriptor(Eval, PropertyFlag.Configurable | PropertyFlag.Writable));

            Options = new Options();

            options?.Invoke(this, Options);

            // gather some options as fields for faster checks
            _isDebugMode       = Options.IsDebugMode;
            _isStrict          = Options.IsStrict;
            _constraints       = Options._Constraints;
            _referenceResolver = Options.ReferenceResolver;

            _referencePool         = new ReferencePool();
            _argumentsInstancePool = new ArgumentsInstancePool(this);
            _jsValueArrayPool      = new JsValueArrayPool();

            if (Options._IsClrAllowed)
            {
                Global.SetProperty("System", new PropertyDescriptor(new NamespaceReference(this, "System"), PropertyFlag.AllForbidden));
                Global.SetProperty("importNamespace", new PropertyDescriptor(new ClrFunctionInstance(
                                                                                 this,
                                                                                 "importNamespace",
                                                                                 (thisObj, arguments) => new NamespaceReference(this, TypeConverter.ToString(arguments.At(0)))), PropertyFlag.AllForbidden));
            }

            ClrTypeConverter = new DefaultTypeConverter(this);
        }
Example #8
0
        private void Initialize_impl(Type type, string methodName, List <MethodBase> methods)
        {
            this.m_Type       = type;
            this.m_MethodName = methodName;
            List <FunctionBase> list  = new List <FunctionBase>();
            List <FunctionBase> list2 = new List <FunctionBase>();
            bool          @params     = false;
            Type          paramType   = null;
            List <Type>   list3       = new List <Type>();
            List <object> list4       = new List <object>();
            int           count       = methods.Count;
            MethodBase    method      = null;

            for (int i = 0; i < count; i++)
            {
                FunctionBase base3;
                method    = methods[i];
                @params   = false;
                paramType = null;
                list3.Clear();
                list4.Clear();
                ParameterInfo[] parameters = method.GetParameters();
                if (Util.IsExtensionMethod(method))
                {
                    for (int j = 1; j < parameters.Length; j++)
                    {
                        ParameterInfo info = parameters[j];
                        list3.Add(info.ParameterType);
                        if (info.DefaultValue != DBNull.Value)
                        {
                            list4.Add(info.DefaultValue);
                        }
                        @params = Util.IsParamArray(info);
                        if (@params)
                        {
                            paramType = info.ParameterType.GetElementType();
                        }
                    }
                    base3 = new ExtensionMethod(method as MethodInfo, list3.ToArray(), list4.ToArray(), paramType, @params, "");
                }
                else
                {
                    foreach (ParameterInfo info2 in parameters)
                    {
                        list3.Add(info2.ParameterType);
                        if (info2.DefaultValue != DBNull.Value)
                        {
                            list4.Add(info2.DefaultValue);
                        }
                        @params = Util.IsParamArray(info2);
                        if (@params)
                        {
                            paramType = info2.ParameterType.GetElementType();
                        }
                    }
                    if (method is MethodInfo)
                    {
                        base3 = new FunctionMethod(method as MethodInfo, list3.ToArray(), list4.ToArray(), paramType, @params, "");
                    }
                    else
                    {
                        base3 = new FunctionConstructor(method as ConstructorInfo, list3.ToArray(), list4.ToArray(), paramType, @params, "");
                    }
                }
                if (base3.IsGeneric)
                {
                    list2.Add(base3);
                }
                else
                {
                    list.Add(base3);
                }
            }
            this.m_Methods        = list.ToArray();
            this.m_Count          = this.m_Methods.Length;
            this.m_GenericMethods = list2.ToArray();
            this.m_GenericCount   = this.m_GenericMethods.Length;
        }
Example #9
0
        public ScriptEngine()
        {
            // Create the initial hidden class schema.  This must be done first.
            this.emptySchema = HiddenClassSchema.CreateEmptySchema();

            // Create the base of the prototype chain.
            var baseObject = ObjectInstance.CreateRootObject(this);

            // Create the global object.
            this.globalObject = new GlobalObject(baseObject);

            // Create the function object that second to last in the prototype chain.
            var baseFunction = UserDefinedFunction.CreateEmptyFunction(baseObject);

            // Object must be created first, then function.
            this.objectConstructor   = new ObjectConstructor(baseFunction, baseObject);
            this.functionConstructor = new FunctionConstructor(baseFunction, baseFunction);

            // Create all the built-in objects.
            this.mathObject = new MathObject(baseObject);
            this.jsonObject = new JSONObject(baseObject);

            // Create all the built-in functions.
            this.arrayConstructor   = new ArrayConstructor(baseFunction);
            this.booleanConstructor = new BooleanConstructor(baseFunction);
            this.dateConstructor    = new DateConstructor(baseFunction);
            this.numberConstructor  = new NumberConstructor(baseFunction);
            this.regExpConstructor  = new RegExpConstructor(baseFunction);
            this.stringConstructor  = new StringConstructor(baseFunction);

            // Create the error functions.
            this.errorConstructor          = new ErrorConstructor(baseFunction, "Error");
            this.rangeErrorConstructor     = new ErrorConstructor(baseFunction, "RangeError");
            this.typeErrorConstructor      = new ErrorConstructor(baseFunction, "TypeError");
            this.syntaxErrorConstructor    = new ErrorConstructor(baseFunction, "SyntaxError");
            this.uriErrorConstructor       = new ErrorConstructor(baseFunction, "URIError");
            this.evalErrorConstructor      = new ErrorConstructor(baseFunction, "EvalError");
            this.referenceErrorConstructor = new ErrorConstructor(baseFunction, "ReferenceError");

            // Populate the instance prototypes (TODO: optimize this, currently takes about 15ms).
            this.globalObject.PopulateFunctions();
            this.objectConstructor.PopulateFunctions();
            this.objectConstructor.InstancePrototype.PopulateFunctions();
            this.functionConstructor.InstancePrototype.PopulateFunctions(typeof(FunctionInstance));
            this.mathObject.PopulateFunctions();
            this.mathObject.PopulateFields();
            this.jsonObject.PopulateFunctions();
            this.arrayConstructor.PopulateFunctions();
            this.arrayConstructor.InstancePrototype.PopulateFunctions();
            this.booleanConstructor.InstancePrototype.PopulateFunctions();
            this.dateConstructor.PopulateFunctions();
            this.dateConstructor.InstancePrototype.PopulateFunctions();
            this.numberConstructor.InstancePrototype.PopulateFunctions();
            this.numberConstructor.PopulateFields();
            this.regExpConstructor.InstancePrototype.PopulateFunctions();
            this.stringConstructor.PopulateFunctions();
            this.stringConstructor.InstancePrototype.PopulateFunctions();
            this.errorConstructor.InstancePrototype.PopulateFunctions();

            // Add them as JavaScript-accessible properties of the global instance.
            this.globalObject.FastSetProperty("Array", this.arrayConstructor, PropertyAttributes.NonEnumerable);
            this.globalObject.FastSetProperty("Boolean", this.booleanConstructor, PropertyAttributes.NonEnumerable);
            this.globalObject.FastSetProperty("Date", this.dateConstructor, PropertyAttributes.NonEnumerable);
            this.globalObject.FastSetProperty("Function", this.functionConstructor, PropertyAttributes.NonEnumerable);
            this.globalObject.FastSetProperty("JSON", this.jsonObject, PropertyAttributes.NonEnumerable);
            this.globalObject.FastSetProperty("Math", this.mathObject, PropertyAttributes.NonEnumerable);
            this.globalObject.FastSetProperty("Number", this.numberConstructor, PropertyAttributes.NonEnumerable);
            this.globalObject.FastSetProperty("Object", this.objectConstructor, PropertyAttributes.NonEnumerable);
            this.globalObject.FastSetProperty("RegExp", this.regExpConstructor, PropertyAttributes.NonEnumerable);
            this.globalObject.FastSetProperty("String", this.stringConstructor, PropertyAttributes.NonEnumerable);

            // And the errors.
            this.globalObject.FastSetProperty("Error", this.errorConstructor, PropertyAttributes.NonEnumerable);
            this.globalObject.FastSetProperty("RangeError", this.rangeErrorConstructor, PropertyAttributes.NonEnumerable);
            this.globalObject.FastSetProperty("TypeError", this.typeErrorConstructor, PropertyAttributes.NonEnumerable);
            this.globalObject.FastSetProperty("SyntaxError", this.syntaxErrorConstructor, PropertyAttributes.NonEnumerable);
            this.globalObject.FastSetProperty("URIError", this.uriErrorConstructor, PropertyAttributes.NonEnumerable);
            this.globalObject.FastSetProperty("EvalError", this.evalErrorConstructor, PropertyAttributes.NonEnumerable);
            this.globalObject.FastSetProperty("ReferenceError", this.referenceErrorConstructor, PropertyAttributes.NonEnumerable);
        }