Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: tools/testing/frogpad/frogpad.dart

Issue 9610002: remove node.js dependency by running the frog compiler in (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix frog html Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 /** 6 /**
7 * This is the entrypoint for a version of the frog compiler that 7 * This is the entrypoint for a version of the frog compiler that
8 * can run in the browser. 8 * can run in the browser.
9 * Because this is running in the browser, frog cannot access 9 * Because this is running in the browser, frog cannot access
10 * the file system. Instead, we assume the all necessary files 10 * the file system. Instead, we assume the all necessary files
11 * have been placed in inert <script> elements somewhere on the page. 11 * have been placed in inert <script> elements somewhere on the page.
12 * (See frogpad.py for more details on how the html page is constructed.) 12 * (See frogpad.py for more details on how the html page is constructed.)
13 */ 13 */
14 14
15 #import("dart:html", prefix:"html"); 15 #import("dart:html", prefix:"html");
16 #import("../../../frog/lang.dart"); 16 #import("../../../frog/lang.dart");
17 #import("../../../frog/file_system.dart"); 17 #import("../../../frog/file_system.dart");
18 18
19 // id of script element containing name of the main dart file 19 // id of script element containing name of the main dart file
20 // to compile. 20 // to compile.
21 final String MAIN_ID = "main_id"; 21 final String MAIN_ID = "main_id";
22 22
23 void main() { 23 void main() {
24 String warnings = ""; 24 String warnings = "";
25 HtmlFileSystem fs = new HtmlFileSystem(); 25 HtmlFileSystem fs = new HtmlFileSystem();
26 String mainFile = getText(MAIN_ID); 26 String mainFile = getText(MAIN_ID);
27 setText("input", fs.readAll(mainFile)); 27 setText("input", fs.readAll(mainFile));
28 28
29 int time1 = new Date.now().value; 29 int time1 = new Date.now().value;
30 List<String> args = ["dummy_arg1", "dummy_arg2", mainFile]; 30 List<String> args = [
31 "dummy_arg1",
32 "dummy_arg2",
33 "--enable_type_checks",
34 "--enable_asserts",
35 mainFile];
31 parseOptions("dummy_home_dir", args, fs); 36 parseOptions("dummy_home_dir", args, fs);
32 37
33 options.useColors = false; 38 options.useColors = false;
34 39
35 initializeWorld(fs); 40 initializeWorld(fs);
36 world.messageHandler = void _( 41 world.messageHandler = void _(
37 String prefix, String message, SourceSpan span) { 42 String prefix, String message, SourceSpan span) {
38 String location = ""; 43 String location = "";
39 if (span !== null) { 44 if (span !== null) {
40 location = span.locationText; 45 location = span.locationText;
41 } 46 }
42 warnings += prefix + message + location + "\n"; 47 warnings += prefix + message + location + "\n";
43 }; 48 };
44 bool success = world.compile(); 49 bool success = world.compile();
45 int time2 = new Date.now().value; 50 int time2 = new Date.now().value;
46 String output = world.getGeneratedCode(); 51 String output = "throw 'frogpad compilation error';\n";
47 if (success) { 52 if (success) {
48 setText("output", output); 53 output = world.getGeneratedCode();
49 } 54 }
55 setText("output", output);
50 setText("warnings", warnings); 56 setText("warnings", warnings);
51 57
52 ((time2 - time1) / 1000).toStringAsPrecision(3); 58 String timing = "generated ${output.length} characters in " +
53 String timing = "generated ${output.length} characters in " +
54 "${((time2 - time1) / 1000).toStringAsPrecision(3)} seconds"; 59 "${((time2 - time1) / 1000).toStringAsPrecision(3)} seconds";
55 setText("timing", timing); 60 setText("timing", timing);
56 } 61 }
57 62
58 void setText(String id, String text) { 63 void setText(String id, String text) {
59 html.Element element = html.document.query("#$id"); 64 html.Element element = html.document.query("#$id");
60 if (element === null) { 65 if (element === null) {
61 throw new Exception("Can't find element $id"); 66 throw new Exception("Can't find element $id");
62 } 67 }
63 element.innerHTML = htmlEscape(text); 68 element.innerHTML = htmlEscape(text);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 return Strings.join(components, "_").replaceAll(".", "_"); 126 return Strings.join(components, "_").replaceAll(".", "_");
122 } 127 }
123 128
124 void writeString(String outfile, String text) { 129 void writeString(String outfile, String text) {
125 throw new UnsupportedOperationException(""); 130 throw new UnsupportedOperationException("");
126 } 131 }
127 132
128 bool fileExists(String filename) { 133 bool fileExists(String filename) {
129 // frog calls this to check if files exist before reading them. We return 134 // frog calls this to check if files exist before reading them. We return
130 // true here for all files, and let it fail later if frog attempts to read 135 // true here for all files, and let it fail later if frog attempts to read
131 // the contents of a non-existant file. 136 // the contents of a non-existent file.
132 return true; 137 return true;
133 } 138 }
134 139
135 void createDirectory(String path, [bool recursive]) { 140 void createDirectory(String path, [bool recursive]) {
136 throw new UnsupportedOperationException(""); 141 throw new UnsupportedOperationException("");
137 } 142 }
138 143
139 void removeDirectory(String path, [bool recursive]) { 144 void removeDirectory(String path, [bool recursive]) {
140 throw new UnsupportedOperationException(""); 145 throw new UnsupportedOperationException("");
141 } 146 }
142 } 147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698