Search in sources :

Example 11 with OrdinaryFunction

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

the class FunctionOperations method EvaluatePropertyDefinitionGetter.

/**
 * 14.3 Method Definitions
 * <p>
 * 14.3.8 Runtime Semantics: PropertyDefinitionEvaluation
 * <ul>
 * <li>get PropertyName ( ) { 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 getter method
 */
public static OrdinaryFunction EvaluatePropertyDefinitionGetter(OrdinaryObject object, Object propKey, RuntimeInfo.Function fd, ExecutionContext cx) {
    /* steps 1-3 (generated code) */
    /* step 4 */
    LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
    /* steps 5-6 */
    OrdinaryFunction closure = FunctionCreate(cx, FunctionKind.Method, fd, scope);
    /* step 7 */
    MakeMethod(closure, object);
    /* step 8  */
    SetFunctionName(closure, propKey, "get");
    /* steps 9-10 (generated code) */
    return closure;
}
Also used : OrdinaryFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryFunction)

Example 12 with OrdinaryFunction

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

the class ScriptRuntime method EvaluatePropertyDefinitionGetter.

/**
     * 14.3 Method Definitions
     * <p>
     * 14.3.9 Runtime Semantics: PropertyDefinitionEvaluation
     * <ul>
     * <li>get PropertyName ( ) { FunctionBody }
     * </ul>
     * 
     * @param object
     *            the script object
     * @param propKey
     *            the property key
     * @param enumerable
     *            the enumerable property attribute
     * @param fd
     *            the function runtime info object
     * @param cx
     *            the execution context
     */
public static void EvaluatePropertyDefinitionGetter(OrdinaryObject object, String propKey, boolean enumerable, RuntimeInfo.Function fd, ExecutionContext cx) {
    /* steps 1-3 (generated code) */
    /* step 4 */
    LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
    /* steps 5-6 */
    OrdinaryFunction closure = FunctionCreate(cx, FunctionKind.Method, fd, scope);
    /* step 7 */
    MakeMethod(closure, object);
    /* steps 8-9 */
    SetFunctionName(closure, propKey, "get");
    /* step 10 */
    PropertyDescriptor desc = AccessorPropertyDescriptor(closure, null, enumerable, true);
    /* step 11 */
    DefinePropertyOrThrow(cx, object, propKey, desc);
}
Also used : AccessorPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.AccessorPropertyDescriptor) ToPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.ToPropertyDescriptor) FromPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.FromPropertyDescriptor) OrdinaryFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryFunction)

Example 13 with OrdinaryFunction

use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryFunction 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 14 with OrdinaryFunction

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

the class FunctionOperations method EvaluateArrowFunction.

/**
 * 14.2 Arrow Function Definitions
 * <p>
 * 14.2.17 Runtime Semantics: Evaluation
 * <ul>
 * <li>ArrowFunction : ArrowParameters {@literal =>} ConciseBody
 * </ul>
 *
 * @param fd
 *            the function runtime info object
 * @param cx
 *            the execution context
 * @return the new function instance
 */
public static OrdinaryFunction EvaluateArrowFunction(RuntimeInfo.Function fd, ExecutionContext cx) {
    /* step 1 (not applicable) */
    /* step 2 */
    LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
    /* step 4 */
    OrdinaryFunction closure = FunctionCreate(cx, FunctionKind.Arrow, fd, scope);
    /* step 5 */
    return closure;
}
Also used : OrdinaryFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryFunction)

Aggregations

OrdinaryFunction (com.github.anba.es6draft.runtime.types.builtins.OrdinaryFunction)14 AccessorPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.AccessorPropertyDescriptor)6 FromPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.FromPropertyDescriptor)6 ToPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.ToPropertyDescriptor)6 Property (com.github.anba.es6draft.runtime.types.Property)3 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)1 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)1 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)1