private void runCajoled(String js, Object golden, String context) throws Exception { Block uncajoledModuleBody = js(fromString(js)); System.err.println("\n\nblock\n=====\n" + uncajoledModuleBody.toStringDeep(1)); PluginMeta meta = new PluginMeta(); meta.setDebugMode(true); Jobs jobs = new Jobs(mc, mq, meta); jobs.getJobs().add(new Job(AncestorChain.instance(uncajoledModuleBody))); Pipeline<Jobs> pipeline = new Pipeline<Jobs>(); pipeline.getStages().add(new ConsolidateCodeStage()); pipeline.getStages().add(new ValidateJavascriptStage(new TestBuildInfo())); pipeline.getStages().add(new InferFilePositionsStage()); pipeline.getStages().add(new DebuggingSymbolsStage()); if (!pipeline.apply(jobs)) { StringBuilder sb = new StringBuilder(); for (Message msg : mq.getMessages()) { if (0 == sb.length()) { sb.append('\n'); } sb.append(msg.getMessageLevel()).append(": "); msg.format(mc, sb); } fail(sb.toString()); } CajoledModule cajoledModule = jobs.getJobs().get(0).getRoot().cast(CajoledModule.class).node; try { String cajoledText = String.format(context, render(cajoledModule)); Object actual = RhinoTestBed.runJs( new RhinoTestBed.Input(getClass(), "/js/json_sans_eval/json_sans_eval.js"), new RhinoTestBed.Input(getClass(), "../console-stubs.js"), new RhinoTestBed.Input(getClass(), "/com/google/caja/cajita.js"), new RhinoTestBed.Input(getClass(), "/com/google/caja/log-to-console.js"), new RhinoTestBed.Input(getClass(), "/com/google/caja/cajita-debugmode.js"), new RhinoTestBed.Input(cajoledText, getName())); assertEquals(golden, actual); } catch (Exception ex) { System.err.println(render(cajoledModule)); throw ex; } catch (Error ex) { System.err.println(render(cajoledModule)); throw ex; } }
private void assertConsistent(String js) throws Exception { // Execute js in the presence of cajita so it can use Caja symbols. Object golden = RhinoTestBed.runJs( new RhinoTestBed.Input(getClass(), "/js/json_sans_eval/json_sans_eval.js"), new RhinoTestBed.Input(getClass(), "/com/google/caja/cajita.js"), new RhinoTestBed.Input(js, getName())); runCajoled( "result(" + js + ");", golden, "var output = '<no-output>';" + "___.getNewModuleHandler().getImports().result = " + " ___.markFuncFreeze(function (x) { output = x; });" + "%s;" + "output"); }