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 part of dart2js; | 5 part of dart2js; |
6 | 6 |
7 /** | 7 /** |
8 * If true, print a warning for each method that was resolved, but not | 8 * If true, print a warning for each method that was resolved, but not |
9 * compiled. | 9 * compiled. |
10 */ | 10 */ |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 396 |
397 createInvocationMirrorElement = | 397 createInvocationMirrorElement = |
398 findHelper(CREATE_INVOCATION_MIRROR); | 398 findHelper(CREATE_INVOCATION_MIRROR); |
399 enqueuer.resolution.addToWorkList(createInvocationMirrorElement); | 399 enqueuer.resolution.addToWorkList(createInvocationMirrorElement); |
400 enqueuer.codegen.addToWorkList(createInvocationMirrorElement); | 400 enqueuer.codegen.addToWorkList(createInvocationMirrorElement); |
401 } | 401 } |
402 | 402 |
403 void enableIsolateSupport(LibraryElement element) { | 403 void enableIsolateSupport(LibraryElement element) { |
404 // TODO(ahe): Move this method to Enqueuer. | 404 // TODO(ahe): Move this method to Enqueuer. |
405 isolateLibrary = element.patch; | 405 isolateLibrary = element.patch; |
406 isolateHelperLibrary = scanBuiltinLibrary('_isolate_helper'); | |
407 importForeignLibrary(isolateHelperLibrary); | |
408 importHelperLibrary(isolateHelperLibrary); | |
409 | |
410 libraryLoader.importLibrary(isolateLibrary, isolateHelperLibrary, null); | |
411 enqueuer.resolution.addToWorkList( | 406 enqueuer.resolution.addToWorkList( |
412 isolateHelperLibrary.find(START_ROOT_ISOLATE)); | 407 isolateHelperLibrary.find(START_ROOT_ISOLATE)); |
413 enqueuer.resolution.addToWorkList( | 408 enqueuer.resolution.addToWorkList( |
414 isolateHelperLibrary.find(const SourceString('_currentIsolate'))); | 409 isolateHelperLibrary.find(const SourceString('_currentIsolate'))); |
415 enqueuer.resolution.addToWorkList( | 410 enqueuer.resolution.addToWorkList( |
416 isolateHelperLibrary.find(const SourceString('_callInIsolate'))); | 411 isolateHelperLibrary.find(const SourceString('_callInIsolate'))); |
417 enqueuer.codegen.addToWorkList( | 412 enqueuer.codegen.addToWorkList( |
418 isolateHelperLibrary.find(START_ROOT_ISOLATE)); | 413 isolateHelperLibrary.find(START_ROOT_ISOLATE)); |
419 | |
420 // The helper library does not use the native language extension, | |
421 // so we manually set the native classes this library defines. | |
422 // TODO(ngeoffray): Enable annotations on these classes. | |
423 ClassElement cls = isolateHelperLibrary.find(const SourceString('_Window')); | |
424 cls.setNative('"*DOMWindow"'); | |
425 | |
426 cls = isolateHelperLibrary.find(const SourceString('_WorkerStub')); | |
427 cls.setNative('"*Worker"'); | |
428 | |
429 enqueuer.resolution.nativeEnqueuer.processNativeClassesInLibrary( | |
430 isolateHelperLibrary); | |
431 enqueuer.codegen.nativeEnqueuer.processNativeClassesInLibrary( | |
432 isolateHelperLibrary); | |
433 } | 414 } |
434 | 415 |
435 bool hasIsolateSupport() => isolateLibrary != null; | 416 bool hasIsolateSupport() => isolateLibrary != null; |
436 | 417 |
437 /** | 418 /** |
438 * This method is called before [library] import and export scopes have been | 419 * This method is called before [library] import and export scopes have been |
439 * set up. | 420 * set up. |
440 */ | 421 */ |
441 void onLibraryScanned(LibraryElement library, Uri uri) { | 422 void onLibraryScanned(LibraryElement library, Uri uri) { |
442 if (dynamicClass != null) { | 423 if (dynamicClass != null) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 types = new Types(this, dynamicClass); | 459 types = new Types(this, dynamicClass); |
479 if (!missingClasses.isEmpty) { | 460 if (!missingClasses.isEmpty) { |
480 cancel('core library does not contain required classes: $missingClasses'); | 461 cancel('core library does not contain required classes: $missingClasses'); |
481 } | 462 } |
482 } | 463 } |
483 | 464 |
484 void scanBuiltinLibraries() { | 465 void scanBuiltinLibraries() { |
485 jsHelperLibrary = scanBuiltinLibrary('_js_helper'); | 466 jsHelperLibrary = scanBuiltinLibrary('_js_helper'); |
486 interceptorsLibrary = scanBuiltinLibrary('_interceptors'); | 467 interceptorsLibrary = scanBuiltinLibrary('_interceptors'); |
487 foreignLibrary = scanBuiltinLibrary('_foreign_helper'); | 468 foreignLibrary = scanBuiltinLibrary('_foreign_helper'); |
| 469 isolateHelperLibrary = scanBuiltinLibrary('_isolate_helper'); |
| 470 // The helper library does not use the native language extension, |
| 471 // so we manually set the native classes this library defines. |
| 472 // TODO(ngeoffray): Enable annotations on these classes. |
| 473 ClassElement cls = |
| 474 isolateHelperLibrary.find(const SourceString('_WorkerStub')); |
| 475 cls.setNative('"*Worker"'); |
488 | 476 |
489 // The core library was loaded and patched before jsHelperLibrary was | 477 // The core library was loaded and patched before jsHelperLibrary was |
490 // initialized, so it wasn't imported into those two libraries during | 478 // initialized, so it wasn't imported into those two libraries during |
491 // patching. | 479 // patching. |
492 importHelperLibrary(coreLibrary); | 480 importHelperLibrary(coreLibrary); |
493 importHelperLibrary(interceptorsLibrary); | 481 importHelperLibrary(interceptorsLibrary); |
494 | 482 |
495 importForeignLibrary(jsHelperLibrary); | 483 importForeignLibrary(jsHelperLibrary); |
496 importForeignLibrary(interceptorsLibrary); | 484 importForeignLibrary(interceptorsLibrary); |
497 | 485 |
| 486 importForeignLibrary(isolateHelperLibrary); |
| 487 importHelperLibrary(isolateHelperLibrary); |
| 488 |
498 assertMethod = jsHelperLibrary.find(const SourceString('assertHelper')); | 489 assertMethod = jsHelperLibrary.find(const SourceString('assertHelper')); |
499 identicalFunction = coreLibrary.find(const SourceString('identical')); | 490 identicalFunction = coreLibrary.find(const SourceString('identical')); |
500 | 491 |
501 initializeSpecialClasses(); | 492 initializeSpecialClasses(); |
502 | 493 |
503 functionClass.ensureResolved(this); | 494 functionClass.ensureResolved(this); |
504 functionApplyMethod = | 495 functionApplyMethod = |
505 functionClass.lookupLocalMember(const SourceString('apply')); | 496 functionClass.lookupLocalMember(const SourceString('apply')); |
506 jsInvocationMirrorClass.ensureResolved(this); | 497 jsInvocationMirrorClass.ensureResolved(this); |
507 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember( | 498 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember( |
(...skipping 12 matching lines...) Expand all Loading... |
520 */ | 511 */ |
521 Uri resolvePatchUri(String dartLibraryPath); | 512 Uri resolvePatchUri(String dartLibraryPath); |
522 | 513 |
523 /** Define the JS helper functions in the given library. */ | 514 /** Define the JS helper functions in the given library. */ |
524 void importForeignLibrary(LibraryElement library) { | 515 void importForeignLibrary(LibraryElement library) { |
525 if (foreignLibrary != null) { | 516 if (foreignLibrary != null) { |
526 libraryLoader.importLibrary(library, foreignLibrary, null); | 517 libraryLoader.importLibrary(library, foreignLibrary, null); |
527 } | 518 } |
528 } | 519 } |
529 | 520 |
| 521 void importIsolateHelperLibrary(LibraryElement library) { |
| 522 if (isolateHelperLibrary != null) { |
| 523 libraryLoader.importLibrary(library, isolateHelperLibrary, null); |
| 524 } |
| 525 } |
| 526 |
530 // TODO(karlklose,floitsch): move this to the javascript backend. | 527 // TODO(karlklose,floitsch): move this to the javascript backend. |
531 /** Enable the 'JS' helper for a library if needed. */ | 528 /** Enable the 'JS' helper for a library if needed. */ |
532 void maybeEnableJSHelper(LibraryElement library) { | 529 void maybeEnableJSHelper(LibraryElement library) { |
533 String libraryName = library.uri.toString(); | 530 String libraryName = library.uri.toString(); |
534 bool nativeTest = library.entryCompilationUnit.script.name.contains( | 531 bool nativeTest = library.entryCompilationUnit.script.name.contains( |
535 'dart/tests/compiler/dart2js_native'); | 532 'dart/tests/compiler/dart2js_native'); |
536 if (nativeTest | 533 if (nativeTest |
537 || libraryName == 'dart:mirrors' | 534 || libraryName == 'dart:mirrors' |
538 || libraryName == 'dart:math' | 535 || libraryName == 'dart:math' |
539 || libraryName == 'dart:html' | 536 || libraryName == 'dart:html' |
(...skipping 15 matching lines...) Expand all Loading... |
555 library.addToScope( | 552 library.addToScope( |
556 foreignLibrary.findLocal(const SourceString('JS')), this); | 553 foreignLibrary.findLocal(const SourceString('JS')), this); |
557 Element jsIndexingBehaviorInterface = | 554 Element jsIndexingBehaviorInterface = |
558 findHelper(const SourceString('JavaScriptIndexingBehavior')); | 555 findHelper(const SourceString('JavaScriptIndexingBehavior')); |
559 if (jsIndexingBehaviorInterface != null) { | 556 if (jsIndexingBehaviorInterface != null) { |
560 library.addToScope(jsIndexingBehaviorInterface, this); | 557 library.addToScope(jsIndexingBehaviorInterface, this); |
561 } | 558 } |
562 } | 559 } |
563 } | 560 } |
564 | 561 |
| 562 void maybeEnableIsolateHelper(LibraryElement library) { |
| 563 String libraryName = library.uri.toString(); |
| 564 if (libraryName == 'dart:isolate' |
| 565 || libraryName == 'dart:html') { |
| 566 importIsolateHelperLibrary(library); |
| 567 } |
| 568 } |
| 569 |
565 void runCompiler(Uri uri) { | 570 void runCompiler(Uri uri) { |
566 log('compiling $uri ($BUILD_ID)'); | 571 log('compiling $uri ($BUILD_ID)'); |
567 scanBuiltinLibraries(); | 572 scanBuiltinLibraries(); |
568 mainApp = libraryLoader.loadLibrary(uri, null, uri); | 573 mainApp = libraryLoader.loadLibrary(uri, null, uri); |
569 libraries.forEach((_, library) { | 574 libraries.forEach((_, library) { |
570 maybeEnableJSHelper(library); | 575 maybeEnableJSHelper(library); |
| 576 maybeEnableIsolateHelper(library); |
571 }); | 577 }); |
572 final Element main = mainApp.find(MAIN); | 578 final Element main = mainApp.find(MAIN); |
573 if (main == null) { | 579 if (main == null) { |
574 reportFatalError('Could not find $MAIN', mainApp); | 580 reportFatalError('Could not find $MAIN', mainApp); |
575 } else { | 581 } else { |
576 if (!main.isFunction()) reportFatalError('main is not a function', main); | 582 if (!main.isFunction()) reportFatalError('main is not a function', main); |
577 FunctionElement mainMethod = main; | 583 FunctionElement mainMethod = main; |
578 FunctionSignature parameters = mainMethod.computeSignature(this); | 584 FunctionSignature parameters = mainMethod.computeSignature(this); |
579 parameters.forEachParameter((Element parameter) { | 585 parameters.forEachParameter((Element parameter) { |
580 reportFatalError('main cannot have parameters', parameter); | 586 reportFatalError('main cannot have parameters', parameter); |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 982 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
977 // information on assertion errors. | 983 // information on assertion errors. |
978 if (condition is Function){ | 984 if (condition is Function){ |
979 condition = condition(); | 985 condition = condition(); |
980 } | 986 } |
981 if (spannable == null || !condition) { | 987 if (spannable == null || !condition) { |
982 throw new SpannableAssertionFailure(spannable, message); | 988 throw new SpannableAssertionFailure(spannable, message); |
983 } | 989 } |
984 return true; | 990 return true; |
985 } | 991 } |
OLD | NEW |