// Copyright (c) 2013-2014, Webit Team. All Rights Reserved.
package webit.script.core.ast.expressions;

import java.util.HashMap;
import java.util.Map;
import webit.script.Context;
import webit.script.core.ast.AbstractExpression;
import webit.script.core.ast.Expression;
import webit.script.util.StatementUtil;

/**
 *
 * @author Zqq
 */
public final class MapValue extends AbstractExpression {

    private final static float DEFAULT_MAP_FACTOR = 0.75f;
    private final static int MIN_MAP_CAPACITY = 4;
    private final Object[] keys;
    private final Expression[] valueExprs;
    private final int initialCapacity;

    public MapValue(Object[] keys, Expression[] valueExprs, int line, int column) {
        super(line, column);
        this.keys = keys;
        this.valueExprs = valueExprs;
        int cap = (keys.length + 1) * 4 / 3;
        this.initialCapacity = cap > MIN_MAP_CAPACITY ? cap : MIN_MAP_CAPACITY;
    }

    @SuppressWarnings("unchecked")
    public Object execute(final Context context) {
        final int len = valueExprs.length;
        final Map value = new HashMap(initialCapacity, DEFAULT_MAP_FACTOR);
        for (int i = 0; i < len; i++) {
            value.put(keys[i], StatementUtil.execute(valueExprs[i], context));
        }
        return value;
    }
}

@@ -1007,24 +1007,122 @@
  context) %7B%0A
+        final Object%5B%5D keys = this.keys;%0A        final Expression%5B%5D valueExprs = this.valueExprs;%0A
         fina

Update MapValue