예제 #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;
  }
예제 #2
0
  private void performDeclarationBindingInstantiation(JSFunction function, Object[] arguments) {
    // 10.5 (Functions)
    String[] names = function.getFormalParameters();

    Object v = null;

    DeclarativeEnvironmentRecord env =
        (DeclarativeEnvironmentRecord) this.variableEnvironment.getRecord();

    // * 4
    for (int i = 0; i < names.length; ++i) {
      if ((i + 1) > arguments.length) {
        v = Types.UNDEFINED;
      } else {
        v = arguments[i];
      }

      if (!env.hasBinding(this, names[i])) {
        env.createMutableBinding(this, names[i], false);
      }

      env.setMutableBinding(this, names[i], v, function.isStrict());
    }

    // * 5
    performFunctionDeclarationBindings(function, false);

    // * 6
    if (!env.hasBinding(this, "arguments")) {
      // * 7
      Arguments argsObj = createArgumentsObject(function, arguments);

      if (function.isStrict()) {
        env.createImmutableBinding("arguments");
        env.initializeImmutableBinding("arguments", argsObj);
      } else {
        env.createMutableBinding(this, "arguments", false);
        env.setMutableBinding(this, "arguments", argsObj, false);
      }
    }

    // * 8
    performVariableDeclarationBindings(function, false);
  }
예제 #3
0
 private void performDeclarationBindingInstantiation(JSProgram program) {
   performFunctionDeclarationBindings(program, false);
   performVariableDeclarationBindings(program, false);
 }