| 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 library mock_compiler; | 5 library mock_compiler; |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:collection'; | 9 import 'dart:collection'; |
| 10 | 10 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 import 'dart:_interceptors'; | 248 import 'dart:_interceptors'; |
| 249 import 'dart:_isolate_helper'; | 249 import 'dart:_isolate_helper'; |
| 250 '''; | 250 '''; |
| 251 | 251 |
| 252 const String DEFAULT_ISOLATE_HELPERLIB = r''' | 252 const String DEFAULT_ISOLATE_HELPERLIB = r''' |
| 253 var startRootIsolate; | 253 var startRootIsolate; |
| 254 var _currentIsolate; | 254 var _currentIsolate; |
| 255 var _callInIsolate; | 255 var _callInIsolate; |
| 256 class _WorkerBase {}'''; | 256 class _WorkerBase {}'''; |
| 257 | 257 |
| 258 const String DEFAULT_MIRRORS = r''' |
| 259 class Comment {} |
| 260 class MirrorSystem {} |
| 261 class MirrorsUsed {} |
| 262 '''; |
| 263 |
| 258 class MockCompiler extends Compiler { | 264 class MockCompiler extends Compiler { |
| 259 api.DiagnosticHandler diagnosticHandler; | 265 api.DiagnosticHandler diagnosticHandler; |
| 260 List<WarningMessage> warnings; | 266 List<WarningMessage> warnings; |
| 261 List<WarningMessage> errors; | 267 List<WarningMessage> errors; |
| 262 List<WarningMessage> hints; | 268 List<WarningMessage> hints; |
| 263 List<WarningMessage> infos; | 269 List<WarningMessage> infos; |
| 264 List<WarningMessage> crashes; | 270 List<WarningMessage> crashes; |
| 265 /// Expected number of warnings. If `null`, the number of warnings is | 271 /// Expected number of warnings. If `null`, the number of warnings is |
| 266 /// not checked. | 272 /// not checked. |
| 267 final int expectedWarnings; | 273 final int expectedWarnings; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 310 |
| 305 clearMessages(); | 311 clearMessages(); |
| 306 | 312 |
| 307 registerSource(Compiler.DART_CORE, coreSource); | 313 registerSource(Compiler.DART_CORE, coreSource); |
| 308 registerSource(PATCH_CORE, PATCH_CORE_SOURCE); | 314 registerSource(PATCH_CORE, PATCH_CORE_SOURCE); |
| 309 | 315 |
| 310 registerSource(Compiler.DART_JS_HELPER, DEFAULT_HELPERLIB); | 316 registerSource(Compiler.DART_JS_HELPER, DEFAULT_HELPERLIB); |
| 311 registerSource(Compiler.DART_FOREIGN_HELPER, FOREIGN_LIBRARY); | 317 registerSource(Compiler.DART_FOREIGN_HELPER, FOREIGN_LIBRARY); |
| 312 registerSource(Compiler.DART_INTERCEPTORS, interceptorsSource); | 318 registerSource(Compiler.DART_INTERCEPTORS, interceptorsSource); |
| 313 registerSource(Compiler.DART_ISOLATE_HELPER, DEFAULT_ISOLATE_HELPERLIB); | 319 registerSource(Compiler.DART_ISOLATE_HELPER, DEFAULT_ISOLATE_HELPERLIB); |
| 320 registerSource(Compiler.DART_MIRRORS, DEFAULT_MIRRORS); |
| 314 } | 321 } |
| 315 | 322 |
| 316 /// Initialize the mock compiler with an empty main library. | 323 /// Initialize the mock compiler with an empty main library. |
| 317 Future init([String mainSource = ""]) { | 324 Future init([String mainSource = ""]) { |
| 318 Uri uri = new Uri(scheme: "mock"); | 325 Uri uri = new Uri(scheme: "mock"); |
| 319 registerSource(uri, mainSource); | 326 registerSource(uri, mainSource); |
| 320 return libraryLoader.loadLibrary(uri, null, uri) | 327 return libraryLoader.loadLibrary(uri) |
| 321 .then((LibraryElement library) { | 328 .then((LibraryElement library) { |
| 322 coreLibrary = libraries['${Compiler.DART_CORE}']; | |
| 323 jsHelperLibrary = libraries['${Compiler.DART_JS_HELPER}']; | |
| 324 foreignLibrary = libraries['${Compiler.DART_FOREIGN_HELPER}']; | |
| 325 interceptorsLibrary = libraries['${Compiler.DART_INTERCEPTORS}']; | |
| 326 isolateHelperLibrary = libraries['${Compiler.DART_ISOLATE_HELPER}']; | |
| 327 | |
| 328 assertMethod = jsHelperLibrary.find('assertHelper'); | |
| 329 identicalFunction = coreLibrary.find('identical'); | |
| 330 | |
| 331 mainApp = library; | 329 mainApp = library; |
| 332 initializeSpecialClasses(); | |
| 333 // We need to make sure the Object class is resolved. When registering a | 330 // We need to make sure the Object class is resolved. When registering a |
| 334 // dynamic invocation the ArgumentTypesRegistry eventually iterates over | 331 // dynamic invocation the ArgumentTypesRegistry eventually iterates over |
| 335 // the interfaces of the Object class which would be 'null' if the class | 332 // the interfaces of the Object class which would be 'null' if the class |
| 336 // wasn't resolved. | 333 // wasn't resolved. |
| 337 objectClass.ensureResolved(this); | 334 objectClass.ensureResolved(this); |
| 338 }); | 335 }); |
| 339 } | 336 } |
| 340 | 337 |
| 341 Future runCompiler(Uri uri) { | 338 Future runCompiler(Uri uri) { |
| 342 return init().then((_) { | 339 return init().then((_) { |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 | 593 |
| 597 class MockElement extends FunctionElementX { | 594 class MockElement extends FunctionElementX { |
| 598 MockElement(Element enclosingElement) | 595 MockElement(Element enclosingElement) |
| 599 : super('', ElementKind.FUNCTION, Modifiers.EMPTY, | 596 : super('', ElementKind.FUNCTION, Modifiers.EMPTY, |
| 600 enclosingElement, false); | 597 enclosingElement, false); |
| 601 | 598 |
| 602 get node => null; | 599 get node => null; |
| 603 | 600 |
| 604 parseNode(_) => null; | 601 parseNode(_) => null; |
| 605 } | 602 } |
| OLD | NEW |