Search in sources :

Example 11 with Property

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

the class BuiltinFunction method defineProperty.

@Override
protected boolean defineProperty(ExecutionContext cx, String propertyKey, PropertyDescriptor desc) {
    if (hasDefaultName && "name".equals(propertyKey)) {
        hasDefaultName = false;
        defineOwnPropertyUnchecked(propertyKey, new Property(name, false, false, true));
    }
    if (hasDefaultLength && "length".equals(propertyKey)) {
        hasDefaultLength = false;
        defineOwnPropertyUnchecked(propertyKey, new Property(arity, false, false, true));
    }
    return super.defineProperty(cx, propertyKey, desc);
}
Also used : Property(com.github.anba.es6draft.runtime.types.Property)

Example 12 with Property

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

the class ArgumentsObject method CreateMappedArgumentsObject.

/**
     * 9.4.4.7 CreateMappedArgumentsObject ( func, formals, argumentsList, env )
     * <p>
     * [Called from generated code]
     * 
     * @param cx
     *            the execution context
     * @param func
     *            the function callee
     * @param argumentsList
     *            the function arguments
     * @param map
     *            the parameter map
     * @return the mapped arguments object
     */
static ArgumentsObject CreateMappedArgumentsObject(ExecutionContext cx, FunctionObject func, Object[] argumentsList, ParameterMap map) {
    /* step 1 (not applicable) */
    /* step 2 */
    int len = argumentsList.length;
    /* steps 3-11 */
    ArgumentsObject obj = new ArgumentsObject(cx.getRealm());
    obj.setPrototype(cx.getIntrinsic(Intrinsics.ObjectPrototype));
    /* steps 14-15 */
    for (int index = 0; index < len; ++index) {
        obj.setIndexed(index, argumentsList[index]);
    }
    /* step 16 */
    obj.infallibleDefineOwnProperty("length", new Property(len, true, false, true));
    /* steps 17-21 */
    obj.parameterMap = map;
    /* step 22 */
    obj.infallibleDefineOwnProperty(BuiltinSymbol.iterator.get(), new Property(cx.getIntrinsic(Intrinsics.ArrayProto_values), true, false, true));
    /* steps 23-24 */
    obj.infallibleDefineOwnProperty("callee", new Property(func, true, false, true));
    /* step 25 */
    return obj;
}
Also used : Property(com.github.anba.es6draft.runtime.types.Property)

Example 13 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, String 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 14 with Property

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

the class OrdinaryObject method ordinaryDefineOwnProperty.

/**
     * 9.1.6.1 OrdinaryDefineOwnProperty (O, P, Desc)
     * 
     * @param cx
     *            the execution context
     * @param propertyKey
     *            the property key
     * @param desc
     *            the property descriptor
     * @return {@code true} on success
     */
protected final boolean ordinaryDefineOwnProperty(ExecutionContext cx, long propertyKey, PropertyDescriptor desc) {
    /* steps 1-2 */
    Property current = getProperty(cx, propertyKey);
    /* step 3 */
    boolean extensible = isExtensible();
    /* step 4 */
    return validateAndApplyPropertyDescriptor(indexedProperties, propertyKey, extensible, desc, current);
}
Also used : Property(com.github.anba.es6draft.runtime.types.Property)

Example 15 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, Symbol 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)

Aggregations

Property (com.github.anba.es6draft.runtime.types.Property)51 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)33 Callable (com.github.anba.es6draft.runtime.types.Callable)26 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)10 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)8 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)4 ArrayList (java.util.ArrayList)3 CompilationException (com.github.anba.es6draft.compiler.CompilationException)2 ParserException (com.github.anba.es6draft.parser.ParserException)2 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)2 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)2 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)2 Source (com.github.anba.es6draft.runtime.internal.Source)2 FunctionConstructor.functionSource (com.github.anba.es6draft.runtime.objects.FunctionConstructor.functionSource)2 Intrinsics (com.github.anba.es6draft.runtime.types.Intrinsics)2 ImmutablePrototypeObject (com.github.anba.es6draft.runtime.types.builtins.ImmutablePrototypeObject)2 HasOwnProperty (com.github.anba.es6draft.runtime.AbstractOperations.HasOwnProperty)1 ToFlatString (com.github.anba.es6draft.runtime.AbstractOperations.ToFlatString)1 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)1 AtomicsObject (com.github.anba.es6draft.runtime.objects.atomics.AtomicsObject)1