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 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1289 } | 1289 } |
1290 | 1290 |
1291 /// Returns the "reflection name" of an [Element] or [Selector]. | 1291 /// Returns the "reflection name" of an [Element] or [Selector]. |
1292 /// The reflection name of a getter 'foo' is 'foo'. | 1292 /// The reflection name of a getter 'foo' is 'foo'. |
1293 /// The reflection name of a setter 'foo' is 'foo='. | 1293 /// The reflection name of a setter 'foo' is 'foo='. |
1294 /// The reflection name of a method 'foo' is 'foo:N:M:O', where N is the | 1294 /// The reflection name of a method 'foo' is 'foo:N:M:O', where N is the |
1295 /// number of required arguments, M is the number of optional arguments, and | 1295 /// number of required arguments, M is the number of optional arguments, and |
1296 /// O is the named arguments. | 1296 /// O is the named arguments. |
1297 /// The reflection name of a constructor is similar to a regular method but | 1297 /// The reflection name of a constructor is similar to a regular method but |
1298 /// starts with 'new '. | 1298 /// starts with 'new '. |
1299 /// The reflection name of class 'C' is 'C'. | |
1300 /// An anonymous mixin application has no reflection name. | |
1299 /// This is used by js_mirrors.dart. | 1301 /// This is used by js_mirrors.dart. |
1300 String getReflectionName(elementOrSelector, String mangledName) { | 1302 String getReflectionName(elementOrSelector, String mangledName) { |
1301 SourceString name = elementOrSelector.name; | 1303 SourceString name = elementOrSelector.name; |
1302 if (!backend.shouldRetainName(name)) { | 1304 if (!backend.shouldRetainName(name)) { |
1303 if (name == const SourceString('') && elementOrSelector is Element) { | 1305 if (name == const SourceString('') && elementOrSelector is Element) { |
1304 // Make sure to retain names of unnamed constructors. | 1306 // Make sure to retain names of unnamed constructors. |
1305 if (!backend.isNeededForReflection(elementOrSelector)) return null; | 1307 if (!backend.isNeededForReflection(elementOrSelector)) return null; |
1306 } else { | 1308 } else { |
1307 return null; | 1309 return null; |
1308 } | 1310 } |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1975 } | 1977 } |
1976 | 1978 |
1977 // TODO(ahe): This method (generateClass) should return a jsAst.Expression. | 1979 // TODO(ahe): This method (generateClass) should return a jsAst.Expression. |
1978 if (!buffer.isEmpty) { | 1980 if (!buffer.isEmpty) { |
1979 buffer.write(',$n$n'); | 1981 buffer.write(',$n$n'); |
1980 } | 1982 } |
1981 buffer.write('$className:$_'); | 1983 buffer.write('$className:$_'); |
1982 buffer.write(jsAst.prettyPrint(builder.toObjectInitializer(), compiler)); | 1984 buffer.write(jsAst.prettyPrint(builder.toObjectInitializer(), compiler)); |
1983 if (backend.shouldRetainName(classElement.name)) { | 1985 if (backend.shouldRetainName(classElement.name)) { |
1984 String reflectionName = getReflectionName(classElement, className); | 1986 String reflectionName = getReflectionName(classElement, className); |
1985 buffer.write(',$n$n"+$reflectionName": 0'); | 1987 List<int> interfaces = <int>[]; |
1988 for (DartType interface in classElement.interfaces) { | |
1989 interfaces.add(reifyType(interface)); | |
1990 } | |
1991 buffer.write(',$n$n"+$reflectionName": $interfaces'); | |
1986 } | 1992 } |
1987 } | 1993 } |
1988 | 1994 |
1989 bool get getterAndSetterCanBeImplementedByFieldSpec => true; | 1995 bool get getterAndSetterCanBeImplementedByFieldSpec => true; |
1990 | 1996 |
1991 /// If this is true then we can generate the noSuchMethod handlers at startup | 1997 /// If this is true then we can generate the noSuchMethod handlers at startup |
1992 /// time, instead of them being emitted as part of the Object class. | 1998 /// time, instead of them being emitted as part of the Object class. |
1993 bool get generateTrivialNsmHandlers => true; | 1999 bool get generateTrivialNsmHandlers => true; |
1994 | 2000 |
1995 int _selectorRank(Selector selector) { | 2001 int _selectorRank(Selector selector) { |
(...skipping 2010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4006 compiler.reportMessage(compiler.spanFromSpannable(element), | 4012 compiler.reportMessage(compiler.spanFromSpannable(element), |
4007 MessageKind.GENERIC.error({'text': message}), | 4013 MessageKind.GENERIC.error({'text': message}), |
4008 api.Diagnostic.WARNING); | 4014 api.Diagnostic.WARNING); |
4009 } | 4015 } |
4010 | 4016 |
4011 // TODO(ahe): This code should be integrated in finishClasses. | 4017 // TODO(ahe): This code should be integrated in finishClasses. |
4012 String getReflectionDataParser() { | 4018 String getReflectionDataParser() { |
4013 String metadataField = '"${namer.metadataField}"'; | 4019 String metadataField = '"${namer.metadataField}"'; |
4014 return ''' | 4020 return ''' |
4015 (function (reflectionData) { | 4021 (function (reflectionData) { |
4022 ''' | |
4023 // [map] returns an object literal that V8 shouldn't try to optimize with a | |
4024 // hidden class. This prevents a potential performance problem where V8 tries | |
4025 // to build a hidden class for an object used as a hashMap. | |
4026 ''' | |
4027 function map(x){x={x:x};delete x.x;return x} | |
4016 if (!init.libraries) init.libraries = []; | 4028 if (!init.libraries) init.libraries = []; |
4017 if (!init.mangledNames) init.mangledNames = {}; | 4029 if (!init.mangledNames) init.mangledNames = map(); |
4018 if (!init.mangledGlobalNames) init.mangledGlobalNames = {}; | 4030 if (!init.mangledGlobalNames) init.mangledGlobalNames = map(); |
4019 if (!init.statics) init.statics = {}; | 4031 if (!init.statics) init.statics = map(); |
4032 if (!init.interfaces) init.interfaces = map(); | |
4020 var libraries = init.libraries; | 4033 var libraries = init.libraries; |
4021 var mangledNames = init.mangledNames; | 4034 var mangledNames = init.mangledNames; |
4022 var mangledGlobalNames = init.mangledGlobalNames; | 4035 var mangledGlobalNames = init.mangledGlobalNames; |
4023 var hasOwnProperty = Object.prototype.hasOwnProperty; | 4036 var hasOwnProperty = Object.prototype.hasOwnProperty; |
4024 var length = reflectionData.length; | 4037 var length = reflectionData.length; |
4025 for (var i = 0; i < length; i++) { | 4038 for (var i = 0; i < length; i++) { |
4026 var data = reflectionData[i]; | 4039 var data = reflectionData[i]; |
4027 ''' | 4040 ''' |
4028 // [data] contains these elements: | 4041 // [data] contains these elements: |
4029 // 0. The library name (not unique). | 4042 // 0. The library name (not unique). |
(...skipping 15 matching lines...) Expand all Loading... | |
4045 var functions = []; | 4058 var functions = []; |
4046 function processStatics(descriptor) { | 4059 function processStatics(descriptor) { |
4047 for (var property in descriptor) { | 4060 for (var property in descriptor) { |
4048 if (!hasOwnProperty.call(descriptor, property)) continue; | 4061 if (!hasOwnProperty.call(descriptor, property)) continue; |
4049 if (property === "") continue; | 4062 if (property === "") continue; |
4050 var element = descriptor[property]; | 4063 var element = descriptor[property]; |
4051 var firstChar = property.substring(0, 1); | 4064 var firstChar = property.substring(0, 1); |
4052 var previousProperty; | 4065 var previousProperty; |
4053 if (firstChar === "+") { | 4066 if (firstChar === "+") { |
4054 mangledGlobalNames[previousProperty] = property.substring(1); | 4067 mangledGlobalNames[previousProperty] = property.substring(1); |
4068 if (element && element.length) ''' | |
ngeoffray
2013/08/15 06:52:33
This ''' quote here is confusing. My guess is that
ahe
2013/08/15 09:58:24
Done.
| |
4069 '''init.interfaces[previousProperty] = element; | |
4055 } else if (firstChar === "@") { | 4070 } else if (firstChar === "@") { |
4056 property = property.substring(1); | 4071 property = property.substring(1); |
4057 ${namer.CURRENT_ISOLATE}[property][$metadataField] = element; | 4072 ${namer.CURRENT_ISOLATE}[property][$metadataField] = element; |
4058 } else if (typeof element === "function") { | 4073 } else if (typeof element === "function") { |
4059 ${namer.CURRENT_ISOLATE}[previousProperty = property] = element; | 4074 ${namer.CURRENT_ISOLATE}[previousProperty = property] = element; |
4060 functions.push(property); | 4075 functions.push(property); |
4061 } else { | 4076 } else { |
4062 previousProperty = property; | 4077 previousProperty = property; |
4063 var newDesc = {}; | 4078 var newDesc = {}; |
4064 var previousProp; | 4079 var previousProp; |
(...skipping 28 matching lines...) Expand all Loading... | |
4093 | 4108 |
4094 const String HOOKS_API_USAGE = """ | 4109 const String HOOKS_API_USAGE = """ |
4095 // The code supports the following hooks: | 4110 // The code supports the following hooks: |
4096 // dartPrint(message) - if this function is defined it is called | 4111 // dartPrint(message) - if this function is defined it is called |
4097 // instead of the Dart [print] method. | 4112 // instead of the Dart [print] method. |
4098 // dartMainRunner(main) - if this function is defined, the Dart [main] | 4113 // dartMainRunner(main) - if this function is defined, the Dart [main] |
4099 // method will not be invoked directly. | 4114 // method will not be invoked directly. |
4100 // Instead, a closure that will invoke [main] is | 4115 // Instead, a closure that will invoke [main] is |
4101 // passed to [dartMainRunner]. | 4116 // passed to [dartMainRunner]. |
4102 """; | 4117 """; |
OLD | NEW |