Search in sources :

Example 1 with Intrinsics

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

the class GeneratorFunctionConstructor method CreateDynamicGenerator.

private static OrdinaryGenerator CreateDynamicGenerator(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 */
    OrdinaryGenerator f = OrdinaryGenerator.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);
    f.infallibleDefineOwnProperty("prototype", new Property(prototype, true, false, false));
    /* 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) FunctionConstructor.functionSource(com.github.anba.es6draft.runtime.objects.FunctionConstructor.functionSource) Source(com.github.anba.es6draft.runtime.internal.Source) OrdinaryGenerator(com.github.anba.es6draft.runtime.types.builtins.OrdinaryGenerator) Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) Property(com.github.anba.es6draft.runtime.types.Property) ScriptLoader(com.github.anba.es6draft.runtime.internal.ScriptLoader)

Example 2 with Intrinsics

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

the class Realm method initializeReflectModule.

/**
     * <h1>26 Reflection</h1>
     * 
     * @param realm
     *            the realm instance
     */
private static void initializeReflectModule(Realm realm) {
    EnumMap<Intrinsics, OrdinaryObject> intrinsics = realm.intrinsics;
    // allocation phase
    ProxyConstructor proxy = new ProxyConstructor(realm);
    ReflectObject reflect = new ReflectObject(realm);
    // registration phase
    intrinsics.put(Intrinsics.Proxy, proxy);
    intrinsics.put(Intrinsics.Reflect, reflect);
    // initialization phase
    proxy.initialize(realm);
    if (realm.isEnabled(CompatibilityOption.Realm)) {
        RealmConstructor realmConstructor = new RealmConstructor(realm);
        RealmPrototype realmPrototype = new RealmPrototype(realm);
        intrinsics.put(Intrinsics.Realm, realmConstructor);
        intrinsics.put(Intrinsics.RealmPrototype, realmPrototype);
        realmConstructor.initialize(realm);
        realmPrototype.initialize(realm);
    }
    if (realm.isEnabled(CompatibilityOption.Loader)) {
        LoaderConstructor loaderConstructor = new LoaderConstructor(realm);
        LoaderPrototype loaderPrototype = new LoaderPrototype(realm);
        intrinsics.put(Intrinsics.Loader, loaderConstructor);
        intrinsics.put(Intrinsics.LoaderPrototype, loaderPrototype);
        loaderConstructor.initialize(realm);
        loaderPrototype.initialize(realm);
    }
    if (realm.isEnabled(CompatibilityOption.System) || realm.isEnabled(CompatibilityOption.SystemGlobal)) {
        SystemObject systemObject = new SystemObject(realm);
        intrinsics.put(Intrinsics.System, systemObject);
        systemObject.initialize(realm);
    }
    reflect.initialize(realm);
}
Also used : RealmConstructor(com.github.anba.es6draft.runtime.objects.reflect.RealmConstructor) Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) LoaderPrototype(com.github.anba.es6draft.runtime.objects.reflect.LoaderPrototype) ReflectObject(com.github.anba.es6draft.runtime.objects.reflect.ReflectObject) SystemObject(com.github.anba.es6draft.runtime.objects.reflect.SystemObject) LoaderConstructor(com.github.anba.es6draft.runtime.objects.reflect.LoaderConstructor) RealmPrototype(com.github.anba.es6draft.runtime.objects.reflect.RealmPrototype) ProxyConstructor(com.github.anba.es6draft.runtime.objects.reflect.ProxyConstructor)

Example 3 with Intrinsics

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

the class Realm method initializeObservableModule.

/**
     * <h1>Extension: Observable</h1>
     * 
     * @param realm
     *            the realm instance
     */
private static void initializeObservableModule(Realm realm) {
    EnumMap<Intrinsics, OrdinaryObject> intrinsics = realm.intrinsics;
    // allocation phase
    ObservableConstructor observableConstructor = new ObservableConstructor(realm);
    ObservablePrototype observablePrototype = new ObservablePrototype(realm);
    SubscriptionPrototype subscriptionPrototype = new SubscriptionPrototype(realm);
    SubscriptionObserverPrototype subscriptionObserverPrototype = new SubscriptionObserverPrototype(realm);
    // registration phase
    intrinsics.put(Intrinsics.Observable, observableConstructor);
    intrinsics.put(Intrinsics.ObservablePrototype, observablePrototype);
    intrinsics.put(Intrinsics.SubscriptionPrototype, subscriptionPrototype);
    intrinsics.put(Intrinsics.SubscriptionObserverPrototype, subscriptionObserverPrototype);
    // initialization phase
    observableConstructor.initialize(realm);
    observablePrototype.initialize(realm);
    subscriptionPrototype.initialize(realm);
    subscriptionObserverPrototype.initialize(realm);
}
Also used : SubscriptionObserverPrototype(com.github.anba.es6draft.runtime.objects.observable.SubscriptionObserverPrototype) ObservableConstructor(com.github.anba.es6draft.runtime.objects.observable.ObservableConstructor) Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) SubscriptionPrototype(com.github.anba.es6draft.runtime.objects.observable.SubscriptionPrototype) ObservablePrototype(com.github.anba.es6draft.runtime.objects.observable.ObservablePrototype)

Example 4 with Intrinsics

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

the class Realm method initializeFundamentalObjects.

/**
     * <h1>19.1 Object Objects - 19.2 Function Objects</h1>
     * 
     * Fundamental built-in objects which must be initialized early
     * 
     * @param realm
     *            the realm instance
     */
private static void initializeFundamentalObjects(Realm realm) {
    EnumMap<Intrinsics, OrdinaryObject> intrinsics = realm.intrinsics;
    // allocation phase
    ObjectConstructor objectConstructor = new ObjectConstructor(realm);
    ObjectPrototype objectPrototype = new ObjectPrototype(realm);
    FunctionConstructor functionConstructor = new FunctionConstructor(realm);
    FunctionPrototype functionPrototype = new FunctionPrototype(realm);
    // registration phase
    intrinsics.put(Intrinsics.Object, objectConstructor);
    intrinsics.put(Intrinsics.ObjectPrototype, objectPrototype);
    intrinsics.put(Intrinsics.Function, functionConstructor);
    intrinsics.put(Intrinsics.FunctionPrototype, functionPrototype);
    // Create [[ThrowTypeError]] function before initializing intrinsics.
    realm.throwTypeError = new TypeErrorThrower(realm);
    // Also stored in intrinsics table.
    intrinsics.put(Intrinsics.ThrowTypeError, realm.throwTypeError);
    // initialization phase
    objectConstructor.initialize(realm);
    objectPrototype.initialize(realm);
    functionConstructor.initialize(realm);
    functionPrototype.initialize(realm);
    AddRestrictedFunctionProperties(functionPrototype, realm);
    // Object.prototype.toString is also an intrinsic
    Object objectPrototypeToString = objectPrototype.lookupOwnProperty("toString").getValue();
    intrinsics.put(Intrinsics.ObjProto_toString, (OrdinaryObject) objectPrototypeToString);
}
Also used : AsyncFunctionPrototype(com.github.anba.es6draft.runtime.objects.async.AsyncFunctionPrototype) GeneratorFunctionPrototype(com.github.anba.es6draft.runtime.objects.iteration.GeneratorFunctionPrototype) AsyncGeneratorFunctionPrototype(com.github.anba.es6draft.runtime.objects.async.iteration.AsyncGeneratorFunctionPrototype) Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) SystemObject(com.github.anba.es6draft.runtime.objects.reflect.SystemObject) AtomicsObject(com.github.anba.es6draft.runtime.objects.atomics.AtomicsObject) MathObject(com.github.anba.es6draft.runtime.objects.number.MathObject) ReflectObject(com.github.anba.es6draft.runtime.objects.reflect.ReflectObject) IntlObject(com.github.anba.es6draft.runtime.objects.intl.IntlObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) RealmObject(com.github.anba.es6draft.runtime.objects.reflect.RealmObject) AsyncGeneratorFunctionConstructor(com.github.anba.es6draft.runtime.objects.async.iteration.AsyncGeneratorFunctionConstructor) GeneratorFunctionConstructor(com.github.anba.es6draft.runtime.objects.iteration.GeneratorFunctionConstructor) AsyncFunctionConstructor(com.github.anba.es6draft.runtime.objects.async.AsyncFunctionConstructor) TypeErrorThrower(com.github.anba.es6draft.runtime.types.builtins.TypeErrorThrower)

Example 5 with Intrinsics

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

the class Realm method initializePromiseObjects.

/**
     * <h1>25 Control Abstraction Objects</h1><br>
     * <h2>25.4 Promise Objects</h2>
     * 
     * @param realm
     *            the realm instance
     */
private static void initializePromiseObjects(Realm realm) {
    EnumMap<Intrinsics, OrdinaryObject> intrinsics = realm.intrinsics;
    // allocation phase
    PromiseConstructor promiseConstructor = new PromiseConstructor(realm);
    PromisePrototype promisePrototype = new PromisePrototype(realm);
    // registration phase
    intrinsics.put(Intrinsics.Promise, promiseConstructor);
    intrinsics.put(Intrinsics.PromisePrototype, promisePrototype);
    // initialization phase
    promiseConstructor.initialize(realm);
    promisePrototype.initialize(realm);
}
Also used : PromiseConstructor(com.github.anba.es6draft.runtime.objects.promise.PromiseConstructor) PromisePrototype(com.github.anba.es6draft.runtime.objects.promise.PromisePrototype) Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)

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