Esempio n. 1
0
        public static Constant JsonToObject(Dictionary <string, object> json, Scope scope)
        {
            var obj = new Javascript.Object(Tool.Construct("Object", scope));

            foreach (var key in json.Keys)
            {
                obj.Set(key, JsonToValue(json[key], scope));
            }
            return(obj);
        }
Esempio n. 2
0
        public void Init()
        {
            // Object and Function need to be bootstrapped because they are dependent on each other
            var objectPrototype   = new Javascript.Object(null);
            var functionPrototype = new Javascript.Object(objectPrototype);

            var objectConstructor = new Javascript.Object(functionPrototype);

            objectConstructor.Set("prototype", objectPrototype);
            objectPrototype.Set("constructor", objectConstructor);

            var functionConstructor = new Javascript.Object(functionPrototype);

            functionConstructor.Set("prototype", functionPrototype);
            functionPrototype.Set("constructor", functionConstructor);

            Scope.SetVariable("Object", objectConstructor);
            _prototypes["Object"] = objectConstructor;

            Scope.SetVariable("Function", functionConstructor);
            _prototypes["Function"] = functionConstructor;

            RegisterType(typeof(Internal.Object));
            RegisterType(typeof(Internal.Function));
            RegisterType(typeof(Internal.Array));
            RegisterType(typeof(Internal.Date));
            RegisterType(typeof(Internal.String));
            RegisterType(typeof(Internal.Number));
            RegisterType(typeof(Internal.Boolean));
            RegisterType(typeof(Internal.RegExp));

            RegisterClass(typeof(Internal.JSON));
            RegisterClass(typeof(Internal.Math));

            RegisterFunctions(typeof(Internal.Functions));
        }