Search in sources :

Example 1 with CreateRealmAndSetRealmGlobalObject

use of com.github.anba.es6draft.runtime.Realm.CreateRealmAndSetRealmGlobalObject in project es6draft by anba.

the class RealmConstructor method construct.

/**
 * 26.?.1.1 Reflect.Realm ( [ target , handler ] )
 */
@Override
public RealmObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    // Disable Realm constructor if only FrozenRealm option is enabled.
    if (!getRealm().getRuntimeContext().isEnabled(CompatibilityOption.Realm)) {
        throw newTypeError(calleeContext(), Messages.Key.InvalidCall, "Realm");
    }
    /* steps 2-3 */
    RealmObject realmObject = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.RealmPrototype, RealmObject::new);
    /* steps 4-5 */
    ScriptObject newGlobal;
    if (args.length != 0) {
        /* step 4 */
        Object target = argument(args, 0);
        Object handler = argument(args, 1);
        newGlobal = ProxyCreate(calleeContext, target, handler);
    } else {
        /* step 5 */
        newGlobal = null;
    }
    /* steps 6-7, 17 (Moved before extracting extension hooks to avoid uninitialized object state) */
    Realm realm = CreateRealmAndSetRealmGlobalObject(calleeContext, realmObject, newGlobal, newGlobal);
    /* steps 8-9 */
    Callable translate = GetMethod(calleeContext, realmObject, "directEval");
    /* steps 10-11 */
    Callable fallback = GetMethod(calleeContext, realmObject, "nonEval");
    /* steps 12-13 */
    Callable indirectEval = GetMethod(calleeContext, realmObject, "indirectEval");
    /* steps 14-16 */
    realm.setExtensionHooks(translate, fallback, indirectEval);
    /* steps 18-19 */
    Callable initGlobal = GetMethod(calleeContext, realmObject, "initGlobal");
    /* steps 20-21 */
    if (initGlobal != null) {
        /* step 20 */
        initGlobal.call(calleeContext, realmObject);
    } else {
        /* step 21 */
        SetDefaultGlobalBindings(calleeContext, realm);
    }
    /* step 22 */
    return realmObject;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) CreateRealmAndSetRealmGlobalObject(com.github.anba.es6draft.runtime.Realm.CreateRealmAndSetRealmGlobalObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) Realm(com.github.anba.es6draft.runtime.Realm) Callable(com.github.anba.es6draft.runtime.types.Callable)

Aggregations

ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)1 Realm (com.github.anba.es6draft.runtime.Realm)1 CreateRealmAndSetRealmGlobalObject (com.github.anba.es6draft.runtime.Realm.CreateRealmAndSetRealmGlobalObject)1 Callable (com.github.anba.es6draft.runtime.types.Callable)1 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)1 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)1