Search in sources :

Example 11 with Intrinsics

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

the class Realm method initializeStandardObjects.

/**
     * <h1>19.3, 19.4, 19.5, 20, 21, 22.1, 24.3</h1>
     * 
     * Standard built-in objects
     * 
     * @param realm
     *            the realm instance
     */
private static void initializeStandardObjects(Realm realm) {
    EnumMap<Intrinsics, OrdinaryObject> intrinsics = realm.intrinsics;
    // allocation phase
    ArrayConstructor arrayConstructor = new ArrayConstructor(realm);
    ArrayPrototype arrayPrototype = new ArrayPrototype(realm);
    ArrayIteratorPrototype arrayIteratorPrototype = new ArrayIteratorPrototype(realm);
    StringConstructor stringConstructor = new StringConstructor(realm);
    StringPrototype stringPrototype = new StringPrototype(realm);
    StringIteratorPrototype stringIteratorPrototype = new StringIteratorPrototype(realm);
    SymbolConstructor symbolConstructor = new SymbolConstructor(realm);
    SymbolPrototype symbolPrototype = new SymbolPrototype(realm);
    BooleanConstructor booleanConstructor = new BooleanConstructor(realm);
    BooleanPrototype booleanPrototype = new BooleanPrototype(realm);
    NumberConstructor numberConstructor = new NumberConstructor(realm);
    NumberPrototype numberPrototype = new NumberPrototype(realm);
    MathObject mathObject = new MathObject(realm);
    DateConstructor dateConstructor = new DateConstructor(realm);
    DatePrototype datePrototype = new DatePrototype(realm);
    RegExpConstructor regExpConstructor = new RegExpConstructor(realm);
    RegExpPrototype regExpPrototype = new RegExpPrototype(realm);
    ErrorConstructor errorConstructor = new ErrorConstructor(realm);
    ErrorPrototype errorPrototype = new ErrorPrototype(realm);
    JSONObject jsonObject = new JSONObject(realm);
    IteratorPrototype iteratorPrototype = new IteratorPrototype(realm);
    // registration phase
    intrinsics.put(Intrinsics.Array, arrayConstructor);
    intrinsics.put(Intrinsics.ArrayPrototype, arrayPrototype);
    intrinsics.put(Intrinsics.ArrayIteratorPrototype, arrayIteratorPrototype);
    intrinsics.put(Intrinsics.String, stringConstructor);
    intrinsics.put(Intrinsics.StringPrototype, stringPrototype);
    intrinsics.put(Intrinsics.StringIteratorPrototype, stringIteratorPrototype);
    intrinsics.put(Intrinsics.Symbol, symbolConstructor);
    intrinsics.put(Intrinsics.SymbolPrototype, symbolPrototype);
    intrinsics.put(Intrinsics.Boolean, booleanConstructor);
    intrinsics.put(Intrinsics.BooleanPrototype, booleanPrototype);
    intrinsics.put(Intrinsics.Number, numberConstructor);
    intrinsics.put(Intrinsics.NumberPrototype, numberPrototype);
    intrinsics.put(Intrinsics.Math, mathObject);
    intrinsics.put(Intrinsics.Date, dateConstructor);
    intrinsics.put(Intrinsics.DatePrototype, datePrototype);
    intrinsics.put(Intrinsics.RegExp, regExpConstructor);
    intrinsics.put(Intrinsics.RegExpPrototype, regExpPrototype);
    intrinsics.put(Intrinsics.Error, errorConstructor);
    intrinsics.put(Intrinsics.ErrorPrototype, errorPrototype);
    intrinsics.put(Intrinsics.JSON, jsonObject);
    intrinsics.put(Intrinsics.IteratorPrototype, iteratorPrototype);
    // initialization phase
    arrayConstructor.initialize(realm);
    arrayPrototype.initialize(realm);
    arrayIteratorPrototype.initialize(realm);
    stringConstructor.initialize(realm);
    stringPrototype.initialize(realm);
    stringIteratorPrototype.initialize(realm);
    symbolConstructor.initialize(realm);
    symbolPrototype.initialize(realm);
    booleanConstructor.initialize(realm);
    booleanPrototype.initialize(realm);
    numberConstructor.initialize(realm);
    numberPrototype.initialize(realm);
    mathObject.initialize(realm);
    dateConstructor.initialize(realm);
    datePrototype.initialize(realm);
    regExpConstructor.initialize(realm);
    regExpPrototype.initialize(realm);
    errorConstructor.initialize(realm);
    errorPrototype.initialize(realm);
    jsonObject.initialize(realm);
    iteratorPrototype.initialize(realm);
    // Array.prototype.values is also an intrinsic
    Object arrayPrototypeValues = arrayPrototype.lookupOwnProperty("values").getValue();
    intrinsics.put(Intrinsics.ArrayProto_values, (OrdinaryObject) arrayPrototypeValues);
    if (realm.isEnabled(CompatibilityOption.StringMatchAll)) {
        RegExpStringIteratorPrototype regExpStringIteratorPrototype = new RegExpStringIteratorPrototype(realm);
        intrinsics.put(Intrinsics.RegExpStringIteratorPrototype, regExpStringIteratorPrototype);
        regExpStringIteratorPrototype.initialize(realm);
    }
}
Also used : NumberPrototype(com.github.anba.es6draft.runtime.objects.number.NumberPrototype) TypedArrayPrototype(com.github.anba.es6draft.runtime.objects.binary.TypedArrayPrototype) DatePrototype(com.github.anba.es6draft.runtime.objects.date.DatePrototype) DateConstructor(com.github.anba.es6draft.runtime.objects.date.DateConstructor) StringConstructor(com.github.anba.es6draft.runtime.objects.text.StringConstructor) RegExpConstructor(com.github.anba.es6draft.runtime.objects.text.RegExpConstructor) StringIteratorPrototype(com.github.anba.es6draft.runtime.objects.text.StringIteratorPrototype) AsyncIteratorPrototype(com.github.anba.es6draft.runtime.objects.async.iteration.AsyncIteratorPrototype) RegExpStringIteratorPrototype(com.github.anba.es6draft.runtime.objects.text.RegExpStringIteratorPrototype) IteratorPrototype(com.github.anba.es6draft.runtime.objects.iteration.IteratorPrototype) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) StringIteratorPrototype(com.github.anba.es6draft.runtime.objects.text.StringIteratorPrototype) RegExpStringIteratorPrototype(com.github.anba.es6draft.runtime.objects.text.RegExpStringIteratorPrototype) NumberConstructor(com.github.anba.es6draft.runtime.objects.number.NumberConstructor) TypedArrayConstructor(com.github.anba.es6draft.runtime.objects.binary.TypedArrayConstructor) StringPrototype(com.github.anba.es6draft.runtime.objects.text.StringPrototype) RegExpPrototype(com.github.anba.es6draft.runtime.objects.text.RegExpPrototype) Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) 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) MathObject(com.github.anba.es6draft.runtime.objects.number.MathObject) RegExpStringIteratorPrototype(com.github.anba.es6draft.runtime.objects.text.RegExpStringIteratorPrototype)

Example 12 with Intrinsics

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

the class Realm method initializeIterationModule.

/**
     * <h1>25 Control Abstraction Objects</h1>
     * 
     * @param realm
     *            the realm instance
     */
private static void initializeIterationModule(Realm realm) {
    EnumMap<Intrinsics, OrdinaryObject> intrinsics = realm.intrinsics;
    // allocation phase
    GeneratorFunctionConstructor generatorFunctionConstructor = new GeneratorFunctionConstructor(realm);
    GeneratorPrototype generatorPrototype = new GeneratorPrototype(realm);
    GeneratorFunctionPrototype generator = new GeneratorFunctionPrototype(realm);
    // registration phase
    intrinsics.put(Intrinsics.GeneratorFunction, generatorFunctionConstructor);
    intrinsics.put(Intrinsics.GeneratorPrototype, generatorPrototype);
    intrinsics.put(Intrinsics.Generator, generator);
    // initialization phase
    generatorFunctionConstructor.initialize(realm);
    generatorPrototype.initialize(realm);
    generator.initialize(realm);
    if (realm.isEnabled(CompatibilityOption.LegacyGenerator)) {
        OrdinaryObject legacyGeneratorPrototype = ObjectCreate(realm, Intrinsics.ObjectPrototype);
        intrinsics.put(Intrinsics.LegacyGeneratorPrototype, legacyGeneratorPrototype);
    }
}
Also used : AsyncGeneratorPrototype(com.github.anba.es6draft.runtime.objects.async.iteration.AsyncGeneratorPrototype) GeneratorPrototype(com.github.anba.es6draft.runtime.objects.iteration.GeneratorPrototype) AsyncGeneratorFunctionConstructor(com.github.anba.es6draft.runtime.objects.async.iteration.AsyncGeneratorFunctionConstructor) GeneratorFunctionConstructor(com.github.anba.es6draft.runtime.objects.iteration.GeneratorFunctionConstructor) Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) GeneratorFunctionPrototype(com.github.anba.es6draft.runtime.objects.iteration.GeneratorFunctionPrototype) AsyncGeneratorFunctionPrototype(com.github.anba.es6draft.runtime.objects.async.iteration.AsyncGeneratorFunctionPrototype)

Example 13 with Intrinsics

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

the class Realm method initializeAtomicsModule.

/**
     * <h1>Extension: Shared Memory and Atomics</h1>
     * 
     * @param realm
     *            the realm instance
     */
private static void initializeAtomicsModule(Realm realm) {
    EnumMap<Intrinsics, OrdinaryObject> intrinsics = realm.intrinsics;
    // allocation phase
    AtomicsObject atomicsObject = new AtomicsObject(realm);
    SharedArrayBufferConstructor sharedArrayBufferConstructor = new SharedArrayBufferConstructor(realm);
    SharedArrayBufferPrototype sharedArrayBufferPrototype = new SharedArrayBufferPrototype(realm);
    // registration phase
    intrinsics.put(Intrinsics.Atomics, atomicsObject);
    intrinsics.put(Intrinsics.SharedArrayBuffer, sharedArrayBufferConstructor);
    intrinsics.put(Intrinsics.SharedArrayBufferPrototype, sharedArrayBufferPrototype);
    // initialization phase
    atomicsObject.initialize(realm);
    sharedArrayBufferConstructor.initialize(realm);
    sharedArrayBufferPrototype.initialize(realm);
}
Also used : SharedArrayBufferPrototype(com.github.anba.es6draft.runtime.objects.atomics.SharedArrayBufferPrototype) Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) SharedArrayBufferConstructor(com.github.anba.es6draft.runtime.objects.atomics.SharedArrayBufferConstructor) AtomicsObject(com.github.anba.es6draft.runtime.objects.atomics.AtomicsObject)

Example 14 with Intrinsics

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

the class RuntimeFunctions method SetIntrinsic.

/**
     * Native function: {@code %SetIntrinsic(<name>, <realm>)}.
     * <p>
     * Sets the intrinsic to a new value.
     * 
     * @param cx
     *            the execution context
     * @param name
     *            the intrinsic name
     * @param intrinsic
     *            the new intrinsic object
     * @return the intrinsic
     */
public static OrdinaryObject SetIntrinsic(ExecutionContext cx, String name, OrdinaryObject intrinsic) {
    Intrinsics id = getIntrinsicByName(cx, name);
    cx.getRealm().setIntrinsic(id, intrinsic);
    return intrinsic;
}
Also used : Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics)

Example 15 with Intrinsics

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

the class AsyncFunctionConstructor 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 generator function object
     */
private static OrdinaryAsyncFunction CreateDynamicFunction(ExecutionContext callerContext, ExecutionContext cx, Constructor newTarget, Object... args) {
    /* step 1 (not applicable) */
    /* step 2 (not applicable) */
    /* step 3 */
    Intrinsics fallbackProto = Intrinsics.AsyncFunction;
    /* steps 4-10 */
    String[] sourceText = functionSourceText(cx, args);
    String parameters = sourceText[0], bodyText = sourceText[1];
    /* steps 11, 13-20 */
    Source source = functionSource(SourceKind.AsyncFunction, cx.getRealm(), callerContext);
    RuntimeInfo.Function function;
    try {
        ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
        function = scriptLoader.asyncFunction(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 */
    OrdinaryAsyncFunction f = 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));
    /* steps 27-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) Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) OrdinaryAsyncFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncFunction) 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