Search in sources :

Example 11 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, String 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 12 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, long 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 13 with PropertyDescriptor

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

the class JSONParser method jsonObject.

/**
     * <pre>
     * JSONObject :
     *      { }
     *      { JSONMemberList }
     * JSONMemberList :
     *      JSONMember 
     *      JSONMemberList , JSONMember
     * JSONMember :
     *      JSONString : JSONValue
     * </pre>
     * 
     * @return the script object represented by the JSON object
     */
private OrdinaryObject jsonObject() {
    OrdinaryObject object = ObjectCreate(cx, Intrinsics.ObjectPrototype);
    consume(Token.LC);
    if (token() != Token.RC) {
        for (; ; ) {
            consume(Token.STRING);
            String name = ts.getString();
            consume(Token.COLON);
            Object value = jsonValue();
            object.defineOwnProperty(cx, name, new PropertyDescriptor(value, true, true, true));
            if (token() == Token.RC) {
                break;
            }
            consume(Token.COMMA);
        }
    }
    consume(Token.RC);
    return object;
}
Also used : PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

Example 14 with PropertyDescriptor

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

the class JSONParser method jsonArray.

/**
     * <pre>
     * JSONArray :
     *      [ ]
     *      [ JSONElementList ]
     * JSONElementList :
     *      JSONValue
     *      JSONElementList , JSONValue
     * </pre>
     * 
     * @return the script object represented by the JSON array
     */
private ArrayObject jsonArray() {
    ArrayObject array = ArrayCreate(cx, 0);
    consume(Token.LB);
    if (token() != Token.RB) {
        for (long index = 0; ; ) {
            Object value = jsonValue();
            array.defineOwnProperty(cx, index++, new PropertyDescriptor(value, true, true, true));
            if (token() == Token.RB) {
                break;
            }
            consume(Token.COMMA);
        }
    }
    consume(Token.RB);
    return array;
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

Example 15 with PropertyDescriptor

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

the class Realm method SetDefaultGlobalBindings.

/**
     * 8.2.4 SetDefaultGlobalBindings ( realmRec )
     * <p>
     * Initializes {@code [[globalObject]]} with the default properties of the Global Object.
     * 
     * @param cx
     *            the execution context
     * @param realm
     *            the realm instance
     * @return the global object
     */
public static ScriptObject SetDefaultGlobalBindings(ExecutionContext cx, Realm realm) {
    /* step 1 */
    ScriptObject globalObject = realm.getGlobalObject();
    GlobalObject globalTemplate = realm.getGlobalObjectTemplate();
    assert globalObject != null && globalTemplate != null;
    /* step 2 */
    for (Object key : globalTemplate.ownPropertyKeys(cx)) {
        Property prop = globalTemplate.getOwnProperty(cx, key);
        if (prop != null) {
            PropertyDescriptor desc = prop.toPropertyDescriptor();
            DefinePropertyOrThrow(cx, globalObject, key, desc);
        }
    }
    /* step 3 */
    return globalObject;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) SystemObject(com.github.anba.es6draft.runtime.objects.reflect.SystemObject) AtomicsObject(com.github.anba.es6draft.runtime.objects.atomics.AtomicsObject) MathObject(com.github.anba.es6draft.runtime.objects.number.MathObject) ReflectObject(com.github.anba.es6draft.runtime.objects.reflect.ReflectObject) IntlObject(com.github.anba.es6draft.runtime.objects.intl.IntlObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) RealmObject(com.github.anba.es6draft.runtime.objects.reflect.RealmObject) Property(com.github.anba.es6draft.runtime.types.Property)

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