public static void flush(Environment env) throws Throwable { OutputBuffer root = env.getDefaultBuffer(); if (root != null) { root.flush(); } }
public void decLock(){ if (isRoot()) lock--; else environment.getDefaultBuffer().decLock(); }
public void incLock(){ if (isRoot()) lock++; else environment.getDefaultBuffer().incLock(); }
public static void catchThrowable(Throwable e, Environment environment) { if (e instanceof BaseBaseException) { BaseBaseException baseException = (BaseBaseException) e; baseException.getEnvironment().catchUncaught(baseException); return; } else if (e instanceof Exception) { Environment env = environment == null ? null : environment; if (env != null) { try { env.catchUncaught((Exception) e); } catch (RuntimeException e2) { if (env.getDefaultBuffer() == null || env.getDefaultBuffer().getOutput() == null) { e2.printStackTrace(); } else { e2.getCause().printStackTrace(new PrintStream(env.getDefaultBuffer().getOutput())); } } return; } } Environment env = environment == null ? null : environment; if (env != null) { e.printStackTrace(new PrintStream(env.getDefaultBuffer().getOutput())); } else { e.printStackTrace(); } }
public boolean isLock(){ return isRoot() ? lock > 0 : environment.getDefaultBuffer().isLock(); }
@Signature(@Arg("callback")) public Memory onOutput(Environment env, Memory... args) { if (args[0].isNull()) { Invoker invoker = Invoker.valueOf(this.environment, null, args[0]); if (invoker == null) { env.exception("Argument 1 must be callable in environment"); return Memory.NULL; } invoker.setTrace(env.trace()); this.environment.getDefaultBuffer().setCallback(args[0], invoker); } else { this.environment.getDefaultBuffer().setCallback(null); } return Memory.NULL; }
environment.getDefaultBuffer().setImplicitFlush(true);
public static void ob_implicit_flush(Environment env, TraceInfo trace, Memory value){ OutputBuffer root = env.getDefaultBuffer(); switch (value.getRealType()){ case ARRAY: case STRING: case OBJECT: env.warning(trace, "ob_implicit_flush() expects parameter 1 to be long, " + value.getRealType().toString() + " given" ); return; } if (root != null) root.setImplicitFlush(value.toBoolean()); }
scope = new CompileScope(); env = new ConcurrentEnvironment(scope, System.out); env.getDefaultBuffer().setImplicitFlush(true);
@Signature({ @Arg(value = "parent", nativeType = WrapEnvironment.class, optional = @Optional("NULL")), @Arg(value = "flags", optional = @Optional(value = "0", type = HintType.INT)) }) public Memory __construct(Environment env, Memory... args){ CompileScope scope = env.scope; int flags = args[1].toInteger(); boolean hotReload = (flags & HOT_RELOAD) == HOT_RELOAD; boolean concurrent = (flags & CONCURRENT) == CONCURRENT; if (hotReload) { scope = new CompileScope(scope); } if (args[0].isNull()) { if (concurrent) setEnvironment(new ConcurrentEnvironment(scope, env.getDefaultBuffer().getOutput())); else setEnvironment(new Environment(scope, env.getDefaultBuffer().getOutput())); } else { if (hotReload) env.exception("Environment cannot be hot-reloadable with parent"); if (concurrent) setEnvironment(new ConcurrentEnvironment(args[0].toObject(WrapEnvironment.class).getWrapEnvironment())); else setEnvironment(new Environment(args[0].toObject(WrapEnvironment.class).getWrapEnvironment())); } return Memory.NULL; }
public JPHPScriptEngine() { super(); Launcher launcher = new Launcher(); try { launcher.run(false); } catch (Throwable e) { //pass } environment = new Environment(launcher.getCompileScope(), System.out); environment.getDefaultBuffer().setImplicitFlush(true); JPHPContext ctx = new JPHPContext(); ctx.setBindings(createBindings(), ScriptContext.ENGINE_SCOPE); setContext(ctx); put(LANGUAGE_VERSION, __LANGUAGE_VERSION__); put(LANGUAGE, __LANGUAGE__); put(ENGINE, __NAME__); put(ENGINE_VERSION, __ENGINE_VERSION__); put(NAME, __SHORT_NAME__); }
environment.getErrorReportHandler().onFatal(e); try { environment.getDefaultBuffer().flush(); } catch (Throwable throwable) { throw new RuntimeException(throwable);