Search in sources :

Example 76 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) {
    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)

Example 77 with Property

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

the class FunctionOperations method EvaluatePropertyDefinitionGenerator.

/**
 * 14.4 Generator Function Definitions
 * <p>
 * 14.4.12 Runtime Semantics: PropertyDefinitionEvaluation
 * <ul>
 * <li>GeneratorMethod : * PropertyName ( StrictFormalParameters ) { FunctionBody }
 * </ul>
 *
 * @param object
 *            the script object
 * @param propKey
 *            the property key
 * @param fd
 *            the function runtime info object
 * @param cx
 *            the execution context
 * @return the generator method
 */
public static OrdinaryGenerator EvaluatePropertyDefinitionGenerator(OrdinaryObject object, Object propKey, RuntimeInfo.Function fd, ExecutionContext cx) {
    /* steps 1-2 (generated code) */
    /* step 3 (not applicable) */
    /* step 4 */
    LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
    /* step 5 */
    OrdinaryGenerator closure = GeneratorFunctionCreate(cx, FunctionKind.Method, fd, scope);
    /* step 6 */
    MakeMethod(closure, object);
    /* step 7 */
    OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.GeneratorPrototype);
    /* step 8 */
    closure.infallibleDefineOwnProperty("prototype", new Property(prototype, true, false, false));
    /* step 9 */
    SetFunctionName(closure, propKey);
    /* steps 10-11 (generated code) */
    return closure;
}
Also used : OrdinaryGenerator(com.github.anba.es6draft.runtime.types.builtins.OrdinaryGenerator) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) Property(com.github.anba.es6draft.runtime.types.Property)

Example 78 with Property

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

the class FunctionOperations method InstantiateGeneratorObject.

/**
 * 14.4 Generator Function Definitions
 * <p>
 * 14.4.12 Runtime Semantics: InstantiateFunctionObject
 *
 * @param scope
 *            the current lexical scope
 * @param cx
 *            the execution context
 * @param fd
 *            the function runtime info object
 * @return the new generator function instance
 */
public static OrdinaryGenerator InstantiateGeneratorObject(LexicalEnvironment<?> scope, ExecutionContext cx, RuntimeInfo.Function fd) {
    /* step 1 (not applicable) */
    /* step 2 */
    String name = fd.functionName();
    /* step 3 */
    OrdinaryGenerator f = GeneratorFunctionCreate(cx, FunctionKind.Normal, fd, scope);
    /* step 4 */
    OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.GeneratorPrototype);
    /* step 5 */
    f.infallibleDefineOwnProperty("prototype", new Property(prototype, true, false, false));
    /* step 6 */
    SetFunctionName(f, name);
    /* step 7 */
    return f;
}
Also used : OrdinaryGenerator(com.github.anba.es6draft.runtime.types.builtins.OrdinaryGenerator) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) Property(com.github.anba.es6draft.runtime.types.Property)

Example 79 with Property

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

the class RegExpPrototype method findProperty.

private static Property findProperty(OrdinaryObject object, String name) {
    final int MAX_PROTO_CHAIN_LENGTH = 5;
    for (int i = 0; i < MAX_PROTO_CHAIN_LENGTH; ++i) {
        Property p = object.lookupOwnProperty(name);
        if (p != null) {
            return p;
        }
        ScriptObject proto = object.getPrototype();
        if (!(proto instanceof OrdinaryObject)) {
            break;
        }
        object = (OrdinaryObject) proto;
    }
    return null;
}
Also used : 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 80 with Property

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

the class RegExpPrototype method isBuiltinRegExpPrototypeForExec.

private static boolean isBuiltinRegExpPrototypeForExec(ExecutionContext cx) {
    OrdinaryObject prototype = cx.getIntrinsic(Intrinsics.RegExpPrototype);
    Property exec = prototype.lookupOwnProperty("exec");
    return exec != null && isBuiltinExec(cx.getRealm(), exec.getValue());
}
Also used : OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) Property(com.github.anba.es6draft.runtime.types.Property)

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