Exemplo n.º 1
0
 public synchronized void removeModuleLoader(String extension) {
   int length = loaders.length;
   for (int i = 0; i < length; i++) {
     if (loaders[i] instanceof ScriptedModuleLoader
         && extension.equals(loaders[i].getExtension())) {
       ModuleLoader[] newLoaders = new ModuleLoader[length - 1];
       if (i > 0) System.arraycopy(loaders, 0, newLoaders, 0, i);
       if (i < length - 1) System.arraycopy(loaders, i + 1, newLoaders, i, length - i - 1);
       loaders = newLoaders;
       return;
     }
   }
 }
Exemplo n.º 2
0
 /**
  * Get the script arguments as object array suitable for use with Context.newArray().
  *
  * @return the script arguments
  */
 public Object[] getArguments() {
   String[] args = config.getArguments();
   if (args == null) {
     return ScriptRuntime.emptyArgs;
   } else {
     Object[] array = new Object[args.length];
     System.arraycopy(args, 0, array, 0, args.length);
     return array;
   }
 }
Exemplo n.º 3
0
 public synchronized void addModuleLoader(String extension, Object value) {
   if (value == null || value == Undefined.instance) {
     removeModuleLoader(extension);
   } else if (!(value instanceof Function)) {
     throw Context.reportRuntimeError("Module loader must be a function");
   }
   Function function = (Function) value;
   int length = loaders.length;
   for (int i = 0; i < length; i++) {
     if (extension.equals(loaders[i].getExtension())) {
       // replace existing loader
       loaders[i] = new ScriptedModuleLoader(extension, function);
       return;
     }
   }
   ModuleLoader[] newLoaders = new ModuleLoader[length + 1];
   System.arraycopy(loaders, 0, newLoaders, 0, length);
   newLoaders[length] = new ScriptedModuleLoader(extension, function);
   loaders = newLoaders;
 }