コード例 #1
0
ファイル: JSService.cs プロジェクト: arjenst/NetJS
        // Every template is executed via this function
        public string RunTemplate(string template, Core.Javascript.Object arguments, ref JSApplication application, ref JSSession session, ref XHTMLMerge.SVCache svCache)
        {
            try {
                if (arguments == null)
                {
                    arguments = Core.Tool.Construct("Object", application.Engine.Scope);
                }

                var scope = new Scope(application.Engine.Scope, null, ScopeType.Session);
                scope.SetVariable("__application__", new Foreign(application));
                scope.SetVariable("__session__", new Foreign(session));
                scope.SetVariable("__svCache__", new Foreign(svCache));

                // TODO: better way to forward session
                var result = External.Functions.include(
                    Static.Undefined,
                    new Constant[] { new Core.Javascript.String(template), arguments },
                    scope
                    );

                if (result is Core.Javascript.String s)
                {
                    return(s.Value);
                }
            } catch (Error e) {
                return(e.Message + "\n" + string.Join("\n", e.StackTrace.Select(loc => Debug.GetFileName(loc.FileId) + " (" + loc.LineNr + ")")));
            } catch (Exception e) {
                return("System error - " + e.ToString());
            }

            return("");
        }
コード例 #2
0
ファイル: Convert.cs プロジェクト: arjenst/NetJS
        public static Dictionary <string, object> ObjectToJson(Javascript.Object obj, Scope scope)
        {
            var json = new Dictionary <string, object>();

            foreach (var key in obj.GetKeys())
            {
                json[key] = ValueToJson(obj.Get(key), scope);
            }
            return(json);
        }
コード例 #3
0
ファイル: Convert.cs プロジェクト: arjenst/NetJS
        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);
        }
コード例 #4
0
ファイル: JSService.cs プロジェクト: arjenst/NetJS
        public string RunTemplate(string template, Core.Javascript.Object arguments, ref JSApplication application)
        {
            if (application == null)
            {
                application = new JSApplication();
            }

            var session = new JSSession();
            var svCache = new XHTMLMerge.SVCache();

            return(RunTemplate(template, arguments, ref application, ref session, ref svCache));
        }
コード例 #5
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));
        }
コード例 #6
0
ファイル: Tool.cs プロジェクト: arjenst/NetJS
 public static bool IsType(Javascript.Object obj, Javascript.Object prototype)
 {
     return(obj.__proto__ == prototype.Get <Javascript.Object>("prototype"));
 }