Search in sources :

Example 1 with Console

use of com.github.anba.es6draft.runtime.internal.Console 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 2 with Console

use of com.github.anba.es6draft.runtime.internal.Console in project es6draft by anba.

the class ScriptEngineImpl method eval.

Object eval(Script script, ScriptContext context) throws javax.script.ScriptException {
    Realm realm = getEvalRealm(context);
    RuntimeContext runtimeContext = realm.getWorld().getContext();
    Console console = runtimeContext.getConsole();
    runtimeContext.setConsole(new ScriptingConsole(context));
    try {
        // Prepare a new execution context before calling the generated code.
        ExecutionContext evalCxt = newScriptingExecutionContext(realm, script, new LexicalEnvironment<>(realm.getGlobalEnv(), new ScriptContextEnvironmentRecord(realm.defaultContext(), context)));
        Object result = script.evaluate(evalCxt);
        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)

Aggregations

ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)2 ExecutionContext.newScriptingExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext.newScriptingExecutionContext)2 Realm (com.github.anba.es6draft.runtime.Realm)2 Console (com.github.anba.es6draft.runtime.internal.Console)2 RuntimeContext (com.github.anba.es6draft.runtime.internal.RuntimeContext)2 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)2 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)2 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)1 Callable (com.github.anba.es6draft.runtime.types.Callable)1