Search in sources :

Example 1 with ToPropertyDescriptor

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

the class ObjectConstructor method ObjectDefineProperties.

/**
     * 19.1.2.3.1 Runtime Semantics: ObjectDefineProperties ( O, Properties )
     * 
     * @param cx
     *            the execution context
     * @param o
     *            the script object
     * @param properties
     *            the properties object
     * @return the script object
     */
public static ScriptObject ObjectDefineProperties(ExecutionContext cx, Object o, Object properties) {
    /* step 1 */
    if (!Type.isObject(o)) {
        throw newTypeError(cx, Messages.Key.NotObjectType);
    }
    ScriptObject obj = Type.objectValue(o);
    /* steps 2-3 */
    ScriptObject props = ToObject(cx, properties);
    /* steps 4-5 */
    List<?> keys = props.ownPropertyKeys(cx);
    /* step 6 */
    int initialSize = Math.min(32, keys.size());
    ArrayList<PropertyDescriptor> descriptors = new ArrayList<>(initialSize);
    ArrayList<Object> names = new ArrayList<>(initialSize);
    /* step 7 */
    for (Object nextKey : keys) {
        Property propDesc = props.getOwnProperty(cx, nextKey);
        if (propDesc != null && propDesc.isEnumerable()) {
            Object descObj = Get(cx, props, nextKey);
            PropertyDescriptor desc = ToPropertyDescriptor(cx, descObj);
            descriptors.add(desc);
            names.add(nextKey);
        }
    }
    /* step 8 */
    for (int i = 0, size = names.size(); i < size; ++i) {
        Object p = names.get(i);
        PropertyDescriptor desc = descriptors.get(i);
        DefinePropertyOrThrow(cx, obj, p, desc);
    }
    /* step 9 */
    return obj;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ToPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.ToPropertyDescriptor) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) FromPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.FromPropertyDescriptor) ArrayList(java.util.ArrayList) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ImmutablePrototypeObject(com.github.anba.es6draft.runtime.types.builtins.ImmutablePrototypeObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) Property(com.github.anba.es6draft.runtime.types.Property)

Example 2 with ToPropertyDescriptor

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

the class ScriptRuntime method evaluateMethodDecorators.

private static int evaluateMethodDecorators(OrdinaryObject object, ArrayList<Object> decorators, int start, ExecutionContext cx) {
    int count = 0;
    for (int i = start, size = decorators.size(); i < size; ++i, ++count) {
        if (!(decorators.get(i) instanceof Callable))
            break;
    }
    assert count > 0;
    Object propKey = decorators.get(start + count);
    Property property = object.getOwnProperty(cx, propKey);
    // Current proposal uses `undefined` instead of the initial property descriptor in, and only
    // in, object literals. We don't support this distinction between decorators for object and
    // decorators for class methods.
    Object desc = FromPropertyDescriptor(cx, property);
    for (int i = start; i < start + count; ++i) {
        Callable decorator = (Callable) decorators.get(i);
        Object result = decorator.call(cx, UNDEFINED, object, propKey, desc);
        if (Type.isObject(result)) {
            // So, this means a bad decorator can mess up all following decorators?
            // Example: `({ @(()=>({})) @((o,p,d)=>{ print(JSON.stringify(d)) }) m() {} })`
            desc = result;
        }
    }
    if (Type.isObject(desc)) {
        PropertyDescriptor pdesc = ToPropertyDescriptor(cx, desc);
        DefinePropertyOrThrow(cx, object, propKey, pdesc);
    }
    return count;
}
Also used : AccessorPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.AccessorPropertyDescriptor) ToPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.ToPropertyDescriptor) FromPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.FromPropertyDescriptor) GeneratorObject(com.github.anba.es6draft.runtime.objects.iteration.GeneratorObject) TypedArrayObject(com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject) CompiledObject(com.github.anba.es6draft.compiler.CompiledObject)

Example 3 with ToPropertyDescriptor

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

the class ProxyObject method validateGetOwnProperty.

private Property validateGetOwnProperty(ExecutionContext cx, ScriptObject target, Object trapResultObj, Property targetDesc) {
    /* step 14 */
    if (Type.isUndefined(trapResultObj)) {
        if (targetDesc == null) {
            return null;
        }
        if (!targetDesc.isConfigurable()) {
            throw newTypeError(cx, Messages.Key.ProxyNotConfigurable);
        }
        boolean extensibleTarget = IsExtensible(cx, target);
        if (!extensibleTarget) {
            throw newTypeError(cx, Messages.Key.ProxyNotExtensible);
        }
        return null;
    }
    if (targetDesc != null) {
        // need copy because of possible side-effects in IsExtensible()
        targetDesc = targetDesc.clone();
    }
    /* steps 15-16 */
    boolean extensibleTarget = IsExtensible(cx, target);
    /* steps 17-18 */
    PropertyDescriptor resultDesc = ToPropertyDescriptor(cx, trapResultObj);
    /* step 19 */
    CompletePropertyDescriptor(resultDesc);
    /* step 20 */
    boolean valid = IsCompatiblePropertyDescriptor(extensibleTarget, resultDesc, targetDesc);
    /* step 21 */
    if (!valid) {
        throw newTypeError(cx, Messages.Key.ProxyIncompatibleDescriptor);
    }
    /* step 22 */
    if (!resultDesc.isConfigurable()) {
        if (targetDesc == null || targetDesc.isConfigurable()) {
            throw newTypeError(cx, Messages.Key.ProxyAbsentOrConfigurable);
        }
    }
    /* step 23 */
    return resultDesc.toProperty();
}
Also used : CompletePropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.CompletePropertyDescriptor) ToPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.ToPropertyDescriptor) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) FromPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.FromPropertyDescriptor) IsCompatiblePropertyDescriptor(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject.IsCompatiblePropertyDescriptor)

Aggregations

FromPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.FromPropertyDescriptor)3 ToPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.ToPropertyDescriptor)3 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)2 CompiledObject (com.github.anba.es6draft.compiler.CompiledObject)1 TypedArrayObject (com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject)1 GeneratorObject (com.github.anba.es6draft.runtime.objects.iteration.GeneratorObject)1 Property (com.github.anba.es6draft.runtime.types.Property)1 AccessorPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.AccessorPropertyDescriptor)1 CompletePropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.CompletePropertyDescriptor)1 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)1 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)1 ImmutablePrototypeObject (com.github.anba.es6draft.runtime.types.builtins.ImmutablePrototypeObject)1 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)1 IsCompatiblePropertyDescriptor (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject.IsCompatiblePropertyDescriptor)1 ArrayList (java.util.ArrayList)1