 Chromium Code Reviews
 Chromium Code Reviews Issue 858843002:
  Add hook for compiling to JavaScript.  (Closed) 
  Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
    
  
    Issue 858843002:
  Add hook for compiling to JavaScript.  (Closed) 
  Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge| Index: dart/pkg/dart2js_incremental/lib/server.dart | 
| diff --git a/dart/pkg/dart2js_incremental/lib/server.dart b/dart/pkg/dart2js_incremental/lib/server.dart | 
| index a0ed328fb674239adbe22b3fc98a316865a061ba..e6f827453612dfc885034cb3790ddb9d8c0138b9 100644 | 
| --- a/dart/pkg/dart2js_incremental/lib/server.dart | 
| +++ b/dart/pkg/dart2js_incremental/lib/server.dart | 
| @@ -37,6 +37,7 @@ class Conversation { | 
| } | 
| notFound(path) { | 
| + response.headers.set(CONTENT_TYPE, 'text/html'); | 
| response.statusCode = HttpStatus.NOT_FOUND; | 
| response.write(htmlInfo('Not Found', | 
| 'The file "$path" could not be found.')); | 
| @@ -44,6 +45,7 @@ class Conversation { | 
| } | 
| badRequest(String problem) { | 
| + response.headers.set(CONTENT_TYPE, 'text/html'); | 
| response.statusCode = HttpStatus.BAD_REQUEST; | 
| response.write(htmlInfo("Bad request", | 
| "Bad request '${request.uri}': $problem")); | 
| @@ -53,6 +55,11 @@ class Conversation { | 
| internalError(error, stack) { | 
| print(error); | 
| if (stack != null) print(stack); | 
| + try { | 
| + response.headers.set(CONTENT_TYPE, 'text/html'); | 
| + } catch (_) { | 
| + // Ignored. | 
| 
kasperl
2015/01/19 11:21:04
What kind of exception can happen here and why are
 
ahe
2015/01/19 11:37:12
The kind of exception isn't specified. All that is
 | 
| + } | 
| response.statusCode = HttpStatus.INTERNAL_SERVER_ERROR; | 
| response.write(htmlInfo("Internal Server Error", | 
| "Internal Server Error: $error\n$stack")); | 
| @@ -90,30 +97,44 @@ class Conversation { | 
| } | 
| String path = uri.path; | 
| Uri root = documentRoot; | 
| - String dartType = 'application/dart'; | 
| if (path.startsWith('${PACKAGES_PATH}/')) { | 
| root = packageRoot; | 
| path = path.substring(PACKAGES_PATH.length); | 
| } | 
| - String filePath = root.resolve('.$path').toFilePath(); | 
| + Uri resolvedRequest = root.resolve('.$path'); | 
| switch (request.method) { | 
| case 'GET': | 
| - return handleGet(filePath, dartType); | 
| + return handleGet(resolvedRequest); | 
| default: | 
| String method = const HtmlEscape().convert(request.method); | 
| return badRequest("Unsupported method: '$method'"); | 
| } | 
| } | 
| - void handleGet(String path, String dartType) { | 
| - var f = new File(path); | 
| + void handleGet(Uri uri) { | 
| + String path = uri.path; | 
| + var f = new File.fromUri(uri); | 
| f.exists().then((bool exists) { | 
| - if (!exists) return notFound(request.uri); | 
| + if (!exists) { | 
| + if (path.endsWith('.dart.js')) { | 
| + Uri dartScript = uri.resolve(path.substring(0, path.length - 3)); | 
| + new File.fromUri(dartScript).exists().then((bool exists) { | 
| + if (exists) { | 
| + compileToJavaScript(dartScript); | 
| + } else { | 
| + notFound(request.uri); | 
| + } | 
| + }); | 
| + return; | 
| + } | 
| + notFound(request.uri); | 
| + return; | 
| + } | 
| if (path.endsWith('.html')) { | 
| response.headers.set(CONTENT_TYPE, 'text/html'); | 
| } else if (path.endsWith('.dart')) { | 
| - response.headers.set(CONTENT_TYPE, dartType); | 
| + response.headers.set(CONTENT_TYPE, 'application/dart'); | 
| } else if (path.endsWith('.js')) { | 
| response.headers.set(CONTENT_TYPE, 'application/javascript'); | 
| } else if (path.endsWith('.ico')) { | 
| @@ -125,6 +146,13 @@ class Conversation { | 
| }); | 
| } | 
| + void compileToJavaScript(Uri dartScript) { | 
| + Uri outputUri = request.uri; | 
| + print("Compiling $dartScript to $outputUri"); | 
| + // TODO(ahe): Implement this. | 
| + notFound(request.uri); | 
| + } | 
| + | 
| static onRequest(HttpRequest request) { | 
| Conversation conversation = new Conversation(request, request.response); | 
| if (WebSocketTransformer.isUpgradeRequest(request)) { |