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

Side by Side Diff: dart/frog/leg/apiimpl.dart

Issue 9813012: Add "mock" compilation feature to dart2js and use it to improve test coverage. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments 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 // 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 #library('leg_apiimpl'); 5 #library('leg_apiimpl');
6 6
7 #import('leg.dart', prefix: 'leg'); 7 #import('leg.dart', prefix: 'leg');
8 #import('elements/elements.dart', prefix: 'leg'); 8 #import('elements/elements.dart', prefix: 'leg');
9 #import('tree/tree.dart', prefix: 'leg'); 9 #import('tree/tree.dart', prefix: 'leg');
10 #import('ssa/tracer.dart', prefix: 'ssa'); 10 #import('ssa/tracer.dart', prefix: 'ssa');
11 #import('../lang.dart', prefix: 'frog'); 11 #import('../lang.dart', prefix: 'frog');
12 #import('api.dart'); 12 #import('api.dart');
13 #import('../../lib/uri/uri.dart'); 13 #import('../../lib/uri/uri.dart');
14 14
15 class Compiler extends leg.Compiler { 15 class Compiler extends leg.Compiler {
16 ReadUriFromString provider; 16 ReadUriFromString provider;
17 DiagnosticHandler handler; 17 DiagnosticHandler handler;
18 Uri libraryRoot; 18 Uri libraryRoot;
19 List<String> options;
20 bool mockableLibraryUsed = false;
19 21
20 Compiler(this.provider, this.handler, this.libraryRoot) 22 Compiler(this.provider, this.handler, this.libraryRoot, this.options)
21 : super.withCurrentDirectory(null, tracer: new ssa.HTracer()); 23 : super.withCurrentDirectory(null, tracer: new ssa.HTracer());
22 24
23 leg.LibraryElement scanBuiltinLibrary(String filename) { 25 leg.LibraryElement scanBuiltinLibrary(String filename) {
24 Uri uri = libraryRoot.resolve(filename); 26 Uri uri = libraryRoot.resolve(filename);
25 leg.LibraryElement library = scanner.loadLibrary(uri, null); 27 leg.LibraryElement library = scanner.loadLibrary(uri, null);
26 return library; 28 return library;
27 } 29 }
28 30
29 void log(message) { 31 void log(message) {
30 handler(null, null, null, message, false); 32 handler(null, null, null, message, false);
(...skipping 12 matching lines...) Expand all
43 cancel("${uri}: $exception", node: node); 45 cancel("${uri}: $exception", node: node);
44 } 46 }
45 frog.SourceFile sourceFile = new frog.SourceFile(uri.toString(), text); 47 frog.SourceFile sourceFile = new frog.SourceFile(uri.toString(), text);
46 return new leg.Script(uri, sourceFile); 48 return new leg.Script(uri, sourceFile);
47 } 49 }
48 50
49 translateDartUri(Uri uri, leg.ScriptTag node) { 51 translateDartUri(Uri uri, leg.ScriptTag node) {
50 String uriName = uri.toString(); 52 String uriName = uri.toString();
51 // TODO(ahe): Clean this up. 53 // TODO(ahe): Clean this up.
52 if (uriName == 'dart:dom') { 54 if (uriName == 'dart:dom') {
55 mockableLibraryUsed = true;
53 return libraryRoot.resolve('../../../client/dom/frog/dom_frog.dart'); 56 return libraryRoot.resolve('../../../client/dom/frog/dom_frog.dart');
54 } else if (uriName == 'dart:html') { 57 } else if (uriName == 'dart:html') {
58 mockableLibraryUsed = true;
55 return libraryRoot.resolve('../../../client/html/frog/html_frog.dart'); 59 return libraryRoot.resolve('../../../client/html/frog/html_frog.dart');
56 } else if (uriName == 'dart:json') { 60 } else if (uriName == 'dart:json') {
57 return libraryRoot.resolve('../../../lib/json/json.dart'); 61 return libraryRoot.resolve('../../../lib/json/json.dart');
58 } else if (uriName == 'dart:isolate') { 62 } else if (uriName == 'dart:isolate') {
59 return libraryRoot.resolve('../../../lib/isolate/isolate_leg.dart'); 63 return libraryRoot.resolve('../../../lib/isolate/isolate_leg.dart');
60 } else if (uriName == 'dart:io') { 64 } else if (uriName == 'dart:io') {
65 mockableLibraryUsed = true;
61 return libraryRoot.resolve('io.dart'); 66 return libraryRoot.resolve('io.dart');
62 } else if (uriName == 'dart:utf') { 67 } else if (uriName == 'dart:utf') {
63 return libraryRoot.resolve('../../../lib/utf/utf.dart'); 68 return libraryRoot.resolve('../../../lib/utf/utf.dart');
64 } else if (uriName == 'dart:uri') { 69 } else if (uriName == 'dart:uri') {
65 return libraryRoot.resolve('../../../lib/uri/uri.dart'); 70 return libraryRoot.resolve('../../../lib/uri/uri.dart');
66 } 71 }
67 reportError(node, "library not found $uriName"); 72 reportError(node, "library not found $uriName");
68 } 73 }
69 74
70 bool run(Uri uri) { 75 bool run(Uri uri) {
71 bool success = super.run(uri); 76 bool success = super.run(uri);
72 for (final task in tasks) { 77 for (final task in tasks) {
73 log('${task.name} took ${task.timing}msec'); 78 log('${task.name} took ${task.timing}msec');
74 } 79 }
75 return success; 80 return success;
76 } 81 }
77 82
78 void reportDiagnostic(leg.SourceSpan span, String message, bool fatal) { 83 void reportDiagnostic(leg.SourceSpan span, String message, bool fatal) {
79 if (span === null) { 84 if (span === null) {
80 handler(null, null, null, message, fatal); 85 handler(null, null, null, message, fatal);
81 } else { 86 } else {
82 handler(span.uri, span.begin, span.end, message, fatal); 87 handler(span.uri, span.begin, span.end, message, fatal);
83 } 88 }
84 } 89 }
90
91 bool get isMockCompilation() {
92 return mockableLibraryUsed
93 && (options.indexOf('--allow-mock-compilation') !== -1);
94 }
85 } 95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698