Search in sources :

Example 81 with Property

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

the class FunctionObject method AddRestrictedFunctionProperties.

/**
 * 9.2.7 AddRestrictedFunctionProperties ( F, realm )
 *
 * @param <FUNCTION>
 *            the function type
 * @param f
 *            the function object
 * @param realm
 *            the realm object
 */
public static <FUNCTION extends OrdinaryObject & Callable> void AddRestrictedFunctionProperties(FUNCTION f, Realm realm) {
    /* steps 1-2 */
    Callable thrower = realm.getThrowTypeError();
    /* step 3 */
    f.infallibleDefineOwnProperty("caller", new Property(thrower, thrower, false, true));
    /* step 4 */
    f.infallibleDefineOwnProperty("arguments", new Property(thrower, thrower, false, true));
}
Also used : Property(com.github.anba.es6draft.runtime.types.Property) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 82 with Property

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

the class FunctionObject method SetFunctionName.

/**
 * 9.2.11 SetFunctionName (F, name, prefix)
 *
 * @param <FUNCTION>
 *            the function type
 * @param f
 *            the function object
 * @param name
 *            the function name
 * @param prefix
 *            the function name prefix
 */
public static <FUNCTION extends OrdinaryObject & Callable> void SetFunctionName(FUNCTION f, PrivateName name, String prefix) {
    /* step 1 */
    assert f.isExtensible() && !f.ordinaryHasOwnProperty("name");
    /* steps 2-4 (not applicable) */
    /* step 5 */
    String sname = name.toString();
    /* step 6 */
    if (prefix != null) {
        sname = prefix + " " + sname;
    }
    /* step 7 */
    assert sname.length() <= StringObject.MAX_LENGTH;
    f.infallibleDefineOwnProperty("name", new Property(sname, false, false, true));
}
Also used : Property(com.github.anba.es6draft.runtime.types.Property)

Example 83 with Property

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

the class FunctionObject method SetFunctionName.

/**
 * 9.2.11 SetFunctionName (F, name, prefix)
 *
 * @param <FUNCTION>
 *            the function type
 * @param f
 *            the function object
 * @param name
 *            the function name
 * @param prefix
 *            the function name prefix
 */
public static <FUNCTION extends OrdinaryObject & Callable> void SetFunctionName(FUNCTION f, Symbol name, String prefix) {
    /* step 1 */
    assert f.isExtensible() && !f.ordinaryHasOwnProperty("name");
    /* steps 2-3 (not applicable) */
    /* step 4 */
    String description = name.getDescription();
    String sname = description == null ? "" : "[" + description + "]";
    /* step 5 */
    if (prefix != null) {
        sname = prefix + " " + sname;
    }
    /* step 6 */
    assert sname.length() <= StringObject.MAX_LENGTH;
    f.infallibleDefineOwnProperty("name", new Property(sname, false, false, true));
}
Also used : Property(com.github.anba.es6draft.runtime.types.Property)

Example 84 with Property

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

the class FunctionObject method FunctionInitialize.

/**
 * 9.2.4 FunctionInitialize (F, kind, ParameterList, Body, Scope)
 *
 * @param <FUNCTION>
 *            the function type
 * @param f
 *            the function object
 * @param kind
 *            the function kind
 * @param function
 *            the function code
 * @param scope
 *            the lexical environment
 * @param executable
 *            the executable object
 * @return the function object
 */
public static <FUNCTION extends FunctionObject> FUNCTION FunctionInitialize(FUNCTION f, FunctionKind kind, RuntimeInfo.Function function, LexicalEnvironment<?> scope, Executable executable) {
    FunctionObject fo = (FunctionObject) f;
    assert fo.function == null && function != null : "function object already initialized";
    assert fo.functionKind == kind : String.format("%s != %s", fo.functionKind, kind);
    /* step 1 */
    assert f.isExtensible() && !f.ordinaryHasOwnProperty("length");
    /* step 2 */
    int len = function.expectedArgumentCount();
    /* step 3 */
    f.infallibleDefineOwnProperty("length", new Property(len, false, false, true));
    /* step 4 */
    boolean strict = fo.strict;
    /* step 5 */
    fo.environment = scope;
    /* steps 6-8 */
    fo.function = function;
    fo.callMethod = tailCallAdapter(function, f);
    fo.tailCallMethod = function.callMethod();
    fo.constructMethod = tailConstructAdapter(function, f);
    /* steps 9-11 */
    if (kind == FunctionKind.Arrow) {
        fo.thisMode = ThisMode.Lexical;
    } else if (strict) {
        fo.thisMode = ThisMode.Strict;
    } else {
        fo.thisMode = ThisMode.Global;
    }
    fo.executable = executable;
    /* step 12 */
    return f;
}
Also used : Property(com.github.anba.es6draft.runtime.types.Property)

Example 85 with Property

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

the class OrdinaryObject method ordinaryGet.

/**
 * 9.1.8.1 OrdinaryGet (O, P, Receiver)
 *
 * @param cx
 *            the execution context
 * @param propertyKey
 *            the property key
 * @param receiver
 *            the receiver object
 * @return the property value
 */
protected final Object ordinaryGet(ExecutionContext cx, Symbol propertyKey, Object receiver) {
    /* step 1 (implicit) */
    /* step 2 */
    Property desc = getOwnProperty(cx, propertyKey);
    /* step 3 */
    if (desc == null) {
        ScriptObject parent = getPrototypeOf(cx);
        if (parent == null) {
            return UNDEFINED;
        }
        return parent.get(cx, propertyKey, receiver);
    }
    /* step 4 */
    if (desc.isDataDescriptor()) {
        return desc.getValue();
    }
    /* step 5 */
    assert desc.isAccessorDescriptor();
    /* step 6 */
    Callable getter = desc.getGetter();
    /* step 7 */
    if (getter == null) {
        return UNDEFINED;
    }
    /* step 8 */
    return getter.call(cx, receiver, EMPTY_ARRAY);
}
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

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