| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #import("dart:html", prefix:"html"); | 5 #import("dart:html", prefix:"html"); |
| 6 #import('../../../lib/compiler/compiler.dart', prefix: "compiler_lib"); | 6 #import('../../../lib/compiler/compiler.dart', prefix: "compiler_lib"); |
| 7 #import('../../../lib/uri/uri.dart', prefix:"uri_lib"); | 7 #import('../../../lib/uri/uri.dart', prefix:"uri_lib"); |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * This is the entrypoint for a version of the leg compiler that | 10 * This is the entrypoint for a version of the leg compiler that |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 String readAll(String filename) { | 36 String readAll(String filename) { |
| 37 String text = getText(idOfFilename(filename)); | 37 String text = getText(idOfFilename(filename)); |
| 38 print("read $filename (${text.length} bytes)"); | 38 print("read $filename (${text.length} bytes)"); |
| 39 return text; | 39 return text; |
| 40 } | 40 } |
| 41 | 41 |
| 42 void diagnosticHandler(uri_lib.Uri uri, int begin, int end, | 42 void diagnosticHandler(uri_lib.Uri uri, int begin, int end, |
| 43 String message, bool fatal) { | 43 String message, bool fatal) { |
| 44 warnings.add(message); | 44 warnings.add(message); |
| 45 if (uri !== null) { | 45 if (uri != null) { |
| 46 warnings.add(" ($uri: $begin, $end)"); | 46 warnings.add(" ($uri: $begin, $end)"); |
| 47 } | 47 } |
| 48 if (fatal) { | 48 if (fatal) { |
| 49 warnings.add(" (fatal)"); | 49 warnings.add(" (fatal)"); |
| 50 } | 50 } |
| 51 warnings.add("\n"); | 51 warnings.add("\n"); |
| 52 } | 52 } |
| 53 | 53 |
| 54 Future<String> readUriFromString(uri_lib.Uri uri) { | 54 Future<String> readUriFromString(uri_lib.Uri uri) { |
| 55 Completer<String> completer = new Completer<String>(); | 55 Completer<String> completer = new Completer<String>(); |
| 56 completer.complete(readAll(uri.toString())); | 56 completer.complete(readAll(uri.toString())); |
| 57 return completer.future; | 57 return completer.future; |
| 58 } | 58 } |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * Returns the id of the <script> element that contains | 61 * Returns the id of the <script> element that contains |
| 62 * the contents of this file. (Replace all slashes | 62 * the contents of this file. (Replace all slashes |
| 63 * and dots in the file name with underscores.) | 63 * and dots in the file name with underscores.) |
| 64 */ | 64 */ |
| 65 String idOfFilename(String filename) { | 65 String idOfFilename(String filename) { |
| 66 return filename.replaceAll("/", "_").replaceAll(".", "_"); | 66 return filename.replaceAll("/", "_").replaceAll(".", "_"); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void run() { | 69 void run() { |
| 70 String mainFile = getText(MAIN_ID); | 70 String mainFile = getText(MAIN_ID); |
| 71 setText("input", readAll(mainFile)); | 71 setText("input", readAll(mainFile)); |
| 72 Stopwatch stopwatch = new Stopwatch()..start(); | 72 Stopwatch stopwatch = new Stopwatch()..start(); |
| 73 runLeg(); | 73 runLeg(); |
| 74 int elapsedMillis = stopwatch.elapsedMilliseconds; | 74 int elapsedMillis = stopwatch.elapsedMilliseconds; |
| 75 if (output === null) { | 75 if (output == null) { |
| 76 output = "throw 'dart2js compilation error';\n"; | 76 output = "throw 'dart2js compilation error';\n"; |
| 77 } | 77 } |
| 78 | 78 |
| 79 setText("output", output); | 79 setText("output", output); |
| 80 setText("warnings", warnings.toString()); | 80 setText("warnings", warnings.toString()); |
| 81 int lineCount = lineCount(output); | 81 int lineCount = lineCount(output); |
| 82 String timing = "generated $lineCount lines " | 82 String timing = "generated $lineCount lines " |
| 83 "(${output.length} characters) in " | 83 "(${output.length} characters) in " |
| 84 "${((elapsedMillis) / 1000).toStringAsPrecision(3)} seconds"; | 84 "${((elapsedMillis) / 1000).toStringAsPrecision(3)} seconds"; |
| 85 setText("timing", timing); | 85 setText("timing", timing); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 107 libraryRoot, readUriFromString, diagnosticHandler, compilerArgs); | 107 libraryRoot, readUriFromString, diagnosticHandler, compilerArgs); |
| 108 | 108 |
| 109 if (futureJavascript == null) { | 109 if (futureJavascript == null) { |
| 110 return; | 110 return; |
| 111 } | 111 } |
| 112 output = futureJavascript.value; | 112 output = futureJavascript.value; |
| 113 } | 113 } |
| 114 | 114 |
| 115 void setText(String id, String text) { | 115 void setText(String id, String text) { |
| 116 html.Element element = html.document.query("#$id"); | 116 html.Element element = html.document.query("#$id"); |
| 117 if (element === null) { | 117 if (element == null) { |
| 118 throw new Exception("Can't find element $id"); | 118 throw new Exception("Can't find element $id"); |
| 119 } | 119 } |
| 120 element.innerHTML = htmlEscape(text); | 120 element.innerHTML = htmlEscape(text); |
| 121 } | 121 } |
| 122 | 122 |
| 123 String getText(String id) { | 123 String getText(String id) { |
| 124 html.Element element = html.document.query("#$id"); | 124 html.Element element = html.document.query("#$id"); |
| 125 if (element === null) { | 125 if (element == null) { |
| 126 throw new Exception("Can't find element $id"); | 126 throw new Exception("Can't find element $id"); |
| 127 } | 127 } |
| 128 return element.text.trim(); | 128 return element.text.trim(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 // TODO(mattsh): should exist in standard lib somewhere | 131 // TODO(mattsh): should exist in standard lib somewhere |
| 132 static String htmlEscape(String text) { | 132 static String htmlEscape(String text) { |
| 133 return text.replaceAll('&', '&').replaceAll( | 133 return text.replaceAll('&', '&').replaceAll( |
| 134 '>', '>').replaceAll('<', '<'); | 134 '>', '>').replaceAll('<', '<'); |
| 135 } | 135 } |
| 136 } | 136 } |
| OLD | NEW |