Search in sources :

Example 6 with ScriptObject

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

the class OrdinaryAsyncGenerator method AsyncGeneratorFunctionCreate.

/**
     * 9.2.6 GeneratorFunctionCreate (kind, ParameterList, Body, Scope, Strict)
     * 
     * @param cx
     *            the execution context
     * @param kind
     *            the function kind
     * @param function
     *            the function code
     * @param scope
     *            the lexical environment
     * @return the new async generator function object
     */
public static OrdinaryAsyncGenerator AsyncGeneratorFunctionCreate(ExecutionContext cx, FunctionKind kind, RuntimeInfo.Function function, LexicalEnvironment<?> scope) {
    assert function.isAsync() && function.isGenerator() && kind != FunctionKind.ClassConstructor;
    /* step 1 */
    ScriptObject functionPrototype = cx.getIntrinsic(Intrinsics.AsyncGenerator);
    /* step 2 */
    OrdinaryAsyncGenerator f = FunctionAllocate(cx, functionPrototype, function.isStrict(), kind);
    /* step 3 */
    FunctionInitialize(f, kind, function, scope, cx.getCurrentExecutable());
    return f;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject)

Example 7 with ScriptObject

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

the class OrdinaryConstructorGenerator method ConstructorGeneratorFunctionCreate.

/**
     * 9.2.6 GeneratorFunctionCreate (kind, ParameterList, Body, Scope, Strict)
     * 
     * @param cx
     *            the execution context
     * @param kind
     *            the function kind
     * @param function
     *            the function code
     * @param scope
     *            the lexical environment
     * @return the new generator function object
     */
public static OrdinaryConstructorGenerator ConstructorGeneratorFunctionCreate(ExecutionContext cx, FunctionKind kind, RuntimeInfo.Function function, LexicalEnvironment<?> scope) {
    assert function.isGenerator() && kind != FunctionKind.ClassConstructor;
    /* step 1 */
    ScriptObject functionPrototype = cx.getIntrinsic(Intrinsics.Generator);
    /* step 2 */
    OrdinaryConstructorGenerator f = FunctionAllocate(cx, functionPrototype, function.isStrict(), kind);
    /* step 3 */
    FunctionInitialize(f, kind, function, scope, cx.getCurrentExecutable());
    return f;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject)

Example 8 with ScriptObject

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

the class LegacyConstructorFunction method LegacyFunctionCreate.

/**
     * 9.2.5 FunctionCreate (kind, ParameterList, Body, Scope, Strict)
     * 
     * @param cx
     *            the execution context
     * @param function
     *            the function code
     * @param scope
     *            the lexical environment
     * @return the new function object
     */
public static LegacyConstructorFunction LegacyFunctionCreate(ExecutionContext cx, RuntimeInfo.Function function, LexicalEnvironment<?> scope) {
    /* step 1 */
    ScriptObject prototype = cx.getIntrinsic(Intrinsics.FunctionPrototype);
    /* steps 2-3 */
    assert !function.isGenerator() && !function.isAsync();
    /* step 4 */
    LegacyConstructorFunction f = FunctionAllocate(cx, prototype);
    /* step 5 */
    FunctionInitialize(f, FunctionKind.Normal, function, scope, cx.getCurrentExecutable());
    return f;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject)

Example 9 with ScriptObject

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

the class SIMD method ArrayJoin.

/**
     * Internal algorithms on SIMD types
     * <p>
     * ArrayJoin( array, separator )
     * 
     * @param cx
     *            the execution context
     * @param array
     *            the array object
     * @param separator
     *            the separator string
     * @return the result string
     */
public static String ArrayJoin(ExecutionContext cx, Object array, Object separator) {
    /* steps 1-2 */
    ScriptObject o = ToObject(cx, array);
    /* steps 3-4 */
    long len = ToLength(cx, Get(cx, o, "length"));
    /* step 5 */
    if (Type.isUndefined(separator)) {
        separator = "";
    }
    /* steps 6-7 */
    String sep = ToFlatString(cx, separator);
    /* step 8 */
    if (len == 0) {
        return "";
    }
    StringBuilder r = new StringBuilder();
    /* step 9 */
    Object element0 = Get(cx, o, 0);
    /* steps 10-11 */
    if (!Type.isUndefinedOrNull(element0)) {
        r.append(AbstractOperations.ToString(cx, element0));
    }
    /* steps 12-13 */
    for (int k = 1; k < len; ++k) {
        /* step 13.a */
        r.append(sep);
        /* step 13.b */
        Object element = Get(cx, o, k);
        /* steps 13.c-e */
        if (!Type.isUndefinedOrNull(element)) {
            r.append(AbstractOperations.ToString(cx, element));
        }
    }
    /* step 14 */
    return r.toString();
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) TypedArrayObject(com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)

Example 10 with ScriptObject

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

the class OrdinaryObject method getValue.

/**
     * 9.1.8 [[Get]] (P, Receiver)
     *
     * @param cx
     *            the execution context
     * @param propertyKey
     *            the property key
     * @param receiver
     *            the receiver object
     * @return the property value
     */
protected Object getValue(ExecutionContext cx, String propertyKey, Object receiver) {
    /* step 1 (implicit) */
    /* steps 2-3 */
    Property desc = getProperty(cx, propertyKey);
    /* step 4 */
    if (desc == null) {
        ScriptObject parent = getPrototypeOf(cx);
        if (parent == null) {
            return UNDEFINED;
        }
        return parent.get(cx, propertyKey, receiver);
    }
    /* step 5 */
    if (desc.isDataDescriptor()) {
        return desc.getValue();
    }
    assert desc.isAccessorDescriptor();
    /* step 6 */
    Callable getter = desc.getGetter();
    /* step 7 */
    if (getter == null) {
        return UNDEFINED;
    }
    /* step 8 */
    return getter.call(cx, receiver, EMPTY_GETTER_ARGS);
}
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