/** [15.2.8 Runtime Semantics: GlobalDeclarationInstantiation] */
  public static void GlobalDeclarationInstantiation(
      ExecutionContext cx,
      Script script,
      LexicalEnvironment globalEnv,
      LexicalEnvironment lexicalEnv,
      boolean deletableBindings) {
    LexicalEnvironment env = globalEnv;
    GlobalEnvironmentRecord envRec = (GlobalEnvironmentRecord) env.getEnvRec();

    for (String name : VarDeclaredNames(script)) {
      if (envRec.hasLexicalDeclaration(name)) {
        throw newSyntaxError(cx, Messages.Key.VariableRedeclaration, name);
      }
    }
    List<StatementListItem> varDeclarations = VarScopedDeclarations(script);
    Set<String> declaredVarNames = new HashSet<>();
    for (StatementListItem d : varDeclarations) {
      assert d instanceof VariableStatement;
      for (String vn : BoundNames((VariableStatement) d)) {
        boolean vnDefinable = envRec.canDeclareGlobalVar(vn);
        if (!vnDefinable) {
          throw newTypeError(cx, Messages.Key.InvalidDeclaration, vn);
        }
        if (!declaredVarNames.contains(vn)) {
          declaredVarNames.add(vn);
        }
      }
    }
    for (String vn : declaredVarNames) {
      envRec.createGlobalVarBinding(vn, deletableBindings);
    }
  }
  /** [18.2.1.2 Eval Declaration Instantiation] */
  public static void EvalDeclarationInstantiation(
      ExecutionContext cx,
      Script script,
      LexicalEnvironment varEnv,
      LexicalEnvironment lexEnv,
      boolean deletableBindings) {
    // FIXME: spec incomplete (using modified ES5.1 algorithm for now...)

    LexicalEnvironment env = varEnv;
    EnvironmentRecord envRec = env.getEnvRec();
    // boolean strict = script.isStrict();
    for (StatementListItem d : VarScopedDeclarations(script)) {
      assert d instanceof VariableStatement;
      for (String dn : BoundNames((VariableStatement) d)) {
        boolean varAlreadyDeclared = envRec.hasBinding(dn);
        if (!varAlreadyDeclared) {
          envRec.createMutableBinding(dn, deletableBindings);
          // envRec.setMutableBinding(dn, UNDEFINED, strict);
          envRec.initialiseBinding(dn, UNDEFINED);
        }
      }
    }
  }