示例#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;
  }