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