Search in sources :

Example 41 with ScriptObject

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

the class RegExpConstructor method RegExpCreate.

private static RegExpObject RegExpCreate(ExecutionContext cx, Constructor newTarget, Object pattern, Object flags, boolean patternIsRegExp) {
    /* steps 5-7 */
    Object p, f;
    if (pattern instanceof RegExpObject) {
        /* step 5 */
        RegExpObject regexp = (RegExpObject) pattern;
        /* step 5.a */
        p = regexp.getOriginalSource();
        /* steps 5.b-5.c */
        f = Type.isUndefined(flags) ? regexp.getOriginalFlags() : flags;
    } else if (patternIsRegExp) {
        /* step 6 */
        ScriptObject patternObject = Type.objectValue(pattern);
        /* steps 6.a-b */
        p = Get(cx, patternObject, "source");
        /* steps 6.c-d */
        f = Type.isUndefined(flags) ? Get(cx, patternObject, "flags") : flags;
    } else {
        /* step 7 */
        p = pattern;
        f = flags;
    }
    /* steps 8-9 */
    RegExpObject obj = RegExpAlloc(cx, newTarget);
    /* step 10 */
    return RegExpInitialize(cx, obj, p, f);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject)

Example 42 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 43 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 44 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 45 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)

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