Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.js_emitter; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 | 7 |
| 8 class OldEmitter implements Emitter { | 8 class OldEmitter implements Emitter { |
| 9 final Compiler compiler; | 9 final Compiler compiler; |
| 10 final CodeEmitterTask task; | 10 final CodeEmitterTask task; |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 | 501 |
| 502 jsAst.Expression finishedClassesAccess = | 502 jsAst.Expression finishedClassesAccess = |
| 503 generateEmbeddedGlobalAccess(embeddedNames.FINISHED_CLASSES); | 503 generateEmbeddedGlobalAccess(embeddedNames.FINISHED_CLASSES); |
| 504 jsAst.Expression interceptorsByTagAccess = | 504 jsAst.Expression interceptorsByTagAccess = |
| 505 generateEmbeddedGlobalAccess(embeddedNames.INTERCEPTORS_BY_TAG); | 505 generateEmbeddedGlobalAccess(embeddedNames.INTERCEPTORS_BY_TAG); |
| 506 jsAst.Expression leafTagsAccess = | 506 jsAst.Expression leafTagsAccess = |
| 507 generateEmbeddedGlobalAccess(embeddedNames.LEAF_TAGS); | 507 generateEmbeddedGlobalAccess(embeddedNames.LEAF_TAGS); |
| 508 | 508 |
| 509 return js.statement(''' | 509 return js.statement(''' |
| 510 { | 510 { |
| 511 var finishedClasses = #; // finishedClassesAccess. | 511 var finishedClasses = #finishedClassesAccess; |
| 512 | 512 |
| 513 function finishClass(cls) { | 513 function finishClass(cls) { |
| 514 | 514 |
| 515 if (finishedClasses[cls]) return; | 515 if (finishedClasses[cls]) return; |
| 516 finishedClasses[cls] = true; | 516 finishedClasses[cls] = true; |
| 517 | 517 |
| 518 var superclass = pendingClasses[cls]; | 518 var superclass = pendingClasses[cls]; |
| 519 | |
| 520 // The superclass is only false (empty string) for the Dart Object | 519 // The superclass is only false (empty string) for the Dart Object |
| 521 // class. The minifier together with noSuchMethod can put methods on | 520 // class. The minifier together with noSuchMethod can put methods on |
| 522 // the Object.prototype object, and they show through here, so we check | 521 // the Object.prototype object, and they show through here, so we check |
| 523 // that we have a string. | 522 // that we have a string. |
| 524 if (!superclass || typeof superclass != "string") return; | 523 if (!superclass || typeof superclass != "string") return; |
| 525 finishClass(superclass); | 524 finishClass(superclass); |
| 526 var constructor = allClasses[cls]; | |
| 527 var superConstructor = allClasses[superclass]; | 525 var superConstructor = allClasses[superclass]; |
| 528 | 526 |
| 529 if (!superConstructor) | 527 if (!superConstructor) |
| 530 superConstructor = existingIsolateProperties[superclass]; | 528 superConstructor = existingIsolateProperties[superclass]; |
| 531 | 529 |
| 530 var constructor = allClasses[cls]; | |
| 532 var prototype = inheritFrom(constructor, superConstructor); | 531 var prototype = inheritFrom(constructor, superConstructor); |
| 533 | 532 |
| 534 if (#) { // !nativeClasses.isEmpty, | 533 if (#hasNativeClasses) { |
| 535 // The property looks like this: | 534 // The property looks like this: |
| 536 // | 535 // |
| 537 // HtmlElement: { | 536 // HtmlElement: { |
| 538 // "%": "HTMLDivElement|HTMLAnchorElement;HTMLElement;FancyButton" | 537 // "%": "HTMLDivElement|HTMLAnchorElement;HTMLElement;FancyButton" |
| 539 // | 538 // |
| 540 // The first two semicolon-separated parts contain dispatch tags, the | 539 // The first two semicolon-separated parts contain dispatch tags, the |
| 541 // third contains the JavaScript names for classes. | 540 // third contains the JavaScript names for classes. |
| 542 // | 541 // |
| 543 // The tags indicate that JavaScript objects with the dispatch tags | 542 // The tags indicate that JavaScript objects with the dispatch tags |
| 544 // (usually constructor names) HTMLDivElement, HTMLAnchorElement and | 543 // (usually constructor names) HTMLDivElement, HTMLAnchorElement and |
| 545 // HTMLElement all map to the Dart native class named HtmlElement. | 544 // HTMLElement all map to the Dart native class named HtmlElement. |
| 546 // The first set is for effective leaf nodes in the hierarchy, the | 545 // The first set is for effective leaf nodes in the hierarchy, the |
| 547 // second set is non-leaf nodes. | 546 // second set is non-leaf nodes. |
| 548 // | 547 // |
| 549 // The third part contains the JavaScript names of Dart classes that | 548 // The third part contains the JavaScript names of Dart classes that |
| 550 // extend the native class. Here, FancyButton extends HtmlElement, so | 549 // extend the native class. Here, FancyButton extends HtmlElement, so |
| 551 // the runtime needs to know that window.HTMLElement.prototype is the | 550 // the runtime needs to know that window.HTMLElement.prototype is the |
| 552 // prototype that needs to be extended in creating the custom element. | 551 // prototype that needs to be extended in creating the custom element. |
| 553 // | 552 // |
| 554 // The information is used to build tables referenced by | 553 // The information is used to build tables referenced by |
| 555 // getNativeInterceptor and custom element support. | 554 // getNativeInterceptor and custom element support. |
| 556 if (Object.prototype.hasOwnProperty.call(prototype, $specProperty)) { | 555 if (Object.prototype.hasOwnProperty.call(prototype, $specProperty)) { |
| 557 var nativeSpec = prototype[$specProperty].split(";"); | 556 var nativeSpec = prototype[$specProperty].split(";"); |
| 558 if (nativeSpec[0]) { | 557 if (nativeSpec[0]) { |
| 559 var tags = nativeSpec[0].split("|"); | 558 var tags = nativeSpec[0].split("|"); |
| 560 for (var i = 0; i < tags.length; i++) { | 559 for (var i = 0; i < tags.length; i++) { |
| 561 #[tags[i]] = constructor; // embedded interceptorsByTag. | 560 #interceptorsByTagAccess[tags[i]] = constructor; |
| 562 #[tags[i]] = true; // embedded leafTags. | 561 #leafTagsAccess[tags[i]] = true; |
| 563 } | 562 } |
| 564 } | 563 } |
| 565 if (nativeSpec[1]) { | 564 if (nativeSpec[1]) { |
| 566 tags = nativeSpec[1].split("|"); | 565 tags = nativeSpec[1].split("|"); |
| 567 if (#) { // User subclassing of native classes? | 566 if (#allowNativesSubclassing) { |
| 568 if (nativeSpec[2]) { | 567 if (nativeSpec[2]) { |
| 569 var subclasses = nativeSpec[2].split("|"); | 568 var subclasses = nativeSpec[2].split("|"); |
| 570 for (var i = 0; i < subclasses.length; i++) { | 569 for (var i = 0; i < subclasses.length; i++) { |
| 571 var subclass = allClasses[subclasses[i]]; | 570 var subclass = allClasses[subclasses[i]]; |
| 572 subclass.\$nativeSuperclassTag = tags[0]; | 571 subclass.\$nativeSuperclassTag = tags[0]; |
| 573 } | 572 } |
| 574 } | 573 } |
| 575 for (i = 0; i < tags.length; i++) { | 574 for (i = 0; i < tags.length; i++) { |
| 576 #[tags[i]] = constructor; // embedded interceptorsByTag. | 575 #interceptorsByTagAccess[tags[i]] = constructor; |
| 577 #[tags[i]] = false; // embedded leafTags. | 576 #leafTagsAccess[tags[i]] = false; |
| 578 } | 577 } |
| 579 } | 578 } |
| 580 } | 579 } |
| 581 } | 580 } |
| 582 } | 581 } |
| 583 } | 582 } |
| 584 }''', [finishedClassesAccess, | 583 }''', {'finishedClassesAccess': finishedClassesAccess, |
| 585 !nativeClasses.isEmpty, | 584 'hasNativeClasses': nativeClasses.isNotEmpty, |
| 586 interceptorsByTagAccess, | 585 'interceptorsByTagAccess': interceptorsByTagAccess, |
| 587 leafTagsAccess, | 586 'leafTagsAccess': leafTagsAccess, |
| 588 true, | 587 'allowNativesSubclassing': true}); |
| 589 interceptorsByTagAccess, | |
| 590 leafTagsAccess]); | |
| 591 } | 588 } |
| 592 | 589 |
| 593 jsAst.Fun get finishIsolateConstructorFunction { | 590 jsAst.Fun get finishIsolateConstructorFunction { |
| 594 // We replace the old Isolate function with a new one that initializes | 591 // We replace the old Isolate function with a new one that initializes |
| 595 // all its fields with the initial (and often final) value of all globals. | 592 // all its fields with the initial (and often final) value of all globals. |
| 596 // | 593 // |
| 597 // We also copy over old values like the prototype, and the | 594 // We also copy over old values like the prototype, and the |
| 598 // isolateProperties themselves. | 595 // isolateProperties themselves. |
| 599 return js(''' | 596 return js(''' |
| 600 function (oldIsolate) { | 597 function (oldIsolate) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 686 } | 683 } |
| 687 ''', [laziesAccess, laziesAccess, | 684 ''', [laziesAccess, laziesAccess, |
| 688 laziesAccess, | 685 laziesAccess, |
| 689 cyclicThrow]); | 686 cyclicThrow]); |
| 690 } | 687 } |
| 691 | 688 |
| 692 List buildDefineClassAndFinishClassFunctionsIfNecessary() { | 689 List buildDefineClassAndFinishClassFunctionsIfNecessary() { |
| 693 if (!needsDefineClass) return []; | 690 if (!needsDefineClass) return []; |
| 694 return defineClassFunction | 691 return defineClassFunction |
| 695 ..add(buildInheritFrom()) | 692 ..add(buildInheritFrom()) |
| 696 ..add(js('$finishClassesName = #', finishClassesFunction)) | 693 ..add(js('$finishClassesName = #', finishClassesFunction)) |
|
floitsch
2014/11/25 14:25:13
fix indentation (already previous line).
herhut
2014/11/26 09:41:36
Done.
| |
| 697 ..add(initFinishClasses); | 694 ..add(initFinishClasses); |
| 698 } | 695 } |
| 699 | 696 |
| 700 List buildLazyInitializerFunctionIfNecessary() { | 697 List buildLazyInitializerFunctionIfNecessary() { |
| 701 if (!needsLazyInitializer) return []; | 698 if (!needsLazyInitializer) return []; |
| 702 | 699 |
| 703 return [js('# = #', [js(lazyInitializerName), lazyInitializerFunction])]; | 700 return [js('# = #', [js(lazyInitializerName), lazyInitializerFunction])]; |
| 704 } | 701 } |
| 705 | 702 |
| 706 List buildFinishIsolateConstructor() { | 703 List buildFinishIsolateConstructor() { |
| (...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2013 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2010 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 2014 if (element.isInstanceMember) { | 2011 if (element.isInstanceMember) { |
| 2015 cachedClassBuilders.remove(element.enclosingClass); | 2012 cachedClassBuilders.remove(element.enclosingClass); |
| 2016 | 2013 |
| 2017 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2014 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 2018 | 2015 |
| 2019 } | 2016 } |
| 2020 } | 2017 } |
| 2021 } | 2018 } |
| 2022 } | 2019 } |
| OLD | NEW |