Search in sources :

Example 51 with Property

use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.

the class ArgumentsObject method getProperty.

/**
     * 9.4.4.1 [[GetOwnProperty]] (P)
     */
@Override
protected Property getProperty(ExecutionContext cx, long propertyKey) {
    /* step 1 (not applicable) */
    /* step 2 */
    Property desc = ordinaryGetOwnProperty(propertyKey);
    /* step 3 */
    if (desc == null) {
        return desc;
    }
    /* step 4 */
    ParameterMap map = this.parameterMap;
    /* steps 5-6 */
    boolean isMapped = map != null && map.hasOwnProperty(propertyKey);
    /* step 7 */
    if (isMapped) {
        // FIXME: spec issue - maybe add assertion: IsDataDescriptor(desc)?
        assert desc.isDataDescriptor();
        PropertyDescriptor d = desc.toPropertyDescriptor();
        d.setValue(map.get(propertyKey));
        desc = d.toProperty();
    }
    /* step 9 */
    return desc;
}
Also used : PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) Property(com.github.anba.es6draft.runtime.types.Property)

Example 52 with Property

use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.

the class OrdinaryObject method getValue.

/**
     * 9.1.8 [[Get]] (P, Receiver)
     *
     * @param cx
     *            the execution context
     * @param propertyKey
     *            the property key
     * @param receiver
     *            the receiver object
     * @return the property value
     */
protected Object getValue(ExecutionContext cx, long propertyKey, Object receiver) {
    /* step 1 (implicit) */
    /* steps 2-3 */
    Property desc = getProperty(cx, propertyKey);
    /* step 4 */
    if (desc == null) {
        ScriptObject parent = getPrototypeOf(cx);
        if (parent == null) {
            return UNDEFINED;
        }
        return parent.get(cx, propertyKey, receiver);
    }
    /* step 5 */
    if (desc.isDataDescriptor()) {
        return desc.getValue();
    }
    assert desc.isAccessorDescriptor();
    /* step 6 */
    Callable getter = desc.getGetter();
    /* step 7 */
    if (getter == null) {
        return UNDEFINED;
    }
    /* step 8 */
    return getter.call(cx, receiver, EMPTY_GETTER_ARGS);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Property(com.github.anba.es6draft.runtime.types.Property) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 53 with Property

use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.

the class OrdinaryObject method setValue.

/**
     * 9.1.9 [[Set] (P, V, Receiver)
     * 
     * @param cx
     *            the execution context
     * @param propertyKey
     *            the property key
     * @param value
     *            the new property value
     * @param receiver
     *            the receiver object
     * @return {@code true} on success
     */
protected boolean setValue(ExecutionContext cx, long propertyKey, Object value, Object receiver) {
    /* step 1 (implicit) */
    /* steps 2-3 */
    Property ownDesc = getProperty(cx, propertyKey);
    /* step 4 */
    if (ownDesc == null) {
        ScriptObject parent = getPrototypeOf(cx);
        if (parent != null) {
            return parent.set(cx, propertyKey, value, receiver);
        } else {
            ownDesc = new Property(UNDEFINED, true, true, true);
        }
    } else if (receiver == this && ownDesc.isWritable()) {
        // Optimize the common case for own, writable properties
        return setPropertyValue(cx, propertyKey, value, ownDesc);
    }
    /* step 5 */
    if (ownDesc.isDataDescriptor()) {
        if (!ownDesc.isWritable()) {
            return false;
        }
        if (!Type.isObject(receiver)) {
            return false;
        }
        ScriptObject _receiver = Type.objectValue(receiver);
        Property existingDescriptor = _receiver.getOwnProperty(cx, propertyKey);
        if (existingDescriptor != null) {
            if (existingDescriptor.isAccessorDescriptor() || !existingDescriptor.isWritable()) {
                return false;
            }
            PropertyDescriptor valueDesc = new PropertyDescriptor(value);
            return _receiver.defineOwnProperty(cx, propertyKey, valueDesc);
        } else {
            return CreateDataProperty(cx, _receiver, propertyKey, value);
        }
    }
    /* step 6 */
    assert ownDesc.isAccessorDescriptor();
    Callable setter = ownDesc.getSetter();
    if (setter == null) {
        return false;
    }
    setter.call(cx, receiver, value);
    return true;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) Property(com.github.anba.es6draft.runtime.types.Property) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 54 with Property

use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.

the class OrdinaryObject method isEnumerableOwnProperty.

/**
     * Subclasses need to override this method if they have virtual, configurable properties.
     * 
     * @param propertyKey
     *            the property key
     * @return the property enumerable status
     */
protected Enumerability isEnumerableOwnProperty(String propertyKey) {
    Property prop;
    long index = IndexedMap.toIndex(propertyKey);
    if (IndexedMap.isIndex(index)) {
        prop = ordinaryGetOwnProperty(index);
    } else {
        prop = ordinaryGetOwnProperty(propertyKey);
    }
    if (prop == null) {
        return Enumerability.Deleted;
    }
    return Enumerability.isEnumerable(prop.isEnumerable());
}
Also used : Property(com.github.anba.es6draft.runtime.types.Property)

Example 55 with Property

use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.

the class OrdinaryFunction method FunctionInitialize.

/**
     * 9.2.4 FunctionInitialize (F, kind, ParameterList, Body, Scope)
     * 
     * @param f
     *            the function object
     * @param kind
     *            the function kind
     * @param function
     *            the function code
     * @param scope
     *            the lexical environment
     * @param executable
     *            the executable object
     */
public static void FunctionInitialize(FunctionObject f, FunctionKind kind, RuntimeInfo.Function function, LexicalEnvironment<?> scope, Executable executable) {
    /* step 1 */
    assert f.isExtensible() && !f.ordinaryHasOwnProperty("length");
    /* step 2 */
    int len = function.expectedArgumentCount();
    /* steps 3-4 */
    f.infallibleDefineOwnProperty("length", new Property(len, false, false, true));
    /* steps 5-11 */
    f.initialize(kind, function, scope, executable);
/* step 12 (return) */
}
Also used : Property(com.github.anba.es6draft.runtime.types.Property)

Aggregations

Property (com.github.anba.es6draft.runtime.types.Property)93 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)54 Callable (com.github.anba.es6draft.runtime.types.Callable)44 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)19 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)18 OrdinaryGenerator (com.github.anba.es6draft.runtime.types.builtins.OrdinaryGenerator)6 OrdinaryAsyncGenerator (com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncGenerator)5 PrivateName (com.github.anba.es6draft.runtime.types.PrivateName)4 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)4 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)4 CreateDataProperty (com.github.anba.es6draft.runtime.AbstractOperations.CreateDataProperty)3 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)3 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)3 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)3 OrdinaryFunction (com.github.anba.es6draft.runtime.types.builtins.OrdinaryFunction)3 ArrayList (java.util.ArrayList)3 CompilationException (com.github.anba.es6draft.compiler.CompilationException)2 ParserException (com.github.anba.es6draft.parser.ParserException)2 DeclarativeEnvironmentRecord (com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)2 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)2