| 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 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 split = supr.split(":"); | 521 split = supr.split(":"); |
| 522 if (split.length == 2) { | 522 if (split.length == 2) { |
| 523 supr = split[0]; | 523 supr = split[0]; |
| 524 var functionSignature = split[1]; | 524 var functionSignature = split[1]; |
| 525 if (functionSignature) | 525 if (functionSignature) |
| 526 desc.$signaturePropertyName = (function(s) { | 526 desc.$signaturePropertyName = (function(s) { |
| 527 return function(){ return #metadata[s]; }; | 527 return function(){ return #metadata[s]; }; |
| 528 })(functionSignature); | 528 })(functionSignature); |
| 529 } | 529 } |
| 530 | 530 |
| 531 if (#needsMixinSupport) | |
| 532 if (supr && supr.indexOf("+") > 0) { | |
| 533 s = supr.split("+"); | |
| 534 supr = s[0]; | |
| 535 var mixin = collectedClasses[s[1]]; | |
| 536 if (mixin instanceof Array) mixin = mixin[1]; | |
| 537 for (var d in mixin) { | |
| 538 if (hasOwnProperty.call(mixin, d) && | |
| 539 !hasOwnProperty.call(desc, d)) | |
| 540 desc[d] = mixin[d]; | |
| 541 } | |
| 542 } | |
| 543 | |
| 544 if (typeof dart_precompiled != "function") { | 531 if (typeof dart_precompiled != "function") { |
| 545 combinedConstructorFunction += defineClass(cls, fields); | 532 combinedConstructorFunction += defineClass(cls, fields); |
| 546 constructorsList.push(cls); | 533 constructorsList.push(cls); |
| 547 } | 534 } |
| 548 if (supr) pendingClasses[cls] = supr; | 535 if (supr) pendingClasses[cls] = supr; |
| 549 } | 536 } |
| 550 | 537 |
| 551 if (typeof dart_precompiled != "function") { | 538 if (typeof dart_precompiled != "function") { |
| 552 combinedConstructorFunction += | 539 combinedConstructorFunction += |
| 553 "return [\\n " + constructorsList.join(",\\n ") + "\\n]"; | 540 "return [\\n " + constructorsList.join(",\\n ") + "\\n]"; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 576 | 563 |
| 577 #finishClassFunction; | 564 #finishClassFunction; |
| 578 | 565 |
| 579 #trivialNsmHandlers; | 566 #trivialNsmHandlers; |
| 580 | 567 |
| 581 for (var cls in pendingClasses) finishClass(cls); | 568 for (var cls in pendingClasses) finishClass(cls); |
| 582 }''', { 'allClasses': allClassesAccess, | 569 }''', { 'allClasses': allClassesAccess, |
| 583 'debugFastObjects': DEBUG_FAST_OBJECTS, | 570 'debugFastObjects': DEBUG_FAST_OBJECTS, |
| 584 'hasRetainedMetadata': backend.hasRetainedMetadata, | 571 'hasRetainedMetadata': backend.hasRetainedMetadata, |
| 585 'metadata': metadataAccess, | 572 'metadata': metadataAccess, |
| 586 'needsMixinSupport': needsMixinSupport, | |
| 587 'isTreeShakingDisabled': backend.isTreeShakingDisabled, | 573 'isTreeShakingDisabled': backend.isTreeShakingDisabled, |
| 588 'finishClassFunction': buildFinishClass(), | 574 'finishClassFunction': buildFinishClass(), |
| 589 'trivialNsmHandlers': nsmEmitter.buildTrivialNsmHandlers()}); | 575 'trivialNsmHandlers': nsmEmitter.buildTrivialNsmHandlers()}); |
| 590 } | 576 } |
| 591 | 577 |
| 592 jsAst.Node optional(bool condition, jsAst.Node node) { | 578 jsAst.Node optional(bool condition, jsAst.Node node) { |
| 593 return condition ? node : new jsAst.EmptyStatement(); | 579 return condition ? node : new jsAst.EmptyStatement(); |
| 594 } | 580 } |
| 595 | 581 |
| 596 jsAst.Statement buildFinishClass() { | 582 jsAst.Statement buildFinishClass() { |
| 597 String specProperty = '"${namer.nativeSpecProperty}"'; // "%" | 583 String specProperty = '"${namer.nativeSpecProperty}"'; // "%" |
| 598 | 584 |
| 599 jsAst.Expression finishedClassesAccess = | 585 jsAst.Expression finishedClassesAccess = |
| 600 generateEmbeddedGlobalAccess(embeddedNames.FINISHED_CLASSES); | 586 generateEmbeddedGlobalAccess(embeddedNames.FINISHED_CLASSES); |
| 601 jsAst.Expression interceptorsByTagAccess = | 587 jsAst.Expression interceptorsByTagAccess = |
| 602 generateEmbeddedGlobalAccess(embeddedNames.INTERCEPTORS_BY_TAG); | 588 generateEmbeddedGlobalAccess(embeddedNames.INTERCEPTORS_BY_TAG); |
| 603 jsAst.Expression leafTagsAccess = | 589 jsAst.Expression leafTagsAccess = |
| 604 generateEmbeddedGlobalAccess(embeddedNames.LEAF_TAGS); | 590 generateEmbeddedGlobalAccess(embeddedNames.LEAF_TAGS); |
| 605 | 591 |
| 606 return js.statement(''' | 592 return js.statement(''' |
| 607 { | 593 { |
| 608 var finishedClasses = #finishedClassesAccess; | 594 var finishedClasses = #finishedClassesAccess; |
| 609 | 595 |
| 610 function finishClass(cls) { | 596 function finishClass(cls) { |
| 611 | 597 |
| 612 if (finishedClasses[cls]) return; | 598 if (finishedClasses[cls]) return; |
| 613 finishedClasses[cls] = true; | 599 finishedClasses[cls] = true; |
| 614 | 600 |
| 615 var superclass = pendingClasses[cls]; | 601 var superclass = pendingClasses[cls]; |
| 602 |
| 603 if (#needsMixinSupport) { |
| 604 if (superclass && superclass.indexOf("+") > 0) { |
| 605 var s = superclass.split("+"); |
| 606 superclass = s[0]; |
| 607 var mixinClass = s[1]; |
| 608 finishClass(mixinClass); |
| 609 var mixin = allClasses[mixinClass]; |
| 610 // TODO(floitsch): this test shouldn't be necessary. Without it |
| 611 // we have a crash in pkg/analysis_server/tool/spec/check_all_test. |
| 612 if (mixin) { |
| 613 var mixinPrototype = mixin.prototype; |
| 614 var clsPrototype = allClasses[cls].prototype; |
| 615 for (var d in mixinPrototype) { |
| 616 if (hasOwnProperty.call(mixinPrototype, d) && |
| 617 !hasOwnProperty.call(clsPrototype, d)) |
| 618 clsPrototype[d] = mixinPrototype[d]; |
| 619 } |
| 620 } |
| 621 } |
| 622 } |
| 623 |
| 616 // The superclass is only false (empty string) for the Dart Object | 624 // The superclass is only false (empty string) for the Dart Object |
| 617 // class. The minifier together with noSuchMethod can put methods on | 625 // class. The minifier together with noSuchMethod can put methods on |
| 618 // the Object.prototype object, and they show through here, so we check | 626 // the Object.prototype object, and they show through here, so we check |
| 619 // that we have a string. | 627 // that we have a string. |
| 620 if (!superclass || typeof superclass != "string") return; | 628 if (!superclass || typeof superclass != "string") return; |
| 621 finishClass(superclass); | 629 finishClass(superclass); |
| 622 var superConstructor = allClasses[superclass]; | 630 var superConstructor = allClasses[superclass]; |
| 623 | 631 |
| 624 if (!superConstructor) | 632 if (!superConstructor) |
| 625 superConstructor = existingIsolateProperties[superclass]; | 633 superConstructor = existingIsolateProperties[superclass]; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 for (i = 0; i < tags.length; i++) { | 679 for (i = 0; i < tags.length; i++) { |
| 672 #interceptorsByTagAccess[tags[i]] = constructor; | 680 #interceptorsByTagAccess[tags[i]] = constructor; |
| 673 #leafTagsAccess[tags[i]] = false; | 681 #leafTagsAccess[tags[i]] = false; |
| 674 } | 682 } |
| 675 } | 683 } |
| 676 } | 684 } |
| 677 } | 685 } |
| 678 } | 686 } |
| 679 } | 687 } |
| 680 }''', {'finishedClassesAccess': finishedClassesAccess, | 688 }''', {'finishedClassesAccess': finishedClassesAccess, |
| 689 'needsMixinSupport': needsMixinSupport, |
| 681 'hasNativeClasses': nativeClasses.isNotEmpty, | 690 'hasNativeClasses': nativeClasses.isNotEmpty, |
| 682 'interceptorsByTagAccess': interceptorsByTagAccess, | 691 'interceptorsByTagAccess': interceptorsByTagAccess, |
| 683 'leafTagsAccess': leafTagsAccess, | 692 'leafTagsAccess': leafTagsAccess, |
| 684 'allowNativesSubclassing': true}); | 693 'allowNativesSubclassing': true}); |
| 685 } | 694 } |
| 686 | 695 |
| 687 jsAst.Fun get finishIsolateConstructorFunction { | 696 jsAst.Fun get finishIsolateConstructorFunction { |
| 688 // We replace the old Isolate function with a new one that initializes | 697 // We replace the old Isolate function with a new one that initializes |
| 689 // all its fields with the initial (and often final) value of all globals. | 698 // all its fields with the initial (and often final) value of all globals. |
| 690 // | 699 // |
| (...skipping 1525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2216 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2225 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 2217 if (element.isInstanceMember) { | 2226 if (element.isInstanceMember) { |
| 2218 cachedClassBuilders.remove(element.enclosingClass); | 2227 cachedClassBuilders.remove(element.enclosingClass); |
| 2219 | 2228 |
| 2220 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2229 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 2221 | 2230 |
| 2222 } | 2231 } |
| 2223 } | 2232 } |
| 2224 } | 2233 } |
| 2225 } | 2234 } |
| OLD | NEW |