| 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 typeAccess(compiler.objectClass)); | 275 typeAccess(compiler.objectClass)); |
| 276 | 276 |
| 277 case JsBuiltin.isCheckPropertyToJsConstructorName: | 277 case JsBuiltin.isCheckPropertyToJsConstructorName: |
| 278 int isPrefixLength = namer.operatorIsPrefix.length; | 278 int isPrefixLength = namer.operatorIsPrefix.length; |
| 279 return jsAst.js.expressionTemplateFor('#.substring($isPrefixLength)'); | 279 return jsAst.js.expressionTemplateFor('#.substring($isPrefixLength)'); |
| 280 | 280 |
| 281 case JsBuiltin.isFunctionType: | 281 case JsBuiltin.isFunctionType: |
| 282 return backend.rti.representationGenerator.templateForIsFunctionType; | 282 return backend.rti.representationGenerator.templateForIsFunctionType; |
| 283 | 283 |
| 284 case JsBuiltin.rawRtiToJsConstructorName: | 284 case JsBuiltin.rawRtiToJsConstructorName: |
| 285 return jsAst.js.expressionTemplateFor("#.name"); | 285 return jsAst.js.expressionTemplateFor("#.$typeNameProperty"); |
| 286 | 286 |
| 287 case JsBuiltin.rawRuntimeType: | 287 case JsBuiltin.rawRuntimeType: |
| 288 return jsAst.js.expressionTemplateFor("#.constructor"); | 288 return jsAst.js.expressionTemplateFor("#.constructor"); |
| 289 | 289 |
| 290 case JsBuiltin.createFunctionTypeRti: | 290 case JsBuiltin.createFunctionTypeRti: |
| 291 return backend.rti.representationGenerator | 291 return backend.rti.representationGenerator |
| 292 .templateForCreateFunctionType; | 292 .templateForCreateFunctionType; |
| 293 | 293 |
| 294 case JsBuiltin.isSubtype: | 294 case JsBuiltin.isSubtype: |
| 295 // TODO(floitsch): move this closer to where is-check properties are | 295 // TODO(floitsch): move this closer to where is-check properties are |
| 296 // built. | 296 // built. |
| 297 String isPrefix = namer.operatorIsPrefix; | 297 String isPrefix = namer.operatorIsPrefix; |
| 298 return jsAst.js.expressionTemplateFor( | 298 return jsAst.js.expressionTemplateFor( |
| 299 "('$isPrefix' + #) in #.prototype"); | 299 "('$isPrefix' + #) in #.prototype"); |
| 300 | 300 |
| 301 case JsBuiltin.isGivenTypeRti: | 301 case JsBuiltin.isGivenTypeRti: |
| 302 return jsAst.js.expressionTemplateFor('#.name === #'); | 302 return jsAst.js.expressionTemplateFor('#.$typeNameProperty === #'); |
| 303 | 303 |
| 304 case JsBuiltin.getMetadata: | 304 case JsBuiltin.getMetadata: |
| 305 String metadataAccess = | 305 String metadataAccess = |
| 306 generateEmbeddedGlobalAccessString(embeddedNames.METADATA); | 306 generateEmbeddedGlobalAccessString(embeddedNames.METADATA); |
| 307 return jsAst.js.expressionTemplateFor("$metadataAccess[#]"); | 307 return jsAst.js.expressionTemplateFor("$metadataAccess[#]"); |
| 308 | 308 |
| 309 case JsBuiltin.getType: | 309 case JsBuiltin.getType: |
| 310 String typesAccess = | 310 String typesAccess = |
| 311 generateEmbeddedGlobalAccessString(embeddedNames.TYPES); | 311 generateEmbeddedGlobalAccessString(embeddedNames.TYPES); |
| 312 return jsAst.js.expressionTemplateFor("$typesAccess[#]"); | 312 return jsAst.js.expressionTemplateFor("$typesAccess[#]"); |
| (...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 jsAst.Node fieldNamesArray; | 1018 jsAst.Node fieldNamesArray; |
| 1019 if (hasIsolateSupport) { | 1019 if (hasIsolateSupport) { |
| 1020 fieldNamesArray = | 1020 fieldNamesArray = |
| 1021 new jsAst.ArrayInitializer(fields.map(js.quoteName).toList()); | 1021 new jsAst.ArrayInitializer(fields.map(js.quoteName).toList()); |
| 1022 } else { | 1022 } else { |
| 1023 fieldNamesArray = new jsAst.LiteralNull(); | 1023 fieldNamesArray = new jsAst.LiteralNull(); |
| 1024 } | 1024 } |
| 1025 | 1025 |
| 1026 cspPrecompiledFunctionFor(outputUnit).add(js.statement(r''' | 1026 cspPrecompiledFunctionFor(outputUnit).add(js.statement(r''' |
| 1027 { | 1027 { |
| 1028 if (typeof #constructorName.name != "string") { | 1028 #constructorName.#typeNameProperty = #constructorNameString; |
| 1029 // IE does not store the name, but allows to modify the property. | 1029 // IE does not have a name property. |
| 1030 #constructorName.name = #constructorNameString; | 1030 if (!("name" in #constructorName)) |
| 1031 } | 1031 #constructorName.name = #constructorNameString; |
| 1032 $desc = $collectedClasses$.#constructorName[1]; | 1032 $desc = $collectedClasses$.#constructorName[1]; |
| 1033 #constructorName.prototype = $desc; | 1033 #constructorName.prototype = $desc; |
| 1034 ''' /* next string is not a raw string */ ''' | 1034 ''' /* next string is not a raw string */ ''' |
| 1035 if (#hasIsolateSupport) { | 1035 if (#hasIsolateSupport) { |
| 1036 #constructorName.$fieldNamesProperty = #fieldNamesArray; | 1036 #constructorName.$fieldNamesProperty = #fieldNamesArray; |
| 1037 } | 1037 } |
| 1038 }''', | 1038 }''', |
| 1039 {"constructorName": constructorName, | 1039 {"constructorName": constructorName, |
| 1040 "typeNameProperty": typeNameProperty, |
| 1040 "constructorNameString": js.quoteName(constructorName), | 1041 "constructorNameString": js.quoteName(constructorName), |
| 1041 "hasIsolateSupport": hasIsolateSupport, | 1042 "hasIsolateSupport": hasIsolateSupport, |
| 1042 "fieldNamesArray": fieldNamesArray})); | 1043 "fieldNamesArray": fieldNamesArray})); |
| 1043 | 1044 |
| 1044 cspPrecompiledConstructorNamesFor(outputUnit).add(js('#', constructorName)); | 1045 cspPrecompiledConstructorNamesFor(outputUnit).add(js('#', constructorName)); |
| 1045 } | 1046 } |
| 1046 | 1047 |
| 1047 void assembleTypedefs(Program program) { | 1048 void assembleTypedefs(Program program) { |
| 1048 Fragment mainFragment = program.mainFragment; | 1049 Fragment mainFragment = program.mainFragment; |
| 1049 OutputUnit mainOutputUnit = mainFragment.outputUnit; | 1050 OutputUnit mainOutputUnit = mainFragment.outputUnit; |
| (...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1996 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 1997 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 1997 if (element.isInstanceMember) { | 1998 if (element.isInstanceMember) { |
| 1998 cachedClassBuilders.remove(element.enclosingClass); | 1999 cachedClassBuilders.remove(element.enclosingClass); |
| 1999 | 2000 |
| 2000 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2001 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 2001 | 2002 |
| 2002 } | 2003 } |
| 2003 } | 2004 } |
| 2004 } | 2005 } |
| 2005 } | 2006 } |
| OLD | NEW |