| 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 js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A function element that represents a closure call. The signature is copied | 8 * A function element that represents a closure call. The signature is copied |
| 9 * from the given element. | 9 * from the given element. |
| 10 */ | 10 */ |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 * string encoding fields, constructor and superclass. Get | 606 * string encoding fields, constructor and superclass. Get |
| 607 * the superclass and the fields in the format | 607 * the superclass and the fields in the format |
| 608 * '[name/]Super;field1,field2' | 608 * '[name/]Super;field1,field2' |
| 609 * from the null-string property on the descriptor. | 609 * from the null-string property on the descriptor. |
| 610 * The 'name/' is optional and contains the name that should be used | 610 * The 'name/' is optional and contains the name that should be used |
| 611 * when printing the runtime type string. It is used, for example, to | 611 * when printing the runtime type string. It is used, for example, to |
| 612 * print the runtime type JSInt as 'int'. | 612 * print the runtime type JSInt as 'int'. |
| 613 */ | 613 */ |
| 614 js('var classData = desc[""], supr, name = cls, fields = classData'), | 614 js('var classData = desc[""], supr, name = cls, fields = classData'), |
| 615 optional( | 615 optional( |
| 616 compiler.mirrorSystemClass != null, | 616 compiler.mirrorsEnabled, |
| 617 js.if_('typeof classData == "object" && ' | 617 js.if_('typeof classData == "object" && ' |
| 618 'classData instanceof Array', | 618 'classData instanceof Array', |
| 619 [js('classData = fields = classData[0]')])), | 619 [js('classData = fields = classData[0]')])), |
| 620 | 620 |
| 621 js.if_('typeof classData == "string"', [ | 621 js.if_('typeof classData == "string"', [ |
| 622 js('var split = classData.split("/")'), | 622 js('var split = classData.split("/")'), |
| 623 js.if_('split.length == 2', [ | 623 js.if_('split.length == 2', [ |
| 624 js('name = split[0]'), | 624 js('name = split[0]'), |
| 625 js('fields = split[1]') | 625 js('fields = split[1]') |
| 626 ]) | 626 ]) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 640 js('supr = s[0]'), | 640 js('supr = s[0]'), |
| 641 js('var mixin = collectedClasses[s[1]]'), | 641 js('var mixin = collectedClasses[s[1]]'), |
| 642 js.forIn('d', 'mixin', [ | 642 js.forIn('d', 'mixin', [ |
| 643 js.if_('hasOwnProperty.call(mixin, d)' | 643 js.if_('hasOwnProperty.call(mixin, d)' |
| 644 '&& !hasOwnProperty.call(desc, d)', | 644 '&& !hasOwnProperty.call(desc, d)', |
| 645 js('desc[d] = mixin[d]')) | 645 js('desc[d] = mixin[d]')) |
| 646 ]), | 646 ]), |
| 647 ])), | 647 ])), |
| 648 | 648 |
| 649 js('var constructor = defineClass(name, cls, fields, desc)'), | 649 js('var constructor = defineClass(name, cls, fields, desc)'), |
| 650 optional(compiler.mirrorSystemClass != null, | 650 optional(compiler.mirrorsEnabled, |
| 651 js('constructor["${namer.metadataField}"] = desc')), | 651 js('constructor["${namer.metadataField}"] = desc')), |
| 652 js('isolateProperties[cls] = constructor'), | 652 js('isolateProperties[cls] = constructor'), |
| 653 js.if_('supr', js('pendingClasses[cls] = supr')) | 653 js.if_('supr', js('pendingClasses[cls] = supr')) |
| 654 ]) | 654 ]) |
| 655 ]), | 655 ]), |
| 656 | 656 |
| 657 js('var finishedClasses = {}'), | 657 js('var finishedClasses = {}'), |
| 658 | 658 |
| 659 buildFinishClass(), | 659 buildFinishClass(), |
| 660 ]; | 660 ]; |
| (...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1463 bool needsCheckedSetter) { | 1463 bool needsCheckedSetter) { |
| 1464 // Ignore needsCheckedSetter - that is handled below. | 1464 // Ignore needsCheckedSetter - that is handled below. |
| 1465 bool needsAccessor = (needsGetter || needsSetter); | 1465 bool needsAccessor = (needsGetter || needsSetter); |
| 1466 // We need to output the fields for non-native classes so we can auto- | 1466 // We need to output the fields for non-native classes so we can auto- |
| 1467 // generate the constructor. For native classes there are no | 1467 // generate the constructor. For native classes there are no |
| 1468 // constructors, so we don't need the fields unless we are generating | 1468 // constructors, so we don't need the fields unless we are generating |
| 1469 // accessors at runtime. | 1469 // accessors at runtime. |
| 1470 if (!classIsNative || needsAccessor) { | 1470 if (!classIsNative || needsAccessor) { |
| 1471 buffer.write(separator); | 1471 buffer.write(separator); |
| 1472 separator = ','; | 1472 separator = ','; |
| 1473 if (compiler.mirrorSystemClass != null) { | 1473 if (compiler.mirrorsEnabled) { |
| 1474 var metadata = buildMetadataFunction(member); | 1474 var metadata = buildMetadataFunction(member); |
| 1475 fieldMetadata.add(metadata); | 1475 fieldMetadata.add(metadata); |
| 1476 if (metadata != null) { | 1476 if (metadata != null) { |
| 1477 hasMetadata = true; | 1477 hasMetadata = true; |
| 1478 } | 1478 } |
| 1479 } | 1479 } |
| 1480 if (!needsAccessor) { | 1480 if (!needsAccessor) { |
| 1481 // Emit field for constructor generation. | 1481 // Emit field for constructor generation. |
| 1482 assert(!classIsNative); | 1482 assert(!classIsNative); |
| 1483 buffer.write(name); | 1483 buffer.write(name); |
| (...skipping 1481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2965 if (compiler.enableMinification) buffer.write('\n'); | 2965 if (compiler.enableMinification) buffer.write('\n'); |
| 2966 } | 2966 } |
| 2967 | 2967 |
| 2968 /// The metadata function returns the metadata associated with | 2968 /// The metadata function returns the metadata associated with |
| 2969 /// [element] in generated code. The metadata needs to be wrapped | 2969 /// [element] in generated code. The metadata needs to be wrapped |
| 2970 /// in a function as it refers to constants that may not have been | 2970 /// in a function as it refers to constants that may not have been |
| 2971 /// constructed yet. For example, a class is allowed to be | 2971 /// constructed yet. For example, a class is allowed to be |
| 2972 /// annotated with itself. The metadata function is used by | 2972 /// annotated with itself. The metadata function is used by |
| 2973 /// mirrors_patch to implement DeclarationMirror.metadata. | 2973 /// mirrors_patch to implement DeclarationMirror.metadata. |
| 2974 jsAst.Fun buildMetadataFunction(Element element) { | 2974 jsAst.Fun buildMetadataFunction(Element element) { |
| 2975 if (compiler.mirrorSystemClass == null) return null; | 2975 if (!compiler.mirrorsEnabled) return null; |
| 2976 var metadata = []; | 2976 var metadata = []; |
| 2977 Link link = element.metadata; | 2977 Link link = element.metadata; |
| 2978 // TODO(ahe): Why is metadata sometimes null? | 2978 // TODO(ahe): Why is metadata sometimes null? |
| 2979 if (link != null) { | 2979 if (link != null) { |
| 2980 for (; !link.isEmpty; link = link.tail) { | 2980 for (; !link.isEmpty; link = link.tail) { |
| 2981 metadata.add(constantReference(link.head.value)); | 2981 metadata.add(constantReference(link.head.value)); |
| 2982 } | 2982 } |
| 2983 } | 2983 } |
| 2984 if (metadata.isEmpty) return null; | 2984 if (metadata.isEmpty) return null; |
| 2985 return js.fun([], [js.return_(new jsAst.ArrayInitializer.from(metadata))]); | 2985 return js.fun([], [js.return_(new jsAst.ArrayInitializer.from(metadata))]); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3320 | 3320 |
| 3321 const String HOOKS_API_USAGE = """ | 3321 const String HOOKS_API_USAGE = """ |
| 3322 // The code supports the following hooks: | 3322 // The code supports the following hooks: |
| 3323 // dartPrint(message) - if this function is defined it is called | 3323 // dartPrint(message) - if this function is defined it is called |
| 3324 // instead of the Dart [print] method. | 3324 // instead of the Dart [print] method. |
| 3325 // dartMainRunner(main) - if this function is defined, the Dart [main] | 3325 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 3326 // method will not be invoked directly. | 3326 // method will not be invoked directly. |
| 3327 // Instead, a closure that will invoke [main] is | 3327 // Instead, a closure that will invoke [main] is |
| 3328 // passed to [dartMainRunner]. | 3328 // passed to [dartMainRunner]. |
| 3329 """; | 3329 """; |
| OLD | NEW |