Search in sources :

Example 26 with Property

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

the class WrapperProxy method get.

@Override
public Object get(ExecutionContext cx, String propertyKey, Object receiver) {
    /* modified 9.1.8 [[Get]] (P, Receiver) */
    Property desc = proxyTarget.getOwnProperty(cx, propertyKey);
    if (desc == null) {
        // modified
        ScriptObject parent = getPrototype();
        if (parent == null) {
            return UNDEFINED;
        }
        return parent.get(cx, propertyKey, receiver);
    }
    if (desc.isDataDescriptor()) {
        return desc.getValue();
    }
    assert desc.isAccessorDescriptor();
    Callable getter = desc.getGetter();
    if (getter == null) {
        return UNDEFINED;
    }
    return getter.call(cx, receiver);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Property(com.github.anba.es6draft.runtime.types.Property) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 27 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, 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 28 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();
    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)

Example 29 with Property

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

the class Properties method createAliasFunction.

private static void createAliasFunction(Realm realm, OrdinaryObject target, AliasFunctionLayout layout) {
    Object propertyKey = layout.propertyKey;
    Property fun;
    if (propertyKey instanceof String) {
        fun = target.lookupOwnProperty((String) propertyKey);
    } else {
        fun = target.lookupOwnProperty(((BuiltinSymbol) propertyKey).get());
    }
    assert fun != null : "property not found: " + propertyKey;
    defineProperty(target, layout, valueProperty(layout, fun.getValue()));
}
Also used : BuiltinSymbol(com.github.anba.es6draft.runtime.types.BuiltinSymbol) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) Property(com.github.anba.es6draft.runtime.types.Property)

Example 30 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)

Aggregations

Property (com.github.anba.es6draft.runtime.types.Property)51 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)33 Callable (com.github.anba.es6draft.runtime.types.Callable)26 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)10 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)8 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)4 ArrayList (java.util.ArrayList)3 CompilationException (com.github.anba.es6draft.compiler.CompilationException)2 ParserException (com.github.anba.es6draft.parser.ParserException)2 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)2 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)2 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)2 Source (com.github.anba.es6draft.runtime.internal.Source)2 FunctionConstructor.functionSource (com.github.anba.es6draft.runtime.objects.FunctionConstructor.functionSource)2 Intrinsics (com.github.anba.es6draft.runtime.types.Intrinsics)2 ImmutablePrototypeObject (com.github.anba.es6draft.runtime.types.builtins.ImmutablePrototypeObject)2 HasOwnProperty (com.github.anba.es6draft.runtime.AbstractOperations.HasOwnProperty)1 ToFlatString (com.github.anba.es6draft.runtime.AbstractOperations.ToFlatString)1 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)1 AtomicsObject (com.github.anba.es6draft.runtime.objects.atomics.AtomicsObject)1