예제 #1
0
  public ExecutionContext createFunctionExecutionContext(
      Object functionReference, JSFunction function, Object thisArg, Object... arguments) {
    // 10.4.3
    Object thisBinding = null;
    if (function.isStrict()) {
      thisBinding = thisArg;
    } else {
      if (thisArg == null || thisArg == Types.NULL || thisArg == Types.UNDEFINED) {
        thisBinding = this.getLexicalEnvironment().getGlobalObject();
      } else if (!(thisArg instanceof JSObject)) {
        // thisBinding = Types.toObject(this, thisArg);
        thisBinding = Types.toThisObject(this, thisArg);
      } else {
        thisBinding = thisArg;
      }
    }

    LexicalEnvironment scope = function.getScope();
    LexicalEnvironment localEnv = LexicalEnvironment.newDeclarativeEnvironment(scope);

    ExecutionContext context =
        new ExecutionContext(this, localEnv, localEnv, thisBinding, function.isStrict());
    context.performDeclarationBindingInstantiation(function, arguments);
    context.fileName = function.getFileName();
    // System.err.println( "debug null: " + ( function.getDebugContext() == null ? function : "not
    // null") );
    context.debugContext = function.getDebugContext();
    context.functionReference = functionReference;
    return context;
  }
예제 #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();
   }
 }