Search in sources :

Example 71 with Property

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

the class Properties method createAccessor.

private static void createAccessor(Realm realm, OrdinaryObject target, AccessorLayout layout) {
    int arity = accessorArity(layout.type);
    NativeFunction fun = new NativeFunction(realm, layout.accessorName, arity, layout.nativeId, layout.methodHandle);
    Property accessorProperty = lookupOwnProperty(target, layout);
    if (accessorProperty == null) {
        defineProperty(target, layout, accessorProperty(layout, fun));
    } else {
        assert accessorProperty.isAccessorDescriptor();
        assert accessorProperty.isConfigurable() == layout.configurable();
        assert accessorProperty.isEnumerable() == layout.enumerable();
        assert (layout.type == Accessor.Type.Getter ? accessorProperty.getGetter() : accessorProperty.getSetter()) == null;
        accessorProperty.apply(accessorPropertyDescriptor(layout, fun));
    }
}
Also used : NativeFunction(com.github.anba.es6draft.runtime.types.builtins.NativeFunction) Property(com.github.anba.es6draft.runtime.types.Property)

Example 72 with Property

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

the class ClassOperations method DefineField.

public static void DefineField(Object fieldName, Object initValue, ExecutionContext cx) {
    EnvironmentRecord envRec = cx.getThisEnvironment();
    assert envRec instanceof FunctionEnvironmentRecord;
    FunctionEnvironmentRecord fEnvRec = (FunctionEnvironmentRecord) envRec;
    assert fEnvRec.getThisBindingStatus() == FunctionEnvironmentRecord.ThisBindingStatus.Initialized;
    assert fEnvRec.getThisValue() instanceof ScriptObject;
    ScriptObject receiver = (ScriptObject) fEnvRec.getThisValue();
    if (fieldName instanceof PrivateName) {
        PrivateName name = (PrivateName) fieldName;
        Property desc = new Property(initValue, true, false, false);
        privateFieldDefine(cx, receiver, name, desc);
    } else {
        assert IsPropertyKey(fieldName);
        CreateDataPropertyOrThrow(cx, receiver, fieldName, initValue);
    }
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) PrivateName(com.github.anba.es6draft.runtime.types.PrivateName) FunctionEnvironmentRecord(com.github.anba.es6draft.runtime.FunctionEnvironmentRecord) FunctionEnvironmentRecord(com.github.anba.es6draft.runtime.FunctionEnvironmentRecord) EnvironmentRecord(com.github.anba.es6draft.runtime.EnvironmentRecord) Property(com.github.anba.es6draft.runtime.types.Property)

Example 73 with Property

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

the class ClassOperations method InitializeInstanceFields.

public static void InitializeInstanceFields(ScriptObject thisValue, OrdinaryConstructorFunction constructor, ExecutionContext cx) {
    Property initializerDesc = constructor.get(CLASS_INSTANCE_INITIALIZER);
    if (initializerDesc != null) {
        assert initializerDesc.isDataDescriptor();
        Object initializer = initializerDesc.getValue();
        assert initializer instanceof OrdinaryFunction;
        OrdinaryFunction initializerFn = (OrdinaryFunction) initializer;
        Property instanceMethods = initializerFn.get(INSTANCE_METHODS);
        assert instanceMethods != null && instanceMethods.isDataDescriptor();
        if (instanceMethods.getValue() != null) {
            initializeInstanceMethods(thisValue, arrayValue(instanceMethods, InstanceMethod[].class), cx);
        }
        // Call the instance fields initializer.
        Property classFields = initializerFn.get(CLASS_FIELDS);
        assert classFields != null && classFields.isDataDescriptor();
        if (classFields.getValue() != null) {
            initializerFn.call(cx, thisValue);
        }
    }
}
Also used : OrdinaryFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryFunction) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) FunctionObject(com.github.anba.es6draft.runtime.types.builtins.FunctionObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) Property(com.github.anba.es6draft.runtime.types.Property)

Example 74 with Property

use of com.github.anba.es6draft.runtime.types.Property 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();
    OrdinaryObject globalProperties = realm.getGlobalPropertiesObject();
    assert globalObject != null && globalProperties != null;
    /* step 2 */
    for (Object key : globalProperties.ownPropertyKeys(cx)) {
        Property prop = globalProperties.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) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ZoneObject(com.github.anba.es6draft.runtime.objects.zone.ZoneObject) 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) 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)

Example 75 with Property

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

the class WrapperProxy method set.

@Override
public boolean set(ExecutionContext cx, Symbol propertyKey, Object value, Object receiver) {
    Property ownDesc = proxyTarget.getOwnProperty(cx, propertyKey);
    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);
        }
    }
    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) CreateDataProperty(com.github.anba.es6draft.runtime.AbstractOperations.CreateDataProperty) IsCallable(com.github.anba.es6draft.runtime.AbstractOperations.IsCallable) Callable(com.github.anba.es6draft.runtime.types.Callable)

Aggregations

Property (com.github.anba.es6draft.runtime.types.Property)93 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)54 Callable (com.github.anba.es6draft.runtime.types.Callable)44 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)19 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)18 OrdinaryGenerator (com.github.anba.es6draft.runtime.types.builtins.OrdinaryGenerator)6 OrdinaryAsyncGenerator (com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncGenerator)5 PrivateName (com.github.anba.es6draft.runtime.types.PrivateName)4 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)4 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)4 CreateDataProperty (com.github.anba.es6draft.runtime.AbstractOperations.CreateDataProperty)3 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)3 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)3 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)3 OrdinaryFunction (com.github.anba.es6draft.runtime.types.builtins.OrdinaryFunction)3 ArrayList (java.util.ArrayList)3 CompilationException (com.github.anba.es6draft.compiler.CompilationException)2 ParserException (com.github.anba.es6draft.parser.ParserException)2 DeclarativeEnvironmentRecord (com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)2 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)2