Exemple #1
0
  public static void runRhinoTest(
      @NotNull List<String> fileNames,
      @NotNull RhinoResultChecker checker,
      @Nullable Map<String, Object> variables,
      @NotNull EcmaVersion ecmaVersion,
      @NotNull List<String> jsLibraries)
      throws Exception {
    Context context = createContext(ecmaVersion);

    context.setOptimizationLevel(OPTIMIZATION_OFF);
    if (variables != null) {
      context.setOptimizationLevel(getOptimizationLevel(variables));
    }

    try {
      ScriptableObject scope = getScope(ecmaVersion, context, jsLibraries);
      putGlobalVariablesIntoScope(scope, variables);

      context.evaluateString(
          scope, "kotlin.out = new kotlin.BufferedOutput();", "setup Kotlin.out", 0, null);

      for (String filename : fileNames) {
        runFileWithRhino(filename, context, scope);
        // String problems = lintIt(context, filename, scope);
        // if (problems != null) {
        //    //fail(problems);
        //    System.out.print(problems);
        // }
      }
      checker.runChecks(context, scope);
    } finally {
      Context.exit();
    }
  }
Exemple #2
0
 /** Close the context. */
 public void close() {
   try {
     ((Context) cx).exit();
   } catch (Exception e) {
     suite.passed = false;
     file.passed = false;
     file.exception = "file failed with exception:  " + e;
   }
 }
Exemple #3
0
 public static Object eval(String source, Map<String, Scriptable> bindings) {
   Context cx = ContextFactory.getGlobal().enterContext();
   try {
     Scriptable scope = cx.initStandardObjects();
     if (bindings != null) {
       for (String id : bindings.keySet()) {
         Scriptable object = bindings.get(id);
         object.setParentScope(scope);
         scope.put(id, scope, object);
       }
     }
     return cx.evaluateString(scope, source, "source", 1, null);
   } finally {
     Context.exit();
   }
 }
Exemple #4
0
 JavaMembers(Scriptable scope, Class<?> cl, boolean includeProtected) {
   try {
     Context cx = ContextFactory.getGlobal().enterContext();
     ClassShutter shutter = cx.getClassShutter();
     if (shutter != null && !shutter.visibleToScripts(cl.getName())) {
       throw Context.reportRuntimeError1("msg.access.prohibited", cl.getName());
     }
     this.includePrivate = cx.hasFeature(Context.FEATURE_ENHANCED_JAVA_ACCESS);
     this.members = new HashMap<String, Object>();
     this.staticMembers = new HashMap<String, Object>();
     this.cl = cl;
     reflect(scope, includeProtected);
   } finally {
     Context.exit();
   }
 }
Exemple #5
0
  protected T invoke(final Callable<T> call) throws Exception {
    initialContext.enter();

    Throwable throwable = null;
    try {
      taskStarting(
          future, executor, delegate); // do it in try to avoid issues if an exception is thrown
      return call.call();
    } catch (final Throwable t) {
      throwable = t;
      taskAborted(throwable);
      return rethrow(t);
    } finally {
      taskDone(future, executor, delegate, throwable);

      initialContext.exit();
    }
  }
Exemple #6
0
 /** @deprecated Use {@link Context#exit()} instead. */
 public final void exit() {
   Context.exit();
 }