Example #1
0
  public ExecutionContext createEvalExecutionContext(JSProgram eval, boolean direct) {
    // 10.4.2 (with caller)
    ExecutionContext context = null;

    Object evalThisBinding = null;
    LexicalEnvironment evalLexEnv = null;
    LexicalEnvironment evalVarEnv = null;

    if (!direct) {
      evalThisBinding = getGlobalObject();
      evalLexEnv = LexicalEnvironment.newGlobalEnvironment(getGlobalObject());
      evalVarEnv = LexicalEnvironment.newGlobalEnvironment(getGlobalObject());
    } else {
      evalThisBinding = this.thisBinding;
      evalLexEnv = this.getLexicalEnvironment();
      evalVarEnv = this.getVariableEnvironment();
    }

    if (eval.isStrict()) {
      LexicalEnvironment strictVarEnv =
          LexicalEnvironment.newDeclarativeEnvironment(this.getLexicalEnvironment());
      evalLexEnv = strictVarEnv;
      evalVarEnv = strictVarEnv;
    }

    context = new ExecutionContext(this, evalLexEnv, evalVarEnv, evalThisBinding, eval.isStrict());
    context.performFunctionDeclarationBindings(eval, true);
    context.performVariableDeclarationBindings(eval, true);
    context.fileName = eval.getFileName();
    return context;
  }
Example #2
0
 public Completion execute(JSProgram program) {
   try {
     ThreadContextManager.pushContext(this);
     setStrict(program.isStrict());
     this.fileName = program.getFileName();
     performDeclarationBindingInstantiation(program);
     try {
       return program.execute(this);
     } catch (ThrowException e) {
       throw e;
     } catch (Throwable t) {
       throw new ThrowException(this, t);
     }
   } finally {
     ThreadContextManager.popContext();
   }
 }
Example #3
0
 public Object eval(JSProgram eval, boolean direct) {
   try {
     ExecutionContext evalContext = createEvalExecutionContext(eval, direct);
     ThreadContextManager.pushContext(evalContext);
     Completion result = eval.execute(evalContext);
     return result.value;
   } finally {
     ThreadContextManager.popContext();
   }
 }