| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // TODO(ahe): Share these with js_helper.dart. | 7 // TODO(ahe): Share these with js_helper.dart. |
| 8 const FUNCTION_INDEX = 0; | 8 const FUNCTION_INDEX = 0; |
| 9 const NAME_INDEX = 1; | 9 const NAME_INDEX = 1; |
| 10 const CALL_NAME_INDEX = 2; | 10 const CALL_NAME_INDEX = 2; |
| 11 const REQUIRED_PARAMETER_INDEX = 3; | 11 const REQUIRED_PARAMETER_INDEX = 3; |
| 12 const OPTIONAL_PARAMETER_INDEX = 4; | 12 const OPTIONAL_PARAMETER_INDEX = 4; |
| 13 const DEFAULT_ARGUMENTS_INDEX = 5; | 13 const DEFAULT_ARGUMENTS_INDEX = 5; |
| 14 | 14 |
| 15 const bool VALIDATE_DATA = false; | 15 const bool VALIDATE_DATA = false; |
| 16 | 16 |
| 17 // TODO(ahe): This code should be integrated in CodeEmitterTask.finishClasses. | 17 // TODO(ahe): This code should be integrated in CodeEmitterTask.finishClasses. |
| 18 jsAst.Expression getReflectionDataParser(String classesCollector, | 18 jsAst.Expression getReflectionDataParser(String classesCollector, |
| 19 JavaScriptBackend backend) { | 19 JavaScriptBackend backend) { |
| 20 Namer namer = backend.namer; | 20 Namer namer = backend.namer; |
| 21 Compiler compiler = backend.compiler; | 21 Compiler compiler = backend.compiler; |
| 22 | 22 |
| 23 String metadataField = '"${namer.metadataField}"'; | 23 String metadataField = '"${namer.metadataField}"'; |
| 24 String reflectableField = namer.reflectableField; | 24 String reflectableField = namer.reflectableField; |
| 25 | 25 |
| 26 // TODO(ahe): Move this string constants to namer. | 26 // TODO(ahe): Move this string constants to namer. |
| 27 String reflectionInfoField = r'$reflectionInfo'; | 27 String reflectionInfoField = r'$reflectionInfo'; |
| 28 String reflectionNameField = r'$reflectionName'; | 28 String reflectionNameField = r'$reflectionName'; |
| 29 String metadataIndexField = r'$metadataIndex'; | 29 String metadataIndexField = r'$metadataIndex'; |
| 30 String redirectionTargetNameIndex = r'$redirectionTargetIndex'; | |
| 31 | 30 |
| 32 String defaultValuesField = namer.defaultValuesField; | 31 String defaultValuesField = namer.defaultValuesField; |
| 33 String methodsWithOptionalArgumentsField = | 32 String methodsWithOptionalArgumentsField = |
| 34 namer.methodsWithOptionalArgumentsField; | 33 namer.methodsWithOptionalArgumentsField; |
| 35 | 34 |
| 36 String unmangledNameIndex = backend.mustRetainMetadata | 35 String unmangledNameIndex = backend.mustRetainMetadata |
| 37 ? ' 3 * optionalParameterCount + 2 * requiredParameterCount + 3' | 36 ? ' 3 * optionalParameterCount + 2 * requiredParameterCount + 3' |
| 38 : ' 2 * optionalParameterCount + requiredParameterCount + 3'; | 37 : ' 2 * optionalParameterCount + requiredParameterCount + 3'; |
| 39 | 38 |
| 40 | 39 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 f.\$callName = null; | 174 f.\$callName = null; |
| 176 if (isIntercepted) init.interceptedNames[getterStubName] = true; | 175 if (isIntercepted) init.interceptedNames[getterStubName] = true; |
| 177 } | 176 } |
| 178 if (isReflectable) { | 177 if (isReflectable) { |
| 179 for (var i = 0; i < funcs.length; i++) { | 178 for (var i = 0; i < funcs.length; i++) { |
| 180 funcs[i].$reflectableField = 1; | 179 funcs[i].$reflectableField = 1; |
| 181 funcs[i].$reflectionInfoField = array; | 180 funcs[i].$reflectionInfoField = array; |
| 182 } | 181 } |
| 183 var mangledNames = isStatic ? init.mangledGlobalNames : init.mangledNames; | 182 var mangledNames = isStatic ? init.mangledGlobalNames : init.mangledNames; |
| 184 var unmangledName = ${readString("array", "unmangledNameIndex")}; | 183 var unmangledName = ${readString("array", "unmangledNameIndex")}; |
| 185 var metadataIndex = unmangledNameIndex + 1; | |
| 186 | |
| 187 if (unmangledName.substring(0, 6) == "new-> ") { | |
| 188 // Redirecting constructor. | |
| 189 funcs[0].$redirectionTargetNameIndex = metadataIndex; | |
| 190 metadataIndex++; | |
| 191 unmangledName = "new " + unmangledName.substring(6); | |
| 192 } | |
| 193 // The function is either a getter, a setter, or a method. | 184 // The function is either a getter, a setter, or a method. |
| 194 // If it is a method, it might also have a tear-off closure. | 185 // If it is a method, it might also have a tear-off closure. |
| 195 // The unmangledName is the same as the getter-name. | 186 // The unmangledName is the same as the getter-name. |
| 196 var reflectionName = unmangledName; | 187 var reflectionName = unmangledName; |
| 197 if (getterStubName) mangledNames[getterStubName] = reflectionName; | 188 if (getterStubName) mangledNames[getterStubName] = reflectionName; |
| 198 if (isSetter) { | 189 if (isSetter) { |
| 199 reflectionName += "="; | 190 reflectionName += "="; |
| 200 } else if (!isGetter) { | 191 } else if (!isGetter) { |
| 201 reflectionName += ":" + requiredParameterCount + | 192 reflectionName += ":" + requiredParameterCount + |
| 202 ":" + optionalParameterCount; | 193 ":" + optionalParameterCount; |
| 203 } | 194 } |
| 204 mangledNames[name] = reflectionName; | 195 mangledNames[name] = reflectionName; |
| 205 funcs[0].$reflectionNameField = reflectionName; | 196 funcs[0].$reflectionNameField = reflectionName; |
| 206 funcs[0].$metadataIndexField = metadataIndex; | 197 funcs[0].$metadataIndexField = unmangledNameIndex + 1; |
| 207 if (optionalParameterCount) descriptor[unmangledName + "*"] = funcs[0]; | 198 if (optionalParameterCount) descriptor[unmangledName + "*"] = funcs[0]; |
| 208 } | 199 } |
| 209 } | 200 } |
| 210 '''; | 201 '''; |
| 211 | 202 |
| 212 List<jsAst.Statement> tearOffCode = buildTearOffCode(backend); | 203 List<jsAst.Statement> tearOffCode = buildTearOffCode(backend); |
| 213 | 204 |
| 214 String init = ''' | 205 String init = ''' |
| 215 var functionCounter = 0; | 206 var functionCounter = 0; |
| 216 var tearOffGetter = (typeof dart_precompiled == "function") | 207 var tearOffGetter = (typeof dart_precompiled == "function") |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 (function() { | 374 (function() { |
| 384 var result = $array[$index]; | 375 var result = $array[$index]; |
| 385 if ($check) { | 376 if ($check) { |
| 386 throw new Error( | 377 throw new Error( |
| 387 name + ": expected value of type \'$type\' at index " + ($index) + | 378 name + ": expected value of type \'$type\' at index " + ($index) + |
| 388 " but got " + (typeof result)); | 379 " but got " + (typeof result)); |
| 389 } | 380 } |
| 390 return result; | 381 return result; |
| 391 })()'''; | 382 })()'''; |
| 392 } | 383 } |
| OLD | NEW |