示例#1
0
        public void ShouldNotRunInRun()
        {
            var filename = Path.GetTempFileName();
            File.WriteAllText(filename, "a='bar'");

            var engine = new JintEngine().AddPermission(new FileIOPermission(PermissionState.None));
            engine.AllowClr();
            engine.SetFunction("load", new Action<string>(p => engine.ExecuteFile(p)));
            engine.SetFunction("print", new Action<string>(Console.WriteLine));
            engine.Execute("var a='foo'; load('" + EscapeStringLiteral(filename) + "'); print(a);");
        }
示例#2
0
        public void ShouldRunInRun()
        {
            var filename = Path.GetTempFileName();
            File.WriteAllText(filename, "a='bar'");

            var engine = new JintEngine().AddPermission(new FileIOPermission(PermissionState.Unrestricted));
            engine.AllowClr();

            // The DLR compiler won't compile with permissions set
            engine.DisableSecurity();

            engine.SetFunction("load", new Action<string>(p => engine.ExecuteFile(p)));
            engine.SetFunction("print", new Action<string>(Console.WriteLine));
            engine.Execute("var a='foo'; load('" + EscapeStringLiteral(filename) + "'); print(a);");

            File.Delete(filename);
        }
示例#3
0
        public Plugin(DirectoryInfo directory, string name, string code)
        {
            Name          = name;
            Code          = code;
            RootDirectory = directory;
            Timers        = new Dictionary <String, TimedEvent>();

            Engine = new JintEngine();
            Engine.AllowClr(true);

            InitGlobals();
            Engine.Run(code);
            try
            {
                Engine.CallFunction("On_PluginInit");
            }
            catch { }
        }
示例#4
0
        public MagmaPlugin(DirectoryInfo directory, string name, string code)
        {
            Name           = name;
            Code           = code;
            RootDirectory  = directory;
            FunctionNames  = new List <string>();
            CommandList    = new List <string>();
            Timers         = new Dictionary <String, TimedEvent>();
            AdvancedTimers = new AdvancedTimer(this);
            Engine         = new JintEngine();
            Engine.AllowClr(true);

            InitGlobals();
            Engine.Run(code);
            object author  = GetGlobalObject("Author");
            object about   = GetGlobalObject("About");
            object version = GetGlobalObject("Version");

            Author  = author == null || author == "undefined" ? "Unknown" : author.ToString();
            About   = about == null || about == "undefined" ? "" : about.ToString();
            Version = version == null || version == "undefined" ? "1.0" : version.ToString();
        }
示例#5
0
        public void ShouldRunInRun() {
            var filename = Path.GetTempFileName();
            File.WriteAllText(filename, "a='bar'");

            var engine = new JintEngine().AddPermission(new FileIOPermission(PermissionState.Unrestricted));
            engine.AllowClr();
            engine.SetFunction("load", new Action<string>(delegate(string fileName) { using (var reader = File.OpenText(fileName)) { engine.Run(reader); } }));
            engine.SetFunction("print", new Action<string>(Console.WriteLine));
            engine.Run("var a='foo'; load('" + JintEngine.EscapteStringLiteral(filename) + "'); print(a);");

            File.Delete(filename);
        }