use of com.github.anba.es6draft.runtime.Realm 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.getRuntimeContext();
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);
}
}
use of com.github.anba.es6draft.runtime.Realm 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.getRuntimeContext();
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, (Object) 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);
}
}
use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class DefaultLocaleTimezone method testGreenwich.
@Test
public void testGreenwich() throws Exception {
Realm realm = newRealm(TimeZone.getTimeZone("Greenwich"));
assertEquals("UTC", resolvedTimeZone(realm));
}
use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class DefaultLocaleTimezone method testAustralia_Tasmania.
@Test
public void testAustralia_Tasmania() throws Exception {
Realm realm = newRealm(TimeZone.getTimeZone("Australia/Tasmania"));
assertEquals("Australia/Hobart", resolvedTimeZone(realm));
}
use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class DefaultLocaleTimezone method testGMT_minus_0.
@Test
public void testGMT_minus_0() throws Exception {
Realm realm = newRealm(TimeZone.getTimeZone("GMT-0"));
assertEquals("UTC", resolvedTimeZone(realm));
}
Aggregations