Пример #1
0
 /// <summary>
 /// Executes a JavaScript file in the current context
 /// </summary>
 /// <param name="filename"></param>
 /// <returns></returns>
 public bool injectJs(string filename)
 {
     if (Program.Context.Find(filename) != null)
     {
         try
         {
             Program.Context.RunFile(filename);
             return(true);
         }
         catch (Exception ex)
         {
             Context.Handle(ex);
         }
     }
     return(false);
 }
Пример #2
0
 /// <summary>
 /// Creates a module
 /// </summary>
 /// <param name="js"></param>
 public static void createModule(string name, string src)
 {
     try
     {
         // Fix the path separator
         name = name.Replace("\\", "\\\\");
         string code = "(function(require, exports, module) {" +
                       src +
                       "}.call({}," +
                       "require," +
                       "require.cache['" + name + "'].exports," +
                       "require.cache['" + name + "']" +
                       "));";
         Program.Context.Run(
             code
             );
     }
     catch (Exception ex)
     {
         Context.Handle(ex);
     }
 }