Search in sources :

Example 6 with PropertyDescriptor

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

the class GlobalEnvironmentRecord method createGlobalFunctionBinding.

/**
     * 8.1.1.4.18 CreateGlobalFunctionBinding (N, V, D)
     * 
     * @param name
     *            the binding name
     * @param value
     *            the function value
     * @param deletable
     *            the deletable for the binding
     */
public void createGlobalFunctionBinding(String name, Object value, boolean deletable) {
    /* steps 1-3 (omitted) */
    /* steps 4-5 */
    Property existingProp = globalObject.getOwnProperty(cx, name);
    /* steps 6-7 */
    PropertyDescriptor desc;
    if (existingProp == null || existingProp.isConfigurable()) {
        desc = new PropertyDescriptor(value, true, true, deletable);
    } else {
        desc = new PropertyDescriptor(value);
    }
    /* steps 8-9 */
    DefinePropertyOrThrow(cx, globalObject, name, desc);
    /* steps 10-12  */
    Set(cx, globalObject, name, value, false);
    /* steps 13-14 */
    varNames.add(name);
/* step 15 (return) */
}
Also used : PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) Property(com.github.anba.es6draft.runtime.types.Property) HasOwnProperty(com.github.anba.es6draft.runtime.AbstractOperations.HasOwnProperty)

Example 7 with PropertyDescriptor

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

the class ObjectEnvironmentRecord method createMutableBinding.

/**
     * 8.1.1.2.2 CreateMutableBinding (N,D)
     */
@Override
public void createMutableBinding(String name, boolean deletable) {
    /* steps 1-2 (omitted) */
    /* steps 3-4 */
    PropertyDescriptor desc = new PropertyDescriptor(UNDEFINED, true, true, deletable);
    DefinePropertyOrThrow(cx, bindings, name, desc);
}
Also used : PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor)

Example 8 with PropertyDescriptor

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

the class WrapperProxy method set.

@Override
public boolean set(ExecutionContext cx, Symbol propertyKey, Object value, Object receiver) {
    /* modified 9.1.9 [[Set] (P, V, Receiver) */
    Property ownDesc = proxyTarget.getOwnProperty(cx, propertyKey);
    if (ownDesc == null) {
        // modified
        ScriptObject parent = getPrototype();
        if (parent != null) {
            return parent.set(cx, propertyKey, value, receiver);
        } else {
            ownDesc = new Property(UNDEFINED, true, true, true);
        }
    }
    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) {
            PropertyDescriptor valueDesc = new PropertyDescriptor(value);
            return _receiver.defineOwnProperty(cx, propertyKey, valueDesc);
        } else {
            return CreateDataProperty(cx, _receiver, propertyKey, value);
        }
    }
    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 9 with PropertyDescriptor

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

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

the class IntlAbstractOperations method SupportedLocales.

/**
     * 9.2.9 SupportedLocales (availableLocales, requestedLocales, options)
     * 
     * @param cx
     *            the execution context
     * @param availableLocales
     *            the set of available locales
     * @param requestedLocales
     *            the set of requested locales
     * @param options
     *            the options object
     * @return the supported locales array
     */
public static ScriptObject SupportedLocales(ExecutionContext cx, Set<String> availableLocales, Set<String> requestedLocales, Object options) {
    /* step 1 */
    String matcher = null;
    if (!Type.isUndefined(options)) {
        matcher = GetStringOption(cx, ToObject(cx, options), "localeMatcher", set("lookup", "best fit"), "best fit");
    }
    /* steps 2-5 */
    List<String> supportedLocales;
    if (matcher == null || "best fit".equals(matcher)) {
        supportedLocales = BestFitSupportedLocales(availableLocales, requestedLocales);
    } else {
        supportedLocales = LookupSupportedLocales(availableLocales, requestedLocales);
    }
    /* steps 6-8 */
    ArrayObject subset = ArrayCreate(cx, supportedLocales.size());
    int index = 0;
    for (Object value : supportedLocales) {
        subset.defineOwnProperty(cx, index++, new PropertyDescriptor(value, false, true, false));
    }
    PropertyDescriptor nonConfigurableWritable = new PropertyDescriptor();
    nonConfigurableWritable.setConfigurable(false);
    nonConfigurableWritable.setWritable(false);
    subset.defineOwnProperty(cx, "length", nonConfigurableWritable);
    /* step 9 */
    return subset;
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

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