Package org.mozilla.javascript

Examples of org.mozilla.javascript.CompilerEnvirons


public class ObjectLiteralTest {
 
  private static ObjectLiteral getLiteralNode(String literalStr) throws InvalidLiteralNode {
    String scriptSource = "var lit = " + literalStr;
   
    CompilerEnvirons ce = new CompilerEnvirons();
    ScriptParserErrorReporter errorReporter = new ScriptParserErrorReporter();
   
    ce.setGenerateDebugInfo(true);   
    ce.initFromContext(ContextFactory.getGlobal().enterContext());
    ce.setErrorReporter(errorReporter);
   
    Parser p = new Parser(ce, errorReporter);
    ScriptOrFnNode ast = p.parse(scriptSource, "script", 0);
   
    return new ObjectLiteral(ast.getFirstChild().getFirstChild().getFirstChild());
View Full Code Here


    private AstRoot parse(String string) {
        return parse(string, true);   
    }

    private AstRoot parse(String string, boolean jsdoc) {
        CompilerEnvirons environment = new CompilerEnvirons();

        TestErrorReporter testErrorReporter = new TestErrorReporter(null, null);
        environment.setErrorReporter(testErrorReporter);

        environment.setRecordingComments(true);
        environment.setRecordingLocalJsDocComments(jsdoc);

        Parser p = new Parser(environment, testErrorReporter);
        AstRoot script = p.parse(string, null, 0);

        assertTrue(testErrorReporter.hasEncounteredAllErrors());
View Full Code Here

        return script;
    }

    private AstRoot parseAsReader(String string) throws IOException {
        CompilerEnvirons environment = new CompilerEnvirons();

        TestErrorReporter testErrorReporter = new TestErrorReporter(null, null);
        environment.setErrorReporter(testErrorReporter);

        environment.setRecordingComments(true);
        environment.setRecordingLocalJsDocComments(true);

        Parser p = new Parser(environment, testErrorReporter);
        AstRoot script = p.parse(new StringReader(string), null, 0);

        assertTrue(testErrorReporter.hasEncounteredAllErrors());
View Full Code Here

  private void scan(final File source) throws IOException {
    log.debug("Scanning: " + source);

    ErrorReporter errorReporter = new LogErrorReporter(log);

    CompilerEnvirons env = new CompilerEnvirons();
    env.setErrorReporter(errorReporter);

    Parser parser = new Parser(env, errorReporter);
    Reader reader = new BufferedReader(new FileReader(source));
    try {
      AstRoot root = parser.parse(reader, source.getAbsolutePath(), 0);
View Full Code Here

    @Test
    public void shouldServeInstrumentedJSForWebServer() throws IOException {
        File wwwRoot = new File("wwwRoot");
        ReflectionUtils.setField(webServer, HttpServer.class, "wwwRoot", wwwRoot);
        CompilerEnvirons compilerEnvirons = new CompilerEnvirons();
        given(configuration.getCompilerEnvirons()).willReturn(compilerEnvirons);
        given(configuration.skipInstrumentation("/js/production.js")).willReturn(false);

        webServer.handleGet(new HttpRequest("/js/production.js", null, null, 0, null));
View Full Code Here

    @Test
    public void shouldRecordInstrumentedURIsForWebServer() throws IOException {
        given(configuration.isIncludeUnloadedJS()).willReturn(true);
        File wwwRoot = new File("wwwRoot");
        ReflectionUtils.setField(webServer, HttpServer.class, "wwwRoot", wwwRoot);
        CompilerEnvirons compilerEnvirons = new CompilerEnvirons();
        given(configuration.getCompilerEnvirons()).willReturn(compilerEnvirons);
        given(configuration.skipInstrumentation("/js/production.js")).willReturn(false);

        webServer.handleGet(new HttpRequest("/js/production.js", null, null, 0, null));
View Full Code Here

    @Test
    public void shouldNotRecordInstrumentedURIsForWebServerIfNotFound() throws IOException {
        given(configuration.isIncludeUnloadedJS()).willReturn(true);
        File wwwRoot = new File("wwwRoot");
        ReflectionUtils.setField(webServer, HttpServer.class, "wwwRoot", wwwRoot);
        CompilerEnvirons compilerEnvirons = new CompilerEnvirons();
        given(configuration.getCompilerEnvirons()).willReturn(compilerEnvirons);
        given(configuration.skipInstrumentation("/js/production.js")).willReturn(false);
        given(instrumenterService.instrumentJSForWebServer(configuration, new File("wwwRoot/js/production.js"), "/js/production.js")).willThrow(new UriNotFound("Ouch!", null));

        webServer.handleGet(new HttpRequest("/js/production.js", null, null, 0, null));
View Full Code Here

    @Test
    public void shouldServeInstrumentedJSForProxyServer() throws IOException {
        given(configuration.isProxy()).willReturn(true);
        File wwwRoot = new File("wwwRoot");
        ReflectionUtils.setField(webServer, HttpServer.class, "wwwRoot", wwwRoot);
        CompilerEnvirons compilerEnvirons = new CompilerEnvirons();
        given(configuration.getCompilerEnvirons()).willReturn(compilerEnvirons);
        given(configuration.skipInstrumentation("/js/production.js")).willReturn(false);
        String uri = "http://someserver.org/exclude/js/production.js";
        HttpRequest request = new HttpRequest(uri, null, null, 0, null);
        given(proxyService.getUrl(request)).willReturn("someJavaScript;");
View Full Code Here

    @Test
    public void shouldServeNonInstrumentedJS() throws IOException {
        File wwwRoot = new File("wwwRoot");
        ReflectionUtils.setField(webServer, HttpServer.class, "wwwRoot", wwwRoot);
        CompilerEnvirons compilerEnvirons = new CompilerEnvirons();
        given(configuration.getCompilerEnvirons()).willReturn(compilerEnvirons);
        given(configuration.skipInstrumentation("test/production.js")).willReturn(true);

        webServer.handleGet(new HttpRequest("/test/production.js", null, null, 0, null));
View Full Code Here

    @Test
    public void shouldServeNonInstrumentedJSWhenViewingSource() throws IOException {
        File wwwRoot = new File("wwwRoot");
        ReflectionUtils.setField(webServer, HttpServer.class, "wwwRoot", wwwRoot);
        CompilerEnvirons compilerEnvirons = new CompilerEnvirons();
        given(configuration.getCompilerEnvirons()).willReturn(compilerEnvirons);
        given(configuration.skipInstrumentation("test/production.js")).willReturn(false);

        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        headers.put("NoInstrument", new ArrayList<String>(){{add("true");}});
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.CompilerEnvirons

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.