Search in sources :

Example 1 with Callable

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

the class SubscriptionAbstractOperations method CleanupSubscription.

/**
     * CleanupSubscription ( subscription ) Abstract Operation
     * 
     * @param cx
     *            the execution context
     * @param subscription
     *            the subscription object
     */
public static void CleanupSubscription(ExecutionContext cx, SubscriptionObject subscription) {
    /* step 1 (implicit) */
    /* step 2 */
    Callable cleanup = subscription.getCleanup();
    /* step 3 */
    if (cleanup == null) {
        return;
    }
    /* step 4 (implicit) */
    /* step 5 */
    subscription.setCleanup(null);
    /* steps 6-7 */
    cleanup.call(cx, UNDEFINED);
/* step 8 (return) */
}
Also used : Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 2 with Callable

use of com.github.anba.es6draft.runtime.types.Callable 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();
    /* 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 */
    Realm realm = CreateRealmAndSetRealmGlobalObject(calleeContext, realmObject, newGlobal, newGlobal);
    /* step 17 (Moved before extracting extension hooks to avoid uninitialized object state) */
    realmObject.setRealm(realm);
    // Run any initialization scripts, if required. But do _not_ install extensions!
    try {
        GlobalObject globalTemplate = realm.getGlobalObjectTemplate();
        assert globalTemplate != null;
        globalTemplate.initializeScripted();
    } catch (ParserException | CompilationException e) {
        throw e.toScriptException(calleeContext);
    } catch (IOException | URISyntaxException e) {
        throw newError(calleeContext, e.getMessage());
    }
    /* 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) GlobalObject(com.github.anba.es6draft.runtime.objects.GlobalObject) CreateRealmAndSetRealmGlobalObject(com.github.anba.es6draft.runtime.Realm.CreateRealmAndSetRealmGlobalObject) ParserException(com.github.anba.es6draft.parser.ParserException) CompilationException(com.github.anba.es6draft.compiler.CompilationException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Callable(com.github.anba.es6draft.runtime.types.Callable) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) GlobalObject(com.github.anba.es6draft.runtime.objects.GlobalObject) CreateRealmAndSetRealmGlobalObject(com.github.anba.es6draft.runtime.Realm.CreateRealmAndSetRealmGlobalObject) Realm(com.github.anba.es6draft.runtime.Realm)

Example 3 with Callable

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

the class ReflectParser method toBuilderMap.

private static EnumMap<Type, Callable> toBuilderMap(ExecutionContext cx, ScriptObject builderObject) {
    EnumMap<Type, Callable> map = new EnumMap<>(Type.class);
    for (Type builder : Type.values()) {
        String methodName = builder.name;
        if (methodName == null) {
            continue;
        }
        if (!HasProperty(cx, builderObject, methodName)) {
            continue;
        }
        Callable method = GetMethod(cx, builderObject, methodName);
        if (method == null) {
            continue;
        }
        map.put(builder, method);
    }
    return map;
}
Also used : EnumMap(java.util.EnumMap) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 4 with Callable

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

the class ScriptEngineImpl method invoke.

private Object invoke(ScriptObject thisValue, String name, Object... args) throws javax.script.ScriptException, NoSuchMethodException {
    Realm realm = getEvalRealm(context);
    RuntimeContext runtimeContext = realm.getWorld().getContext();
    Console console = runtimeContext.getConsole();
    runtimeContext.setConsole(new ScriptingConsole(context));
    try {
        Object[] arguments = TypeConverter.fromJava(args);
        if (thisValue == null) {
            thisValue = realm.getGlobalThis();
        }
        ExecutionContext cx = realm.defaultContext();
        Object func = thisValue.get(cx, name, thisValue);
        if (!IsCallable(func)) {
            throw new NoSuchMethodException(name);
        }
        Object result = ((Callable) func).call(cx, thisValue, arguments);
        realm.getWorld().runEventLoop();
        return TypeConverter.toJava(result);
    } catch (ScriptException e) {
        throw new javax.script.ScriptException(e);
    } finally {
        runtimeContext.setConsole(console);
    }
}
Also used : ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ExecutionContext.newScriptingExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext.newScriptingExecutionContext) Console(com.github.anba.es6draft.runtime.internal.Console) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) RuntimeContext(com.github.anba.es6draft.runtime.internal.RuntimeContext) Realm(com.github.anba.es6draft.runtime.Realm) IsCallable(com.github.anba.es6draft.runtime.AbstractOperations.IsCallable) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 5 with Callable

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

the class OrdinaryFunction method AddRestrictedFunctionProperties.

/**
     * 9.2.7 AddRestrictedFunctionProperties ( F, realm )
     * 
     * @param <FUNCTION>
     *            the function type
     * @param f
     *            the function object
     * @param realm
     *            the realm object
     */
public static <FUNCTION extends OrdinaryObject & Callable> void AddRestrictedFunctionProperties(FUNCTION f, Realm realm) {
    /* steps 1-2 */
    Callable thrower = realm.getThrowTypeError();
    /* steps 3-4 */
    f.infallibleDefineOwnProperty("caller", new Property(thrower, thrower, false, true));
    /* steps 5-6 */
    f.infallibleDefineOwnProperty("arguments", new Property(thrower, thrower, false, true));
}
Also used : Property(com.github.anba.es6draft.runtime.types.Property) Callable(com.github.anba.es6draft.runtime.types.Callable)

Aggregations

Callable (com.github.anba.es6draft.runtime.types.Callable)59 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)49 Property (com.github.anba.es6draft.runtime.types.Property)26 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)10 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)7 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)7 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)6 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)3 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)3 ArrayList (java.util.ArrayList)3 Jump (com.github.anba.es6draft.compiler.assembler.Jump)2 Realm (com.github.anba.es6draft.runtime.Realm)2 PromiseObject (com.github.anba.es6draft.runtime.objects.promise.PromiseObject)2 com.github.anba.es6draft.ast (com.github.anba.es6draft.ast)1 Abrupt (com.github.anba.es6draft.ast.AbruptNode.Abrupt)1 BlockScope (com.github.anba.es6draft.ast.scope.BlockScope)1 ModuleScope (com.github.anba.es6draft.ast.scope.ModuleScope)1 Name (com.github.anba.es6draft.ast.scope.Name)1 Scope (com.github.anba.es6draft.ast.scope.Scope)1 ScriptScope (com.github.anba.es6draft.ast.scope.ScriptScope)1