Search in sources :

Example 16 with PropertyDescriptor

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

the class Properties method createExternalAccessors.

private static void createExternalAccessors(ExecutionContext cx, OrdinaryObject target, ObjectLayout layout, Converter converter) {
    LinkedHashMap<String, PropertyDescriptor> stringProps = new LinkedHashMap<>();
    EnumMap<BuiltinSymbol, PropertyDescriptor> symbolProps = new EnumMap<>(BuiltinSymbol.class);
    for (Entry<Accessor, MethodHandle> entry : layout.accessors.entrySet()) {
        MethodHandle handle = getStaticMethodHandle(cx, converter, entry.getValue());
        createExternalAccessor(cx, entry.getKey(), handle, stringProps, symbolProps);
    }
    defineProperties(cx, target, stringProps, symbolProps);
}
Also used : BuiltinSymbol(com.github.anba.es6draft.runtime.types.BuiltinSymbol) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) AccessorPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.AccessorPropertyDescriptor) EnumMap(java.util.EnumMap) LinkedHashMap(java.util.LinkedHashMap) MethodHandle(java.lang.invoke.MethodHandle)

Example 17 with PropertyDescriptor

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

the class Properties method createConstructor.

private static OrdinaryObject createConstructor(ExecutionContext cx, String className, OrdinaryObject proto, Converter converter, ObjectLayout layout) {
    Entry<Function, MethodHandle> constructorEntry = findConstructor(layout);
    if (constructorEntry != null) {
        // User supplied method, perform manual ClassDefinitionEvaluation for constructors
        Function function = constructorEntry.getKey();
        MethodHandle unreflect = constructorEntry.getValue();
        MethodHandle callMethod = getConstructorStaticMethodHandle(cx, converter, unreflect, MethodKind.Call);
        MethodHandle constructMethod = getConstructorStaticMethodHandle(cx, converter, unreflect, MethodKind.Construct);
        NativeConstructor constructor = new NativeConstructor(cx.getRealm(), className, function.arity(), callMethod, constructMethod);
        constructor.defineOwnProperty(cx, "prototype", new PropertyDescriptor(proto, false, false, false));
        proto.defineOwnProperty(cx, "constructor", new PropertyDescriptor(constructor, true, false, true));
        return constructor;
    }
    // Create default constructor
    String sourceText = String.format("(class %s { })", sanitizeName(className));
    ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
    Script script = scriptLoader.script(new Source("<Constructor>", 1), sourceText);
    Object constructor = script.evaluate(cx);
    assert constructor instanceof OrdinaryConstructorFunction : constructor.getClass();
    return (OrdinaryConstructorFunction) constructor;
}
Also used : NativeFunction(com.github.anba.es6draft.runtime.types.builtins.NativeFunction) OrdinaryConstructorFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction) BuiltinFunction(com.github.anba.es6draft.runtime.types.builtins.BuiltinFunction) NativeTailCallFunction(com.github.anba.es6draft.runtime.types.builtins.NativeTailCallFunction) NativeConstructor(com.github.anba.es6draft.runtime.types.builtins.NativeConstructor) Script(com.github.anba.es6draft.Script) OrdinaryConstructorFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) AccessorPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.AccessorPropertyDescriptor) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) MethodHandle(java.lang.invoke.MethodHandle)

Example 18 with PropertyDescriptor

use of com.github.anba.es6draft.runtime.types.PropertyDescriptor 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 19 with PropertyDescriptor

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

the class ArrayObject method ArraySetLength.

/**
     * 9.4.2.4 ArraySetLength(A, Desc)
     * 
     * @param cx
     *            the execution context
     * @param array
     *            the array object
     * @param desc
     *            the property descriptor
     * @return {@code true} on success
     */
public static boolean ArraySetLength(ExecutionContext cx, ArrayObject array, PropertyDescriptor desc) {
    /* step 1 */
    if (!desc.hasValue()) {
        return array.defineLength(desc, -1);
    }
    /* step 2 */
    PropertyDescriptor newLenDesc = desc.clone();
    /* steps 3-4 */
    long newLen = ToUint32(cx, desc.getValue());
    /* steps 5-6 */
    double numberLen = ToNumber(cx, desc.getValue());
    /* step 7 */
    if (newLen != numberLen) {
        throw newRangeError(cx, Messages.Key.InvalidArrayLength);
    }
    /* step 8 */
    newLenDesc.setValue(newLen);
    /* steps 9-11 */
    long oldLen = array.length;
    /* step 12 */
    if (newLen >= oldLen) {
        return array.defineLength(newLenDesc, newLen);
    }
    /* step 13 */
    if (!array.lengthWritable) {
        return false;
    }
    /* steps 14-15 */
    boolean newWritable;
    if (!newLenDesc.hasWritable() || newLenDesc.isWritable()) {
        newWritable = true;
    } else {
        newWritable = false;
        newLenDesc.setWritable(true);
    }
    /* steps 16-17 */
    boolean succeeded = array.defineLength(newLenDesc, newLen);
    /* step 18 */
    if (!succeeded) {
        return false;
    }
    /* step 19 */
    long nonDeletableIndex = array.deleteRange(newLen, oldLen);
    /* step 19.d */
    if (nonDeletableIndex >= 0) {
        array.length = nonDeletableIndex + 1;
        if (!newWritable) {
            array.lengthWritable = false;
        }
        return false;
    }
    /* step 20 */
    if (!newWritable) {
        array.lengthWritable = false;
    }
    /* step 21 */
    return true;
}
Also used : PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor)

Example 20 with PropertyDescriptor

use of com.github.anba.es6draft.runtime.types.PropertyDescriptor 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

PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)21 Property (com.github.anba.es6draft.runtime.types.Property)10 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)10 Callable (com.github.anba.es6draft.runtime.types.Callable)6 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)5 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)5 AccessorPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.AccessorPropertyDescriptor)4 BuiltinSymbol (com.github.anba.es6draft.runtime.types.BuiltinSymbol)3 MethodHandle (java.lang.invoke.MethodHandle)3 FromPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.FromPropertyDescriptor)2 ToPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.ToPropertyDescriptor)2 NativeFunction (com.github.anba.es6draft.runtime.types.builtins.NativeFunction)2 EnumMap (java.util.EnumMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Script (com.github.anba.es6draft.Script)1 HasOwnProperty (com.github.anba.es6draft.runtime.AbstractOperations.HasOwnProperty)1 AtomicsObject (com.github.anba.es6draft.runtime.objects.atomics.AtomicsObject)1 IntlObject (com.github.anba.es6draft.runtime.objects.intl.IntlObject)1 MathObject (com.github.anba.es6draft.runtime.objects.number.MathObject)1 RealmObject (com.github.anba.es6draft.runtime.objects.reflect.RealmObject)1