Search in sources :

Example 66 with ScriptObject

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

the class SourceBuilder method toSource.

private String toSource(ExecutionContext cx, HashSet<ScriptObject> stack, Object value) {
    if (Type.isObject(value)) {
        ScriptObject objValue = Type.objectValue(value);
        Object toSource = Get(cx, objValue, "toSource");
        if (IsCallable(toSource)) {
            return ToFlatString(cx, ((Callable) toSource).call(cx, objValue));
        }
    }
    return format(source(cx, stack, value), style(stack, value));
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) DateObject(com.github.anba.es6draft.runtime.objects.date.DateObject) RegExpObject(com.github.anba.es6draft.runtime.objects.text.RegExpObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

Example 67 with ScriptObject

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

the class WrapperProxy method get.

@Override
public Object get(ExecutionContext cx, Symbol 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 68 with ScriptObject

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

the class WrapperProxy method hasProperty.

@Override
public boolean hasProperty(ExecutionContext cx, String propertyKey) {
    /* modified 9.1.7 [[HasProperty]](P) */
    boolean hasOwn = HasOwnProperty(cx, proxyTarget, propertyKey);
    if (hasOwn) {
        return true;
    }
    // modified
    ScriptObject parent = getPrototype();
    if (parent != null) {
        return parent.hasProperty(cx, propertyKey);
    }
    return false;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject)

Example 69 with ScriptObject

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

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

Aggregations

ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)129 Callable (com.github.anba.es6draft.runtime.types.Callable)43 Property (com.github.anba.es6draft.runtime.types.Property)32 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)26 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)21 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)16 Constructor (com.github.anba.es6draft.runtime.types.Constructor)11 Realm (com.github.anba.es6draft.runtime.Realm)9 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)9 ParserException (com.github.anba.es6draft.parser.ParserException)8 CompilationException (com.github.anba.es6draft.compiler.CompilationException)7 Source (com.github.anba.es6draft.runtime.internal.Source)7 ArrayList (java.util.ArrayList)7 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)6 ImmutablePrototypeObject (com.github.anba.es6draft.runtime.types.builtins.ImmutablePrototypeObject)6 OrdinaryCreateFromConstructor (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject.OrdinaryCreateFromConstructor)6 Test (org.junit.Test)6 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)5 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)4 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)4