Search in sources :

Example 16 with Intrinsics

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

the class TypedArrayConstructor method TypedArraySpeciesCreate.

/**
     * TypedArraySpeciesCreate( exemplar, argumentList )
     * 
     * @param cx
     *            the execution context
     * @param exemplar
     *            the typed array object
     * @param length
     *            the new typed array length
     * @return the new typed array object
     */
public static TypedArrayObject TypedArraySpeciesCreate(ExecutionContext cx, TypedArrayObject exemplar, long length) {
    /* step 1 (implicit) */
    /* step 2 */
    Intrinsics defaultConstructor = exemplar.getElementType().getConstructor();
    /* step 3 */
    Constructor constructor = SpeciesConstructor(cx, exemplar, defaultConstructor);
    /* step 4 */
    return TypedArrayCreate(cx, constructor, length);
}
Also used : Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) Constructor(com.github.anba.es6draft.runtime.types.Constructor) BuiltinConstructor(com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor) SpeciesConstructor(com.github.anba.es6draft.runtime.AbstractOperations.SpeciesConstructor) ArrayBufferConstructor(com.github.anba.es6draft.runtime.objects.binary.ArrayBufferConstructor)

Example 17 with Intrinsics

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

the class TypedArrayConstructor method TypedArraySpeciesCreate.

/**
     * TypedArraySpeciesCreate( exemplar, argumentList )
     * 
     * @param cx
     *            the execution context
     * @param exemplar
     *            the typed array object
     * @param args
     *            the constructor function arguments
     * @return the new typed array object
     */
public static TypedArrayObject TypedArraySpeciesCreate(ExecutionContext cx, TypedArrayObject exemplar, Object... args) {
    /* step 1 (implicit) */
    /* step 2 */
    Intrinsics defaultConstructor = exemplar.getElementType().getConstructor();
    /* step 3 */
    Constructor constructor = SpeciesConstructor(cx, exemplar, defaultConstructor);
    /* step 4 */
    return TypedArrayCreate(cx, constructor, args);
}
Also used : Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) Constructor(com.github.anba.es6draft.runtime.types.Constructor) BuiltinConstructor(com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor) SpeciesConstructor(com.github.anba.es6draft.runtime.AbstractOperations.SpeciesConstructor) ArrayBufferConstructor(com.github.anba.es6draft.runtime.objects.binary.ArrayBufferConstructor)

Example 18 with Intrinsics

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

the class GeneratorFunctionConstructor method CreateDynamicConstructorGenerator.

private static OrdinaryConstructorGenerator CreateDynamicConstructorGenerator(ExecutionContext callerContext, ExecutionContext cx, Constructor newTarget, Object... args) {
    /* step 1 (not applicable) */
    /* step 2 (not applicable) */
    /* step 3 */
    Intrinsics fallbackProto = Intrinsics.Generator;
    /* steps 4-10 */
    String[] sourceText = functionSourceText(cx, args);
    String parameters = sourceText[0], bodyText = sourceText[1];
    /* steps 11, 13-20 */
    Source source = functionSource(SourceKind.Generator, cx.getRealm(), callerContext);
    RuntimeInfo.Function function;
    try {
        ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
        function = scriptLoader.generator(source, parameters, bodyText).getFunction();
    } catch (ParserException | CompilationException e) {
        throw e.toScriptException(cx);
    }
    /* step 12 */
    boolean strict = function.isStrict();
    /* steps 21-22 */
    ScriptObject proto = GetPrototypeFromConstructor(cx, newTarget, fallbackProto);
    /* step 23 */
    OrdinaryConstructorGenerator f = OrdinaryConstructorGenerator.FunctionAllocate(cx, proto, strict, FunctionKind.Normal);
    /* steps 24-25 */
    LexicalEnvironment<GlobalEnvironmentRecord> scope = f.getRealm().getGlobalEnv();
    /* step 26 */
    FunctionInitialize(f, FunctionKind.Normal, function, scope, newFunctionExecutable(source));
    /* step 27 */
    OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.GeneratorPrototype);
    MakeConstructor(f, true, prototype);
    /* step 28 (not applicable) */
    /* step 29 */
    SetFunctionName(f, "anonymous");
    /* step 30 */
    return f;
}
Also used : ParserException(com.github.anba.es6draft.parser.ParserException) CompilationException(com.github.anba.es6draft.compiler.CompilationException) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) RuntimeInfo(com.github.anba.es6draft.runtime.internal.RuntimeInfo) GlobalEnvironmentRecord(com.github.anba.es6draft.runtime.GlobalEnvironmentRecord) OrdinaryConstructorGenerator(com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorGenerator) FunctionConstructor.functionSource(com.github.anba.es6draft.runtime.objects.FunctionConstructor.functionSource) Source(com.github.anba.es6draft.runtime.internal.Source) Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ScriptLoader(com.github.anba.es6draft.runtime.internal.ScriptLoader)

Example 19 with Intrinsics

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

the class FunctionConstructor method CreateDynamicFunction.

/**
     * 19.2.1.1.1 RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, kind, args)
     * 
     * @param callerContext
     *            the caller execution context
     * @param cx
     *            the execution context
     * @param newTarget
     *            the newTarget constructor function
     * @param args
     *            the function arguments
     * @return the new function object
     */
private static FunctionObject CreateDynamicFunction(ExecutionContext callerContext, ExecutionContext cx, Constructor newTarget, Object... args) {
    /* step 1 (not applicable) */
    /* step 2 */
    Intrinsics fallbackProto = Intrinsics.FunctionPrototype;
    /* step 3 (not applicable) */
    /* steps 4-10 */
    String[] sourceText = functionSourceText(cx, args);
    String parameters = sourceText[0], bodyText = sourceText[1];
    /* steps 11, 13-20 */
    Source source = functionSource(SourceKind.Function, cx.getRealm(), callerContext);
    RuntimeInfo.Function function;
    try {
        ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
        function = scriptLoader.function(source, parameters, bodyText).getFunction();
    } catch (ParserException | CompilationException e) {
        throw e.toScriptException(cx);
    }
    /* steps 12, 21-30 */
    return CreateDynamicFunction(cx, source, function, newTarget, fallbackProto);
}
Also used : ParserException(com.github.anba.es6draft.parser.ParserException) CompilationException(com.github.anba.es6draft.compiler.CompilationException) RuntimeInfo(com.github.anba.es6draft.runtime.internal.RuntimeInfo) Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) ToFlatString(com.github.anba.es6draft.runtime.AbstractOperations.ToFlatString) Source(com.github.anba.es6draft.runtime.internal.Source) ScriptLoader(com.github.anba.es6draft.runtime.internal.ScriptLoader)

Aggregations

Intrinsics (com.github.anba.es6draft.runtime.types.Intrinsics)19 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)14 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)6 CompilationException (com.github.anba.es6draft.compiler.CompilationException)5 ParserException (com.github.anba.es6draft.parser.ParserException)5 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)5 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)5 Source (com.github.anba.es6draft.runtime.internal.Source)5 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)4 FunctionConstructor.functionSource (com.github.anba.es6draft.runtime.objects.FunctionConstructor.functionSource)4 AsyncGeneratorFunctionConstructor (com.github.anba.es6draft.runtime.objects.async.iteration.AsyncGeneratorFunctionConstructor)3 AsyncGeneratorFunctionPrototype (com.github.anba.es6draft.runtime.objects.async.iteration.AsyncGeneratorFunctionPrototype)3 AtomicsObject (com.github.anba.es6draft.runtime.objects.atomics.AtomicsObject)3 ArrayBufferConstructor (com.github.anba.es6draft.runtime.objects.binary.ArrayBufferConstructor)3 IntlObject (com.github.anba.es6draft.runtime.objects.intl.IntlObject)3 SpeciesConstructor (com.github.anba.es6draft.runtime.AbstractOperations.SpeciesConstructor)2 AsyncFunctionConstructor (com.github.anba.es6draft.runtime.objects.async.AsyncFunctionConstructor)2 AsyncFunctionPrototype (com.github.anba.es6draft.runtime.objects.async.AsyncFunctionPrototype)2 AsyncGeneratorPrototype (com.github.anba.es6draft.runtime.objects.async.iteration.AsyncGeneratorPrototype)2 AsyncIteratorPrototype (com.github.anba.es6draft.runtime.objects.async.iteration.AsyncIteratorPrototype)2